diff options
author | Christian Pointner <equinox@helsinki.at> | 2009-11-14 00:16:16 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2009-11-14 00:16:16 (GMT) |
commit | a5e4a809402eb929e55072573a176d8c2ed44712 (patch) | |
tree | 88ada41b94d9a74949202bcce4c839cc63d6ab8b | |
parent | df4967d2f9d158711038c054aa0edf543d21e8d3 (diff) |
added baudrate parameter
-rw-r--r-- | options.c | 36 | ||||
-rw-r--r-- | options.h | 2 | ||||
-rw-r--r-- | serialclient.c | 5 | ||||
-rw-r--r-- | switchctl.c | 5 |
4 files changed, 45 insertions, 3 deletions
@@ -160,6 +160,7 @@ int options_parse(options_t* opt, int argc, char* argv[]) char* mode = NULL; char* channel = NULL; + char* baudrate = NULL; int i; for(i=1; argc > 0; ++i) @@ -176,6 +177,7 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_STRING_PARAM("-P","--write-pid", opt->pid_file_) PARSE_STRING_LIST("-L","--log", opt->log_targets_) PARSE_STRING_PARAM("-s","--socket", opt->command_sock_) + PARSE_STRING_PARAM("-b","--baudrate", baudrate) #ifdef OPT_SWITCHCTL PARSE_STRING_PARAM("-f","--config", opt->conf_file_) PARSE_STRING_PARAM("-d","--device", opt->switch_dev_) @@ -214,6 +216,22 @@ int options_parse(options_t* opt, int argc, char* argv[]) free(channel); } + if(baudrate) { + int b = atoi(baudrate); + free(baudrate); + switch(b) { + case 1200: opt->baudrate_ = B1200; break; + case 2400: opt->baudrate_ = B2400; break; + case 4800: opt->baudrate_ = B4800; break; + case 9600: opt->baudrate_ = B9600; break; + case 19200: opt->baudrate_ = B19200; break; + case 38400: opt->baudrate_ = B38400; break; + case 57600: opt->baudrate_ = B57600; break; + case 115200: opt->baudrate_ = B115200; break; + default: return -5; + } + } + return 0; } @@ -275,6 +293,7 @@ void options_default(options_t* opt) string_list_init(&opt->log_targets_); opt->command_sock_ = strdup("/var/run/rhctl/switchctl.sock"); + opt->baudrate_ = B19200; /* switchctl */ opt->mode_ = MODE_MASTER; @@ -341,9 +360,10 @@ void options_print_usage() printf(" [-L|--log] <target>:<level>[,<param1>[,<param2>..]]\n"); printf(" add a log target, can be invoked several times\n"); printf(" [-s|--command-sock] <unix sock> the command socket e.g. /var/run/rhctl/switchctl.sock\n"); + printf(" [-b|--baudrate] <baudrate> the baudrate of the tty to use e.g. 19200\n"); #ifdef OPT_SWITCHCTL - printf(" [-f|--config] <file> the configuration file e.g. /etc/rhctl/switchctl.conf\n"); printf(" [-d|--device] <tty> the tty the audio switch is connected to e.g. /dev/audioswitch\n"); + printf(" [-f|--config] <file> the configuration file e.g. /etc/rhctl/switchctl.conf\n"); printf(" [-m|--mode] <mode> the initial mode to use e.g. master\n"); printf(" [-c|--channel] <channel> the initial channel to use e.g. main\n"); #endif @@ -369,6 +389,20 @@ void options_print(options_t* opt) printf("command_sock: '%s'\n", opt->command_sock_); + char* br; + switch(opt->baudrate_) { + case B1200: br = "1200"; break; + case B2400: br = "2400"; break; + case B4800: br = "4800"; break; + case B9600: br = "9600"; break; + case B19200: br = "19200"; break; + case B38400: br = "38400"; break; + case B57600: br = "57600"; break; + case B115200: br = "115200"; break; + default: br = "invalid"; break; + } + printf("baudrate: '%s'\n", br); + #ifdef OPT_SWITCHCTL printf("mode: '%s'\n", opt->mode_ == MODE_MASTER ? "master" : "standby"); printf("channel: '%s'\n", opt->channel_ == CHAN_MAIN ? "main" : "music"); @@ -24,6 +24,7 @@ #include "string_list.h" #include "key_value_storage.h" +#include <termios.h> enum mode_enum { MODE_MASTER, MODE_STANDBY }; typedef enum mode_enum mode_t; @@ -42,6 +43,7 @@ struct options_struct { string_list_t log_targets_; char* command_sock_; + speed_t baudrate_; /* switchctl */ mode_t mode_; diff --git a/serialclient.c b/serialclient.c index a32c691..392288a 100644 --- a/serialclient.c +++ b/serialclient.c @@ -146,6 +146,9 @@ int main(int argc, char* argv[]) if(ret == -2) { fprintf(stderr, "memory error on options_parse, exiting\n"); } + if(ret == -5) { + fprintf(stderr, "syntax error: invalid baudrate\n"); + } if(ret != -2) options_print_usage(); @@ -237,7 +240,7 @@ int main(int argc, char* argv[]) if(serial_fd < 0) ret = 2; else { - ret = setup_tty(serial_fd, B38400); + ret = setup_tty(serial_fd, opt.baudrate_); if(ret) ret = 2; else diff --git a/switchctl.c b/switchctl.c index c04d5b8..b3cc643 100644 --- a/switchctl.c +++ b/switchctl.c @@ -732,6 +732,9 @@ int main(int argc, char* argv[]) if(ret == -4) { fprintf(stderr, "syntax error: channel name must be either main or music\n"); } + if(ret == -5) { + fprintf(stderr, "syntax error: invalid baudrate\n"); + } if(ret != -2) options_print_usage(); @@ -823,7 +826,7 @@ int main(int argc, char* argv[]) if(switch_fd < 0) ret = 2; else { - ret = setup_tty(switch_fd, B19200); + ret = setup_tty(switch_fd, opt.baudrate_); if(ret) ret = 2; else |