remove dependence of libusefull_macros

This commit is contained in:
2025-01-28 20:44:12 +03:00
parent 19f61697d6
commit 5441a87fff
11 changed files with 453 additions and 166 deletions

View File

@@ -25,10 +25,8 @@
typedef struct{
int help;
int confhelp;
int verbose;
char *logfile;
char *conffile;
char *coordsoutput;
} parameters;
@@ -36,10 +34,8 @@ static parameters G = {0};
static sl_option_t cmdlnopts[] = {
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
{"confhelp", NO_ARGS, NULL, 0, arg_int, APTR(&G.confhelp), "show configuration file help"},
{"verbose", NO_ARGS, NULL, 'v', arg_none, APTR(&G.verbose), "verbose level (each -v adds 1)"},
{"logfile", NEED_ARG, NULL, 'l', arg_string, APTR(&G.logfile), "log file name"},
{"conffile", NEED_ARG, NULL, 'c', arg_string, APTR(&G.conffile), "configuration file name"},
{"coordsfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"output file with coordinates log"},
end_option
};
@@ -54,25 +50,25 @@ void signals(int sig){
exit(sig);
}
static conf_t Config = {
.MountPath = "/dev/ttyS1",
.MountSpeed = 19200,
.EncoderPath = "/dev/ttyUSB0",
.EncoderSpeed = 153000
};
int main(int argc, char **argv){
sl_init();
sl_parseargs(&argc, &argv, cmdlnopts);
if(G.help) sl_showhelp(-1, cmdlnopts);
if(G.confhelp) Mount.helpandquit();
if(!G.conffile) ERRX("Point configuration file name");
sl_loglevel_e lvl = G.verbose + LOGLEVEL_ERR;
if(lvl >= LOGLEVEL_AMOUNT) lvl = LOGLEVEL_AMOUNT - 1;
if(G.logfile) OPENLOG(G.logfile, lvl, 1);
time_t curtime = time(NULL);
LOGMSG("Started @ %s", ctime(&curtime));
if(Mount.readconf(G.conffile) < 0) ERRX("Can't read configuration file %s", G.conffile);
green("Got config:\n");
Mount.dumpconf();
if(!Mount.init()) ERRX("Can't init");
DBG("Devices ready");
LOGMSG("Mount device %s @ %d", Conf.MountPath, Conf.MountSpeed);
LOGMSG("Encoder device %s @ %d", Conf.EncoderPath, Conf.EncoderSpeed);
LOGMSG("Mount device %s @ %d", Config.MountPath, Config.MountSpeed);
LOGMSG("Encoder device %s @ %d", Config.EncoderPath, Config.EncoderSpeed);
signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGHUP, SIG_IGN); // hup - ignore
signal(SIGINT, signals); // ctrl+C - quit