wip replate json-cpp by json-c
This commit is contained in:
@@ -33,5 +33,5 @@ target_include_directories (ubus-cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
install (TARGETS ubus-cpp LIBRARY DESTINATION local/lib)
|
||||
|
||||
file (GLOB headers $ENV{SRC_DIR}/src/lib/libubus-cpp/include/ubus-cpp/*)
|
||||
file (GLOB headers ${workspaceRoot}/src/lib/libubus-cpp/include/ubus-cpp/*)
|
||||
install (FILES ${headers} DESTINATION include/ubus-cpp)
|
||||
|
||||
@@ -15,22 +15,23 @@ file(
|
||||
GLOB_RECURSE
|
||||
source_files
|
||||
${workspaceRoot}/src/prog/domod/src/main.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/device.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/devices.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/timers/event.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/devices-manager.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/device.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/light-device.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/shutter-device.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/sprinkler-device.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/light.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/shutter.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/sprinkler.cpp
|
||||
#${workspaceRoot}/src/prog/domod/src/timers/event.cpp
|
||||
#${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp
|
||||
)
|
||||
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/timers/Timers.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/timers/Clock.cpp
|
||||
#
|
||||
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/devices/LightDevice.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/devices/ShutterDevice.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/devices/SprinklerDevice.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/devices/Light.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/devices/Shutter.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/devices/Sprinkler.cpp
|
||||
|
||||
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_lights.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_shutters.cpp
|
||||
|
||||
@@ -29,24 +29,24 @@
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
/*------------------------------ DEPENDENCIES -------------------------------*/
|
||||
|
||||
struct json_object;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Device {
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
Device(void);
|
||||
virtual ~Device(void);
|
||||
|
||||
public:
|
||||
Device (void);
|
||||
virtual ~Device (void);
|
||||
virtual int from_json(const std::string &a_json);
|
||||
virtual struct json_object *to_json(void) const;
|
||||
|
||||
virtual int from_json (const std::string &a_json);
|
||||
virtual struct json_object *to_json (void) const;
|
||||
|
||||
protected:
|
||||
std::string mspeach_name;
|
||||
protected:
|
||||
std::string m_speach_name;
|
||||
};
|
||||
|
||||
#endif /* _DEVICE_H */
|
||||
|
||||
@@ -28,39 +28,71 @@
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
#include <json-c/json.h>
|
||||
#include <json-c/json_util.h>
|
||||
|
||||
#include "devices/Devices.h"
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
|
||||
#define kLightEntry "Lights"
|
||||
#define kShutterEntry "Shutters"
|
||||
#define kSprinklerEntry "Sprinklers"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Devices
|
||||
* @fn DevicesManager
|
||||
*
|
||||
* @brief Constructor of the Devices Managagers.
|
||||
*/
|
||||
Devices::Devices (std::string aPath):
|
||||
mFilePath (aPath)
|
||||
DevicesManager::DevicesManager(const std::string &a_path) : m_file_path(a_path)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~Devices
|
||||
* @fn ~DevicesManager
|
||||
*
|
||||
* @brief Destructor of the Devices Managagers.
|
||||
*/
|
||||
Devices::~Devices (void)
|
||||
DevicesManager::~DevicesManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load
|
||||
*
|
||||
* @brief Load the Devices from the Json File.
|
||||
*/
|
||||
int Devices::load (void)
|
||||
int DevicesManager::load(void)
|
||||
{
|
||||
struct json_object *the_root_node, *the_value_node;
|
||||
fprintf(stderr, "Devices::load...\n");
|
||||
|
||||
the_root_node = json_object_from_file(m_file_path.c_str());
|
||||
if (the_root_node == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to parse the Devices File (%s).\n", m_file_path.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (json_object_object_get_ex(the_root_node, kLightEntry, &the_value_node))
|
||||
{
|
||||
printf(" On a des Lights.\n");
|
||||
}
|
||||
|
||||
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
|
||||
{
|
||||
printf(" On a des shutters.\n");
|
||||
}
|
||||
|
||||
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
|
||||
{
|
||||
printf(" On a des sprintkler.\n");
|
||||
}
|
||||
|
||||
/* Clean the json object. */
|
||||
json_object_put(the_root_node);
|
||||
|
||||
#if 0
|
||||
Json::Reader theReader;
|
||||
Json::Value theRoot;
|
||||
std::ifstream theDevicesFile (mFilePath.c_str());
|
||||
@@ -82,18 +114,18 @@ int Devices::load (void)
|
||||
|
||||
/* Open Sprinklers. */
|
||||
mSprinklers.load_from_json (theRoot["Sprinklers"]);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn save
|
||||
*
|
||||
* @brief Save the Devices from the Json File.
|
||||
*/
|
||||
int Devices::save (void)
|
||||
int DevicesManager::save(void)
|
||||
{
|
||||
#if 0
|
||||
Json::StyledStreamWriter theWriter;
|
||||
|
||||
Json::Value theRoot(Json::objectValue);
|
||||
@@ -106,18 +138,18 @@ int Devices::save (void)
|
||||
/* Save to the File. */
|
||||
std::ofstream theOutput (mFilePath.c_str());
|
||||
theWriter.write (theOutput, theRoot);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn get
|
||||
*
|
||||
* @brief get the list of devices of a specific capabilities.
|
||||
*/
|
||||
std::string Devices::get (const std::string &aCapability)
|
||||
std::string DevicesManager::get(const std::string &a_capability)
|
||||
{
|
||||
#if 0
|
||||
Json::StyledWriter theWriter;
|
||||
Json::Value theOutput;
|
||||
fprintf (stderr, "Devices::get...\n");
|
||||
@@ -136,14 +168,15 @@ std::string Devices::get (const std::string &aCapability)
|
||||
}
|
||||
|
||||
return theWriter.write (theOutput).c_str();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
* @brief get the device of a specific capabilities, with the ID.
|
||||
*/
|
||||
#if 0
|
||||
int Devices::set (const std::string &aCapability, Json::Value anElement)
|
||||
{
|
||||
int theResult = -1;
|
||||
@@ -166,15 +199,16 @@ int Devices::set (const std::string &aCapability, Json::Value anElement)
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
* @brief get the device of a specific capabilities, with the ID.
|
||||
*/
|
||||
int Devices::set (const std::string &aCapability, int anID, bool aState)
|
||||
int DevicesManager::set(const std::string &a_capability, int an_id, bool a_state)
|
||||
{
|
||||
#if 0
|
||||
int theResult = -1;
|
||||
|
||||
if (aCapability == "Lights") {
|
||||
@@ -194,4 +228,5 @@ int Devices::set (const std::string &aCapability, int anID, bool aState)
|
||||
save ();
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
}
|
||||
@@ -23,44 +23,42 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _DEVICES_H
|
||||
#define _DEVICES_H
|
||||
#ifndef _DEVICES_MANAGER_H
|
||||
#define _DEVICES_MANAGER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "devices/LightDevice.h"
|
||||
#include "devices/ShutterDevice.h"
|
||||
#include "devices/SprinklerDevice.h"
|
||||
#include "devices/light-device.h"
|
||||
#include "devices/shutter-device.h"
|
||||
#include "devices/sprinkler-device.h"
|
||||
|
||||
#include "devices/Device.h"
|
||||
#include "devices/device.h"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Devices {
|
||||
class DevicesManager
|
||||
{
|
||||
public:
|
||||
DevicesManager(const std::string &a_path);
|
||||
~DevicesManager(void);
|
||||
|
||||
public:
|
||||
Devices (std::string aPath);
|
||||
~Devices (void);
|
||||
int load(void);
|
||||
int save(void);
|
||||
|
||||
int load (void);
|
||||
int save (void);
|
||||
std::string get(const std::string &a_capability);
|
||||
//int set (const std::string &aCapability, Json::Value anElement);
|
||||
int set(const std::string &a_capability, int an_id, bool a_state);
|
||||
|
||||
std::string get (const std::string &aCapability);
|
||||
int set (const std::string &aCapability, Json::Value anElement);
|
||||
int set (const std::string &aCapability, int anID, bool aState);
|
||||
private:
|
||||
std::string m_file_path;
|
||||
|
||||
private:
|
||||
std::string mFilePath;
|
||||
|
||||
LightDevice mLights;
|
||||
ShutterDevice mShutters;
|
||||
SprinklerDevice mSprinklers;
|
||||
LightDevice m_lights;
|
||||
ShutterDevice m_shutters;
|
||||
SprinklerDevice m_sprinklers;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _DEVICES_H */
|
||||
#endif /* _DEVICES_MANAGER_H */
|
||||
@@ -23,46 +23,41 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "devices/Light.h"
|
||||
|
||||
#include "devices/LightDevice.h"
|
||||
#include "devices/light.h"
|
||||
|
||||
#include "devices/light-device.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn LightDevice
|
||||
*
|
||||
* @brief Constructor of the LightDevice Object.
|
||||
*/
|
||||
LightDevice::LightDevice (void) : Device()
|
||||
LightDevice::LightDevice(void) : Device()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn LightDevice
|
||||
*
|
||||
* @brief Destructor of the Device Object.
|
||||
*/
|
||||
LightDevice::~LightDevice (void)
|
||||
LightDevice::~LightDevice(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load_from_json
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load LightDevice Object From a Json Object.
|
||||
*/
|
||||
int LightDevice::load_from_json (Json::Value anElem)
|
||||
int LightDevice::from_json(struct json_object *a_node)
|
||||
{
|
||||
fprintf (stderr, "LightDevice::load_from_json\n");
|
||||
|
||||
fprintf(stderr, "LightDevice::load_from_json\n");
|
||||
#if 0
|
||||
mspeach_name = anElem["speach_name"].asString();
|
||||
|
||||
for (Json::Value& theElement : anElem["data"]) {
|
||||
@@ -72,18 +67,18 @@ int LightDevice::load_from_json (Json::Value anElem)
|
||||
mLights.push_back (theLight);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
*
|
||||
* @brief Export LightDevice Object as JSON Object.
|
||||
*/
|
||||
Json::Value LightDevice::to_json (bool bDataOnly)
|
||||
struct json_object *LightDevice::to_json(void)
|
||||
{
|
||||
#if 0
|
||||
Json::Value theResult;
|
||||
Json::Value data_json(Json::arrayValue);
|
||||
std::vector<Light>::iterator theLight_it;
|
||||
@@ -102,16 +97,17 @@ Json::Value LightDevice::to_json (bool bDataOnly)
|
||||
return data_json;
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
* @brief set the new light state.
|
||||
*/
|
||||
int LightDevice::set (Json::Value anElement)
|
||||
int LightDevice::set(struct json_object *a_node)
|
||||
{
|
||||
#if 0
|
||||
int theID;
|
||||
bool theState;
|
||||
|
||||
@@ -119,25 +115,28 @@ int LightDevice::set (Json::Value anElement)
|
||||
theState = anElement["state"].asBool();
|
||||
|
||||
return set (theID, theState);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
* @brief set the new light state.
|
||||
*/
|
||||
int LightDevice::set (int anID, bool aState)
|
||||
int LightDevice::set(int an_id, bool a_state)
|
||||
{
|
||||
#if 0
|
||||
std::vector<Light>::iterator theLight_it;
|
||||
|
||||
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++) {
|
||||
|
||||
if ((*theLight_it).getID() == anID) {
|
||||
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++)
|
||||
{
|
||||
|
||||
return (*theLight_it).update (aState);
|
||||
if ((*theLight_it).getID() == anID)
|
||||
{
|
||||
|
||||
return (*theLight_it).update(aState);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -30,30 +30,27 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "devices/Light.h"
|
||||
#include "devices/Device.h"
|
||||
|
||||
#include "devices/light.h"
|
||||
#include "devices/device.h"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class LightDevice : public Device {
|
||||
class LightDevice : public Device
|
||||
{
|
||||
public:
|
||||
LightDevice(void);
|
||||
~LightDevice(void);
|
||||
|
||||
public:
|
||||
LightDevice (void);
|
||||
~LightDevice (void);
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (bool bDataOnly = false);
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void);
|
||||
|
||||
int set (Json::Value anElement);
|
||||
int set (int anID, bool aState);
|
||||
|
||||
private:
|
||||
std::vector <Light> mLights;
|
||||
int set(struct json_object *a_node);
|
||||
int set(int anID, bool aState);
|
||||
|
||||
private:
|
||||
std::vector<Light> mLights;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _LIGHT_DEVICE_H */
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <ubus-cpp/UBusCall.h>
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "devices/Light.h"
|
||||
#include "devices/light.h"
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -53,12 +53,13 @@ Light::~Light (void)
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load_from_json
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load a Light Element from a Json Entry.
|
||||
*/
|
||||
int Light::load_from_json (Json::Value anElem)
|
||||
int Light::from_json (struct json_object *a_node)
|
||||
{
|
||||
#if 0
|
||||
mID = anElem["id"].asInt();
|
||||
mName = anElem["name"].asString();
|
||||
mSpeach_name = anElem["speach_name"].asString();
|
||||
@@ -66,7 +67,7 @@ int Light::load_from_json (Json::Value anElem)
|
||||
mState = anElem["state"].asBool();
|
||||
mSender = anElem["sender"].asInt();
|
||||
mInterruptor = anElem["interruptor"].asInt();
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,8 +77,9 @@ int Light::load_from_json (Json::Value anElem)
|
||||
*
|
||||
* @brief Return Light Object as a Json Object.
|
||||
*/
|
||||
Json::Value Light::to_json (void) const
|
||||
struct json_object *Light::to_json (void) const
|
||||
{
|
||||
#if 0
|
||||
Json::Value aResult(Json::objectValue);
|
||||
fprintf (stderr, "Light::to_json\n");
|
||||
aResult["id"] = mID;
|
||||
@@ -89,6 +91,7 @@ Json::Value Light::to_json (void) const
|
||||
aResult["interruptor"] = mInterruptor;
|
||||
|
||||
return aResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -97,25 +100,25 @@ Json::Value Light::to_json (void) const
|
||||
*
|
||||
* @brief Update the Light State.
|
||||
*/
|
||||
int Light::update (bool aState)
|
||||
int Light::update (bool a_state)
|
||||
{
|
||||
if (mState == aState)
|
||||
if (m_state == a_state)
|
||||
return 1;
|
||||
|
||||
mState = aState;
|
||||
m_state = a_state;
|
||||
|
||||
return sendState ();
|
||||
return send_state ();
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn getID
|
||||
* @fn get_id
|
||||
*
|
||||
* @brief Return the ID of the Light.
|
||||
*/
|
||||
uint16_t Light::getID (void)
|
||||
uint16_t Light::get_id (void)
|
||||
{
|
||||
return mID;
|
||||
return m_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,8 +127,9 @@ uint16_t Light::getID (void)
|
||||
*
|
||||
* @brief Send the Curent State of the Light.
|
||||
*/
|
||||
int Light::sendState (void)
|
||||
int Light::send_state (void)
|
||||
{
|
||||
#if 0
|
||||
UBusCall theCmd;
|
||||
Json::Value theParam;
|
||||
Json::StyledWriter theWriter;
|
||||
@@ -136,4 +140,5 @@ int Light::sendState (void)
|
||||
theParam["state"] = mState;
|
||||
|
||||
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -32,38 +32,34 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Light {
|
||||
class Light
|
||||
{
|
||||
public:
|
||||
Light(void);
|
||||
~Light(void);
|
||||
|
||||
public:
|
||||
Light (void);
|
||||
~Light (void);
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void) const;
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (void) const;
|
||||
int update(bool a_state);
|
||||
|
||||
int update (bool aState);
|
||||
uint16_t get_id(void);
|
||||
|
||||
uint16_t getID (void);
|
||||
private:
|
||||
int send_state(void);
|
||||
|
||||
private:
|
||||
int sendState (void);
|
||||
|
||||
private:
|
||||
uint16_t mID;
|
||||
std::string mName;
|
||||
std::string mSpeach_name;
|
||||
std::string mZone;
|
||||
bool mState;
|
||||
uint32_t mSender;
|
||||
uint8_t mInterruptor;
|
||||
private:
|
||||
uint16_t m_id;
|
||||
std::string m_name;
|
||||
std::string m_speach_name;
|
||||
std::string m_zone;
|
||||
bool m_state;
|
||||
uint32_t m_sender;
|
||||
uint8_t m_interruptor;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _LIGHT_H */
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "devices/ShutterDevice.h"
|
||||
#include "devices/shutter-device.h"
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -53,14 +53,14 @@ ShutterDevice::~ShutterDevice (void)
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load_from_json
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load ShutterDevice Object From a Json Object.
|
||||
*/
|
||||
int ShutterDevice::load_from_json (Json::Value anElem)
|
||||
int ShutterDevice::from_json (struct json_object *a_node)
|
||||
{
|
||||
fprintf (stderr, "ShutterDevice::load_from_json\n");
|
||||
|
||||
#if 0
|
||||
mspeach_name = anElem["speach_name"].asString();
|
||||
|
||||
for (Json::Value& theElement : anElem["data"]) {
|
||||
@@ -70,7 +70,7 @@ int ShutterDevice::load_from_json (Json::Value anElem)
|
||||
mShutter.push_back (theShutter);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,9 @@ int ShutterDevice::load_from_json (Json::Value anElem)
|
||||
*
|
||||
* @brief Export ShutterDevice Object as JSON Object.
|
||||
*/
|
||||
Json::Value ShutterDevice::to_json (bool bDataOnly)
|
||||
struct json_object *ShutterDevice::to_json (void)
|
||||
{
|
||||
#if 0
|
||||
Json::Value theResult;
|
||||
Json::Value data_json(Json::arrayValue);
|
||||
std::vector<Shutter>::iterator theShutter_it;
|
||||
@@ -100,6 +101,7 @@ Json::Value ShutterDevice::to_json (bool bDataOnly)
|
||||
return data_json;
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +110,7 @@ Json::Value ShutterDevice::to_json (bool bDataOnly)
|
||||
*
|
||||
* @brief set the new Shutter state.
|
||||
*/
|
||||
int ShutterDevice::set (Json::Value anElement)
|
||||
int ShutterDevice::set (struct json_object *a_node)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -119,7 +121,7 @@ int ShutterDevice::set (Json::Value anElement)
|
||||
*
|
||||
* @brief set the new Shutter state.
|
||||
*/
|
||||
int ShutterDevice::set (int anID, bool aState)
|
||||
int ShutterDevice::set (int an_id, bool a_state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,29 +30,27 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "devices/Shutter.h"
|
||||
#include "devices/Device.h"
|
||||
#include "devices/shutter.h"
|
||||
#include "devices/device.h"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class ShutterDevice : public Device {
|
||||
class ShutterDevice : public Device
|
||||
{
|
||||
public:
|
||||
ShutterDevice(void);
|
||||
~ShutterDevice(void);
|
||||
|
||||
public:
|
||||
ShutterDevice (void);
|
||||
~ShutterDevice (void);
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void);
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (bool bDataOnly = false);
|
||||
int set(struct json_object *a_node);
|
||||
int set(int an_id, bool a_state);
|
||||
|
||||
int set (Json::Value anElement);
|
||||
int set (int anID, bool aState);
|
||||
|
||||
private:
|
||||
std::vector <Shutter> mShutter;
|
||||
private:
|
||||
std::vector<Shutter> m_shutter;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _SHUTTER_DEVICE_H */
|
||||
|
||||
@@ -27,38 +27,36 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <ubus-cpp/UBusCall.h>
|
||||
|
||||
#include "devices/Shutter.h"
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "devices/shutter.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Shutter
|
||||
*
|
||||
* @brief Constructor of the Shutter Object.
|
||||
*/
|
||||
Shutter::Shutter (void)
|
||||
Shutter::Shutter(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~Shutter
|
||||
*
|
||||
* @brief Destructor of the Shutter Object.
|
||||
*/
|
||||
Shutter::~Shutter (void)
|
||||
Shutter::~Shutter(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load_from_json
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load a Shutter Element from a Json Entry.
|
||||
*/
|
||||
int Shutter::load_from_json (Json::Value anElem)
|
||||
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();
|
||||
@@ -68,18 +66,18 @@ int Shutter::load_from_json (Json::Value anElem)
|
||||
mInterruptor = anElem["interruptor"].asInt();
|
||||
mSpeed_up = anElem["speed_up"].asInt();
|
||||
mSpeed_down = anElem["speed_down"].asInt();
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
*
|
||||
* @brief Return Shutter Object as a Json Object.
|
||||
*/
|
||||
Json::Value Shutter::to_json (void) const
|
||||
struct json_object *Shutter::to_json(void) const
|
||||
{
|
||||
#if 0
|
||||
Json::Value aResult(Json::objectValue);
|
||||
fprintf (stderr, "Shutter::to_json\n");
|
||||
aResult["id"] = mID;
|
||||
@@ -93,42 +91,40 @@ Json::Value Shutter::to_json (void) const
|
||||
aResult["speach_name"] = mSpeach_name;
|
||||
|
||||
return aResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn update
|
||||
*
|
||||
* @brief Update the Shutter State.
|
||||
*/
|
||||
int Shutter::update (bool aState)
|
||||
int Shutter::update(bool a_state)
|
||||
{
|
||||
if (mState == aState)
|
||||
if (m_state == a_state)
|
||||
return 1;
|
||||
|
||||
mState = aState;
|
||||
m_state = a_state;
|
||||
|
||||
return sendState ();
|
||||
return send_state();
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn getID
|
||||
* @fn get_id
|
||||
*
|
||||
* @brief Return the ID of the Shutter.
|
||||
*/
|
||||
uint16_t Shutter::getID (void)
|
||||
uint16_t Shutter::get_id(void)
|
||||
{
|
||||
return mID;
|
||||
return m_id;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn sendState
|
||||
* @fn send_state
|
||||
*
|
||||
* @brief Send the Curent State of the Light.
|
||||
*/
|
||||
int Shutter::sendState (void)
|
||||
int Shutter::send_state(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,39 +32,36 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Shutter {
|
||||
class Shutter
|
||||
{
|
||||
public:
|
||||
Shutter(void);
|
||||
~Shutter(void);
|
||||
|
||||
public:
|
||||
Shutter (void);
|
||||
~Shutter (void);
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void) const;
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (void) const;
|
||||
int update(bool a_state);
|
||||
|
||||
int update (bool aState);
|
||||
uint16_t get_id(void);
|
||||
|
||||
uint16_t getID (void);
|
||||
private:
|
||||
int send_state(void);
|
||||
|
||||
private:
|
||||
int sendState (void);
|
||||
|
||||
private:
|
||||
uint16_t mID;
|
||||
std::string mName;
|
||||
std::string mSpeach_name;
|
||||
std::string mZone;
|
||||
bool mState;
|
||||
uint32_t mSender;
|
||||
uint8_t mInterruptor;
|
||||
uint8_t mSpeed_up;
|
||||
uint8_t mSpeed_down;
|
||||
private:
|
||||
uint16_t m_id;
|
||||
std::string m_name;
|
||||
std::string m_speach_name;
|
||||
std::string m_zone;
|
||||
bool m_state;
|
||||
uint32_t m_sender;
|
||||
uint8_t m_interruptor;
|
||||
uint8_t m_speed_up;
|
||||
uint8_t m_speed_down;
|
||||
};
|
||||
|
||||
#endif /* _SHUTTER_H */
|
||||
|
||||
@@ -53,14 +53,14 @@ SprinklerDevice::~SprinklerDevice (void)
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load_from_json
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load SprinklerDevice Object From a Json Object.
|
||||
*/
|
||||
int SprinklerDevice::load_from_json (Json::Value anElem)
|
||||
int SprinklerDevice::from_json (struct json_object *a_node)
|
||||
{
|
||||
fprintf (stderr, "SprinklerDevice::load_from_json\n");
|
||||
|
||||
#if 0
|
||||
mspeach_name = anElem["speach_name"].asString();
|
||||
|
||||
for (Json::Value& theElement : anElem["data"]) {
|
||||
@@ -70,7 +70,7 @@ int SprinklerDevice::load_from_json (Json::Value anElem)
|
||||
mSprinkler.push_back (theSprinkler);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,9 @@ int SprinklerDevice::load_from_json (Json::Value anElem)
|
||||
*
|
||||
* @brief Export SprinklerDevice Object as JSON Object.
|
||||
*/
|
||||
Json::Value SprinklerDevice::to_json (bool bDataOnly)
|
||||
struct json_object *SprinklerDevice::to_json (void)
|
||||
{
|
||||
#if 0
|
||||
Json::Value theResult;
|
||||
Json::Value data_json(Json::arrayValue);
|
||||
std::vector<Sprinkler>::iterator theSprinkler_it;
|
||||
@@ -100,6 +101,7 @@ Json::Value SprinklerDevice::to_json (bool bDataOnly)
|
||||
return data_json;
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +110,9 @@ Json::Value SprinklerDevice::to_json (bool bDataOnly)
|
||||
*
|
||||
* @brief set the new Sprinkler state.
|
||||
*/
|
||||
int SprinklerDevice::set (Json::Value anElement)
|
||||
int SprinklerDevice::set (struct json_object *a_node)
|
||||
{
|
||||
#if 0
|
||||
int theID;
|
||||
bool theState;
|
||||
|
||||
@@ -117,6 +120,7 @@ int SprinklerDevice::set (Json::Value anElement)
|
||||
theState = anElement["state"].asBool();
|
||||
|
||||
return set (theID, theState);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -126,6 +130,7 @@ int SprinklerDevice::set (Json::Value anElement)
|
||||
*/
|
||||
int SprinklerDevice::set (int anID, bool aState)
|
||||
{
|
||||
#if 0
|
||||
std::vector<Sprinkler>::iterator theSprinkler_it;
|
||||
|
||||
for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) {
|
||||
@@ -135,6 +140,6 @@ int SprinklerDevice::set (int anID, bool aState)
|
||||
return (*theSprinkler_it).update (aState);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -35,24 +35,23 @@
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class SprinklerDevice : public Device {
|
||||
class SprinklerDevice : public Device
|
||||
{
|
||||
|
||||
public:
|
||||
SprinklerDevice (void);
|
||||
~SprinklerDevice (void);
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (bool bDataOnly = false);
|
||||
public:
|
||||
SprinklerDevice(void);
|
||||
~SprinklerDevice(void);
|
||||
|
||||
int set (Json::Value anElement);
|
||||
int set (int anID, bool aState);
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void);
|
||||
|
||||
private:
|
||||
std::vector <Sprinkler> mSprinkler;
|
||||
int set(struct json_object *a_node);
|
||||
int set(int an_id, bool a_state);
|
||||
|
||||
private:
|
||||
std::vector<Sprinkler> m_sprinkler;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _SPRINKLER_DEVICE_H */
|
||||
|
||||
@@ -27,54 +27,52 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <ubus-cpp/UBusCall.h>
|
||||
|
||||
#include "devices/Sprinkler.h"
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "devices/sprinkler.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Sprinkler
|
||||
*
|
||||
* @brief Constructor of the Sprinkler Object.
|
||||
*/
|
||||
Sprinkler::Sprinkler (void)
|
||||
Sprinkler::Sprinkler(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~Sprinkler
|
||||
*
|
||||
* @brief Destructor of the Sprinkler Object.
|
||||
*/
|
||||
Sprinkler::~Sprinkler (void)
|
||||
Sprinkler::~Sprinkler(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load_from_json
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load a Sprinkler Element from a Json Entry.
|
||||
*/
|
||||
int Sprinkler::load_from_json (Json::Value anElem)
|
||||
int Sprinkler::from_json(struct json_object *a_node)
|
||||
{
|
||||
#if 0
|
||||
mID = anElem["id"].asInt();
|
||||
mName = anElem["name"].asString();
|
||||
mSpeach_name = anElem["speach_name"].asString();
|
||||
mState = anElem["state"].asBool();
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
*
|
||||
* @brief Return Sprinkler Object as a Json Object.
|
||||
*/
|
||||
Json::Value Sprinkler::to_json (void) const
|
||||
struct json_object *Sprinkler::to_json(void) const
|
||||
{
|
||||
#if 0
|
||||
Json::Value aResult(Json::objectValue);
|
||||
fprintf (stderr, "Sprinkler::to_json\n");
|
||||
aResult["id"] = mID;
|
||||
@@ -83,43 +81,42 @@ Json::Value Sprinkler::to_json (void) const
|
||||
aResult["state"] = mState;
|
||||
|
||||
return aResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn update
|
||||
*
|
||||
* @brief Update the Sprinkler State.
|
||||
*/
|
||||
int Sprinkler::update (bool aState)
|
||||
int Sprinkler::update(bool a_state)
|
||||
{
|
||||
if (mState == aState)
|
||||
if (m_state == a_state)
|
||||
return 1;
|
||||
|
||||
mState = aState;
|
||||
m_state = a_state;
|
||||
|
||||
return sendState ();
|
||||
return send_state();
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn getID
|
||||
* @fn get_id
|
||||
*
|
||||
* @brief Return the ID of the Sprinkler.
|
||||
*/
|
||||
uint16_t Sprinkler::getID (void)
|
||||
uint16_t Sprinkler::get_id(void)
|
||||
{
|
||||
return mID;
|
||||
return m_id;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn sendState
|
||||
* @fn send_state
|
||||
*
|
||||
* @brief Send the Curent State of the Light.
|
||||
*/
|
||||
int Sprinkler::sendState (void)
|
||||
int Sprinkler::send_state(void)
|
||||
{
|
||||
#if 0
|
||||
UBusCall theCmd;
|
||||
Json::Value theParam;
|
||||
Json::StyledWriter theWriter;
|
||||
@@ -129,4 +126,5 @@ int Sprinkler::sendState (void)
|
||||
theParam["state"] = mState;
|
||||
|
||||
return theCmd.Exec ("sprinklers", "set", theWriter.write(theParam).c_str(),theResult);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -32,34 +32,32 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Sprinkler {
|
||||
class Sprinkler
|
||||
{
|
||||
|
||||
public:
|
||||
Sprinkler (void);
|
||||
~Sprinkler (void);
|
||||
public:
|
||||
Sprinkler(void);
|
||||
~Sprinkler(void);
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (void) const;
|
||||
|
||||
int update (bool aState);
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json (void) const;
|
||||
|
||||
uint16_t getID (void);
|
||||
int update(bool aState);
|
||||
|
||||
private:
|
||||
int sendState (void);
|
||||
uint16_t get_id(void);
|
||||
|
||||
private:
|
||||
uint16_t mID;
|
||||
private:
|
||||
int send_state(void);
|
||||
|
||||
private:
|
||||
uint16_t m_id;
|
||||
std::string mName;
|
||||
std::string mSpeach_name;
|
||||
bool mState;
|
||||
bool m_state;
|
||||
};
|
||||
|
||||
#endif /* _SPRINKLER_H */
|
||||
|
||||
@@ -38,7 +38,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#include "timers/timers.h"
|
||||
#include "devices/devices.h"
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
/*-------------------------------- DEFINES ---------------------------------*/
|
||||
|
||||
@@ -128,19 +128,20 @@ int main(int argc, char *argv[])
|
||||
printf ("config path: %s\n", the_config_path.c_str());
|
||||
|
||||
/* Setup the devices. */
|
||||
Devices the_devices(the_config_path + "/Devices.json");
|
||||
if (theDevices.load() != 0) {
|
||||
DevicesManager the_devices_manager(the_config_path + "/Devices.json");
|
||||
if (the_devices_manager.load() != 0) {
|
||||
fprintf(stderr, "Failed to load devices.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Setup the Timers. */
|
||||
Timers the_timers(the_config_path + "/Timers.json", &the_devices);
|
||||
#if 0
|
||||
Timers the_timers(the_config_path + "/Timers.json", &the_devices_manager);
|
||||
if (the_timers.load() != 0) {
|
||||
fprintf(stderr, "Failed to load timers.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
/* Setup the Ubus context. */
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "devices/Devices.h"
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
#include "timers/Event.h"
|
||||
#include "timers/event.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Event
|
||||
|
||||
@@ -31,11 +31,9 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
class DevicesManager;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
@@ -45,11 +43,11 @@ public:
|
||||
Event (void);
|
||||
~Event (void);
|
||||
|
||||
int load_from_json (Json::Value anElem);
|
||||
Json::Value to_json (void) const;
|
||||
//int load_from_json (Json::Value anElem);
|
||||
//Json::Value to_json (void) const;
|
||||
|
||||
int start (Devices *aDevices);
|
||||
int stop (Devices *aDevices);
|
||||
int start (DevicesManager *aDevices);
|
||||
int stop (DevicesManager *aDevices);
|
||||
|
||||
void dump (void);
|
||||
|
||||
|
||||
@@ -37,14 +37,14 @@
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
class DevicesManager;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Timers : public ULoopTimer {
|
||||
|
||||
public:
|
||||
Timers (const std::string &a_path, Devices *a_device);
|
||||
Timers (const std::string &a_path, DevicesManager *a_device);
|
||||
~Timers (void);
|
||||
|
||||
int expire (void);
|
||||
@@ -55,10 +55,10 @@ public:
|
||||
Event get (uint16_t anID);
|
||||
int remove (uint16_t anID);
|
||||
|
||||
Json::Value to_json (void);
|
||||
//Json::Value to_json (void);
|
||||
|
||||
private:
|
||||
Devices *mDevices;
|
||||
DevicesManager *mDevices;
|
||||
std::string mTimersPath;
|
||||
std::vector <Event> mTimers;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user