controller-legacy/models/controller.c

45 lines
1.1 KiB
C
Raw Normal View History

2019-11-15 00:23:43 +00:00
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <uuid/uuid.h>
2019-12-08 22:39:10 +00:00
#include <models/controller.h>
2019-11-15 00:23:43 +00:00
#include <macros.h>
controller*
controller_create(void)
{
controller *result = malloc(sizeof(*result));
uuid_generate(result->id);
2019-11-15 00:23:43 +00:00
strcpy(result->name, "new emgauwa device");
2020-02-09 23:58:17 +00:00
result->command_port = 0;
2020-02-23 00:13:27 +00:00
result->discovery_port = 4421;
2019-11-15 00:23:43 +00:00
result->relay_count = 10;
result->relays = malloc(sizeof(*result->relays) * result->relay_count);
uint8_t i;
for(i = 0; i < result->relay_count; i++)
{
result->relays[i] = relay_init(i);
}
return result;
}
2020-01-07 01:23:16 +00:00
void
controller_debug(controller *cntrlr)
{
2020-02-09 23:58:17 +00:00
if(cntrlr == NULL)
{
LOG_DEBUG("controller is NULL");
}
2020-01-07 01:23:16 +00:00
char uuid_str[37];
uuid_unparse(cntrlr->id, uuid_str);
2020-02-09 23:58:17 +00:00
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);
2020-01-07 01:23:16 +00:00
}