Adding some input checking. Other minor changes.
This commit is contained in:
parent
8b510d71c1
commit
6ec15f77c4
2 changed files with 18 additions and 4 deletions
|
@ -4,13 +4,18 @@
|
||||||
; dev = {tty dev path}
|
; dev = {tty dev path}
|
||||||
; speed = {port baud rate}
|
; speed = {port baud rate}
|
||||||
|
|
||||||
|
; supported baud rates:
|
||||||
|
; 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
|
||||||
|
; 4800, 9600, 19200, 38400, 57600, 115200;
|
||||||
|
|
||||||
|
|
||||||
[4001]
|
[4001]
|
||||||
dev = /dev/ttyUSB0
|
dev = /dev/ttyUSB0
|
||||||
speed = 9600
|
speed = 115200
|
||||||
|
|
||||||
[4002]
|
[4002]
|
||||||
dev = /dev/ttyS2
|
dev = /dev/ttyS2
|
||||||
speed = 115201
|
speed = 115200
|
||||||
|
|
||||||
[4003]
|
[4003]
|
||||||
dev = /dev/ttyS3
|
dev = /dev/ttyS3
|
||||||
|
|
13
moxerver.c
13
moxerver.c
|
@ -65,7 +65,7 @@ int parse_handler(void *user, const char *section, const char *name, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(name, "dev") && (unsigned int)atoi(section) == server.port)
|
if (!strcmp(name, "dev") && (unsigned int)atoi(section) == server.port)
|
||||||
strcpy(tty_dev.path, value);
|
strcpy(tty_dev.path, value);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -90,6 +90,7 @@ int main(int argc, char *argv[]) {
|
||||||
fprintf(stderr, "[%s] error configuring tty device speed\n", NAME);
|
fprintf(stderr, "[%s] error configuring tty device speed\n", NAME);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* enable catching and handling some quit signals, SIGKILL can't be caught */
|
/* enable catching and handling some quit signals, SIGKILL can't be caught */
|
||||||
signal(SIGTERM, quit_handler);
|
signal(SIGTERM, quit_handler);
|
||||||
|
@ -138,7 +139,6 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize */
|
/* 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;
|
if (server_setup(&server, tcp_port) < 0) return -1;
|
||||||
client.socket = -1;
|
client.socket = -1;
|
||||||
tty_dev.fd = -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);
|
fprintf(stderr, "[%s] error parsing congig file %s on line %d\n", NAME, CONFILE, ret);
|
||||||
return -1;
|
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 */
|
/* open tty device */
|
||||||
if (tty_open(&tty_dev) < 0) {
|
if (tty_open(&tty_dev) < 0) {
|
||||||
fprintf(stderr, "[%s] error: opening of tty device at %s failed\n"
|
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;
|
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 */
|
/* start thread that handles tty device */
|
||||||
ret = pthread_create(&tty_thread, NULL, tty_thread_func, &tty_dev); //TODO check return value?
|
ret = pthread_create(&tty_thread, NULL, tty_thread_func, &tty_dev); //TODO check return value?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue