Adding some input checking. Other minor changes.

This commit is contained in:
Luka Miljak 2014-03-30 16:04:24 +02:00
parent 8b510d71c1
commit 6ec15f77c4
2 changed files with 18 additions and 4 deletions

View file

@ -4,13 +4,18 @@
; dev = {tty dev path}
; speed = {port baud rate}
; supported baud rates:
; 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
; 4800, 9600, 19200, 38400, 57600, 115200;
[4001]
dev = /dev/ttyUSB0
speed = 9600
speed = 115200
[4002]
dev = /dev/ttyS2
speed = 115201
speed = 115200
[4003]
dev = /dev/ttyS3

View file

@ -91,6 +91,7 @@ int main(int argc, char *argv[]) {
return -1;
}
/* enable catching and handling some quit signals, SIGKILL can't be caught */
signal(SIGTERM, quit_handler);
signal(SIGQUIT, quit_handler);
@ -138,7 +139,6 @@ int main(int argc, char *argv[]) {
}
/* initialize */
fprintf(stderr, "[%s] TCP port: %d, TTY device path: %s\n", NAME, tcp_port, tty_dev.path);
if (server_setup(&server, tcp_port) < 0) return -1;
client.socket = -1;
tty_dev.fd = -1;
@ -153,6 +153,13 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "[%s] error parsing congig file %s on line %d\n", NAME, CONFILE, ret);
return -1;
}
if (!strcmp(tty_dev.path, "")) {
fprintf(stderr, "[%s] error: no tty device path given for TCP port: %d\n"
"\t\t-> check config file %s\n", NAME, tcp_port, CONFILE);
return -1;
}
/* open tty device */
if (tty_open(&tty_dev) < 0) {
fprintf(stderr, "[%s] error: opening of tty device at %s failed\n"
@ -160,6 +167,8 @@ int main(int argc, char *argv[]) {
debug_messages = 1;
}
fprintf(stderr, "[%s] TCP port: %d, TTY device path: %s\n", NAME, tcp_port, tty_dev.path);
/* start thread that handles tty device */
ret = pthread_create(&tty_thread, NULL, tty_thread_func, &tty_dev); //TODO check return value?