]> rtime.felk.cvut.cz Git - linux-lin.git/blobdiff - lin_config/src/lin_config.c
lin_config: Help screen
[linux-lin.git] / lin_config / src / lin_config.c
index 96b56d1d2d7f41e91ef91530d6c695502b530825..40f3cb6327f32439cb8d07a1e3fe1da26a4b8ed9 100644 (file)
 #include "sllin_config.h"
 #include "lin_config.h"
 
-struct linc_lin_state linc_lin_state;
+#include "linux/lin_bus.h"
 
+struct linc_lin_state linc_lin_state;
 
 void linc_explain(int argc, char *argv[])
 {
-// FIXME what is default behaviour
-// Write a warning about not using a rs232--usb converter for sllin
        fprintf(stderr, "Usage: %s [OPTIONS] <SERIAL_INTERFACE>\n", argv[0]);
        fprintf(stderr, "\n");
-       fprintf(stderr, "'lin_config' is used for configuring sllin -- " \
-               "simple LIN device implemented\n" \
-               "  as a TTY line discipline for arbitrary UART interface.\n" \
-               "  This program is able to configure PCAN-LIN (RS232 configurable " \
-               "LIN node) as well.\n" \
-               "  When invoked without any OPTIONS, it configures PCAN-LIN device\n" \
-               "  with configuration obtained from '"PCL_DEFAULT_CONFIG"' " \
-               "file (if it exists).\n");
+       fprintf(stderr, "'lin_config' is used for configuring sllin -- simple LIN device implemented\n");
+       fprintf(stderr, "  as a TTY line discipline for arbitrary UART interface (works only on\n");
+       fprintf(stderr, "  built-in interfaces -- not on USB to RS232 convertors).\n");
+       fprintf(stderr, "  This program is able to configure PCAN-LIN (RS232 configurable LIN node) as well.\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "SERIAL_INTERFACE is in format CLASS:PATH\n");
-       fprintf(stderr, "  CLASS defines the device class -- it is either " \
-               "'sllin' or 'pcanlin'\n");
-       fprintf(stderr, "  PATH is path to the serial interface, e.g /dev/ttyS0\n");
+       fprintf(stderr, "  CLASS     defines the device class -- it is either 'sllin' or 'pcanlin'\n");
+       fprintf(stderr, "            (when not set, default is 'sllin')\n");
+       fprintf(stderr, "  PATH      is path to the serial interface, e.g /dev/ttyS0\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "General options:\n");
-       fprintf(stderr, " -c <FILE>   Path to XML configuration file in PCLIN format\n");
-       fprintf(stderr, " -r          Execute only Reset of a device\n");
+       fprintf(stderr, " -c <FILE>  Path to XML configuration file in PCLIN format\n");
+       fprintf(stderr, "            If this parameter is not set, file '"PCL_DEFAULT_CONFIG"' is used\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "PCAN-LIN specific options:\n");
-       fprintf(stderr, " -f          Store the active configuration into internal " \
-               "flash memory\n");
+       fprintf(stderr, " -f         Store the active configuration into internal flash memory\n");
+       fprintf(stderr, " -r         Execute only Reset of a device\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Sllin specific options:\n");
-       fprintf(stderr, " -a          Attach sllin TTY line discipline to " \
-               "particular SERIAL_INTERFACE\n");
-       fprintf(stderr, " -d          Detach sllin TTY line discipline from " \
-               "particular SERIAL_INTERFACE\n");
+       fprintf(stderr, " -a         Attach sllin TTY line discipline to particular SERIAL_INTERFACE\n");
+//     fprintf(stderr, " -d         Detach sllin TTY line discipline from particular SERIAL_INTERFACE\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Examples:\n");
-       fprintf(stderr, " %s sllin:/dev/ttyS0        (Configure the device with the " \
-               "configuration from '"PCL_DEFAULT_CONFIG"')\n", argv[0]);
+       fprintf(stderr, " %s sllin:/dev/ttyS0        (Configure the device with the configuration from '"PCL_DEFAULT_CONFIG"')\n", argv[0]);
        fprintf(stderr, " %s -r pcanlin:/dev/ttyS0   (Reset the device)\n", argv[0]);
 }
 
@@ -77,6 +69,7 @@ int main(int argc, char *argv[])
 {
        int ret;
        int opt;
+       char *c;
        int flags = 0;
        char *filename = NULL;
 
@@ -102,30 +95,41 @@ int main(int argc, char *argv[])
                        return EXIT_FAILURE;
                }
        }
+       linc_lin_state.flags = flags;
 
        /* Expected argument after options */
        if (optind >= argc) {
                linc_explain(argc, argv);
-               exit(EXIT_FAILURE);
+               return EXIT_FAILURE;
        }
 
-       linc_lin_state.dev = strdup(argv[optind]);
-
        ret = linc_parse_configuration(filename, &linc_lin_state);
        if (!ret)
                printf("Configuration file %s parsed correctly\n", filename);
 
-       linc_lin_state.flags = flags;
-       //ret = pcl_config(&linc_lin_state);
-       ret = sllin_config(&linc_lin_state);
+       /* Parse device type and path */
+       c = argv[optind]; /* "devtype:devpath" */
+       while ((*c != ':') && (*c != '\0')) {
+               c++;
+       }
+       *c = '\0'; /* In case we found ":" split the string into two */
+       linc_lin_state.dev = strdup(c + 1); /* Second half of the string -- device name */
+
+       if (!strcmp("pcanlin", argv[optind])) {
+               ret = pcl_config(&linc_lin_state);
+       } else if (!strcmp("sllin", argv[optind])) {
+               ret = sllin_config(&linc_lin_state);
+       } else { /* Default */
+               fprintf(stderr, "Device type is missing. Using default device -- sllin.\n");
+               ret = sllin_config(&linc_lin_state);
+       }
 
        if (ret < 0)
                return EXIT_FAILURE;
-       if (ret == LIN_EXIT_OK) {
-
+       if (ret == LIN_EXIT_OK) /* Do not daemonize */
                return EXIT_SUCCESS;
-       }
 
+       /* Run as daemon -- this is needed for attaching sllin TTY line discipline */
        printf("Running in background ...\n");
        ret = daemon(0, 0);
        if (ret < 0) {
@@ -133,6 +137,7 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
+       // FIXME free() linc_lin_state?
        /* Sleep to keep the line discipline active. */
        pause();