Move all to deprecated folder.

This commit is contained in:
2016-11-16 21:57:57 +01:00
parent 01738a7684
commit 05de7d6c04
9777 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 2.8.11)
project(domod)
include (libubus)
include (libubox)
include (libubuscpp)
include (libjsoncpp)
include_directories(../../src)
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -pedantic -Werror=strict-aliasing")
file(
GLOB_RECURSE
source_files
../../src/timers/Timers.cpp
../../src/timers/Event.cpp
../../src/timers/Clock.cpp
../../src/devices/Devices.cpp
../../src/devices/Device.cpp
../../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
../../src/ubus/capabilities_sprinklers.cpp
../../src/ubus/speach_command.cpp
../../src/ubus/timers.cpp
../../src/helpers/Tokenizer.cpp
../../src/helpers/Strings.cpp
../../src/main.cpp
)
add_executable (
domod
${source_files}
)
target_link_libraries (domod
LINK_PUBLIC
jsoncpp
ubuscpp
rt
)

View File

@@ -0,0 +1,77 @@
/*!
* Device.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: 20/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include "devices/Device.h"
/*! ----------------------------------------------------------------------------
* @fn Device
*
* @brief Constructor of the Device Object.
*/
Device::Device (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Device
*
* @brief Destructor of the Device Object.
*/
Device::~Device (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load LightDevice Object From a Json Object.
*/
int Device::load_from_json (Json::Value anElem)
{
fprintf (stderr, "Device::load_from_json...\n");
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export LightDevice Object as JSON Object.
*/
Json::Value Device::to_json (bool bDataOnly) const
{
Json::Value theResult;
fprintf (stderr, "Device::to_json...\n");
return theResult;
}

View File

@@ -0,0 +1,54 @@
/*!
* Device.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: 20/05/2016
*
*/
#ifndef _DEVICE_H
#define _DEVICE_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <string>
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class Device {
public:
Device (void);
virtual ~Device (void);
virtual int load_from_json (Json::Value anElem);
virtual Json::Value to_json (bool bDataOnly = false) const;
protected:
std::string mspeach_name;
};
#endif /* _DEVICE_H */

View File

@@ -0,0 +1,197 @@
/*!
* Devices.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: 20/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include <fstream>
#include <jsoncpp/json.h>
#include "devices/Devices.h"
/*! ----------------------------------------------------------------------------
* @fn Devices
*
* @brief Constructor of the Devices Managagers.
*/
Devices::Devices (std::string aPath):
mFilePath (aPath)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Devices
*
* @brief Destructor of the Devices Managagers.
*/
Devices::~Devices (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load
*
* @brief Load the Devices from the Json File.
*/
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)) {
fprintf (stderr, "Failed to parse the Devices File (%s).\n",
mFilePath.c_str());
return -1;
}
/* Open Lights. */
mLights.load_from_json (theRoot["Lights"]);
/* Open Shutters. */
mShutters.load_from_json (theRoot["Shutters"]);
/* Open Sprinklers. */
mSprinklers.load_from_json (theRoot["Sprinklers"]);
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn save
*
* @brief Save the Devices from the Json File.
*/
int Devices::save (void)
{
Json::StyledStreamWriter theWriter;
Json::Value theRoot(Json::objectValue);
fprintf (stderr, "Devices::Save...\n");
theRoot["Lights"] = mLights.to_json();
theRoot["Shutters"] = mShutters.to_json();
theRoot["Sprinklers"] = mSprinklers.to_json();
/* Save to the File. */
std::ofstream theOutput (mFilePath.c_str());
theWriter.write (theOutput, theRoot);
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn get
*
* @brief get the list of devices of a specific capabilities.
*/
std::string Devices::get (const std::string &aCapability)
{
Json::StyledWriter theWriter;
Json::Value theOutput;
fprintf (stderr, "Devices::get...\n");
if (aCapability == "Lights") {
theOutput[aCapability] = mLights.to_json (true);
}
else if (aCapability == "Shutters") {
theOutput[aCapability] = mShutters.to_json (true);
}
else if (aCapability == "Sprinklers") {
theOutput[aCapability] = mSprinklers.to_json (true);
}
return theWriter.write (theOutput).c_str();
}
/*! ----------------------------------------------------------------------------
* @fn set
*
* @brief get the device of a specific capabilities, with the ID.
*/
int Devices::set (const std::string &aCapability, Json::Value anElement)
{
int theResult = -1;
if (aCapability == "Lights") {
theResult = mLights.set (anElement);
}
else if (aCapability == "Shutters") {
theResult = mShutters.set (anElement);
}
else if (aCapability == "Sprinklers") {
theResult = mSprinklers.set (anElement);
}
if (theResult == 0)
save ();
return theResult;
}
/*! ----------------------------------------------------------------------------
* @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 theResult = -1;
if (aCapability == "Lights") {
theResult = mLights.set (anID, aState);
}
else if (aCapability == "Shutters") {
theResult = mShutters.set (anID, aState);
}
else if (aCapability == "Sprinklers") {
theResult = mSprinklers.set (anID, aState);
}
if (theResult == 0)
save ();
return theResult;
}

View File

@@ -0,0 +1,66 @@
/*!
* Devices.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: 20/05/2016
*
*/
#ifndef _DEVICES_H
#define _DEVICES_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <string>
#include "devices/LightDevice.h"
#include "devices/ShutterDevice.h"
#include "devices/SprinklerDevice.h"
#include "devices/Device.h"
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class Devices {
public:
Devices (std::string aPath);
~Devices (void);
int load (void);
int save (void);
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 mFilePath;
LightDevice mLights;
ShutterDevice mShutters;
SprinklerDevice mSprinklers;
};
#endif /* _DEVICES_H */

View File

@@ -0,0 +1,139 @@
/*!
* 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 <ubuscpp/UBusCall.h>
#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();
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Return Light Object as a Json Object.
*/
Json::Value Light::to_json (void) const
{
Json::Value aResult(Json::objectValue);
fprintf (stderr, "Light::to_json\n");
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;
}
/*! ----------------------------------------------------------------------------
* @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);
}

View File

@@ -0,0 +1,69 @@
/*!
* 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;
int update (bool aState);
uint16_t getID (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;
};
#endif /* _LIGHT_H */

View File

@@ -0,0 +1,143 @@
/*!
* LightDevice.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: 20/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include "devices/Light.h"
#include "devices/LightDevice.h"
/*! ----------------------------------------------------------------------------
* @fn LightDevice
*
* @brief Constructor of the LightDevice Object.
*/
LightDevice::LightDevice (void) : Device()
{
}
/*! ----------------------------------------------------------------------------
* @fn LightDevice
*
* @brief Destructor of the Device Object.
*/
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");
mspeach_name = anElem["speach_name"].asString();
for (Json::Value& theElement : anElem["data"]) {
Light theLight;
if (theLight.load_from_json (theElement) == 0) {
mLights.push_back (theLight);
}
}
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export LightDevice Object as JSON Object.
*/
Json::Value LightDevice::to_json (bool bDataOnly)
{
Json::Value theResult;
Json::Value data_json(Json::arrayValue);
std::vector<Light>::iterator theLight_it;
fprintf (stderr, "LightDevice::to_json\n");
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++) {
data_json.append ((*theLight_it).to_json());
}
theResult["speach_name"] = mspeach_name;
theResult["data"] = data_json;
if (bDataOnly == true)
return data_json;
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;
}

View File

@@ -0,0 +1,59 @@
/*!
* LightDevice.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: 20/05/2016
*
*/
#ifndef _LIGHT_DEVICE_H
#define _LIGHT_DEVICE_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <vector>
#include "devices/Light.h"
#include "devices/Device.h"
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class LightDevice : public Device {
public:
LightDevice (void);
~LightDevice (void);
int load_from_json (Json::Value anElem);
Json::Value to_json (bool bDataOnly = false);
int set (Json::Value anElement);
int set (int anID, bool aState);
private:
std::vector <Light> mLights;
};
#endif /* _LIGHT_DEVICE_H */

View File

@@ -0,0 +1,134 @@
/*!
* Shutter.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 <ubuscpp/UBusCall.h>
#include "devices/Shutter.h"
/*! ----------------------------------------------------------------------------
* @fn Shutter
*
* @brief Constructor of the Shutter Object.
*/
Shutter::Shutter (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Shutter
*
* @brief Destructor of the Shutter Object.
*/
Shutter::~Shutter (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load a Shutter Element from a Json Entry.
*/
int Shutter::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();
mSpeed_up = anElem["speed_up"].asInt();
mSpeed_down = anElem["speed_down"].asInt();
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Return Shutter Object as a Json Object.
*/
Json::Value Shutter::to_json (void) const
{
Json::Value aResult(Json::objectValue);
fprintf (stderr, "Shutter::to_json\n");
aResult["id"] = mID;
aResult["name"] = mName;
aResult["zone"] = mZone;
aResult["state"] = mState;
aResult["sender"] = mSender;
aResult["interruptor"] = mInterruptor;
aResult["speed_up"] = mSpeed_up;
aResult["speed_down"] = mSpeed_down;
aResult["speach_name"] = mSpeach_name;
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;
}

View File

@@ -0,0 +1,70 @@
/*!
* 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;
int update (bool aState);
uint16_t getID (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;
};
#endif /* _SHUTTER_H */

View File

@@ -0,0 +1,125 @@
/*!
* ShutterDevice.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: 20/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include "devices/ShutterDevice.h"
/*! ----------------------------------------------------------------------------
* @fn ShutterDevice
*
* @brief Constructor of the ShutterDevice Object.
*/
ShutterDevice::ShutterDevice (void) : Device()
{
}
/*! ----------------------------------------------------------------------------
* @fn ShutterDevice
*
* @brief Destructor of the Device Object.
*/
ShutterDevice::~ShutterDevice (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load ShutterDevice Object From a Json Object.
*/
int ShutterDevice::load_from_json (Json::Value anElem)
{
fprintf (stderr, "ShutterDevice::load_from_json\n");
mspeach_name = anElem["speach_name"].asString();
for (Json::Value& theElement : anElem["data"]) {
Shutter theShutter;
if (theShutter.load_from_json (theElement) == 0) {
mShutter.push_back (theShutter);
}
}
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export ShutterDevice Object as JSON Object.
*/
Json::Value ShutterDevice::to_json (bool bDataOnly)
{
Json::Value theResult;
Json::Value data_json(Json::arrayValue);
std::vector<Shutter>::iterator theShutter_it;
fprintf (stderr, "ShutterDevice::to_json\n");
for (theShutter_it = mShutter.begin(); theShutter_it != mShutter.end(); theShutter_it++) {
data_json.append ((*theShutter_it).to_json());
}
theResult["speach_name"] = mspeach_name;
theResult["data"] = data_json;
if (bDataOnly == true)
return data_json;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn set
*
* @brief set the new Shutter state.
*/
int ShutterDevice::set (Json::Value anElement)
{
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn set
*
* @brief set the new Shutter state.
*/
int ShutterDevice::set (int anID, bool aState)
{
return 0;
}

View File

@@ -0,0 +1,58 @@
/*!
* ShutterDevice.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: 20/05/2016
*
*/
#ifndef _SHUTTER_DEVICE_H
#define _SHUTTER_DEVICE_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <vector>
#include "devices/Shutter.h"
#include "devices/Device.h"
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class ShutterDevice : public Device {
public:
ShutterDevice (void);
~ShutterDevice (void);
int load_from_json (Json::Value anElem);
Json::Value to_json (bool bDataOnly = false);
int set (Json::Value anElement);
int set (int anID, bool aState);
private:
std::vector <Shutter> mShutter;
};
#endif /* _SHUTTER_DEVICE_H */

View File

@@ -0,0 +1,132 @@
/*!
* Sprinkler.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 <ubuscpp/UBusCall.h>
#include "devices/Sprinkler.h"
/*! ----------------------------------------------------------------------------
* @fn Sprinkler
*
* @brief Constructor of the Sprinkler Object.
*/
Sprinkler::Sprinkler (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Sprinkler
*
* @brief Destructor of the Sprinkler Object.
*/
Sprinkler::~Sprinkler (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load a Sprinkler Element from a Json Entry.
*/
int Sprinkler::load_from_json (Json::Value anElem)
{
mID = anElem["id"].asInt();
mName = anElem["name"].asString();
mSpeach_name = anElem["speach_name"].asString();
mState = anElem["state"].asBool();
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Return Sprinkler Object as a Json Object.
*/
Json::Value Sprinkler::to_json (void) const
{
Json::Value aResult(Json::objectValue);
fprintf (stderr, "Sprinkler::to_json\n");
aResult["id"] = mID;
aResult["name"] = mName;
aResult["speach_name"] = mSpeach_name;
aResult["state"] = mState;
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);
}

View File

@@ -0,0 +1,65 @@
/*!
* 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;
int update (bool aState);
uint16_t getID (void);
private:
int sendState (void);
private:
uint16_t mID;
std::string mName;
std::string mSpeach_name;
bool mState;
};
#endif /* _SPRINKLER_H */

View File

@@ -0,0 +1,140 @@
/*!
* SprinklerDevice.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: 20/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include "devices/SprinklerDevice.h"
/*! ----------------------------------------------------------------------------
* @fn SprinklerDevice
*
* @brief Constructor of the SprinklerDevice Object.
*/
SprinklerDevice::SprinklerDevice (void) : Device()
{
}
/*! ----------------------------------------------------------------------------
* @fn ~SprinklerDevice
*
* @brief Destructor of the Device Object.
*/
SprinklerDevice::~SprinklerDevice (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load SprinklerDevice Object From a Json Object.
*/
int SprinklerDevice::load_from_json (Json::Value anElem)
{
fprintf (stderr, "SprinklerDevice::load_from_json\n");
mspeach_name = anElem["speach_name"].asString();
for (Json::Value& theElement : anElem["data"]) {
Sprinkler theSprinkler;
if (theSprinkler.load_from_json (theElement) == 0) {
mSprinkler.push_back (theSprinkler);
}
}
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export SprinklerDevice Object as JSON Object.
*/
Json::Value SprinklerDevice::to_json (bool bDataOnly)
{
Json::Value theResult;
Json::Value data_json(Json::arrayValue);
std::vector<Sprinkler>::iterator theSprinkler_it;
fprintf (stderr, "SprinklerDevice::to_json\n");
for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) {
data_json.append ((*theSprinkler_it).to_json());
}
theResult["speach_name"] = mspeach_name;
theResult["data"] = data_json;
if (bDataOnly == true)
return data_json;
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;
}

View File

@@ -0,0 +1,58 @@
/*!
* SprinklerDevice.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: 20/05/2016
*
*/
#ifndef _SPRINKLER_DEVICE_H
#define _SPRINKLER_DEVICE_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <vector>
#include "devices/Sprinkler.h"
#include "devices/Device.h"
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class SprinklerDevice : public Device {
public:
SprinklerDevice (void);
~SprinklerDevice (void);
int load_from_json (Json::Value anElem);
Json::Value to_json (bool bDataOnly = false);
int set (Json::Value anElement);
int set (int anID, bool aState);
private:
std::vector <Sprinkler> mSprinkler;
};
#endif /* _SPRINKLER_DEVICE_H */

View File

@@ -0,0 +1,57 @@
/*!
* strings_helpers.cpp
*
* Copyright (c) 2015, 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: 28/06/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include <locale>
#include <algorithm>
#include "Strings.h"
typedef std::string::value_type char_t;
/*! ----------------------------------------------------------------------------
* @fn SpeachCommand
*
* @brief Constructor of the UBus Speach Command execution.
*/
char_t up_char (char_t ch)
{
return std::use_facet< std::ctype< char_t > >( std::locale() ).toupper (ch);
}
/*! ----------------------------------------------------------------------------
* @fn toupper
*
* @brief method to make a toupper missing commands on the std::string.
*/
std::string toupper (const std::string &src)
{
//std::string result;
//std::transform (src.begin(), src.end(), std::back_inserter (result), up_char);
//return result;
return src;
}

View File

@@ -0,0 +1,34 @@
/*!
* strings_helpers.cpp
*
* Copyright (c) 2015, 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: 28/06/2015
*
*/
#ifndef _HELPERS_STRINGS_H
#define _HELPERS_STRINGS_H
#include <string>
std::string toupper (const std::string &src);
#endif /* _HELPERS_STRINGS_H */

View File

@@ -0,0 +1,116 @@
/*!
* Tokenizer.cpp
*
* Copyright (c) 2015, 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: 04/05/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include "Tokenizer.h"
const std::string Tokenizer::DELIMITERS(" \t\n\r");
/*! ----------------------------------------------------------------------------
* @fn Tokenizer
*
* @brief Constructor of the Tokenizer.
*/
Tokenizer::Tokenizer (const std::string& aString) :
m_offset (0),
m_string (aString),
m_delimiters (DELIMITERS) {}
/*! ----------------------------------------------------------------------------
* @fn Tokenizer
*
* @brief Constructor of the Tokenizer.
*/
Tokenizer::Tokenizer (const std::string& aString, const std::string& aDelimiters) :
m_offset (0),
m_string (aString),
m_delimiters (aDelimiters) {}
/*! ----------------------------------------------------------------------------
* @fn NextToken
*
* @brief Return true if we found another token.
*/
bool Tokenizer::NextToken (void)
{
return NextToken (m_delimiters);
}
/*! ----------------------------------------------------------------------------
* @fn NextToken
*
* @brief Return true if we found another token.
*/
bool Tokenizer::NextToken (const std::string& delimiters)
{
size_t i = m_string.find_first_not_of (delimiters, m_offset);
if (std::string::npos == i) {
m_offset = m_string.length ();
return false;
}
size_t j = m_string.find_first_of (delimiters, i);
if (std::string::npos == j) {
m_token = m_string.substr (i);
m_offset = m_string.length ();
return true;
}
m_token = m_string.substr (i, j - i);
m_offset = j;
return true;
}
/*! ----------------------------------------------------------------------------
* @fn GetToken
*
* @brief Return the Current Token.
*/
const std::string Tokenizer::GetToken (void) const
{
return m_token;
}
/*! ----------------------------------------------------------------------------
* @fn Reset
*
* @brief Return the Current Token navigation.
*/
void Tokenizer::Reset (void)
{
m_offset = 0;
}

View File

@@ -0,0 +1,55 @@
/*!
* Tokenizer.h
*
* Copyright (c) 2015, 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: 04/05/2015
*
*/
#ifndef _HELPERS_TOKENIZER_H
#define _HELPERS_TOKENIZER_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <string>
/*--------------------------------- Define ----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class Tokenizer
{
public:
static const std::string DELIMITERS;
Tokenizer (const std::string& str);
Tokenizer (const std::string& str, const std::string& delimiters);
bool NextToken ();
bool NextToken (const std::string& delimiters);
const std::string GetToken () const;
void Reset ();
protected:
size_t m_offset;
const std::string m_string;
std::string m_token;
std::string m_delimiters;
};
#endif /* _HELPERS_TOKENIZER_H */

View File

@@ -0,0 +1,158 @@
/*!
* main.cpp
*
* Copyright (c) 2015, 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: 04/03/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include <cstdio>
extern "C" {
#include <stdlib.h> /* getenv */
#include <libubus.h>
}
#include "ubus/capabilities.h"
#include "ubus/capabilities_lights.h"
#include "ubus/capabilities_shutters.h"
#include "ubus/capabilities_sprinklers.h"
#include "ubus/speach_command.h"
#include "ubus/timers.h"
#include "timers/Timers.h"
#include "devices/Devices.h"
/*--------------------------------- GLOBALS ---------------------------------*/
/*! ----------------------------------------------------------------------------
* @fn setupUbus
*
* @brief Setup the UBus Mechanism.
*/
extern "C" {
static struct ubus_context *setupUbus (void)
{
ubus_context *theCtx;
if (uloop_init () !=0) {
fprintf (stderr, "Failed to init Uloop.\n");
return NULL;
}
signal (SIGPIPE, SIG_IGN);
theCtx = ubus_connect (NULL);
if (!theCtx) {
fprintf (stderr, "Failed to connect to ubus\n");
return NULL;
}
ubus_add_uloop (theCtx);
return theCtx;
}
} // SetupUbus.
/*! ----------------------------------------------------------------------------
* @fn main
*
* @brief Main function of Domo Daemon.
*/
int main (void)
{
int theRet = 0;
char *theWritePath;
std::string theDevicePath, theTimerPath;
struct ubus_context *theCtx = NULL;
theWritePath = getenv ("DOMO_WRITE_PATH");
if (theWritePath == NULL) {
fprintf (stderr, "you should export DOMO_WRITE_PATH. with the Path of data.\n");
return -1;
}
// Create Configs Paths...
theDevicePath = theWritePath;
theDevicePath += "/Devices.json";
theTimerPath = theWritePath;
theTimerPath += "/Timers.json";
//printf ("DOMO PATH: %s\n", thePath.c_str());
Devices theDevices (theDevicePath);
if (theDevices.load() != 0) {
return -1;
}
/* Setup the Timers. */
Timers theTimers (theTimerPath, &theDevices);
if (theTimers.load() != 0) {
return -1;
}
/* Setup the UBus Models. */
CapabilitiesModel theCapabilities;
CapabilitiesLightsModel theCapLights (&theDevices);
CapabilitiesShuttersModel theCapShutters (&theDevices);
CapabilitiesSprinklersModel theCapSprinklers (&theDevices);
SpeachCommandModel theSpeachCommand (&theDevices);
TimersModel theTimersModel (&theTimers);
/* Setup the Ubus context. */
theCtx = setupUbus ();
if (theCtx == NULL) {
return -1;
}
/* Add the UBus to the model exposed. */
ubus_add_object (theCtx, &theCapabilities);
ubus_add_object (theCtx, &theCapLights);
ubus_add_object (theCtx, &theCapShutters);
ubus_add_object (theCtx, &theCapSprinklers);
ubus_add_object (theCtx, &theSpeachCommand);
ubus_add_object (theCtx, &theTimersModel);
/* Main Event Loop. */
uloop_run ();
ubus_free (theCtx);
uloop_done ();
return theRet;
}

View File

@@ -0,0 +1,205 @@
/*!
* Devices.cpp
*
* Copyright (c) 2015, 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: 27/03/2015
*
*/
#error deprecated
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include <iostream>
#include <fstream>
#include "helpers/Strings.h"
#include "Devices.h"
/*! ----------------------------------------------------------------------------
* @fn Devices
*
* @brief Constructor of the Devices Models.
*/
Devices::Devices (std::string aPath):
mDevicesPath (aPath)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Devices
*
* @brief Destructor of the Devices Models.
*/
Devices::~Devices (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Load
*
* @brief Load the Device object.
*/
int Devices::Load (void)
{
Json::Reader theReader;
std::ifstream theDevicesFile (mDevicesPath.c_str());
if (!theReader.parse (theDevicesFile, mRoot)) {
fprintf (stderr, "Failed to parse the Devices File (%s).\n",
mDevicesPath.c_str());
return -1;
}
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn get
*
* @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());
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;
}
/*! ----------------------------------------------------------------------------
* @fn set
*
* @brief get the device of a specific capabilities, with the ID.
*/
int Devices::set (const std::string &aCapability, int anId, const Json::Value &aNewElement)
{
bool theStateChange = false;
for (Json::Value& theElement : mRoot[aCapability]["data"]) {
if (theElement["id"].asInt() == anId) {
Json::Value::Members memberNames = theElement.getMemberNames();
for(unsigned int i=0; i<memberNames.size(); ++i) {
std::string theMName = memberNames[i];
if (theElement[theMName] != aNewElement[theMName]) {
theElement[theMName] = aNewElement[theMName];
theStateChange = true;
}
}
}
}
if (theStateChange) {
printf ("Model Change, We save it....\n");
Json::StyledStreamWriter theWriter;
std::ofstream theOutput (mDevicesPath);
theWriter.write (theOutput,mRoot);
}
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn setDevice
*
* @brief get the device of a specific capabilities, with the ID.
*/
bool Devices::setDevice (const std::string &aCapability,
const std::string &aDeviceName, bool aState)
{
fprintf (stdout, "setDevice cap:%s deviceName: %s\n", aCapability.c_str(),
aDeviceName.c_str());
for (Json::Value& theCap : mRoot) {
fprintf (stdout, "ici: %s\n", theCap["speach_name"].asString().c_str());
if (theCap["speach_name"].asString() == aCapability) {
for (Json::Value& theElement : theCap["data"]) {
if (theElement["speach_name"].asString() == aDeviceName) {
fprintf (stdout, "Device found.\n");
if (theElement["state"] != aState) {
printf ("Model Change, We save it....\n");
Json::StyledStreamWriter theWriter;
std::ofstream theOutput (mDevicesPath);
theWriter.write (theOutput,mRoot);
//TODO faire le chemin la bonne capability.
return true;
}
}
}
}
}
return false;
}
/*! ----------------------------------------------------------------------------
* @fn isCapability
*
* @brief return true if the capability is available.
*/
bool Devices::isCapability (const std::string &aCapability)
{
fprintf (stdout, "try to found: %s\n", aCapability.c_str());
for (Json::Value& theElement : mRoot) {
fprintf (stdout, "ici: %s\n", theElement["speach_name"].asString().c_str());
if (toupper(theElement["speach_name"].asString()) == aCapability)
return true;
}
return false;
}

View File

@@ -0,0 +1,57 @@
/*!
* Devices.h
*
* Copyright (c) 2015, 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: 27/03/2015
*
*/
#error deprecated
#ifndef _MODELS_DEVICES_H
#define _MODELS_DEVICES_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <jsoncpp/json.h>
#include <string>
class Devices {
public:
Devices (std::string aPath);
~Devices (void);
int Load (void);
std::string get (const std::string &aCapability);
Json::Value get (const std::string &aCapability, int anId);
int set (const std::string &aCapability, int anId, const Json::Value &anElement);
bool setDevice (const std::string &aCapability,
const std::string &aDeviceName, bool aState);
bool isCapability (const std::string &aCapability);
private:
std::string mDevicesPath;
Json::Value mRoot;
};
#endif /* _MODELS_DEVICES_H */

View File

@@ -0,0 +1,119 @@
/*!
* Clock.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: 20/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include "timers/Clock.h"
/*! ----------------------------------------------------------------------------
* @fn Clock
*
* @brief Constructor of the Clock Object.
*/
Clock::Clock (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Clock
*
* @brief Destructor of the Clock Object.
*/
Clock::~Clock (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn isEqual
*
* @brief Set an Event to the Clock.
*/
int Clock::set (const Event &anEvent)
{
mEvent = anEvent;
mNow = time (NULL);
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn isEqualToCurrentTime
*
* @brief return true if the clock is equal to current time.
*/
bool Clock::isEqualToCurrentTime (void)
{
struct tm theComparedTime;
double theDiff;
theComparedTime = *localtime (&mNow);
theComparedTime.tm_hour = mEvent.getHour();
theComparedTime.tm_min = mEvent.getMinute();
theDiff = difftime (mNow, mktime (&theComparedTime));
//printf ("%.f seconds of diff between current time and Timer time.\n", theDiff);
if (theDiff == 0)
return true;
return false;
}
/*! ----------------------------------------------------------------------------
* @fn isExpired
*
* @brief Return true if the curent time has expired.
*/
bool Clock::isExpired (void)
{
time_t theExpired;
struct tm theComparedTime;
double theDiff;
theComparedTime = *localtime (&mNow);
theComparedTime.tm_hour = mEvent.getHour();
theComparedTime.tm_min = mEvent.getMinute();
theExpired = mktime (&theComparedTime) + (mEvent.getDuration() * 60);
theDiff = difftime (mNow, theExpired);
//printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired);
if (theDiff == 0)
return true;
return false;
}

View File

@@ -0,0 +1,54 @@
/*!
* Clock.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: 20/05/2016
*
*/
#ifndef _CLOCK_H
#define _CLOCK_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <ctime>
#include "timers/Event.h"
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class Clock {
public:
Clock (void);
~Clock (void);
int set (const Event &anEvent);
bool isEqualToCurrentTime (void);
bool isExpired (void);
private:
Event mEvent;
time_t mNow;
};
#endif /* _CLOCK_H */

View File

@@ -0,0 +1,285 @@
/*!
* Event.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: 19/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include "devices/Devices.h"
#include "timers/Event.h"
/*! ----------------------------------------------------------------------------
* @fn Event
*
* @brief Constructor of Timer Event Object.
*/
Event::Event (void):
mActive(false),
mID(0),
mDeviceID(0),
mHour(0),
mMinute(0),
mRecurrence(0),
mDuration(0),
mInProgress (false)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Event
*
* @brief Destructor of Timer Event Object.
*/
Event::~Event (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load Event Object.
*/
int Event::load_from_json (Json::Value anElem)
{
std::size_t theSeparator;
std::string::size_type sz; // alias of size_t
mID = anElem["id"].asInt();
mActive = anElem["active"].asBool();
std::string theIDElem = anElem["id"].asString();
theSeparator = theIDElem.find_last_of("/");
mCapability = theIDElem.substr(0, theSeparator);
mDeviceID = std::stoi (theIDElem.substr (theSeparator + 1), &sz);
std::string theStarTime = anElem["start_time"].asString();
theSeparator = theStarTime.find_last_of(":");
mHour = std::stoi (theStarTime.substr (0, theSeparator), &sz);
mMinute = std::stoi (theStarTime.substr (theSeparator + 1), &sz);
mRecurrence = anElem["recurrence"].asInt();
mDuration = anElem["duration"].asInt();
mAction = anElem["action"].asString();
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export Event Object as JSON Object.
*/
Json::Value Event::to_json (void) const
{
Json::Value aResult(Json::objectValue);
aResult ["id"] = mID;
aResult ["active"] = mActive;
aResult ["device_id"] = mCapability + "/" + std::to_string(mDeviceID);
aResult ["action"] = mAction;
aResult["recurrence"] = mRecurrence;
aResult["duration"] = mDuration;
aResult["start_time"] = std::to_string(mHour) + ":" + std::to_string(mMinute);
return aResult;
}
/*! ----------------------------------------------------------------------------
* @fn start
*
* @brief Stop the Event.
*/
int Event::start (Devices *aDevices)
{
setInProgress (true);
return aDevices->set (mCapability.c_str(), mDeviceID, true);
}
/*! ----------------------------------------------------------------------------
* @fn stop
*
* @brief Stop the Event.
*/
int Event::stop (Devices *aDevices)
{
setInProgress (false);
return aDevices->set (mCapability.c_str(), mDeviceID, false);
}
/*! ----------------------------------------------------------------------------
* @fn dump
*
* @brief dump the Event Object.
*/
void Event::dump (void)
{
fprintf (stdout, "Timer Event:\n");
fprintf (stdout, "=========== \n");
fprintf (stdout, " - active: %s\n", (mActive?"true":"false"));
fprintf (stdout, " - capability: %s\n", mCapability.c_str());
fprintf (stdout, " - id: %d\n", mID);
fprintf (stdout, " - device_id: %d\n", mDeviceID);
fprintf (stdout, " - Time: %2d:%2d\n", mHour, mMinute);
fprintf (stdout, " - recurrence: %d\n", mRecurrence);
fprintf (stdout, " - duration: %d\n", mDuration);
fprintf (stdout, " - action: %s\n", mAction.c_str());
}
/*! ----------------------------------------------------------------------------
* @fn isActive
*
* @brief return true if the Timer event is active.
*/
bool Event::isActive (void) const
{
return mActive;
}
/*! ----------------------------------------------------------------------------
* @fn getCapability
*
* @brief return the capability of the Event.
*/
std::string Event::getCapability (void) const
{
return mCapability;
}
/*! ----------------------------------------------------------------------------
* @fn getID
*
* @brief return the ID of the Event.
*/
uint16_t Event::getID (void) const
{
return mID;
}
/*! ----------------------------------------------------------------------------
* @fn getDeviceID
*
* @brief return the Device ID of the Event.
*/
uint16_t Event::getDeviceID (void) const
{
return mDeviceID;
}
/*! ----------------------------------------------------------------------------
* @fn getHour
*
* @brief Return the Hour of the Event.
*/
uint8_t Event::getHour (void) const
{
return mHour;
}
/*! ----------------------------------------------------------------------------
* @fn getMinute
*
* @brief Return the Minute of the Event.
*/
uint8_t Event::getMinute (void) const
{
return mMinute;
}
/*! ----------------------------------------------------------------------------
* @fn getRecurrence
*
* @brief Return the Recurrency of the Event.
*/
uint16_t Event::getRecurrence (void) const
{
return mRecurrence;
}
/*! ----------------------------------------------------------------------------
* @fn getDuration
*
* @brief Return the Duration of the Event.
*/
uint16_t Event::getDuration (void) const
{
return mDuration;
}
/*! ----------------------------------------------------------------------------
* @fn getAction
*
* @brief Return the Action of the Event.
*/
std::string Event::getAction (void) const
{
return mAction;
}
/*! ----------------------------------------------------------------------------
* @fn isInProgress
*
* @brief Return true if the Event Is in Progress.
*/
bool Event::isInProgress (void) const
{
return mInProgress;
}
/*! ----------------------------------------------------------------------------
* @fn setInProgress
*
* @brief Set the InProgress to a new state.
*/
void Event::setInProgress (bool aState)
{
mInProgress = aState;
}

View File

@@ -0,0 +1,84 @@
/*!
* Event.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: 19/05/2016
*
*/
#ifndef _EVENT_H
#define _EVENT_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <string>
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/
class Devices;
/*--------------------------------- CLASS ----------------------------------*/
class Event {
public:
Event (void);
~Event (void);
int load_from_json (Json::Value anElem);
Json::Value to_json (void) const;
int start (Devices *aDevices);
int stop (Devices *aDevices);
void dump (void);
/* Getter */
bool isActive (void) const;
std::string getCapability (void) const;
uint16_t getID (void) const;
uint16_t getDeviceID (void) const;
uint8_t getHour (void) const;
uint8_t getMinute (void) const;
uint16_t getRecurrence (void) const;
uint16_t getDuration (void) const;
std::string getAction (void) const;
bool isInProgress (void) const;
/* Setter */
void setInProgress (bool aState);
private:
bool mActive;
std::string mCapability;
uint16_t mID;
uint16_t mDeviceID;
uint8_t mHour;
uint8_t mMinute;
uint16_t mRecurrence;
uint16_t mDuration;
std::string mAction;
bool mInProgress;
};
#endif /* _EVENT_H */

View File

@@ -0,0 +1,217 @@
/*!
* Timers.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: 17/05/2016
*
*/
/*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio>
#include <ctime>
#include <iostream>
#include <fstream>
#include "devices/Devices.h"
#include "timers/Timers.h"
#include "timers/Clock.h"
//#define k60s 60000
#define k60s 2000
/*! ----------------------------------------------------------------------------
* @fn Timers
*
* @brief Constructor of the Timers Managagers.
*/
Timers::Timers (std::string aPath, Devices *aDevice):
mDevices (aDevice),
mTimersPath (aPath)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~Timers
*
* @brief Destructors of the Timer Managers.
*/
Timers::~Timers (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load
*
* @brief Load the Timer Managers.
*/
int Timers::load (void)
{
Json::Reader theReader;
Json::Value theRoot;
std::ifstream theTimerFile (mTimersPath.c_str());
/* Read and Parse the Json file. */
if (!theReader.parse (theTimerFile, theRoot)) {
fprintf (stderr, "Failed to parse the Timers File (%s).\n",
mTimersPath.c_str());
return -1;
}
/* Create the Objects.. */
for (Json::Value& theElement : theRoot["timers"]) {
Event theEvent;
if (theEvent.load_from_json (theElement) == 0) {
mTimers.push_back (theEvent);
}
}
Start (k60s, true);
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn save
*
* @brief Method to save the Timers Object into a Json File.
*/
int Timers::save (void)
{
Json::StyledStreamWriter theWriter;
/* Save to the File. */
std::ofstream theOutput (mTimersPath.c_str());
theWriter.write (theOutput, to_json());
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn get
*
* @brief Method to get a specific Timers Object.
*/
Event Timers::get (uint16_t anID)
{
std::vector<Event>::iterator timer_evt;
for (timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) {
if ((*timer_evt).getID() == anID)
return (*timer_evt);
}
}
/*! ----------------------------------------------------------------------------
* @fn remove
*
* @brief Method to remove a specific Timers Object.
*/
int Timers::remove (uint16_t anID)
{
std::vector<Event>::iterator timer_evt;
for (timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) {
if ((*timer_evt).getID() == anID)
mTimers.erase (timer_evt);
return 0;
}
return -1;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Method to return the Timers Object into a Json formar into a Json Object.
*/
Json::Value Timers::to_json (void)
{
std::vector<Event>::iterator timer_evt;
Json::Value theRoot(Json::objectValue), timers_json(Json::arrayValue);
for (timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) {
timers_json.append ((*timer_evt).to_json());
}
theRoot["timers"] = timers_json;
return theRoot;
}
/*! ----------------------------------------------------------------------------
* @fn Expire
*
* @brief Method Call when the Timer has expired.
*/
int Timers::Expire (void)
{
std::vector<Event>::iterator timer_evt;
Clock theClock;
fprintf (stderr, "**** >> Manage timers....\n");
for(timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) {
if ((*timer_evt).isActive()) {
theClock.set ((*timer_evt));
if ((*timer_evt).isInProgress()) {
if (theClock.isExpired()) {
// Action Stop.
fprintf (stdout, "Timer Stop\n");
(*timer_evt).stop (mDevices);
}
else {
fprintf (stdout, "Not expired yet.\n");
}
}
else {
if (theClock.isEqualToCurrentTime ()) {
// Action START.
fprintf (stdout, "Timer Start\n");
(*timer_evt).start (mDevices);
}
}
}
}
return 0;
}

View File

@@ -0,0 +1,68 @@
/*!
* Timers.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: 17/05/2016
*
*/
#ifndef _TIMERS_H
#define _TIMERS_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <string>
#include <vector>
#include <jsoncpp/json.h>
#include "ubuscpp/UBusTimer.h"
#include "timers/Event.h"
/*---------------------------------- Deps -----------------------------------*/
class Devices;
/*--------------------------------- CLASS ----------------------------------*/
class Timers : public UBusTimer {
public:
Timers (std::string aPath, Devices *aDevice);
~Timers (void);
int Expire (void);
int load (void);
int save (void);
Event get (uint16_t anID);
int remove (uint16_t anID);
Json::Value to_json (void);
private:
Devices *mDevices;
std::string mTimersPath;
std::vector <Event> mTimers;
};
#endif /* _TIMERS_H */

View File

@@ -0,0 +1,96 @@
/*!
* capabilities.cpp
*
* Copyright (c) 2015, 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: 23/03/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include <fstream>
#include <string>
#include <sstream>
extern "C" {
#include <libubox/blobmsg_json.h>
}
#include "capabilities.h"
namespace {
using namespace UBus;
static ObjectType gCapabilitiesModelUbus_types(
"capabilities",
Method("get", UBUS_CPP(CapabilitiesModel, Get))
);
}
/*! ----------------------------------------------------------------------------
* @fn CapabilitiesModel
*
* @brief Constructor of the UBus Mixer Volume.
*/
CapabilitiesModel::CapabilitiesModel (void) :
UBusObject (gCapabilitiesModelUbus_types, "domo.capabilities")
{
}
/*! ----------------------------------------------------------------------------
* @fn ~CapabilitiesModel
*
* @brief Destructor of the UBus Mixer Volume.
*/
CapabilitiesModel::~CapabilitiesModel (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Get
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult;
struct blob_buf theBuf = {0};
std::ifstream theCapFile ("./rsc/capabilities.json");
std::stringstream theBuffer;
theBuffer << theCapFile.rdbuf();
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf, theBuffer.str().c_str());
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}

View File

@@ -0,0 +1,50 @@
/*!
* capabilities.h
*
* Copyright (c) 2015, 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: 23/03/2015
*
*/
#ifndef _UBUS_CAPABILITIES_MODEL_H
#define _UBUS_CAPABILITIES_MODEL_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <ubuscpp/UBusObject.h>
/*--------------------------------- Define ----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class CapabilitiesModel : public UBusObject {
public:
CapabilitiesModel (void);
~CapabilitiesModel (void);
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private:
};
#endif /* _UBUS_CAPABILITIES_MODEL_H */

View File

@@ -0,0 +1,167 @@
/*!
* capabilities_lights.cpp
*
* Copyright (c) 2015, 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: 24/03/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
extern "C" {
#include <libubox/blobmsg_json.h>
}
#include <jsoncpp/json.h>
#include "devices/Devices.h"
#include "capabilities_lights.h"
namespace {
using namespace UBus;
static ObjectType gCapabilitiesLightsUbus_types(
"lights",
Method("get", UBUS_CPP(CapabilitiesLightsModel, Get)),
Method("delete", UBUS_CPP(CapabilitiesLightsModel, Delete)),
Method("put", UBUS_CPP(CapabilitiesLightsModel, Put)),
Method("post", UBUS_CPP(CapabilitiesLightsModel, Post))
);
}
/*! ----------------------------------------------------------------------------
* @fn CapabilitiesLightsModel
*
* @brief Constructor of the UBus Mixer Volume.
*/
CapabilitiesLightsModel::CapabilitiesLightsModel (Devices *aDevice) :
UBusObject (gCapabilitiesLightsUbus_types, "domo.capabilities.lights"),
mDevices (aDevice)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~CapabilitiesLightsModel
*
* @brief Destructor of the UBus Mixer Volume.
*/
CapabilitiesLightsModel::~CapabilitiesLightsModel (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Get
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesLightsModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult;
struct blob_buf theBuf = {0};
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf, mDevices->get("Lights").c_str());
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Delete
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesLightsModel::Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Put
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesLightsModel::Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Post
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesLightsModel::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult = 0;
struct blob_buf theBuf = {0};
char *theString = blobmsg_format_json (aMsg, true);
Json::Reader theReader;
Json::StyledWriter theWriter;
Json::Value theRoot;
Json::Value theOutput;
Json::Value theElement;
fprintf (stderr,"CapabilitiesLights::Post \n");
if (!theReader.parse (theString, theRoot)) {
fprintf (stderr, "Failed parse the parameters.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
if (mDevices->set ("Lights", theRoot) < 0) {
fprintf (stderr, "Failed to set the new state.\n");
return -1;
}
theOutput["Lights"] = theElement;
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf, theWriter.write(theOutput).c_str());
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}

View File

@@ -0,0 +1,59 @@
/*!
* capabilities_lights.h
*
* Copyright (c) 2015, 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: 24/03/2015
*
*/
#ifndef _UBUS_CAPABILITIES_LIGHTS_MODEL_H
#define _UBUS_CAPABILITIES_LIGHTS_MODEL_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <jsoncpp/json.h>
#include <ubuscpp/UBusObject.h>
/*--------------------------------- Define ----------------------------------*/
class Devices;
/*--------------------------------- CLASS ----------------------------------*/
class CapabilitiesLightsModel : public UBusObject {
public:
CapabilitiesLightsModel (Devices *aDevice);
~CapabilitiesLightsModel (void);
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private:
Devices *mDevices;
};
#endif /* _UBUS_CAPABILITIES_LIGHTS_MODEL_H */

View File

@@ -0,0 +1,204 @@
/*!
* capabilities_shutters.cpp
*
* Copyright (c) 2015, 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: 24/03/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
extern "C" {
#include <libubox/blobmsg_json.h>
}
#include <jsoncpp/json.h>
#include "devices/Devices.h"
#include "capabilities_shutters.h"
namespace {
using namespace UBus;
static ObjectType gCapabilitiesShuttersModelUbus_types(
"shutters",
Method("get", UBUS_CPP(CapabilitiesShuttersModel, Get)),
Method("delete", UBUS_CPP(CapabilitiesShuttersModel, Delete)),
Method("put", UBUS_CPP(CapabilitiesShuttersModel, Put)),
Method("post", UBUS_CPP(CapabilitiesShuttersModel, Post)),
Method("open", UBUS_CPP(CapabilitiesShuttersModel, Open)),
Method("close", UBUS_CPP(CapabilitiesShuttersModel, Close)),
Method("up", UBUS_CPP(CapabilitiesShuttersModel, Up)),
Method("down", UBUS_CPP(CapabilitiesShuttersModel, Down)),
Method("position", UBUS_CPP(CapabilitiesShuttersModel, Position))
);
}
/*! ----------------------------------------------------------------------------
* @fn CapabilitiesShuttersModel
*
* @brief Constructor of the UBus Mixer Volume.
*/
CapabilitiesShuttersModel::CapabilitiesShuttersModel (Devices *aDevice) :
UBusObject (gCapabilitiesShuttersModelUbus_types, "domo.capabilities.shutters"),
mDevices (aDevice)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~CapabilitiesShuttersModel
*
* @brief Destructor of the UBus Mixer Volume.
*/
CapabilitiesShuttersModel::~CapabilitiesShuttersModel (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Get
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult;
struct blob_buf theBuf = {0};
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf, mDevices->get("Shutters").c_str());
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Delete
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Put
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Post
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Open
*
* @brief Open the Shutter
*/
int CapabilitiesShuttersModel::Open (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
printf ("Open the Shutter\n");
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Close
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Close (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
printf ("Close the Shutter\n");
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Up
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Up (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
printf ("Up the Shutter\n");
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Down
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Down (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
printf ("Down the Shutter\n");
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Position
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesShuttersModel::Position (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
printf ("Position the Shutter\n");
return theResult;
}

View File

@@ -0,0 +1,64 @@
/*!
* capabilities_shutters.h
*
* Copyright (c) 2015, 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: 24/03/2015
*
*/
#ifndef _UBUS_CAPABILITIES_SHUTTERS_MODEL_H
#define _UBUS_CAPABILITIES_SHUTTERS_MODEL_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <ubuscpp/UBusObject.h>
/*--------------------------------- Define ----------------------------------*/
class Devices;
/*--------------------------------- CLASS ----------------------------------*/
class CapabilitiesShuttersModel : public UBusObject {
public:
CapabilitiesShuttersModel (Devices *aDevice);
~CapabilitiesShuttersModel (void);
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Open (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Close (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Up (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Down (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Position (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private:
Devices *mDevices;
};
#endif /* _UBUS_CAPABILITIES_SHUTTERS_MODEL_H */

View File

@@ -0,0 +1,168 @@
/*!
* capabilities_sprinklers.cpp
*
* Copyright (c) 2015, 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: 24/03/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
extern "C" {
#include <libubox/blobmsg_json.h>
}
#include <ubuscpp/UBusCall.h>
#include <jsoncpp/json.h>
#include "devices/Devices.h"
#include "capabilities_sprinklers.h"
namespace {
using namespace UBus;
static ObjectType gCapabilitiesSprinklersModelUbus_types(
"sprinklers",
Method("get", UBUS_CPP(CapabilitiesSprinklersModel, Get)),
Method("delete", UBUS_CPP(CapabilitiesSprinklersModel, Delete)),
Method("put", UBUS_CPP(CapabilitiesSprinklersModel, Put)),
Method("post", UBUS_CPP(CapabilitiesSprinklersModel, Post))
);
}
/*! ----------------------------------------------------------------------------
* @fn CapabilitiesSprinkler
*
* @brief Constructor of the UBus Mixer Volume.
*/
CapabilitiesSprinklersModel::CapabilitiesSprinklersModel (Devices *aDevice) :
UBusObject (gCapabilitiesSprinklersModelUbus_types, "domo.capabilities.sprinklers"),
mDevices (aDevice)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~CapabilitiesSprinklersModel
*
* @brief Destructor of the UBus Mixer Volume.
*/
CapabilitiesSprinklersModel::~CapabilitiesSprinklersModel (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Get
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesSprinklersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult;
struct blob_buf theBuf = {0};
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf, mDevices->get("Sprinklers").c_str());
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Delete
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesSprinklersModel::Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Put
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesSprinklersModel::Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
int theResult = 0;
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Post
*
* @brief Get the List of the Capabilities.
*/
int CapabilitiesSprinklersModel::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult;
struct blob_buf theBuf = {0};
char *theString = blobmsg_format_json (aMsg, true);
Json::Reader theReader;
Json::StyledWriter theWriter;
Json::Value theRoot;
Json::Value theOutput;
Json::Value theElement;
int theID;
bool theState;
fprintf (stderr,"CapabilitiesSprinklersModel::Post \n");
if (!theReader.parse (theString, theRoot)) {
fprintf (stderr, "Failed parse the parameters.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
if (mDevices->set ("Sprinklers", theRoot) < 0) {
fprintf (stderr, "Failed to set the new state.\n");
return -1;
}
theOutput["Sprinklers"] = theElement;
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf, theWriter.write(theOutput).c_str());
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}

View File

@@ -0,0 +1,56 @@
/*!
* capabilities_sprinklers.h
*
* Copyright (c) 2015, 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: 24/03/2015
*
*/
#ifndef _UBUS_CAPABILITIES_SPRINKLERS_MODEL_H
#define _UBUS_CAPABILITIES_SPRINKLERS_MODEL_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <ubuscpp/UBusObject.h>
/*--------------------------------- Define ----------------------------------*/
class Devices;
/*--------------------------------- CLASS ----------------------------------*/
class CapabilitiesSprinklersModel : public UBusObject {
public:
CapabilitiesSprinklersModel (Devices *aDevice);
~CapabilitiesSprinklersModel (void);
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private:
Devices *mDevices;
};
#endif /* _UBUS_CAPABILITIES_SPRINKLERS_MODEL_H */

View File

@@ -0,0 +1,183 @@
/*!
* speach_command.cpp
*
* Copyright (c) 2015, 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: 04/05/2015
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include <vector>
extern "C" {
#include <libubox/blobmsg_json.h>
}
#include <ubuscpp/UBusCall.h>
#include "devices/Devices.h"
#include "helpers/Tokenizer.h"
#include "helpers/Strings.h"
#include "speach_command.h"
namespace {
using namespace UBus;
static ObjectType gSpeachCommandModelUbus_types(
"speach",
Method("post", UBUS_CPP(SpeachCommandModel, Post))
);
}
/*! ----------------------------------------------------------------------------
* @fn SpeachCommandModel
*
* @brief Constructor of the UBus Speach Command execution.
*/
SpeachCommandModel::SpeachCommandModel (Devices *aDevice) :
UBusObject (gSpeachCommandModelUbus_types, "domo.speach.command"),
mDevices (aDevice)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~SpeachCommandModel
*
* @brief Destructor of the UBus Speach Command execution.
*/
SpeachCommandModel::~SpeachCommandModel (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Post
*
* @brief Get the List of the Capabilities.
*/
int SpeachCommandModel::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult = 0;
struct blob_buf theBuf = {0};
char *theString = blobmsg_format_json (aMsg, true);
Json::Reader theReader;
Json::Value theRoot;
std::string theCommand;
if (!theReader.parse (theString, theRoot)) {
fprintf (stderr, "Failed parse the parameters.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
theCommand = theRoot["command"].asString();
if (theCommand.empty()) {
fprintf (stderr, "the Command parameter is not present or empty...\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
theResult = AnalyseAndExecute (theCommand);
blob_buf_init (&theBuf, 0);
blobmsg_add_json_from_string (&theBuf,"{}");
ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn AnalyseAndExecute
*
* @brief analyse and Execute the following commmand.
*/
int SpeachCommandModel::AnalyseAndExecute (std::string aCommand)
{
std::vector <std::string> theTokens;
Tokenizer s(aCommand, " ");
fprintf (stdout, "Analyse: <%s>\n", aCommand.c_str());
int theSM = 0;
bool theState = false;
std::string theCapability;
std::string theDeviceName;
while (s.NextToken()) {
theTokens.push_back (s.GetToken());
fprintf (stdout, "word: <%s>\n", s.GetToken().c_str());
// Check the Command
if (theSM == 0) {
if (s.GetToken() == "allumer") {
theState = true;
}
else if (s.GetToken() == "Éteindre") {
theState = false;
}
else if (s.GetToken() == "ouvrir") {
theState = true;
}
else if (s.GetToken() == "fermer") {
theState = false;
}
else {
fprintf (stderr, "Uknown command: %s:\n", s.GetToken().c_str());
return -1;
}
}
/* TODO
else if (theSM == 1) {
theCapability = s.GetToken();
if (!mDevices->isCapability (theCapability)) {
fprintf (stderr, "Uknown capability: <%s>\n", s.GetToken().c_str());
return -2;
}
}
else if (theSM == 2) {
theDeviceName = s.GetToken();
if (!mDevices->setDevice (theCapability, theDeviceName, theState)) {
fprintf (stderr, "Uknown Device: <%s>\n", s.GetToken().c_str());
return -3;
}
}
*/
theSM++;
}
return 0;
}

View File

@@ -0,0 +1,57 @@
/*!
* speach_command.h
*
* Copyright (c) 2015, 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: 04/05/2015
*
*/
#ifndef _UBUS_SPEACH_COMMANDS_MODEL_H
#define _UBUS_SPEACH_COMMANDS_MODEL_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <jsoncpp/json.h>
#include <ubuscpp/UBusObject.h>
/*--------------------------------- Define ----------------------------------*/
class Devices;
/*--------------------------------- CLASS ----------------------------------*/
class SpeachCommandModel : public UBusObject {
public:
SpeachCommandModel (Devices *aDevice);
~SpeachCommandModel (void);
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private:
int AnalyseAndExecute (std::string aCommand);
Devices *mDevices;
};
#endif /* _UBUS_SPEACH_COMMANDS_MODEL_H */

View File

@@ -0,0 +1,152 @@
/*!
* TimersModel.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: 02/07/2016
*
*/
/*-------------------------------- INCLUDES ---------------------------------*/
#include <string.h>
extern "C" {
#include <libubox/blobmsg_json.h>
}
#include <jsoncpp/json.h>
#include "timers/Timers.h"
#include "timers.h"
namespace {
using namespace UBus;
static ObjectType gTimersModelUbus_types(
"TimersModel",
Method("get", UBUS_CPP(TimersModel, Get)),
Method("delete", UBUS_CPP(TimersModel, Delete))
);
}
/*! ----------------------------------------------------------------------------
* @fn TimersModel
*
* @brief Constructor of the Timer Objects.
*/
TimersModel::TimersModel (Timers *aTimers) :
UBusObject (gTimersModelUbus_types, "domo.timers"),
mTimers (aTimers)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~TimersModel
*
* @brief Destructor of the Timer Objects.
*/
TimersModel::~TimersModel (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn Get
*
* @brief Get the List of timer objects.
*/
int TimersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult = 0;
int theID = -1;
Json::Reader theReader;
Json::StyledWriter theWriter;
Json::Value theRoot;
struct blob_buf theBuf = {0};
char *theString = blobmsg_format_json (aMsg, true);
printf ("Get the TimersModel.\n");
if (!theReader.parse (theString, theRoot)) {
fprintf (stderr, "Failed parse the parameters.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
theID = theRoot["id"].asInt();
blob_buf_init (&theBuf, 0);
if (theID == 0)
blobmsg_add_json_from_string (&theBuf, theWriter.write(mTimers->to_json()).c_str());
else {
printf ("we want a specific id :%d\n", theID);
blobmsg_add_json_from_string (&theBuf, theWriter.write(mTimers->get(theID).to_json()).c_str());
}
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
blob_buf_free (&theBuf);
return theResult;
}
/*! ----------------------------------------------------------------------------
* @fn Delete
*
* @brief Delete a Timer Object.
*/
int TimersModel::Delete (struct ubus_context *aCtx, struct ubus_request_data *aReq,
struct blob_attr *aMsg)
{
int theResult = 0;
Json::Reader theReader;
Json::Value theRoot;
int theID = -1;
char *theString = blobmsg_format_json (aMsg, true);
if (!theReader.parse (theString, theRoot)) {
fprintf (stderr, "Failed parse the parameters.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
theID = theRoot["id"].asInt();
printf ("try to delete id: %d\n", theID);
theResult = mTimers->remove (theID);
if (theResult == 0) {
printf ("Successfully removed.\n");
//TODO SAVE and return OK.
}
return theResult;
}

View File

@@ -0,0 +1,54 @@
/*!
* timers.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: 02/07/2016
*
*/
#ifndef _UBUS_TIMERS_H
#define _UBUS_TIMERS_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdint.h>
#include <ubuscpp/UBusObject.h>
/*--------------------------------- Define ----------------------------------*/
class Timers;
/*--------------------------------- CLASS ----------------------------------*/
class TimersModel : public UBusObject {
public:
TimersModel (Timers *aTimers);
~TimersModel (void);
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
int Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
private:
Timers *mTimers;
};
#endif /* _UBUS_TIMERS_H */