]> rtime.felk.cvut.cz Git - linux-lin.git/blob - lin_config/src/lin_config.c
linconf: Modular architecture.
[linux-lin.git] / lin_config / src / lin_config.c
1 /*
2  * PCAN-LIN, RS-232 to CAN/LIN converter control application
3  *
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
7  *   the License.
8  *
9  * Copyright:  (c) 2012 Czech Technical University in Prague
10  * Authors:    Rostislav Lisovy <lisovy@gmail.cz>
11  */
12
13 /*
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
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <string.h>
25 #include <termios.h>
26 #include <stdint.h>
27 #include <assert.h>
28 #include "linc_parse_xml.h"
29 #include "pcl_config.h"
30 #include "lin_config.h"
31
32
33 void linc_explain(int argc, char *argv[])
34 {
35         fprintf(stderr, "Usage: %s [OPTIONS] <SERIAL_INTERFACE>\n", argv[0]);
36         fprintf(stderr, "\n");
37         fprintf(stderr, "'pcan_lin_config' Is used for configuring PEAK PCAN-LIN device.\n");
38         fprintf(stderr, "  When invoked without any OPTIONS, it configures PCAN-LIN device\n");
39         fprintf(stderr, "  with configuration obtained from '"PCL_DEFAULT_CONFIG"' file (if it exists).\n");
40         fprintf(stderr, "  The PCAN-LIN module enables CAN, LIN and serial participants to communicate.\n");
41         fprintf(stderr, "\n");
42         fprintf(stderr, "Options:\n");
43         fprintf(stderr, " -r          Execute only Reset of a device\n");
44         fprintf(stderr, " -f          Flash the active configuration\n");
45         fprintf(stderr, " -c <FILE>   Path to XML configuration file\n");
46         fprintf(stderr, "\n");
47         fprintf(stderr, "Examples:\n");
48         fprintf(stderr, " %s /dev/ttyS0      (Configure the device with the configuration from '"PCL_DEFAULT_CONFIG"')\n",
49                 argv[0]);
50         fprintf(stderr, " %s -r /dev/ttyS0   (Reset the device)\n", argv[0]);
51 }
52
53 int main(int argc, char *argv[])
54 {
55         int ret;
56         int opt;
57         int flags = 0;
58         char *filename = NULL;
59
60         while ((opt = getopt(argc, argv, "rfc:")) != -1) {
61                 switch (opt) {
62                 case 'r':
63                         flags |= RESET_DEVICE_fl;
64                         break;
65                 case 'f':
66                         flags |= FLASH_CONF_fl;
67                         break;
68                 case 'c':
69                         filename = optarg;
70                         break;
71                 default:
72                         linc_explain(argc, argv);
73                         exit(EXIT_FAILURE);
74                 }
75         }
76
77         /* Expected argument after options */
78         if (optind >= argc) {
79                 linc_explain(argc, argv);
80                 exit(EXIT_FAILURE);
81         }
82
83         linc_lin_state.dev = strdup(argv[optind]);
84
85         ret = linc_parse_configuration(filename, &linc_lin_state);
86         if (!ret)
87                 printf("Configuration file %s parsed correctly\n", filename);
88
89         pcl_config(&linc_lin_state, flags);
90
91         return EXIT_SUCCESS;
92 }