add: relay/piface support
This commit is contained in:
parent
fa6ceb2bf4
commit
db64e4f820
34 changed files with 1259 additions and 313 deletions
models
|
@ -7,38 +7,62 @@
|
|||
#include <models/controller.h>
|
||||
#include <macros.h>
|
||||
|
||||
controller*
|
||||
controller_t*
|
||||
controller_create(void)
|
||||
{
|
||||
controller *result = malloc(sizeof(*result));
|
||||
uuid_generate(result->id);
|
||||
controller_t *new_controller = malloc(sizeof(*new_controller));
|
||||
uuid_generate(new_controller->id);
|
||||
|
||||
strcpy(result->name, "new emgauwa device");
|
||||
result->command_port = 0;
|
||||
result->discovery_port = 4421;
|
||||
result->relay_count = 10;
|
||||
strcpy(new_controller->name, "new emgauwa device");
|
||||
new_controller->command_port = 0;
|
||||
new_controller->discovery_port = 4421;
|
||||
new_controller->relay_count = 10;
|
||||
|
||||
result->relays = malloc(sizeof(*result->relays) * result->relay_count);
|
||||
new_controller->relays = malloc(sizeof(relay_t) * new_controller->relay_count);
|
||||
uint8_t i;
|
||||
for(i = 0; i < result->relay_count; i++)
|
||||
for(i = 0; i < new_controller->relay_count; ++i)
|
||||
{
|
||||
result->relays[i] = relay_init(i);
|
||||
new_controller->relays[i] = relay_create(i);
|
||||
}
|
||||
|
||||
return result;
|
||||
return new_controller;
|
||||
}
|
||||
|
||||
void
|
||||
controller_debug(controller *cntrlr)
|
||||
controller_set_name(controller_t *controller, char *name)
|
||||
{
|
||||
if(cntrlr == NULL)
|
||||
strncpy(controller->name, name, MAX_NAME_LENGTH);
|
||||
controller->name[MAX_NAME_LENGTH] = '\0';
|
||||
}
|
||||
|
||||
void
|
||||
controller_free(controller_t *controller)
|
||||
{
|
||||
for(int i = 0; i < controller->relay_count; ++i)
|
||||
{
|
||||
relay_free(controller->relays[i]);
|
||||
}
|
||||
free(controller->relays);
|
||||
free(controller);
|
||||
}
|
||||
|
||||
void
|
||||
controller_debug(controller_t *controller)
|
||||
{
|
||||
if(controller == NULL)
|
||||
{
|
||||
LOG_DEBUG("controller is NULL");
|
||||
return;
|
||||
}
|
||||
char uuid_str[37];
|
||||
uuid_unparse(cntrlr->id, uuid_str);
|
||||
LOG_DEBUG("(1/4) %s @ %p", uuid_str, cntrlr);
|
||||
LOG_DEBUG("(2/4) name: %s", cntrlr->name);
|
||||
LOG_DEBUG("(3/4) relays: %3d", cntrlr->relay_count);
|
||||
LOG_DEBUG("(4/4) command_port: %5d discovery_port: %5d", cntrlr->command_port, cntrlr->discovery_port);
|
||||
uuid_unparse(controller->id, uuid_str);
|
||||
LOG_DEBUG("(1/5) %s @ %p", uuid_str, controller);
|
||||
LOG_DEBUG("(2/5) name: %s", controller->name);
|
||||
LOG_DEBUG("(3/5) command_port: %5d discovery_port: %5d", controller->command_port, controller->discovery_port);
|
||||
LOG_DEBUG("(4/5) relay count: %3d", controller->relay_count);
|
||||
LOG_DEBUG("(5/5) relays @ %p:", controller->relays);
|
||||
for(uint8_t i = 0; i < controller->relay_count; ++i)
|
||||
{
|
||||
relay_debug(controller->relays[i]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue