New Device models is functional.
This commit is contained in:
@@ -69,7 +69,7 @@ int Device::load_from_json (Json::Value anElem)
|
|||||||
*
|
*
|
||||||
* @brief Export LightDevice Object as JSON Object.
|
* @brief Export LightDevice Object as JSON Object.
|
||||||
*/
|
*/
|
||||||
Json::Value Device::to_json (void) const
|
Json::Value Device::to_json (bool bDataOnly) const
|
||||||
{
|
{
|
||||||
Json::Value theResult;
|
Json::Value theResult;
|
||||||
fprintf (stderr, "Device::to_json...\n");
|
fprintf (stderr, "Device::to_json...\n");
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
virtual ~Device (void);
|
virtual ~Device (void);
|
||||||
|
|
||||||
virtual int load_from_json (Json::Value anElem);
|
virtual int load_from_json (Json::Value anElem);
|
||||||
virtual Json::Value to_json (void) const;
|
virtual Json::Value to_json (bool bDataOnly = false) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string mspeach_name;
|
std::string mspeach_name;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ int Devices::load (void)
|
|||||||
Json::Value theRoot;
|
Json::Value theRoot;
|
||||||
std::ifstream theDevicesFile (mFilePath.c_str());
|
std::ifstream theDevicesFile (mFilePath.c_str());
|
||||||
fprintf (stderr, "Devices::load...\n");
|
fprintf (stderr, "Devices::load...\n");
|
||||||
|
|
||||||
/* Load and Parse the Json File. */
|
/* Load and Parse the Json File. */
|
||||||
if (!theReader.parse (theDevicesFile, theRoot)) {
|
if (!theReader.parse (theDevicesFile, theRoot)) {
|
||||||
|
|
||||||
@@ -103,8 +104,7 @@ int Devices::save (void)
|
|||||||
theRoot["Sprinklers"] = mSprinklers.to_json();
|
theRoot["Sprinklers"] = mSprinklers.to_json();
|
||||||
|
|
||||||
/* Save to the File. */
|
/* Save to the File. */
|
||||||
//std::ofstream theOutput (mTimersPath.c_str());
|
std::ofstream theOutput (mFilePath.c_str());
|
||||||
std::ofstream theOutput ("/tmp/toto.json");
|
|
||||||
theWriter.write (theOutput, theRoot);
|
theWriter.write (theOutput, theRoot);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -124,13 +124,15 @@ std::string Devices::get (const std::string &aCapability)
|
|||||||
|
|
||||||
if (aCapability == "Lights") {
|
if (aCapability == "Lights") {
|
||||||
|
|
||||||
theOutput[aCapability] = mLights.to_json(true);
|
theOutput[aCapability] = mLights.to_json (true);
|
||||||
}
|
}
|
||||||
else if (aCapability == "Shutters") {
|
else if (aCapability == "Shutters") {
|
||||||
|
|
||||||
|
theOutput[aCapability] = mShutters.to_json (true);
|
||||||
}
|
}
|
||||||
else if (aCapability == "Sprinklers") {
|
else if (aCapability == "Sprinklers") {
|
||||||
|
|
||||||
|
theOutput[aCapability] = mSprinklers.to_json (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return theWriter.write (theOutput).c_str();
|
return theWriter.write (theOutput).c_str();
|
||||||
@@ -138,51 +140,29 @@ std::string Devices::get (const std::string &aCapability)
|
|||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn get
|
* @fn set
|
||||||
*
|
*
|
||||||
* @brief get the device of a specific capabilities, with the ID.
|
* @brief get the device of a specific capabilities, with the ID.
|
||||||
*/
|
*/
|
||||||
Json::Value Devices::get (const std::string &aCapability, int anId)
|
int Devices::set (const std::string &aCapability, Json::Value anElement)
|
||||||
{
|
{
|
||||||
|
int theResult = -1;
|
||||||
|
|
||||||
}
|
if (aCapability == "Lights") {
|
||||||
|
|
||||||
#if 0
|
theResult = mLights.set (anElement);
|
||||||
|
}
|
||||||
|
else if (aCapability == "Shutters") {
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
theResult = mShutters.set (anElement);
|
||||||
* @fn get
|
}
|
||||||
*
|
else if (aCapability == "Sprinklers") {
|
||||||
* @brief get the list of devices of a specific capabilities.
|
|
||||||
*/
|
|
||||||
std::string Devices::get (const std::string &aCapability)
|
|
||||||
{
|
|
||||||
Json::StyledWriter theWriter;
|
|
||||||
Json::Value theOutput;
|
|
||||||
|
|
||||||
printf ("Get aCapability: %s\n", aCapability.c_str());
|
theResult = mSprinklers.set (anElement);
|
||||||
|
|
||||||
theOutput[aCapability] = mRoot[aCapability]["data"];
|
|
||||||
return theWriter.write (theOutput).c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
|
||||||
* @fn get
|
|
||||||
*
|
|
||||||
* @brief get the device of a specific capabilities, with the ID.
|
|
||||||
*/
|
|
||||||
Json::Value Devices::get (const std::string &aCapability, int anId)
|
|
||||||
{
|
|
||||||
Json::Value theResult;
|
|
||||||
for (const Json::Value& theElement : mRoot[aCapability]["data"]) {
|
|
||||||
|
|
||||||
if (theElement["id"].asInt() == anId) {
|
|
||||||
|
|
||||||
theResult = theElement;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return theResult;
|
if (theResult == 0)
|
||||||
}
|
save ();
|
||||||
|
|
||||||
#endif
|
return theResult;
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
int save (void);
|
int save (void);
|
||||||
|
|
||||||
std::string get (const std::string &aCapability);
|
std::string get (const std::string &aCapability);
|
||||||
Json::Value get (const std::string &aCapability, int anId);
|
int set (const std::string &aCapability, Json::Value anElement);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mFilePath;
|
std::string mFilePath;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <ubuscpp/UBusCall.h>
|
||||||
|
|
||||||
#include "devices/Light.h"
|
#include "devices/Light.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -88,3 +90,50 @@ Json::Value Light::to_json (void) const
|
|||||||
|
|
||||||
return aResult;
|
return aResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn update
|
||||||
|
*
|
||||||
|
* @brief Update the Light State.
|
||||||
|
*/
|
||||||
|
int Light::update (bool aState)
|
||||||
|
{
|
||||||
|
if (mState == aState)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
mState = aState;
|
||||||
|
|
||||||
|
return sendState ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn getID
|
||||||
|
*
|
||||||
|
* @brief Return the ID of the Light.
|
||||||
|
*/
|
||||||
|
uint16_t Light::getID (void)
|
||||||
|
{
|
||||||
|
return mID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn sendState
|
||||||
|
*
|
||||||
|
* @brief Send the Curent State of the Light.
|
||||||
|
*/
|
||||||
|
int Light::sendState (void)
|
||||||
|
{
|
||||||
|
UBusCall theCmd;
|
||||||
|
Json::Value theParam;
|
||||||
|
Json::StyledWriter theWriter;
|
||||||
|
std::string theResult;
|
||||||
|
|
||||||
|
theParam["sender"] = mSender;
|
||||||
|
theParam["interruptor"] = mInterruptor;
|
||||||
|
theParam["state"] = mState;
|
||||||
|
|
||||||
|
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult);
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ public:
|
|||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void) const;
|
Json::Value to_json (void) const;
|
||||||
|
|
||||||
|
int update (bool aState);
|
||||||
|
|
||||||
|
uint16_t getID (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int sendState (void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t mID;
|
uint16_t mID;
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
|||||||
@@ -103,3 +103,41 @@ Json::Value LightDevice::to_json (bool bDataOnly)
|
|||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn set
|
||||||
|
*
|
||||||
|
* @brief set the new light state.
|
||||||
|
*/
|
||||||
|
int LightDevice::set (Json::Value anElement)
|
||||||
|
{
|
||||||
|
int theID;
|
||||||
|
bool theState;
|
||||||
|
|
||||||
|
theID = anElement["id"].asInt();
|
||||||
|
theState = anElement["state"].asBool();
|
||||||
|
|
||||||
|
return set (theID, theState);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn set
|
||||||
|
*
|
||||||
|
* @brief set the new light state.
|
||||||
|
*/
|
||||||
|
int LightDevice::set (int anID, bool aState)
|
||||||
|
{
|
||||||
|
std::vector<Light>::iterator theLight_it;
|
||||||
|
|
||||||
|
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++) {
|
||||||
|
|
||||||
|
if ((*theLight_it).getID() == anID) {
|
||||||
|
|
||||||
|
return (*theLight_it).update (aState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ public:
|
|||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (bool bDataOnly = false);
|
Json::Value to_json (bool bDataOnly = false);
|
||||||
|
|
||||||
|
int set (Json::Value anElement);
|
||||||
|
int set (int anID, bool aState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Light> mLights;
|
std::vector <Light> mLights;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <ubuscpp/UBusCall.h>
|
||||||
|
|
||||||
#include "devices/Shutter.h"
|
#include "devices/Shutter.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -92,3 +94,41 @@ Json::Value Shutter::to_json (void) const
|
|||||||
|
|
||||||
return aResult;
|
return aResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn update
|
||||||
|
*
|
||||||
|
* @brief Update the Shutter State.
|
||||||
|
*/
|
||||||
|
int Shutter::update (bool aState)
|
||||||
|
{
|
||||||
|
if (mState == aState)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
mState = aState;
|
||||||
|
|
||||||
|
return sendState ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn getID
|
||||||
|
*
|
||||||
|
* @brief Return the ID of the Shutter.
|
||||||
|
*/
|
||||||
|
uint16_t Shutter::getID (void)
|
||||||
|
{
|
||||||
|
return mID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn sendState
|
||||||
|
*
|
||||||
|
* @brief Send the Curent State of the Light.
|
||||||
|
*/
|
||||||
|
int Shutter::sendState (void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ public:
|
|||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void) const;
|
Json::Value to_json (void) const;
|
||||||
|
|
||||||
|
int update (bool aState);
|
||||||
|
|
||||||
|
uint16_t getID (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int sendState (void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t mID;
|
uint16_t mID;
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ int ShutterDevice::load_from_json (Json::Value anElem)
|
|||||||
*
|
*
|
||||||
* @brief Export ShutterDevice Object as JSON Object.
|
* @brief Export ShutterDevice Object as JSON Object.
|
||||||
*/
|
*/
|
||||||
Json::Value ShutterDevice::to_json (void)
|
Json::Value ShutterDevice::to_json (bool bDataOnly)
|
||||||
{
|
{
|
||||||
Json::Value theResult;
|
Json::Value theResult;
|
||||||
Json::Value data_json(Json::arrayValue);
|
Json::Value data_json(Json::arrayValue);
|
||||||
@@ -96,5 +96,19 @@ Json::Value ShutterDevice::to_json (void)
|
|||||||
theResult["speach_name"] = mspeach_name;
|
theResult["speach_name"] = mspeach_name;
|
||||||
theResult["data"] = data_json;
|
theResult["data"] = data_json;
|
||||||
|
|
||||||
|
if (bDataOnly == true)
|
||||||
|
return data_json;
|
||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn set
|
||||||
|
*
|
||||||
|
* @brief set the new Shutter state.
|
||||||
|
*/
|
||||||
|
int ShutterDevice::set (Json::Value anElement)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ public:
|
|||||||
~ShutterDevice (void);
|
~ShutterDevice (void);
|
||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void);
|
Json::Value to_json (bool bDataOnly = false);
|
||||||
|
|
||||||
|
int set (Json::Value anElement);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Shutter> mShutter;
|
std::vector <Shutter> mShutter;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <ubuscpp/UBusCall.h>
|
||||||
|
|
||||||
#include "devices/Sprinkler.h"
|
#include "devices/Sprinkler.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -82,3 +84,49 @@ Json::Value Sprinkler::to_json (void) const
|
|||||||
|
|
||||||
return aResult;
|
return aResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn update
|
||||||
|
*
|
||||||
|
* @brief Update the Sprinkler State.
|
||||||
|
*/
|
||||||
|
int Sprinkler::update (bool aState)
|
||||||
|
{
|
||||||
|
if (mState == aState)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
mState = aState;
|
||||||
|
|
||||||
|
return sendState ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn getID
|
||||||
|
*
|
||||||
|
* @brief Return the ID of the Sprinkler.
|
||||||
|
*/
|
||||||
|
uint16_t Sprinkler::getID (void)
|
||||||
|
{
|
||||||
|
return mID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn sendState
|
||||||
|
*
|
||||||
|
* @brief Send the Curent State of the Light.
|
||||||
|
*/
|
||||||
|
int Sprinkler::sendState (void)
|
||||||
|
{
|
||||||
|
UBusCall theCmd;
|
||||||
|
Json::Value theParam;
|
||||||
|
Json::StyledWriter theWriter;
|
||||||
|
std::string theResult;
|
||||||
|
|
||||||
|
theParam["station"] = mID;
|
||||||
|
theParam["state"] = mState;
|
||||||
|
|
||||||
|
return theCmd.Exec ("sprinklers", "set", theWriter.write(theParam).c_str(),theResult);
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,6 +47,13 @@ public:
|
|||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void) const;
|
Json::Value to_json (void) const;
|
||||||
|
|
||||||
|
int update (bool aState);
|
||||||
|
|
||||||
|
uint16_t getID (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int sendState (void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t mID;
|
uint16_t mID;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ int SprinklerDevice::load_from_json (Json::Value anElem)
|
|||||||
*
|
*
|
||||||
* @brief Export SprinklerDevice Object as JSON Object.
|
* @brief Export SprinklerDevice Object as JSON Object.
|
||||||
*/
|
*/
|
||||||
Json::Value SprinklerDevice::to_json (void)
|
Json::Value SprinklerDevice::to_json (bool bDataOnly)
|
||||||
{
|
{
|
||||||
Json::Value theResult;
|
Json::Value theResult;
|
||||||
Json::Value data_json(Json::arrayValue);
|
Json::Value data_json(Json::arrayValue);
|
||||||
@@ -95,6 +95,46 @@ Json::Value SprinklerDevice::to_json (void)
|
|||||||
|
|
||||||
theResult["speach_name"] = mspeach_name;
|
theResult["speach_name"] = mspeach_name;
|
||||||
theResult["data"] = data_json;
|
theResult["data"] = data_json;
|
||||||
|
|
||||||
|
if (bDataOnly == true)
|
||||||
|
return data_json;
|
||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn set
|
||||||
|
*
|
||||||
|
* @brief set the new Sprinkler state.
|
||||||
|
*/
|
||||||
|
int SprinklerDevice::set (Json::Value anElement)
|
||||||
|
{
|
||||||
|
int theID;
|
||||||
|
bool theState;
|
||||||
|
|
||||||
|
theID = anElement["id"].asInt();
|
||||||
|
theState = anElement["state"].asBool();
|
||||||
|
|
||||||
|
return set (theID, theState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn set
|
||||||
|
*
|
||||||
|
* @brief set the new Sprinkler state.
|
||||||
|
*/
|
||||||
|
int SprinklerDevice::set (int anID, bool aState)
|
||||||
|
{
|
||||||
|
std::vector<Sprinkler>::iterator theSprinkler_it;
|
||||||
|
|
||||||
|
for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) {
|
||||||
|
|
||||||
|
if ((*theSprinkler_it).getID() == anID) {
|
||||||
|
|
||||||
|
return (*theSprinkler_it).update (aState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ public:
|
|||||||
~SprinklerDevice (void);
|
~SprinklerDevice (void);
|
||||||
|
|
||||||
int load_from_json (Json::Value anElem);
|
int load_from_json (Json::Value anElem);
|
||||||
Json::Value to_json (void);
|
Json::Value to_json (bool bDataOnly = false);
|
||||||
|
|
||||||
|
int set (Json::Value anElement);
|
||||||
|
int set (int anID, bool aState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Sprinkler> mSprinkler;
|
std::vector <Sprinkler> mSprinkler;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ extern "C" {
|
|||||||
#include <libubox/blobmsg_json.h>
|
#include <libubox/blobmsg_json.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <ubuscpp/UBusCall.h>
|
|
||||||
|
|
||||||
#include <jsoncpp/json.h>
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ int CapabilitiesLights::Put (struct ubus_context*, struct ubus_request_data*, st
|
|||||||
int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
|
int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
|
||||||
struct blob_attr *aMsg)
|
struct blob_attr *aMsg)
|
||||||
{
|
{
|
||||||
int theResult;
|
int theResult = 0;
|
||||||
struct blob_buf theBuf = {0};
|
struct blob_buf theBuf = {0};
|
||||||
char *theString = blobmsg_format_json (aMsg, true);
|
char *theString = blobmsg_format_json (aMsg, true);
|
||||||
Json::Reader theReader;
|
Json::Reader theReader;
|
||||||
@@ -139,8 +139,6 @@ int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_dat
|
|||||||
Json::Value theRoot;
|
Json::Value theRoot;
|
||||||
Json::Value theOutput;
|
Json::Value theOutput;
|
||||||
Json::Value theElement;
|
Json::Value theElement;
|
||||||
int theID;
|
|
||||||
bool theState;
|
|
||||||
fprintf (stderr,"CapabilitiesLights::Post \n");
|
fprintf (stderr,"CapabilitiesLights::Post \n");
|
||||||
|
|
||||||
if (!theReader.parse (theString, theRoot)) {
|
if (!theReader.parse (theString, theRoot)) {
|
||||||
@@ -149,17 +147,12 @@ int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_dat
|
|||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
theID = theRoot["id"].asInt();
|
if (mDevices->set ("Lights", theRoot) < 0) {
|
||||||
theState = theRoot["state"].asBool();
|
|
||||||
/* TODO
|
|
||||||
theElement = mDevices->get("Lights", theID);
|
|
||||||
theElement["state"] = theState;
|
|
||||||
|
|
||||||
if (ChangeState(theElement) == 0) {
|
fprintf (stderr, "Failed to set the new state.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
mDevices->set("Lights", theID, theElement);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
theOutput["Lights"] = theElement;
|
theOutput["Lights"] = theElement;
|
||||||
|
|
||||||
blob_buf_init (&theBuf, 0);
|
blob_buf_init (&theBuf, 0);
|
||||||
@@ -172,23 +165,3 @@ int CapabilitiesLights::Post (struct ubus_context *aCtx, struct ubus_request_dat
|
|||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
|
||||||
* @fn ChangeState
|
|
||||||
*
|
|
||||||
* @brief Get the List of the Capabilities.
|
|
||||||
*/
|
|
||||||
int CapabilitiesLights::ChangeState (const Json::Value &aLight)
|
|
||||||
{
|
|
||||||
UBusCall theCmd;
|
|
||||||
Json::Value theParam;
|
|
||||||
Json::StyledWriter theWriter;
|
|
||||||
std::string theResult;
|
|
||||||
|
|
||||||
theParam["sender"] = aLight["sender"];
|
|
||||||
theParam["interruptor"] = aLight["interruptor"];
|
|
||||||
theParam["state"] = aLight["state"];
|
|
||||||
|
|
||||||
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ public:
|
|||||||
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ChangeState (const Json::Value &aLight);
|
|
||||||
Devices *mDevices;
|
Devices *mDevices;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -148,18 +148,13 @@ int CapabilitiesSprinklers::Post (struct ubus_context *aCtx, struct ubus_request
|
|||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
theID = theRoot["id"].asInt();
|
if (mDevices->set ("Sprinklers", theRoot) < 0) {
|
||||||
theState = theRoot["state"].asBool();
|
|
||||||
/*
|
|
||||||
theElement = mDevices->get("Sprinklers", theID);
|
|
||||||
theElement["state"] = theState;
|
|
||||||
|
|
||||||
if (ChangeState(theElement) == 0) {
|
fprintf (stderr, "Failed to set the new state.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
mDevices->set ("Sprinklers", theID, theElement);
|
theOutput["Sprinklers"] = theElement;
|
||||||
}
|
|
||||||
*/
|
|
||||||
theOutput["Sprinklers"] = theElement;
|
|
||||||
|
|
||||||
blob_buf_init (&theBuf, 0);
|
blob_buf_init (&theBuf, 0);
|
||||||
|
|
||||||
@@ -171,22 +166,3 @@ int CapabilitiesSprinklers::Post (struct ubus_context *aCtx, struct ubus_request
|
|||||||
|
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
|
||||||
* @fn ChangeState
|
|
||||||
*
|
|
||||||
* @brief Change the State of an station.
|
|
||||||
*/
|
|
||||||
int CapabilitiesSprinklers::ChangeState (const Json::Value &aStation)
|
|
||||||
{
|
|
||||||
UBusCall theCmd;
|
|
||||||
Json::Value theParam;
|
|
||||||
Json::StyledWriter theWriter;
|
|
||||||
std::string theResult;
|
|
||||||
|
|
||||||
theParam["station"] = aStation["id"];
|
|
||||||
theParam["state"] = aStation["state"];
|
|
||||||
|
|
||||||
return theCmd.Exec ("sprinklers", "set", theWriter.write(theParam).c_str(),theResult);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ public:
|
|||||||
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ChangeState (const Json::Value &aStation);
|
|
||||||
Devices *mDevices;
|
Devices *mDevices;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user