Import ubuscpp
domod
This commit is contained in:
13
src/CMakeLists.txt
Normal file
13
src/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
# CMakeLists files in this project can
|
||||
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
|
||||
# to the root binary directory of the project as ${HELLO_BINARY_DIR}.
|
||||
cmake_minimum_required (VERSION 2.8.11)
|
||||
|
||||
#add_subdirectory (alarmd/builders/cmake)
|
||||
add_subdirectory (domod/builders/cmake)
|
||||
#add_subdirectory (chacond/builders/cmake)
|
||||
#add_subdirectory (sprinklersd/builders/cmake)
|
||||
#add_subdirectory (rf_listenerd/builders/cmake)
|
||||
#add_subdirectory (restd/builders/cmake)
|
||||
#add_subdirectory (ui/builders/cmake)
|
||||
# add_subdirectory (board/builders/cmake)
|
||||
38
src/domod/builders/cmake/CMakeLists.txt
Normal file
38
src/domod/builders/cmake/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
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/main.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/models/Devices.cpp
|
||||
../../src/helpers/Tokenizer.cpp
|
||||
../../src/helpers/Strings.cpp
|
||||
)
|
||||
|
||||
add_executable (
|
||||
domod
|
||||
${source_files}
|
||||
)
|
||||
|
||||
target_link_libraries (domod
|
||||
LINK_PUBLIC
|
||||
jsoncpp
|
||||
ubuscpp
|
||||
rt
|
||||
)
|
||||
57
src/domod/src/helpers/Strings.cpp
Normal file
57
src/domod/src/helpers/Strings.cpp
Normal 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;
|
||||
}
|
||||
34
src/domod/src/helpers/Strings.h
Normal file
34
src/domod/src/helpers/Strings.h
Normal 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 */
|
||||
116
src/domod/src/helpers/Tokenizer.cpp
Normal file
116
src/domod/src/helpers/Tokenizer.cpp
Normal 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;
|
||||
}
|
||||
55
src/domod/src/helpers/Tokenizer.h
Normal file
55
src/domod/src/helpers/Tokenizer.h
Normal 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 */
|
||||
131
src/domod/src/main.cpp
Normal file
131
src/domod/src/main.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*!
|
||||
* 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 "models/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;
|
||||
std::string thePath;
|
||||
|
||||
struct ubus_context *theCtx = NULL;
|
||||
|
||||
thePath = getenv ("DOMO_WRITE_PATH");
|
||||
thePath += "/Devices.json";
|
||||
|
||||
//printf ("DOMO PATH: %s\n", thePath.c_str());
|
||||
|
||||
Devices theDevices (thePath);
|
||||
|
||||
if (theDevices.Setup() != 0) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Capabilities theCapabilities;
|
||||
CapabilitiesLights theCapLights (&theDevices);
|
||||
CapabilitiesShutters theCapShutters (&theDevices);
|
||||
CapabilitiesSprinklers theCapSprinklers (&theDevices);
|
||||
SpeachCommand theSpeachCommand (&theDevices);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Main Event Loop. */
|
||||
uloop_run ();
|
||||
|
||||
ubus_free (theCtx);
|
||||
uloop_done ();
|
||||
|
||||
return theRet;
|
||||
}
|
||||
205
src/domod/src/models/Devices.cpp
Normal file
205
src/domod/src/models/Devices.cpp
Normal 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*------------------------------- 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 Setup
|
||||
*
|
||||
* @brief Setup the Device object.
|
||||
*/
|
||||
int Devices::Setup (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)
|
||||
{
|
||||
bool theStateChange = false;
|
||||
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;
|
||||
}
|
||||
56
src/domod/src/models/Devices.h
Normal file
56
src/domod/src/models/Devices.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#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 Setup (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 */
|
||||
96
src/domod/src/ubus/capabilities.cpp
Normal file
96
src/domod/src/ubus/capabilities.cpp
Normal 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 gCapabilitiesUbus_types(
|
||||
"capabilities",
|
||||
Method("get", UBUS_CPP(Capabilities, Get))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Capabilities
|
||||
*
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
Capabilities::Capabilities (void) :
|
||||
UBusObject (gCapabilitiesUbus_types, "domo.capabilities")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~Capabilities
|
||||
*
|
||||
* @brief Destructor of the UBus Mixer Volume.
|
||||
*/
|
||||
Capabilities::~Capabilities (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Get
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int Capabilities::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;
|
||||
}
|
||||
50
src/domod/src/ubus/capabilities.h
Normal file
50
src/domod/src/ubus/capabilities.h
Normal 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_H
|
||||
#define _UBUS_CAPABILITIES_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <ubuscpp/UBusObject.h>
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class Capabilities : public UBusObject {
|
||||
|
||||
public:
|
||||
Capabilities (void);
|
||||
~Capabilities (void);
|
||||
|
||||
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* _UBUS_CAPABILITIES_H */
|
||||
191
src/domod/src/ubus/capabilities_lights.cpp
Normal file
191
src/domod/src/ubus/capabilities_lights.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/*!
|
||||
* 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 <ubuscpp/UBusCall.h>
|
||||
|
||||
#include "models/Devices.h"
|
||||
|
||||
#include "capabilities_lights.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace UBus;
|
||||
|
||||
static ObjectType gCapabilitiesLightsUbus_types(
|
||||
"lights",
|
||||
Method("get", UBUS_CPP(CapabilitiesLights, Get)),
|
||||
Method("delete", UBUS_CPP(CapabilitiesLights, Delete)),
|
||||
Method("put", UBUS_CPP(CapabilitiesLights, Put)),
|
||||
Method("post", UBUS_CPP(CapabilitiesLights, Post))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn CapabilitiesLights
|
||||
*
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesLights::CapabilitiesLights (Devices *aDevice) :
|
||||
UBusObject (gCapabilitiesLightsUbus_types, "domo.capabilities.lights"),
|
||||
mDevices (aDevice)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~CapabilitiesLights
|
||||
*
|
||||
* @brief Destructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesLights::~CapabilitiesLights (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Get
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLights::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 CapabilitiesLights::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 CapabilitiesLights::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 CapabilitiesLights::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;
|
||||
|
||||
if (!theReader.parse (theString, theRoot)) {
|
||||
|
||||
fprintf (stderr, "Failed parse the parameters.\n");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
theID = theRoot["id"].asInt();
|
||||
theState = theRoot["state"].asBool();
|
||||
|
||||
theElement = mDevices->get("Lights", theID);
|
||||
theElement["state"] = theState;
|
||||
|
||||
if (ChangeState(theElement) == 0) {
|
||||
|
||||
mDevices->set("Lights", theID, theElement);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ChangeState
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLights::ChangeState (const Json::Value &aLight)
|
||||
{
|
||||
UBusCall theCmd;
|
||||
Json::Value theParam;
|
||||
Json::StyledWriter theWriter;
|
||||
std::string theResult;
|
||||
|
||||
theParam["sender"] = aLight["sender"];
|
||||
theParam["interruptor"] = aLight["interruptor"];
|
||||
theParam["state"] = aLight["state"];
|
||||
|
||||
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult);
|
||||
}
|
||||
60
src/domod/src/ubus/capabilities_lights.h
Normal file
60
src/domod/src/ubus/capabilities_lights.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*!
|
||||
* 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_H
|
||||
#define _UBUS_CAPABILITIES_LIGHTS_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
#include <ubuscpp/UBusObject.h>
|
||||
|
||||
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class CapabilitiesLights : public UBusObject {
|
||||
|
||||
public:
|
||||
CapabilitiesLights (Devices *aDevice);
|
||||
~CapabilitiesLights (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:
|
||||
int ChangeState (const Json::Value &aLight);
|
||||
Devices *mDevices;
|
||||
};
|
||||
|
||||
#endif /* _UBUS_CAPABILITIES_LIGHTS_H */
|
||||
202
src/domod/src/ubus/capabilities_shutters.cpp
Normal file
202
src/domod/src/ubus/capabilities_shutters.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
/*!
|
||||
* 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 "models/Devices.h"
|
||||
|
||||
#include "capabilities_shutters.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace UBus;
|
||||
|
||||
static ObjectType gCapabilitiesShuttersUbus_types(
|
||||
"shutters",
|
||||
Method("get", UBUS_CPP(CapabilitiesShutters, Get)),
|
||||
Method("delete", UBUS_CPP(CapabilitiesShutters, Delete)),
|
||||
Method("put", UBUS_CPP(CapabilitiesShutters, Put)),
|
||||
Method("post", UBUS_CPP(CapabilitiesShutters, Post)),
|
||||
|
||||
Method("open", UBUS_CPP(CapabilitiesShutters, Open)),
|
||||
Method("close", UBUS_CPP(CapabilitiesShutters, Close)),
|
||||
|
||||
Method("up", UBUS_CPP(CapabilitiesShutters, Up)),
|
||||
Method("down", UBUS_CPP(CapabilitiesShutters, Down)),
|
||||
|
||||
Method("position", UBUS_CPP(CapabilitiesShutters, Position))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn CapabilitiesShutters
|
||||
*
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesShutters::CapabilitiesShutters (Devices *aDevice) :
|
||||
UBusObject (gCapabilitiesShuttersUbus_types, "domo.capabilities.shutters"),
|
||||
mDevices (aDevice)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~CapabilitiesShutters
|
||||
*
|
||||
* @brief Destructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesShutters::~CapabilitiesShutters (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Get
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesShutters::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 CapabilitiesShutters::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 CapabilitiesShutters::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 CapabilitiesShutters::Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
|
||||
{
|
||||
int theResult = 0;
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Open
|
||||
*
|
||||
* @brief Open the Shutter
|
||||
*/
|
||||
int CapabilitiesShutters::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 CapabilitiesShutters::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 CapabilitiesShutters::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 CapabilitiesShutters::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 CapabilitiesShutters::Position (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
|
||||
{
|
||||
int theResult = 0;
|
||||
printf ("Position the Shutter\n");
|
||||
return theResult;
|
||||
}
|
||||
64
src/domod/src/ubus/capabilities_shutters.h
Normal file
64
src/domod/src/ubus/capabilities_shutters.h
Normal 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_H
|
||||
#define _UBUS_CAPABILITIES_SHUTTERS_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <ubuscpp/UBusObject.h>
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class CapabilitiesShutters : public UBusObject {
|
||||
|
||||
public:
|
||||
CapabilitiesShutters (Devices *aDevice);
|
||||
~CapabilitiesShutters (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_H */
|
||||
132
src/domod/src/ubus/capabilities_sprinklers.cpp
Normal file
132
src/domod/src/ubus/capabilities_sprinklers.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/*!
|
||||
* 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 "models/Devices.h"
|
||||
|
||||
#include "capabilities_sprinklers.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace UBus;
|
||||
|
||||
static ObjectType gCapabilitiesSprinklersUbus_types(
|
||||
"sprinklers",
|
||||
Method("get", UBUS_CPP(CapabilitiesSprinklers, Get)),
|
||||
Method("delete", UBUS_CPP(CapabilitiesSprinklers, Delete)),
|
||||
Method("put", UBUS_CPP(CapabilitiesSprinklers, Put)),
|
||||
Method("post", UBUS_CPP(CapabilitiesSprinklers, Post))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn CapabilitiesSprinkler
|
||||
*
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesSprinklers::CapabilitiesSprinklers (Devices *aDevice) :
|
||||
UBusObject (gCapabilitiesSprinklersUbus_types, "domo.capabilities.sprinklers"),
|
||||
mDevices (aDevice)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~CapabilitiesSprinklers
|
||||
*
|
||||
* @brief Destructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesSprinklers::~CapabilitiesSprinklers (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Get
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesSprinklers::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("Sprinkers").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 CapabilitiesSprinklers::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 CapabilitiesSprinklers::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 CapabilitiesSprinklers::Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
|
||||
{
|
||||
int theResult = 0;
|
||||
|
||||
return theResult;
|
||||
}
|
||||
56
src/domod/src/ubus/capabilities_sprinklers.h
Normal file
56
src/domod/src/ubus/capabilities_sprinklers.h
Normal 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_H
|
||||
#define _UBUS_CAPABILITIES_SPRINKLERS_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <ubuscpp/UBusObject.h>
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class CapabilitiesSprinklers : public UBusObject {
|
||||
|
||||
public:
|
||||
CapabilitiesSprinklers (Devices *aDevice);
|
||||
~CapabilitiesSprinklers (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_H */
|
||||
181
src/domod/src/ubus/speach_command.cpp
Normal file
181
src/domod/src/ubus/speach_command.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
/*!
|
||||
* 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 "models/Devices.h"
|
||||
|
||||
#include "helpers/Tokenizer.h"
|
||||
#include "helpers/Strings.h"
|
||||
|
||||
#include "speach_command.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace UBus;
|
||||
|
||||
static ObjectType gSpeachCommandUbus_types(
|
||||
"speach",
|
||||
Method("post", UBUS_CPP(SpeachCommand, Post))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn SpeachCommand
|
||||
*
|
||||
* @brief Constructor of the UBus Speach Command execution.
|
||||
*/
|
||||
SpeachCommand::SpeachCommand (Devices *aDevice) :
|
||||
UBusObject (gSpeachCommandUbus_types, "domo.speach.command"),
|
||||
mDevices (aDevice)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~SpeachCommand
|
||||
*
|
||||
* @brief Destructor of the UBus Speach Command execution.
|
||||
*/
|
||||
SpeachCommand::~SpeachCommand (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Post
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int SpeachCommand::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 SpeachCommand::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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
57
src/domod/src/ubus/speach_command.h
Normal file
57
src/domod/src/ubus/speach_command.h
Normal 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_H
|
||||
#define _UBUS_SPEACH_COMMANDS_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
#include <ubuscpp/UBusObject.h>
|
||||
|
||||
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class SpeachCommand : public UBusObject {
|
||||
|
||||
public:
|
||||
SpeachCommand (Devices *aDevice);
|
||||
~SpeachCommand (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_H */
|
||||
Reference in New Issue
Block a user