From 111c608361a3958a3c3cc8e06b1b04604728a31d Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Sat, 21 May 2016 22:51:02 +0200 Subject: [PATCH] Device as Object WIP. --- Domo.sublime-project | 17 ++++ src/domod/builders/cmake/CMakeLists.txt | 3 + src/domod/src/devices/Devices.cpp | 24 +++++ src/domod/src/devices/Devices.h | 6 +- src/domod/src/devices/Light.cpp | 90 +++++++++++++++++++ src/domod/src/devices/Light.h | 62 +++++++++++++ src/domod/src/devices/LightDevice.h | 8 ++ src/domod/src/devices/Shutter.cpp | 0 src/domod/src/devices/Shutter.h | 63 +++++++++++++ src/domod/src/devices/Sprinkler.cpp | 0 src/domod/src/devices/Sprinkler.h | 58 ++++++++++++ src/domod/src/main.cpp | 2 + src/domod/src/ubus/capabilities_lights.cpp | 2 + src/domod/src/ubus/capabilities_shutters.cpp | 2 + .../src/ubus/capabilities_sprinklers.cpp | 2 + 15 files changed, 335 insertions(+), 4 deletions(-) create mode 100644 Domo.sublime-project create mode 100644 src/domod/src/devices/Light.cpp create mode 100644 src/domod/src/devices/Light.h create mode 100644 src/domod/src/devices/Shutter.cpp create mode 100644 src/domod/src/devices/Shutter.h create mode 100644 src/domod/src/devices/Sprinkler.cpp create mode 100644 src/domod/src/devices/Sprinkler.h diff --git a/Domo.sublime-project b/Domo.sublime-project new file mode 100644 index 00000000..debdbdc7 --- /dev/null +++ b/Domo.sublime-project @@ -0,0 +1,17 @@ +{ + "folders": + [ + { + "path": "." + }, + { + "path": "3P" + }, + { + "path": "lib" + }, + { + "path": "src" + } + ] +} diff --git a/src/domod/builders/cmake/CMakeLists.txt b/src/domod/builders/cmake/CMakeLists.txt index 09816bf1..fb69c338 100644 --- a/src/domod/builders/cmake/CMakeLists.txt +++ b/src/domod/builders/cmake/CMakeLists.txt @@ -22,6 +22,9 @@ file( ../../src/devices/LightDevice.cpp ../../src/devices/ShutterDevice.cpp ../../src/devices/SprinklerDevice.cpp + ../../src/devices/Light.cpp + ../../src/devices/Shutter.cpp + ../../src/devices/Sprinkler.cpp ../../src/ubus/capabilities.cpp ../../src/ubus/capabilities_lights.cpp ../../src/ubus/capabilities_shutters.cpp diff --git a/src/domod/src/devices/Devices.cpp b/src/domod/src/devices/Devices.cpp index 9096fdb7..3cefb954 100644 --- a/src/domod/src/devices/Devices.cpp +++ b/src/domod/src/devices/Devices.cpp @@ -26,6 +26,9 @@ /*------------------------------- INCLUDES ----------------------------------*/ #include +#include + +#include #include "devices/Devices.h" @@ -58,6 +61,18 @@ Devices::~Devices (void) */ int Devices::load (void) { + Json::Reader theReader; + Json::Value theRoot; + std::ifstream theDevicesFile (mFilePath.c_str()); + + /* Load and Parse the Json File. */ + if (!theReader.parse (theDevicesFile, theRoot)) { + + fprintf (stderr, "Failed to parse the Devices File (%s).\n", + mFilePath.c_str()); + return -1; + } + //TODO return 0; } @@ -107,5 +122,14 @@ int Devices::load (void) */ int Devices::save (void) { + Json::StyledStreamWriter theWriter; + + Json::Value theRoot(Json::objectValue); + + /* Save to the File. */ + //std::ofstream theOutput (mTimersPath.c_str()); + std::ofstream theOutput ("/tmp/toto.json"); + theWriter.write (theOutput, theRoot); + return 0; } diff --git a/src/domod/src/devices/Devices.h b/src/domod/src/devices/Devices.h index 0dc8c302..ddaaf0c6 100644 --- a/src/domod/src/devices/Devices.h +++ b/src/domod/src/devices/Devices.h @@ -33,8 +33,6 @@ #include "devices/Device.h" -#include - /*---------------------------------- Deps -----------------------------------*/ @@ -45,10 +43,10 @@ class Devices { public: Devices (std::string aPath); ~Devices (void); - + int load (void); int save (void); - + private: std::string mFilePath; std::map mDevices; diff --git a/src/domod/src/devices/Light.cpp b/src/domod/src/devices/Light.cpp new file mode 100644 index 00000000..68f166e6 --- /dev/null +++ b/src/domod/src/devices/Light.cpp @@ -0,0 +1,90 @@ +/*! + * Light.cpp + * + * Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 21/05/2016 + * + */ + +/*------------------------------- INCLUDES ----------------------------------*/ + +#include + +#include "devices/Light.h" + + +/*! ---------------------------------------------------------------------------- + * @fn Light + * + * @brief Constructor of the Light Object. + */ +Light::Light (void) +{ + +} + + +/*! ---------------------------------------------------------------------------- + * @fn ~Light + * + * @brief Destructor of the Light Object. + */ +Light::~Light (void) +{ + +} + + +/*! ---------------------------------------------------------------------------- + * @fn load_from_json + * + * @brief Load a Light Element from a Json Entry. + */ +int Light::load_from_json (Json::Value anElem) +{ + 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(); +} + + +/*! ---------------------------------------------------------------------------- + * @fn to_json + * + * @brief Return Light Object as a Json Object. + */ +Json::Value Light::to_json (void) const +{ + Json::Value aResult(Json::objectValue); + + aResult["id"] = mID; + aResult["name"] = mName; + aResult["speach_name"] = mSpeach_name; + aResult["zone"] = mZone; + aResult["state"] = mState; + aResult["sender"] = mSender; + aResult["interruptor"] = mInterruptor; + + return aResult; +} diff --git a/src/domod/src/devices/Light.h b/src/domod/src/devices/Light.h new file mode 100644 index 00000000..08e63424 --- /dev/null +++ b/src/domod/src/devices/Light.h @@ -0,0 +1,62 @@ +/*! + * Light.h + * + * Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 21/05/2016 + * + */ + +#ifndef _LIGHT_H +#define _LIGHT_H + +/*------------------------------- INCLUDES ----------------------------------*/ + +#include + +#include + +#include + +/*---------------------------------- Deps -----------------------------------*/ + + +/*--------------------------------- CLASS ----------------------------------*/ + +class Light { + +public: + Light (void); + ~Light (void); + + int load_from_json (Json::Value anElem); + Json::Value to_json (void) const; + +private: + uint16_t mID; + std::string mName; + std::string mSpeach_name; + std::string mZone; + bool mState; + uint32_t mSender; + uint8_t mInterruptor; +}; + + +#endif /* _LIGHT_H */ diff --git a/src/domod/src/devices/LightDevice.h b/src/domod/src/devices/LightDevice.h index ff92e114..e91c3cd4 100644 --- a/src/domod/src/devices/LightDevice.h +++ b/src/domod/src/devices/LightDevice.h @@ -28,6 +28,10 @@ /*------------------------------- INCLUDES ----------------------------------*/ +#include +#include + +#include "devices/Light.h" #include "devices/Device.h" /*---------------------------------- Deps -----------------------------------*/ @@ -40,6 +44,10 @@ class LightDevice : public Device { public: LightDevice (void); ~LightDevice (void); + +private: + std::string mspeach_name; + std::vector mLights; }; diff --git a/src/domod/src/devices/Shutter.cpp b/src/domod/src/devices/Shutter.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/domod/src/devices/Shutter.h b/src/domod/src/devices/Shutter.h new file mode 100644 index 00000000..b01cbe98 --- /dev/null +++ b/src/domod/src/devices/Shutter.h @@ -0,0 +1,63 @@ +/*! + * Shutter.h + * + * Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 21/05/2016 + * + */ + +#ifndef _SHUTTER_H +#define _SHUTTER_H + +/*------------------------------- INCLUDES ----------------------------------*/ + +#include + +#include + +#include + +/*---------------------------------- Deps -----------------------------------*/ + + +/*--------------------------------- CLASS ----------------------------------*/ + +class Shutter { + +public: + Shutter (void); + ~Shutter (void); + + int load_from_json (Json::Value anElem); + Json::Value to_json (void) const; + +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; +}; + +#endif /* _SHUTTER_H */ diff --git a/src/domod/src/devices/Sprinkler.cpp b/src/domod/src/devices/Sprinkler.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/domod/src/devices/Sprinkler.h b/src/domod/src/devices/Sprinkler.h new file mode 100644 index 00000000..1f97c738 --- /dev/null +++ b/src/domod/src/devices/Sprinkler.h @@ -0,0 +1,58 @@ +/*! + * Sprinkler.h + * + * Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 21/05/2016 + * + */ + +#ifndef _SPRINKLER_H +#define _SPRINKLER_H + +/*------------------------------- INCLUDES ----------------------------------*/ + +#include + +#include + +#include + +/*---------------------------------- Deps -----------------------------------*/ + + +/*--------------------------------- CLASS ----------------------------------*/ + +class Sprinkler { + +public: + Sprinkler (void); + ~Sprinkler (void); + + int load_from_json (Json::Value anElem); + Json::Value to_json (void) const; + +private: + uint16_t mID; + std::string mName; + std::string mSpeach_name; + bool mState; +}; + +#endif /* _SPRINKLER_H */ diff --git a/src/domod/src/main.cpp b/src/domod/src/main.cpp index b66a4cfe..5a98e205 100644 --- a/src/domod/src/main.cpp +++ b/src/domod/src/main.cpp @@ -113,6 +113,8 @@ int main (void) return -1; } + + theDevices.save(); Capabilities theCapabilities; CapabilitiesLights theCapLights (&theDevices); diff --git a/src/domod/src/ubus/capabilities_lights.cpp b/src/domod/src/ubus/capabilities_lights.cpp index 012a6c8e..1f5b76d2 100644 --- a/src/domod/src/ubus/capabilities_lights.cpp +++ b/src/domod/src/ubus/capabilities_lights.cpp @@ -31,6 +31,8 @@ extern "C" { #include +#include + #include "devices/Devices.h" #include "capabilities_lights.h" diff --git a/src/domod/src/ubus/capabilities_shutters.cpp b/src/domod/src/ubus/capabilities_shutters.cpp index c3b35b61..e0645845 100644 --- a/src/domod/src/ubus/capabilities_shutters.cpp +++ b/src/domod/src/ubus/capabilities_shutters.cpp @@ -29,6 +29,8 @@ extern "C" { #include } +#include + #include "devices/Devices.h" #include "capabilities_shutters.h" diff --git a/src/domod/src/ubus/capabilities_sprinklers.cpp b/src/domod/src/ubus/capabilities_sprinklers.cpp index 357cc8b5..69bb94a2 100644 --- a/src/domod/src/ubus/capabilities_sprinklers.cpp +++ b/src/domod/src/ubus/capabilities_sprinklers.cpp @@ -31,6 +31,8 @@ extern "C" { #include +#include + #include "devices/Devices.h" #include "capabilities_sprinklers.h"