fix: reloading relay schedules during different command caused bad behaviour

This commit is contained in:
Tobias Reisinger 2020-08-25 00:49:39 +02:00
parent 924633f272
commit f91e0bffb1
3 changed files with 17 additions and 5 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project(controller
VERSION 0.3.1
VERSION 0.3.2
LANGUAGES C)
add_executable(controller src/main.c)

View file

@ -161,15 +161,27 @@ handler_command_relay_schedules_set(mpack_node_t map)
{
mpack_node_t schedule_map = mpack_node_array_at(schedules_array, i);
handler_command_schedule_update(schedule_map);
uuid_t schedule_uid;
memcpy(schedule_uid, mpack_node_data(mpack_node_map_uint(schedule_map, COMMAND_MAPPING_SCHEDULE_ID)), sizeof(uuid_t));
uint16_t periods_count = mpack_node_u16(mpack_node_map_uint(schedule_map, COMMAND_MAPPING_PERIODS_COUNT));
uint16_t *periods = (uint16_t*)mpack_node_bin_data(mpack_node_map_uint(schedule_map, COMMAND_MAPPING_PERIODS_BLOB));
schedule_t *schedule = schedule_get_by_uid(schedule_uid);
schedule_t *new_schedule = schedule_create(schedule_uid, periods_count, periods);
if(schedule)
{
new_schedule->id = schedule->id;
schedule_free(schedule);
}
schedule_save(new_schedule);
schedule_debug(new_schedule);
relay_debug(target_relay);
junction_relay_schedule_insert(i, target_relay->id, schedule->id);
junction_relay_schedule_insert(i, target_relay->id, new_schedule->id);
}
relay_reload_schedules(target_relay);

View file

@ -296,7 +296,7 @@ schedule_debug(schedule_t *schedule)
return;
}
char uuid_str[UUID_STR_LEN];
uuid_unparse(schedule->uid, uuid_str);
schedule_uid_unparse(schedule->uid, uuid_str);
LOGGER_DEBUG("(1/3) %s @ %p\n", uuid_str, (void*)schedule);
LOGGER_DEBUG("(2/3) id: %3d; period count: %3d\n", schedule->id, schedule->periods_count);