mirror of
https://github.com/3cky/mbusd.git
synced 2024-06-24 10:14:49 +02:00
Improve serial port config handling and logging
This commit is contained in:
parent
461ce8baa0
commit
252aa45e5d
|
@ -102,10 +102,12 @@ cfg_handle_param(char *name, char *value)
|
|||
}
|
||||
else if (CFG_NAME_MATCH("speed"))
|
||||
{
|
||||
cfg.ttyspeed = strtoul(value, NULL, 0);
|
||||
if (!cfg.ttyspeed)
|
||||
char *end;
|
||||
cfg.ttyspeed = strtoul(value, &end, 0);
|
||||
if (!cfg.ttyspeed || value == end || '\0' != *end)
|
||||
{
|
||||
cfg.ttyspeed = DEFAULT_SPEED;
|
||||
CFG_ERR("invalid serial port speed: %s", value);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (CFG_NAME_MATCH("mode"))
|
||||
|
|
|
@ -164,6 +164,7 @@ main(int argc, char *argv[])
|
|||
int err = 0, rc, err_line;
|
||||
char *exename;
|
||||
char ttyparity;
|
||||
char *end;
|
||||
|
||||
sig_init();
|
||||
|
||||
|
@ -261,10 +262,11 @@ main(int argc, char *argv[])
|
|||
else strncpy(cfg.ttyport, optarg, INTBUFSIZE);
|
||||
break;
|
||||
case 's':
|
||||
cfg.ttyspeed = strtoul(optarg, NULL, 0);
|
||||
if (!cfg.ttyspeed)
|
||||
cfg.ttyspeed = strtoul(optarg, &end, 10);
|
||||
if (!cfg.ttyspeed || optarg == end || '\0' != *end)
|
||||
{
|
||||
cfg.ttyspeed = DEFAULT_SPEED;
|
||||
printf("%s: -s: invalid serial port speed (%s)\n", exename, optarg);
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
|
|
|
@ -114,6 +114,9 @@ tty_open(ttydata_t *mod)
|
|||
errno = buferr;
|
||||
return RC_ERR;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOG
|
||||
logw(2, "tty: trying to open %s (speed %d mode %s)", mod->port, mod->speed, cfg.ttymode);
|
||||
#endif
|
||||
mod->fd = open(mod->port, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||
if (mod->fd < 0)
|
||||
|
@ -374,7 +377,9 @@ tty_transpeed(int speed)
|
|||
break;
|
||||
#endif
|
||||
default:
|
||||
logw(2, "unsupported speed (%d)", speed);
|
||||
#ifdef LOG
|
||||
logw(0, "tty: unsupported speed: %d", speed);
|
||||
#endif
|
||||
exit (-1);
|
||||
}
|
||||
return tspeed;
|
||||
|
|
Loading…
Reference in New Issue
Block a user