diff --git a/src/prog/domod/include/domo.h b/src/prog/domod/include/domo.h index da142b85..7835e5ec 100644 --- a/src/prog/domod/include/domo.h +++ b/src/prog/domod/include/domo.h @@ -31,11 +31,11 @@ /* Device */ /* Device type. */ -#define kLightEntry "Lights" -#define kShutterEntry "Shutters" -#define kSprinklerEntry "Sprinklers" +#define kLightEntry "lights" +#define kShutterEntry "shutters" +#define kSprinklerEntry "sprinklers" -#define k_entry_data "data" +#define k_entry_devices "devices" /* common */ #define k_entry_id "id" diff --git a/src/prog/domod/src/devices/light-device.cpp b/src/prog/domod/src/devices/light-device.cpp index add7e7eb..3d46900b 100644 --- a/src/prog/domod/src/devices/light-device.cpp +++ b/src/prog/domod/src/devices/light-device.cpp @@ -58,23 +58,23 @@ LightDevice::~LightDevice(void) */ int LightDevice::from_json(struct json_object *a_node) { - struct json_object *the_data_node; + struct json_object *the_devices_node; fprintf(stderr, "LightDevice::load_from_json\n"); // speach name Device::from_json(a_node); // Get Light - if (json_object_object_get_ex(a_node, k_entry_data, &the_data_node) && (json_object_get_type(the_data_node) == json_type_array)) + if (json_object_object_get_ex(a_node, k_entry_devices, &the_devices_node) && (json_object_get_type(the_devices_node) == json_type_array)) { int the_len; struct json_object *the_light_node; - the_len = json_object_array_length(the_data_node); + the_len = json_object_array_length(the_devices_node); for (int i = 0; i < the_len; i++) { Light the_light; - the_light_node = json_object_array_get_idx(the_data_node, i); + the_light_node = json_object_array_get_idx(the_devices_node, i); the_light.from_json(the_light_node); m_lights.push_back(the_light); @@ -91,20 +91,20 @@ int LightDevice::from_json(struct json_object *a_node) */ struct json_object *LightDevice::to_json(void) { - struct json_object *the_root_node, *the_data_node; + struct json_object *the_root_node, *the_devices_node; std::vector::iterator the_light_it; the_root_node = json_object_new_object(); - the_data_node = json_object_new_array(); + the_devices_node = json_object_new_array(); // speach_name json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str())); // data - json_object_object_add(the_root_node, k_entry_data, the_data_node); + json_object_object_add(the_root_node, k_entry_devices, the_devices_node); for (the_light_it = m_lights.begin(); the_light_it != m_lights.end(); the_light_it++) { - json_object_array_add(the_data_node, (*the_light_it).to_json()); + json_object_array_add(the_devices_node, (*the_light_it).to_json()); } return the_root_node; diff --git a/src/prog/domod/src/devices/shutter-device.cpp b/src/prog/domod/src/devices/shutter-device.cpp index 6c68f188..1e043d76 100644 --- a/src/prog/domod/src/devices/shutter-device.cpp +++ b/src/prog/domod/src/devices/shutter-device.cpp @@ -58,24 +58,24 @@ ShutterDevice::~ShutterDevice(void) */ int ShutterDevice::from_json(struct json_object *a_node) { - struct json_object *the_data_node; + struct json_object *the_devices_node; fprintf(stderr, "ShutterDevice::load_from_json\n"); // speach name Device::from_json(a_node); // Get Shutter - if (json_object_object_get_ex(a_node, k_entry_data, &the_data_node) && (json_object_get_type(the_data_node) == json_type_array)) + if (json_object_object_get_ex(a_node, k_entry_devices, &the_devices_node) && (json_object_get_type(the_devices_node) == json_type_array)) { int the_len; struct json_object *the_shutter_node; - the_len = json_object_array_length(the_data_node); + the_len = json_object_array_length(the_devices_node); for (int i = 0; i < the_len; i++) { Shutter the_shutter; - the_shutter_node = json_object_array_get_idx(the_data_node, i); + the_shutter_node = json_object_array_get_idx(the_devices_node, i); the_shutter.from_json(the_shutter_node); m_shutters.push_back(the_shutter); @@ -92,21 +92,21 @@ int ShutterDevice::from_json(struct json_object *a_node) */ struct json_object *ShutterDevice::to_json(void) { - struct json_object *the_root_node, *the_data_node; + struct json_object *the_root_node, *the_devices_node; std::vector::iterator the_shutter_it; fprintf(stderr, "ShutterDevice::to_json\n"); the_root_node = json_object_new_object(); - the_data_node = json_object_new_array(); + the_devices_node = json_object_new_array(); // speach_name json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str())); - // data - json_object_object_add(the_root_node, k_entry_data, the_data_node); + // devices + json_object_object_add(the_root_node, k_entry_devices, the_devices_node); for (the_shutter_it = m_shutters.begin(); the_shutter_it != m_shutters.end(); the_shutter_it++) { - json_object_array_add(the_data_node, (*the_shutter_it).to_json()); + json_object_array_add(the_devices_node, (*the_shutter_it).to_json()); } return the_root_node; diff --git a/src/prog/domod/src/devices/sprinkler-device.cpp b/src/prog/domod/src/devices/sprinkler-device.cpp index 86684ad5..298f0a7b 100644 --- a/src/prog/domod/src/devices/sprinkler-device.cpp +++ b/src/prog/domod/src/devices/sprinkler-device.cpp @@ -58,24 +58,24 @@ SprinklerDevice::~SprinklerDevice(void) */ int SprinklerDevice::from_json(struct json_object *a_node) { - struct json_object *the_data_node; + struct json_object *the_devices_node; fprintf(stderr, "SprinklerDevice::load_from_json\n"); // speach name Device::from_json(a_node); // Get Sprinkler - if (json_object_object_get_ex(a_node, k_entry_data, &the_data_node) && (json_object_get_type(the_data_node) == json_type_array)) + if (json_object_object_get_ex(a_node, k_entry_devices, &the_devices_node) && (json_object_get_type(the_devices_node) == json_type_array)) { int the_len; struct json_object *the_sprinkler_node; - the_len = json_object_array_length(the_data_node); + the_len = json_object_array_length(the_devices_node); for (int i = 0; i < the_len; i++) { Sprinkler the_sprinkler; - the_sprinkler_node = json_object_array_get_idx(the_data_node, i); + the_sprinkler_node = json_object_array_get_idx(the_devices_node, i); the_sprinkler.from_json(the_sprinkler_node); m_sprinklers.push_back(the_sprinkler); @@ -92,21 +92,21 @@ int SprinklerDevice::from_json(struct json_object *a_node) */ struct json_object *SprinklerDevice::to_json(void) { - struct json_object *the_root_node, *the_data_node; + struct json_object *the_root_node, *the_devices_node; std::vector::iterator the_sprintkler_it; fprintf(stderr, "SprinklerDevice::to_json\n"); the_root_node = json_object_new_object(); - the_data_node = json_object_new_array(); + the_devices_node = json_object_new_array(); // speach_name json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str())); // data - json_object_object_add(the_root_node, k_entry_data, the_data_node); + json_object_object_add(the_root_node, k_entry_devices, the_devices_node); for (the_sprintkler_it = m_sprinklers.begin(); the_sprintkler_it != m_sprinklers.end(); the_sprintkler_it++) { - json_object_array_add(the_data_node, (*the_sprintkler_it).to_json()); + json_object_array_add(the_devices_node, (*the_sprintkler_it).to_json()); } return the_root_node; diff --git a/src/prog/domod/src/main.cpp b/src/prog/domod/src/main.cpp index 1dfc3772..c47f81f2 100644 --- a/src/prog/domod/src/main.cpp +++ b/src/prog/domod/src/main.cpp @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) printf("config path: %s\n", the_config_path.c_str()); /* Setup the devices. */ - DevicesManager the_devices_manager(the_config_path + "/Devices.json"); + DevicesManager the_devices_manager(the_config_path + "/devices.json"); if (the_devices_manager.load() != 0) { fprintf(stderr, "Failed to load devices.\n"); @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) } /* Setup the Timers. */ - TimerManager the_timers_manager(the_config_path + "/Timers.json", &the_devices_manager); + TimerManager the_timers_manager(the_config_path + "/timers.json", &the_devices_manager); if (the_timers_manager.load() != 0) { fprintf(stderr, "Failed to load timers.\n"); diff --git a/src/prog/domod/src/timers/timers-manager.cpp b/src/prog/domod/src/timers/timers-manager.cpp index 66815462..1375fcef 100644 --- a/src/prog/domod/src/timers/timers-manager.cpp +++ b/src/prog/domod/src/timers/timers-manager.cpp @@ -127,7 +127,7 @@ int TimerManager::save(void) * * @brief Method to get a specific Timers Object. */ -const Event &TimerManager::get(uint16_t an_id) +bool TimerManager::get(uint16_t an_id, Event &an_event) { std::vector::iterator the_timer_evt; @@ -135,10 +135,11 @@ const Event &TimerManager::get(uint16_t an_id) { if ((*the_timer_evt).get_id() == an_id) { - return (*the_timer_evt); + an_event = (*the_timer_evt); + return true; } } - //todo return something. + return false; } /*! ---------------------------------------------------------------------------- diff --git a/src/prog/domod/src/timers/timers-manager.h b/src/prog/domod/src/timers/timers-manager.h index 514c085d..3e55a260 100644 --- a/src/prog/domod/src/timers/timers-manager.h +++ b/src/prog/domod/src/timers/timers-manager.h @@ -53,7 +53,7 @@ class TimerManager : public ULoopTimer int load(void); int save(void); - const Event &get(uint16_t an_id); + bool get(uint16_t an_id, Event &a_event); int remove(uint16_t an_id); struct json_object *to_json(void);