2 * PCAN-LIN, RS-232 to CAN/LIN converter control application
4 * This program is free software; you can distribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; version 2 of
9 * Copyright: (c) 2012 Czech Technical University in Prague
10 * Authors: Rostislav Lisovy <lisovy@gmail.cz>
14 Used prefixes explanation:
15 pcl_ -- PCAN-LIN (hw) related functions
16 sll_ -- sllin (tty lin implementation) related functions
17 linc_ -- LIN config general functions
28 #include "linc_parse_xml.h"
29 #include "pcl_config.h"
30 #include "sllin_config.h"
31 #include "lin_config.h"
34 void linc_explain(int argc, char *argv[])
36 // FIXME what is default behaviour
37 // Write a warning about not using a rs232--usb converter for sllin
38 fprintf(stderr, "Usage: %s [OPTIONS] <SERIAL_INTERFACE>\n", argv[0]);
39 fprintf(stderr, "\n");
40 fprintf(stderr, "'lin_config' is used for configuring sllin -- " \
41 "simple LIN device implemented\n" \
42 " as a TTY line discipline for arbitrary UART interface.\n" \
43 " This program is able to configure PCAN-LIN (RS232 configurable " \
44 "LIN node) as well.\n" \
45 " When invoked without any OPTIONS, it configures PCAN-LIN device\n" \
46 " with configuration obtained from '"PCL_DEFAULT_CONFIG"' " \
47 "file (if it exists).\n");
48 fprintf(stderr, "\n");
49 fprintf(stderr, "SERIAL_INTERFACE is in format CLASS:PATH\n");
50 fprintf(stderr, " CLASS defines the device class -- it is either " \
51 "'sllin' or 'pcanlin'\n");
52 fprintf(stderr, " PATH is path to the serial interface, e.g /dev/ttyS0\n");
53 fprintf(stderr, "\n");
54 fprintf(stderr, "General options:\n");
55 fprintf(stderr, " -c <FILE> Path to XML configuration file in PCLIN format\n");
56 fprintf(stderr, " -r Execute only Reset of a device\n");
57 fprintf(stderr, "\n");
58 fprintf(stderr, "PCAN-LIN specific options:\n");
59 fprintf(stderr, " -f Store the active configuration into internal " \
61 fprintf(stderr, "\n");
62 fprintf(stderr, "Sllin specific options:\n");
63 fprintf(stderr, " -a Attach sllin TTY line discipline to " \
64 "particular SERIAL_INTERFACE\n");
65 fprintf(stderr, " -d Detach sllin TTY line discipline from " \
66 "particular SERIAL_INTERFACE\n");
67 fprintf(stderr, "\n");
68 fprintf(stderr, "Examples:\n");
69 fprintf(stderr, " %s sllin:/dev/ttyS0 (Configure the device with the " \
70 "configuration from '"PCL_DEFAULT_CONFIG"')\n", argv[0]);
71 fprintf(stderr, " %s -r pcanlin:/dev/ttyS0 (Reset the device)\n", argv[0]);
74 int main(int argc, char *argv[])
79 char *filename = NULL;
81 while ((opt = getopt(argc, argv, "rfc:ad")) != -1) {
84 flags |= RESET_DEVICE_fl;
87 flags |= FLASH_CONF_fl;
93 flags |= SLLIN_ATTACH_fl;
96 flags |= SLLIN_DETACH_fl;
99 linc_explain(argc, argv);
104 /* Expected argument after options */
105 if (optind >= argc) {
106 linc_explain(argc, argv);
110 linc_lin_state.dev = strdup(argv[optind]);
112 ret = linc_parse_configuration(filename, &linc_lin_state);
114 printf("Configuration file %s parsed correctly\n", filename);
116 linc_lin_state.flags = flags;
117 //ret = pcl_config(&linc_lin_state);
118 ret = sllin_config(&linc_lin_state);
120 // printf("Press any key to detach %s ...\n", linc_lin_state.dev);