fix: all the bugs with the new database and commanding

This commit is contained in:
Tobias Reisinger 2020-08-24 23:44:49 +02:00
parent 9602e6e937
commit 924633f272
12 changed files with 99 additions and 149 deletions
src/handlers

View file

@ -114,9 +114,26 @@ handler_command_schedule_update(mpack_node_t map)
if(schedule)
{
new_schedule->id = schedule->id;
schedule_free(schedule);
}
schedule_save(new_schedule);
schedule_free(schedule);
schedule_debug(new_schedule);
int *relay_ids = junction_relay_schedule_get_relay_ids_with_schedule(new_schedule->id);
for(int i = 0; i < global_config.relay_count; ++i)
{
for(int j = 0; relay_ids[j] != 0; ++j)
{
if(global_controller->relays[i]->id == relay_ids[j])
{
relay_reload_schedules(global_controller->relays[i]);
}
}
}
free(relay_ids);
schedule_free(new_schedule);
}
@ -151,6 +168,7 @@ handler_command_relay_schedules_set(mpack_node_t map)
schedule_t *schedule = schedule_get_by_uid(schedule_uid);
relay_debug(target_relay);
junction_relay_schedule_insert(i, target_relay->id, schedule->id);
}
@ -182,7 +200,7 @@ handler_command(struct mg_connection *c, int ev, void *ev_data)
mpack_tree_parse(&tree);
mpack_node_t root = mpack_tree_root(&tree);
uint16_t command_code = mpack_node_u8(mpack_node_map_uint(root, COMMAND_MAPPING_CODE));
uint16_t command_code = mpack_node_u16(mpack_node_map_uint(root, COMMAND_MAPPING_CODE));
LOGGER_DEBUG("received command %d\n", command_code);
@ -221,4 +239,6 @@ handler_command(struct mg_connection *c, int ev, void *ev_data)
{
LOGGER_WARNING("error when destroying mpack tree\n");
}
LOGGER_DEBUG("done with command %d - closing connection\n", command_code);
c->flags |= MG_F_SEND_AND_CLOSE;
}