Commit 48e8775d authored by Hermann Mayer's avatar Hermann Mayer

[Utils][Config][Docs] Refactored the config enums. Added the new desired actor…

[Utils][Config][Docs] Refactored the config enums. Added the new desired actor state check configuration parameters. Documented the new parameters. (See #15)
parent 0fb1b22c
......@@ -184,6 +184,38 @@ This value is an
.IR "integer".
.IP "" 0
.IP "" 4
.B "desired_actor_state"
.IP "" 8
With this configuration parameter you can specify in which state the configured
actor should be when the daemon is going to send an action to it. So the
current state of the actor will be queried if a motion was detected and the
light sensor check passed (if configured). If the desired actor state differs
from the current actor state, the action will be canceled. This parameter
accepts the following values:
.IR "on", "off", and "unkown". Defaults to
.IR "unknown".
This parameter is
.I ignored by
.BR "avmctl".
This value is a
.IR "string".
.IP "" 0
.IP "" 4
.B "desired_actor_state_missmatch_timeout"
.IP "" 8
With this parameter you can set a timeout (in seconds) if the desired actor
state check is configured and the states differs. 0 will disable this timeout.
Defaults to
.IR "30" " seconds."
This parameter is
.I ignored by
.BR "avmctl".
This value is an
.IR "integer".
.IP "" 0
.SS "Sensor ports"
.IP "" 4
......
......@@ -55,13 +55,13 @@ int switch_action(struct config *c)
}
switch (c->device.actor_command) {
case ON:
case CMD_ON:
state = switch_on(c->avm.hostname, session_id, c->device.ain);
break;
case OFF:
case CMD_OFF:
state = switch_off(c->avm.hostname, session_id, c->device.ain);
break;
case TOGGLE:
case CMD_TOGGLE:
state = switch_toggle(c->avm.hostname, session_id, c->device.ain);
break;
default:
......@@ -82,7 +82,7 @@ int switch_action(struct config *c)
int switch_action_off(struct config *c)
{
int cur_actn = c->device.actor_command;
c->device.actor_command = OFF;
c->device.actor_command = CMD_OFF;
int ret = switch_action(c);
c->device.actor_command = cur_actn;
return ret;
......
......@@ -47,7 +47,7 @@ struct config* init_config(struct config *conf)
conf->avm.password = (const wchar_t*) strwchar_t("0000");
conf->device.ain = "";
conf->device.actor_command = ON;
conf->device.actor_command = CMD_ON;
conf->device.turn_off_after = 0;
conf->tholds.light_sensor = 0;
......@@ -55,6 +55,8 @@ struct config* init_config(struct config *conf)
conf->tholds.too_bright_timeout= 30;
conf->tholds.backup_action_timeout = 1;
conf->tholds.failed_backup_action_timeout = 30;
conf->tholds.desired_actor_state = STATE_UNKNOWN;
conf->tholds.desired_actor_state_missmatch_timeout = 30;
conf->sensor.motion_gpio = 0;
conf->sensor.light_dev = "/dev/spidev0.0";
......@@ -71,6 +73,8 @@ struct config get_config(const char *path)
const char *avm_passwd;
const char *actor_command = (char*) malloc(sizeof(char) * 7);
memset((char*)actor_command, 0, sizeof(char) * 7);
const char *desired_actor_state = (char*) malloc(sizeof(char) * 8);
memset((char*)desired_actor_state, 0, sizeof(char) * 8);
init_config(&conf);
config_init(c);
......@@ -99,13 +103,13 @@ struct config get_config(const char *path)
config_lookup_int(c, "turn_device_off_after", &conf.device.turn_off_after);
if (0 == strcmp("on", actor_command)) {
conf.device.actor_command = ON;
conf.device.actor_command = CMD_ON;
} else if (0 == strcmp("off", actor_command)) {
conf.device.actor_command = OFF;
conf.device.actor_command = CMD_OFF;
} else if (0 == strcmp("toggle", actor_command)) {
conf.device.actor_command = TOGGLE;
conf.device.actor_command = CMD_TOGGLE;
} else {
conf.device.actor_command = UNKNOWN;
conf.device.actor_command = CMD_UNKNOWN;
}
/*
......@@ -117,6 +121,19 @@ struct config get_config(const char *path)
config_lookup_int(c, "backup_action_timeout", &conf.tholds.backup_action_timeout);
config_lookup_int(c, "failed_backup_action_timeout",
&conf.tholds.failed_backup_action_timeout);
config_lookup_int(c, "desired_actor_state_missmatch_timeout",
&conf.tholds.desired_actor_state_missmatch_timeout);
config_lookup_string(c, "desired_actor_state", &desired_actor_state);
if (0 == strcmp("on", desired_actor_state)) {
conf.tholds.desired_actor_state = STATE_ON;
} else if (0 == strcmp("off", desired_actor_state)) {
conf.tholds.desired_actor_state = STATE_OFF;
} else if (0 == strcmp("unknown", desired_actor_state)) {
conf.tholds.desired_actor_state = STATE_UNKNOWN;
} else {
conf.tholds.desired_actor_state = STATE_UNKNOWN;
}
/*
* Sensor ports section settings
......@@ -126,6 +143,7 @@ struct config get_config(const char *path)
config_lookup_int(c, "light_sensor_channel", &conf.sensor.light_channel);
free((char*) actor_command);
free((char*) desired_actor_state);
conf.ptr = c;
return conf;
......@@ -141,7 +159,7 @@ void validate_config(struct config *conf)
err_cnt++;
}
if (UNKNOWN == conf->device.actor_command) {
if (CMD_UNKNOWN == conf->device.actor_command) {
utlog(LOG_ERR, "%s [%s].\n", "Actor command (actor_command) is none of",
"on, off, toggle");
err_cnt++;
......
......@@ -32,17 +32,17 @@ struct config {
} avm;
struct config_device {
const char *ain;
enum {UNKNOWN, ON, OFF, TOGGLE} actor_command;
enum {CMD_UNKNOWN, CMD_ON, CMD_OFF, CMD_TOGGLE} actor_command;
int turn_off_after;
} device;
struct config_tholds {
int light_sensor;
int motion_locktime;
enum {STATE_UNKNOWN, STATE_ON, STATE_OFF} desired_actor_state;
int too_bright_timeout;
int backup_action_timeout;
int failed_backup_action_timeout;
int desired_actor_state_missmatch_timeout;
} tholds;
struct config_sensor {
int motion_gpio;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment