add: version.h
fix: refactor
This commit is contained in:
parent
532750da74
commit
f5f9be803c
36 changed files with 27 additions and 34 deletions
src/models
72
src/models/controller.c
Normal file
72
src/models/controller.c
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <models/controller.h>
|
||||
#include <macros.h>
|
||||
#include <config.h>
|
||||
#include <constants.h>
|
||||
|
||||
controller_t*
|
||||
controller_create(void)
|
||||
{
|
||||
controller_t *new_controller = malloc(sizeof(*new_controller));
|
||||
uuid_generate(new_controller->id);
|
||||
|
||||
strncpy(new_controller->name, global_config.name, MAX_NAME_LENGTH);
|
||||
new_controller->name[MAX_NAME_LENGTH] = '\0';
|
||||
|
||||
new_controller->command_port = 0;
|
||||
new_controller->discovery_port = global_config.discovery_port;
|
||||
new_controller->relay_count = global_config.relay_count;
|
||||
|
||||
new_controller->relays = malloc(sizeof(relay_t) * new_controller->relay_count);
|
||||
uint8_t i;
|
||||
for(i = 0; i < new_controller->relay_count; ++i)
|
||||
{
|
||||
new_controller->relays[i] = relay_create(i);
|
||||
}
|
||||
|
||||
return new_controller;
|
||||
}
|
||||
|
||||
void
|
||||
controller_set_name(controller_t *controller, const char *name)
|
||||
{
|
||||
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\n");
|
||||
return;
|
||||
}
|
||||
char uuid_str[37];
|
||||
uuid_unparse(controller->id, uuid_str);
|
||||
LOG_DEBUG("(1/5) %s @ %p\n", uuid_str, (void*)controller);
|
||||
LOG_DEBUG("(2/5) name: %s\n", controller->name);
|
||||
LOG_DEBUG("(3/5) command_port: %5d discovery_port: %5d\n", controller->command_port, controller->discovery_port);
|
||||
LOG_DEBUG("(4/5) relay count: %3d\n", controller->relay_count);
|
||||
LOG_DEBUG("(5/5) relays @ %p:\n", (void*)controller->relays);
|
||||
for(int i = 0; i < controller->relay_count; ++i)
|
||||
{
|
||||
relay_debug(controller->relays[i]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue