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"
33 struct linc_lin_state linc_lin_state;
36 void linc_explain(int argc, char *argv[])
38 // FIXME what is default behaviour
39 // Write a warning about not using a rs232--usb converter for sllin
40 fprintf(stderr, "Usage: %s [OPTIONS] <SERIAL_INTERFACE>\n", argv[0]);
41 fprintf(stderr, "\n");
42 fprintf(stderr, "'lin_config' is used for configuring sllin -- " \
43 "simple LIN device implemented\n" \
44 " as a TTY line discipline for arbitrary UART interface.\n" \
45 " This program is able to configure PCAN-LIN (RS232 configurable " \
46 "LIN node) as well.\n" \
47 " When invoked without any OPTIONS, it configures PCAN-LIN device\n" \
48 " with configuration obtained from '"PCL_DEFAULT_CONFIG"' " \
49 "file (if it exists).\n");
50 fprintf(stderr, "\n");
51 fprintf(stderr, "SERIAL_INTERFACE is in format CLASS:PATH\n");
52 fprintf(stderr, " CLASS defines the device class -- it is either " \
53 "'sllin' or 'pcanlin'\n");
54 fprintf(stderr, " PATH is path to the serial interface, e.g /dev/ttyS0\n");
55 fprintf(stderr, "\n");
56 fprintf(stderr, "General options:\n");
57 fprintf(stderr, " -c <FILE> Path to XML configuration file in PCLIN format\n");
58 fprintf(stderr, " -r Execute only Reset of a device\n");
59 fprintf(stderr, "\n");
60 fprintf(stderr, "PCAN-LIN specific options:\n");
61 fprintf(stderr, " -f Store the active configuration into internal " \
63 fprintf(stderr, "\n");
64 fprintf(stderr, "Sllin specific options:\n");
65 fprintf(stderr, " -a Attach sllin TTY line discipline to " \
66 "particular SERIAL_INTERFACE\n");
67 fprintf(stderr, " -d Detach sllin TTY line discipline from " \
68 "particular SERIAL_INTERFACE\n");
69 fprintf(stderr, "\n");
70 fprintf(stderr, "Examples:\n");
71 fprintf(stderr, " %s sllin:/dev/ttyS0 (Configure the device with the " \
72 "configuration from '"PCL_DEFAULT_CONFIG"')\n", argv[0]);
73 fprintf(stderr, " %s -r pcanlin:/dev/ttyS0 (Reset the device)\n", argv[0]);
76 int main(int argc, char *argv[])
81 char *filename = NULL;
83 while ((opt = getopt(argc, argv, "rfc:ad")) != -1) {
86 flags |= RESET_DEVICE_fl;
89 flags |= FLASH_CONF_fl;
95 flags |= SLLIN_ATTACH_fl;
98 flags |= SLLIN_DETACH_fl;
101 linc_explain(argc, argv);
106 /* Expected argument after options */
107 if (optind >= argc) {
108 linc_explain(argc, argv);
112 linc_lin_state.dev = strdup(argv[optind]);
114 ret = linc_parse_configuration(filename, &linc_lin_state);
116 printf("Configuration file %s parsed correctly\n", filename);
118 linc_lin_state.flags = flags;
119 //ret = pcl_config(&linc_lin_state);
120 ret = sllin_config(&linc_lin_state);
124 if (ret == LIN_EXIT_OK) {
129 printf("Running in background ...\n");
136 /* Sleep to keep the line discipline active. */