From e05c267ceca49a8c6eb566a11f58011360c5f065 Mon Sep 17 00:00:00 2001 From: jbnadal Date: Mon, 23 May 2016 18:18:54 +0200 Subject: [PATCH] WIP... --- src/domod/src/devices/Device.cpp | 24 +++++++++++++ src/domod/src/devices/Device.h | 6 +++- src/domod/src/devices/Devices.cpp | 23 ++++++++++-- src/domod/src/devices/LightDevice.cpp | 50 +++++++++++++++++++++++++++ src/domod/src/devices/LightDevice.h | 5 ++- 5 files changed, 104 insertions(+), 4 deletions(-) diff --git a/src/domod/src/devices/Device.cpp b/src/domod/src/devices/Device.cpp index 361daccf..9ed19e6f 100644 --- a/src/domod/src/devices/Device.cpp +++ b/src/domod/src/devices/Device.cpp @@ -50,3 +50,27 @@ Device::Device (void) Device::~Device (void) { } + + +/*! ---------------------------------------------------------------------------- + * @fn load_from_json + * + * @brief Load LightDevice Object From a Json Object. + */ +int Device::load_from_json (Json::Value anElem) +{ + return 0; +} + + +/*! ---------------------------------------------------------------------------- + * @fn to_json + * + * @brief Export LightDevice Object as JSON Object. + */ +Json::Value Device::to_json (void) const +{ + Json::Value theResult; + + return theResult; +} diff --git a/src/domod/src/devices/Device.h b/src/domod/src/devices/Device.h index bd59d843..0179f750 100644 --- a/src/domod/src/devices/Device.h +++ b/src/domod/src/devices/Device.h @@ -28,7 +28,8 @@ /*------------------------------- INCLUDES ----------------------------------*/ - +#include + /*---------------------------------- Deps -----------------------------------*/ @@ -39,6 +40,9 @@ class Device { public: Device (void); virtual ~Device (void); + + virtual int load_from_json (Json::Value anElem); + virtual Json::Value to_json (void) const; }; diff --git a/src/domod/src/devices/Devices.cpp b/src/domod/src/devices/Devices.cpp index 3cefb954..9612cd9d 100644 --- a/src/domod/src/devices/Devices.cpp +++ b/src/domod/src/devices/Devices.cpp @@ -30,6 +30,10 @@ #include +#include "devices/LightDevice.h" +#include "devices/ShutterDevice.h" +#include "devices/SprinklerDevice.h" + #include "devices/Devices.h" @@ -64,7 +68,7 @@ int Devices::load (void) Json::Reader theReader; Json::Value theRoot; std::ifstream theDevicesFile (mFilePath.c_str()); - + fprintf (stderr, "Devices::load...\n"); /* Load and Parse the Json File. */ if (!theReader.parse (theDevicesFile, theRoot)) { @@ -72,7 +76,22 @@ int Devices::load (void) mFilePath.c_str()); return -1; } - //TODO + + /* Open Lights. */ + LightDevice theLights; + theLights.load_from_json (theRoot["Lights"]); + mDevices["Lights"] = theLights; + + /* Open Shutters. */ + ShutterDevice theShutters; + theShutters.load_from_json (theRoot["Shutters"]); + mDevices["Shutters"] = theShutters; + + /* Open Sprinklers. */ + SprinklerDevice theSprinklers; + theSprinklers.load_from_json (theRoot["Sprinklers"]); + mDevices["Sprinklers"] = theSprinklers; + return 0; } diff --git a/src/domod/src/devices/LightDevice.cpp b/src/domod/src/devices/LightDevice.cpp index b893a2fd..1958214b 100644 --- a/src/domod/src/devices/LightDevice.cpp +++ b/src/domod/src/devices/LightDevice.cpp @@ -50,3 +50,53 @@ LightDevice::LightDevice (void) : Device() LightDevice::~LightDevice (void) { } + + +/*! ---------------------------------------------------------------------------- + * @fn load_from_json + * + * @brief Load LightDevice Object From a Json Object. + */ +int LightDevice::load_from_json (Json::Value anElem) +{ + fprintf (stderr, "LightDevice::load_from_json\n"); + return 0; +} + + +/*! ---------------------------------------------------------------------------- + * @fn to_json + * + * @brief Export LightDevice Object as JSON Object. + */ +Json::Value LightDevice::to_json (void) const +{ + fprintf (stderr, "LightDevice::to_json\n"); +} + +/* +int Timers::load (void) +{ + Json::Reader theReader; + Json::Value theRoot; + std::ifstream theTimerFile (mTimersPath.c_str()); + + if (!theReader.parse (theTimerFile, theRoot)) { + + fprintf (stderr, "Failed to parse the Timers File (%s).\n", + mTimersPath.c_str()); + return -1; + } + + for (Json::Value& theElement : theRoot["timers"]) { + Event theEvent; + if (theEvent.load_from_json (theElement) == 0) { + + mTimers.push_back (theEvent); + } + } + + Start (k60s, true); + + return 0; +}*/ diff --git a/src/domod/src/devices/LightDevice.h b/src/domod/src/devices/LightDevice.h index e91c3cd4..4580cd6e 100644 --- a/src/domod/src/devices/LightDevice.h +++ b/src/domod/src/devices/LightDevice.h @@ -44,7 +44,10 @@ class LightDevice : public Device { public: LightDevice (void); ~LightDevice (void); - + + int load_from_json (Json::Value anElem); + Json::Value to_json (void) const; + private: std::string mspeach_name; std::vector mLights;