Device as Object WIP.
This commit is contained in:
17
Domo.sublime-project
Normal file
17
Domo.sublime-project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"folders":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "3P"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "lib"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -22,6 +22,9 @@ file(
|
|||||||
../../src/devices/LightDevice.cpp
|
../../src/devices/LightDevice.cpp
|
||||||
../../src/devices/ShutterDevice.cpp
|
../../src/devices/ShutterDevice.cpp
|
||||||
../../src/devices/SprinklerDevice.cpp
|
../../src/devices/SprinklerDevice.cpp
|
||||||
|
../../src/devices/Light.cpp
|
||||||
|
../../src/devices/Shutter.cpp
|
||||||
|
../../src/devices/Sprinkler.cpp
|
||||||
../../src/ubus/capabilities.cpp
|
../../src/ubus/capabilities.cpp
|
||||||
../../src/ubus/capabilities_lights.cpp
|
../../src/ubus/capabilities_lights.cpp
|
||||||
../../src/ubus/capabilities_shutters.cpp
|
../../src/ubus/capabilities_shutters.cpp
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
#include "devices/Devices.h"
|
#include "devices/Devices.h"
|
||||||
|
|
||||||
@@ -58,6 +61,18 @@ Devices::~Devices (void)
|
|||||||
*/
|
*/
|
||||||
int Devices::load (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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,5 +122,14 @@ int Devices::load (void)
|
|||||||
*/
|
*/
|
||||||
int Devices::save (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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,6 @@
|
|||||||
|
|
||||||
#include "devices/Device.h"
|
#include "devices/Device.h"
|
||||||
|
|
||||||
#include <jsoncpp/json.h>
|
|
||||||
|
|
||||||
/*---------------------------------- Deps -----------------------------------*/
|
/*---------------------------------- Deps -----------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
90
src/domod/src/devices/Light.cpp
Normal file
90
src/domod/src/devices/Light.cpp
Normal file
@@ -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 <cstdio>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
62
src/domod/src/devices/Light.h
Normal file
62
src/domod/src/devices/Light.h
Normal file
@@ -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 <stdint.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
|
/*---------------------------------- 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 */
|
||||||
@@ -28,6 +28,10 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "devices/Light.h"
|
||||||
#include "devices/Device.h"
|
#include "devices/Device.h"
|
||||||
|
|
||||||
/*---------------------------------- Deps -----------------------------------*/
|
/*---------------------------------- Deps -----------------------------------*/
|
||||||
@@ -40,6 +44,10 @@ class LightDevice : public Device {
|
|||||||
public:
|
public:
|
||||||
LightDevice (void);
|
LightDevice (void);
|
||||||
~LightDevice (void);
|
~LightDevice (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string mspeach_name;
|
||||||
|
std::vector <Light> mLights;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
0
src/domod/src/devices/Shutter.cpp
Normal file
0
src/domod/src/devices/Shutter.cpp
Normal file
63
src/domod/src/devices/Shutter.h
Normal file
63
src/domod/src/devices/Shutter.h
Normal file
@@ -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 <stdint.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
|
/*---------------------------------- 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 */
|
||||||
0
src/domod/src/devices/Sprinkler.cpp
Normal file
0
src/domod/src/devices/Sprinkler.cpp
Normal file
58
src/domod/src/devices/Sprinkler.h
Normal file
58
src/domod/src/devices/Sprinkler.h
Normal file
@@ -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 <stdint.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
|
/*---------------------------------- 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 */
|
||||||
@@ -114,6 +114,8 @@ int main (void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
theDevices.save();
|
||||||
|
|
||||||
Capabilities theCapabilities;
|
Capabilities theCapabilities;
|
||||||
CapabilitiesLights theCapLights (&theDevices);
|
CapabilitiesLights theCapLights (&theDevices);
|
||||||
CapabilitiesShutters theCapShutters (&theDevices);
|
CapabilitiesShutters theCapShutters (&theDevices);
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include <ubuscpp/UBusCall.h>
|
#include <ubuscpp/UBusCall.h>
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
#include "devices/Devices.h"
|
#include "devices/Devices.h"
|
||||||
|
|
||||||
#include "capabilities_lights.h"
|
#include "capabilities_lights.h"
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ extern "C" {
|
|||||||
#include <libubox/blobmsg_json.h>
|
#include <libubox/blobmsg_json.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
#include "devices/Devices.h"
|
#include "devices/Devices.h"
|
||||||
|
|
||||||
#include "capabilities_shutters.h"
|
#include "capabilities_shutters.h"
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include <ubuscpp/UBusCall.h>
|
#include <ubuscpp/UBusCall.h>
|
||||||
|
|
||||||
|
#include <jsoncpp/json.h>
|
||||||
|
|
||||||
#include "devices/Devices.h"
|
#include "devices/Devices.h"
|
||||||
|
|
||||||
#include "capabilities_sprinklers.h"
|
#include "capabilities_sprinklers.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user