Replace confini with toml
This commit is contained in:
parent
25eab5d38e
commit
79b1f3b2cf
27 changed files with 3081 additions and 5926 deletions
src
61
src/main.c
61
src/main.c
|
@ -6,6 +6,7 @@
|
|||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <cli.h>
|
||||
#include <logger.h>
|
||||
#include <mongoose.h>
|
||||
#include <models/controller.h>
|
||||
|
@ -21,9 +22,6 @@
|
|||
#include <wiringPi.h>
|
||||
#include <piFace.h>
|
||||
#include <wiring_debug.h>
|
||||
#include <confini.h>
|
||||
|
||||
config_t global_config;
|
||||
|
||||
static struct mg_mgr mgr;
|
||||
|
||||
|
@ -43,7 +41,7 @@ terminate(int signum)
|
|||
controller_free(global_controller);
|
||||
|
||||
LOGGER_DEBUG("freeing relay configs config\n");
|
||||
free(global_config.relay_configs);
|
||||
free(global_config->relay_configs);
|
||||
|
||||
exit(signum);
|
||||
}
|
||||
|
@ -66,45 +64,28 @@ main(int argc, const char** argv)
|
|||
signal(SIGABRT, terminate);
|
||||
signal(SIGTERM, terminate);
|
||||
|
||||
openlog("emgauwa-controller", 0, LOG_USER);
|
||||
setlogmask(LOG_UPTO(LOG_INFO));
|
||||
|
||||
|
||||
/******************** LOAD CONFIG ********************/
|
||||
|
||||
global_config.file = "controller.ini";
|
||||
global_config.discovery_port = 4421;
|
||||
global_config.mqtt_port = 1885;
|
||||
config_init();
|
||||
|
||||
global_config.relay_count = 0;
|
||||
global_config.relays_init = -1;
|
||||
cli_t cli;
|
||||
cli_parse(argc, argv, &cli);
|
||||
|
||||
global_config.log_level = LOG_INFO;
|
||||
global_config.log_file = stdout;
|
||||
config_load(global_config, cli.config_file);
|
||||
|
||||
strcpy(global_config.user, "");
|
||||
strcpy(global_config.group, "");
|
||||
|
||||
helper_parse_cli(argc, argv, &global_config);
|
||||
|
||||
FILE * const ini_file = fopen(global_config.file, "rb");
|
||||
if(ini_file == NULL)
|
||||
if(global_config->logging.file == NULL)
|
||||
{
|
||||
LOGGER_CRIT("config file '%s' was not found\n", global_config.file);
|
||||
exit(1);
|
||||
global_config->logging.file = stdout;
|
||||
}
|
||||
if(load_ini_file( ini_file, INI_DEFAULT_FORMAT, NULL, config_load, &global_config))
|
||||
{
|
||||
LOGGER_CRIT("unable to parse ini file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fclose(ini_file);
|
||||
|
||||
if(global_config.log_file == NULL)
|
||||
if(global_config->include)
|
||||
{
|
||||
global_config.log_file = stdout;
|
||||
config_load_directory(global_config, global_config->include);
|
||||
}
|
||||
openlog("emgauwa-controller", 0, LOG_USER);
|
||||
|
||||
if(sizeof(time_t) < 8)
|
||||
{
|
||||
|
@ -146,38 +127,38 @@ main(int argc, const char** argv)
|
|||
|
||||
int piface_setup = 0;
|
||||
|
||||
for(uint_fast8_t i = 0; i < global_config.relay_count; ++i)
|
||||
for(uint_fast8_t i = 0; i < global_config->relay_count; ++i)
|
||||
{
|
||||
int relay_default = global_config.relay_configs[i].init;
|
||||
int relay_default = global_config->relay_configs[i].init;
|
||||
if(relay_default == -1)
|
||||
{
|
||||
relay_default = global_config.relays_init;
|
||||
relay_default = global_config->relays_init;
|
||||
}
|
||||
if(relay_default == -1)
|
||||
{
|
||||
relay_default = global_config.relay_configs[i].inverted;
|
||||
relay_default = global_config->relay_configs[i].inverted;
|
||||
}
|
||||
|
||||
if(global_config.relay_configs[i].driver == RELAY_DRIVER_GPIO)
|
||||
if(global_config->relay_configs[i].driver == RELAY_DRIVER_GPIO)
|
||||
{
|
||||
pinMode(global_config.relay_configs[i].pin, OUTPUT);
|
||||
driver_gpio_set(global_config.relay_configs[i].pin, relay_default);
|
||||
pinMode(global_config->relay_configs[i].pin, OUTPUT);
|
||||
driver_gpio_set(global_config->relay_configs[i].pin, relay_default);
|
||||
}
|
||||
if(global_config.relay_configs[i].driver == RELAY_DRIVER_PIFACE)
|
||||
if(global_config->relay_configs[i].driver == RELAY_DRIVER_PIFACE)
|
||||
{
|
||||
if(!piface_setup)
|
||||
{
|
||||
piFaceSetup(PIFACE_GPIO_BASE);
|
||||
piface_setup = 1;
|
||||
}
|
||||
driver_piface_set(global_config.relay_configs[i].pin, relay_default);
|
||||
driver_piface_set(global_config->relay_configs[i].pin, relay_default);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************** CHECK FOR TESTING RUN ********************/
|
||||
|
||||
if(global_config.run_type == RUN_TYPE_TEST)
|
||||
if(cli.demo_mode)
|
||||
{
|
||||
runner_test(global_controller);
|
||||
terminate(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue