wip on shutters
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
|
||||
#include "devices/device.h"
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Device
|
||||
*
|
||||
@@ -41,7 +40,6 @@ Device::Device (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Device
|
||||
*
|
||||
@@ -51,7 +49,6 @@ Device::~Device (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn from_json
|
||||
*
|
||||
@@ -59,10 +56,17 @@ Device::~Device (void)
|
||||
*/
|
||||
int Device::from_json(struct json_object *a_node)
|
||||
{
|
||||
struct json_object *the_value_node;
|
||||
fprintf(stderr, "Device::load_from_json...\n");
|
||||
return 0;
|
||||
|
||||
// speach name
|
||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
||||
{
|
||||
m_speach_name = json_object_get_string(the_value_node);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
|
||||
struct json_object;
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
|
||||
#define k_entry_speach_name "speach_name"
|
||||
#define k_entry_data "data"
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Device
|
||||
|
||||
@@ -77,16 +77,19 @@ int DevicesManager::load(void)
|
||||
if (json_object_object_get_ex(the_root_node, kLightEntry, &the_value_node))
|
||||
{
|
||||
printf(" On a des Lights.\n");
|
||||
m_lights.from_json(the_value_node);
|
||||
}
|
||||
|
||||
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
|
||||
{
|
||||
printf(" On a des shutters.\n");
|
||||
m_shutters.from_json(the_value_node);
|
||||
}
|
||||
|
||||
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
|
||||
{
|
||||
printf(" On a des sprintkler.\n");
|
||||
m_sprinklers.from_json(the_value_node);
|
||||
}
|
||||
|
||||
/* Clean the json object. */
|
||||
|
||||
@@ -33,9 +33,6 @@
|
||||
|
||||
#include "devices/light-device.h"
|
||||
|
||||
#define k_entry_speach_name "speach_name"
|
||||
#define k_entry_data "data"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn LightDevice
|
||||
*
|
||||
@@ -61,17 +58,15 @@ LightDevice::~LightDevice(void)
|
||||
*/
|
||||
int LightDevice::from_json(struct json_object *a_node)
|
||||
{
|
||||
struct json_object *the_value_node, *the_data_node;
|
||||
struct json_object *the_data_node;
|
||||
fprintf(stderr, "LightDevice::load_from_json\n");
|
||||
|
||||
// speach name
|
||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node)) {
|
||||
Device::from_json(a_node);
|
||||
|
||||
m_speach_name = json_object_get_string(the_value_node);
|
||||
}
|
||||
// Get Light
|
||||
else 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_data, &the_data_node) && (json_object_get_type(the_data_node) == json_type_array))
|
||||
{
|
||||
int the_len;
|
||||
struct json_object *the_light_node;
|
||||
|
||||
@@ -107,8 +102,8 @@ struct json_object *LightDevice::to_json(void)
|
||||
// data
|
||||
json_object_object_add(the_root_node, k_entry_data, the_data_node);
|
||||
|
||||
|
||||
for (the_light_it = m_lights.begin(); the_light_it != m_lights.end(); the_light_it++) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "devices/light.h"
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
|
||||
#define k_entry_id "id"
|
||||
#define k_entry_name "name"
|
||||
@@ -42,8 +43,6 @@
|
||||
#define k_entry_sender "sender"
|
||||
#define k_entry_interruptor "interruptor"
|
||||
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Light
|
||||
*
|
||||
@@ -53,7 +52,6 @@ Light::Light (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~Light
|
||||
*
|
||||
@@ -63,7 +61,6 @@ Light::~Light (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn from_json
|
||||
*
|
||||
@@ -74,38 +71,44 @@ int Light::from_json (struct json_object *a_node)
|
||||
struct json_object *the_value_node;
|
||||
|
||||
// id
|
||||
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node))
|
||||
{
|
||||
m_id = json_object_get_int(the_value_node);
|
||||
}
|
||||
// name
|
||||
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node))
|
||||
{
|
||||
m_name = json_object_get_string(the_value_node);
|
||||
}
|
||||
// speach_name
|
||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
||||
{
|
||||
m_speach_name = json_object_get_string(the_value_node);
|
||||
}
|
||||
// zone
|
||||
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node))
|
||||
{
|
||||
m_zone = json_object_get_string(the_value_node);
|
||||
}
|
||||
// state
|
||||
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node))
|
||||
{
|
||||
m_state = json_object_get_boolean(the_value_node);
|
||||
}
|
||||
// sender
|
||||
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node))
|
||||
{
|
||||
m_sender = json_object_get_int(the_value_node);
|
||||
}
|
||||
// interruptor
|
||||
if (json_object_object_get_ex(a_node, k_entry_interruptor, &the_value_node)) {
|
||||
if (json_object_object_get_ex(a_node, k_entry_interruptor, &the_value_node))
|
||||
{
|
||||
m_interruptor = json_object_get_int(the_value_node);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
*
|
||||
@@ -135,7 +138,6 @@ struct json_object *Light::to_json (void) const
|
||||
return the_root_node;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn update
|
||||
*
|
||||
@@ -151,7 +153,6 @@ int Light::update (bool a_state)
|
||||
return send_state();
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn get_id
|
||||
*
|
||||
@@ -162,7 +163,6 @@ uint16_t Light::get_id (void)
|
||||
return m_id;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn sendState
|
||||
*
|
||||
|
||||
@@ -23,14 +23,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "devices/shutter-device.h"
|
||||
#include <json-c/json.h>
|
||||
|
||||
#include "devices/shutter-device.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ShutterDevice
|
||||
@@ -41,17 +40,15 @@ ShutterDevice::ShutterDevice (void) : Device()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ShutterDevice
|
||||
*
|
||||
* @brief Destructor of the Device Object.
|
||||
* @brief Destructor of the Shutter Device Object.
|
||||
*/
|
||||
ShutterDevice::~ShutterDevice(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn from_json
|
||||
*
|
||||
@@ -59,22 +56,33 @@ ShutterDevice::~ShutterDevice (void)
|
||||
*/
|
||||
int ShutterDevice::from_json(struct json_object *a_node)
|
||||
{
|
||||
struct json_object *the_data_node;
|
||||
fprintf(stderr, "ShutterDevice::load_from_json\n");
|
||||
#if 0
|
||||
mspeach_name = anElem["speach_name"].asString();
|
||||
|
||||
for (Json::Value& theElement : anElem["data"]) {
|
||||
Shutter theShutter;
|
||||
if (theShutter.load_from_json (theElement) == 0) {
|
||||
// speach name
|
||||
Device::from_json(a_node);
|
||||
|
||||
mShutter.push_back (theShutter);
|
||||
// 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))
|
||||
{
|
||||
|
||||
int the_len;
|
||||
struct json_object *the_shutter_node;
|
||||
|
||||
the_len = json_object_array_length(the_data_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.from_json(the_shutter_node);
|
||||
|
||||
m_shutters.push_back(the_shutter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
*
|
||||
@@ -104,7 +112,6 @@ struct json_object *ShutterDevice::to_json (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
@@ -115,7 +122,6 @@ int ShutterDevice::set (struct json_object *a_node)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
|
||||
@@ -50,7 +50,7 @@ class ShutterDevice : public Device
|
||||
int set(int an_id, bool a_state);
|
||||
|
||||
private:
|
||||
std::vector<Shutter> m_shutter;
|
||||
std::vector<Shutter> m_shutters;
|
||||
};
|
||||
|
||||
#endif /* _SHUTTER_DEVICE_H */
|
||||
|
||||
@@ -27,10 +27,24 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "devices/shutter.h"
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
|
||||
#define k_entry_id "id"
|
||||
#define k_entry_name "name"
|
||||
#define k_entry_speach_name "speach_name"
|
||||
#define k_entry_zone "zone"
|
||||
#define k_entry_state "state"
|
||||
#define k_entry_sender "sender"
|
||||
#define k_entry_interruptor "interruptor"
|
||||
#define k_entry_speed_up "speed_up"
|
||||
#define k_entry_speed_down "speed_down"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Shutter
|
||||
*
|
||||
@@ -56,17 +70,54 @@ Shutter::~Shutter(void)
|
||||
*/
|
||||
int Shutter::from_json(struct json_object *a_node)
|
||||
{
|
||||
#if 0
|
||||
mID = anElem["id"].asInt();
|
||||
mName = anElem["name"].asString();
|
||||
mSpeach_name = anElem["speach_name"].asString();
|
||||
mZone = anElem["zone"].asString();
|
||||
mState = anElem["state"].asBool();
|
||||
mSender = anElem["sender"].asInt();
|
||||
mInterruptor = anElem["interruptor"].asInt();
|
||||
mSpeed_up = anElem["speed_up"].asInt();
|
||||
mSpeed_down = anElem["speed_down"].asInt();
|
||||
#endif
|
||||
struct json_object *the_value_node;
|
||||
// TODO: Should shared with Light.
|
||||
// id
|
||||
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node))
|
||||
{
|
||||
m_id = json_object_get_int(the_value_node);
|
||||
}
|
||||
// name
|
||||
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node))
|
||||
{
|
||||
m_name = json_object_get_string(the_value_node);
|
||||
}
|
||||
// speach_name
|
||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
||||
{
|
||||
m_speach_name = json_object_get_string(the_value_node);
|
||||
}
|
||||
// zone
|
||||
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node))
|
||||
{
|
||||
m_zone = json_object_get_string(the_value_node);
|
||||
}
|
||||
// state
|
||||
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node))
|
||||
{
|
||||
m_state = json_object_get_boolean(the_value_node);
|
||||
}
|
||||
// sender
|
||||
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node))
|
||||
{
|
||||
m_sender = json_object_get_int(the_value_node);
|
||||
}
|
||||
// interruptor
|
||||
if (json_object_object_get_ex(a_node, k_entry_interruptor, &the_value_node))
|
||||
{
|
||||
m_interruptor = json_object_get_int(the_value_node);
|
||||
}
|
||||
// speed up
|
||||
if (json_object_object_get_ex(a_node, k_entry_speed_up, &the_value_node))
|
||||
{
|
||||
m_speed_up = json_object_get_int(the_value_node);
|
||||
}
|
||||
// speed down
|
||||
if (json_object_object_get_ex(a_node, k_entry_speed_down, &the_value_node))
|
||||
{
|
||||
m_speed_down = json_object_get_int(the_value_node);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -77,21 +128,30 @@ int Shutter::from_json(struct json_object *a_node)
|
||||
*/
|
||||
struct json_object *Shutter::to_json(void) const
|
||||
{
|
||||
#if 0
|
||||
Json::Value aResult(Json::objectValue);
|
||||
fprintf (stderr, "Shutter::to_json\n");
|
||||
aResult["id"] = mID;
|
||||
aResult["name"] = mName;
|
||||
aResult["zone"] = mZone;
|
||||
aResult["state"] = mState;
|
||||
aResult["sender"] = mSender;
|
||||
aResult["interruptor"] = mInterruptor;
|
||||
aResult["speed_up"] = mSpeed_up;
|
||||
aResult["speed_down"] = mSpeed_down;
|
||||
aResult["speach_name"] = mSpeach_name;
|
||||
struct json_object *the_root_node;
|
||||
|
||||
return aResult;
|
||||
#endif
|
||||
the_root_node = json_object_new_object();
|
||||
|
||||
// id
|
||||
json_object_object_add(the_root_node, k_entry_id, json_object_new_int(m_id));
|
||||
// name
|
||||
json_object_object_add(the_root_node, k_entry_name, json_object_new_string(m_name.c_str()));
|
||||
// speach_name
|
||||
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
||||
// zone
|
||||
json_object_object_add(the_root_node, k_entry_zone, json_object_new_string(m_zone.c_str()));
|
||||
// state
|
||||
json_object_object_add(the_root_node, k_entry_state, json_object_new_boolean(m_state));
|
||||
// sender
|
||||
json_object_object_add(the_root_node, k_entry_sender, json_object_new_int(m_sender));
|
||||
// interruptor
|
||||
json_object_object_add(the_root_node, k_entry_interruptor, json_object_new_int(m_interruptor));
|
||||
// speed up
|
||||
json_object_object_add(the_root_node, k_entry_speed_up, json_object_new_int(m_speed_up));
|
||||
// speed down
|
||||
json_object_object_add(the_root_node, k_entry_speed_down, json_object_new_int(m_speed_down));
|
||||
|
||||
return the_root_node;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user