Add UBusTimer Object. And Add a Test of it into Domo program.
This commit is contained in:
9
build.local.sh
Executable file
9
build.local.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
if [ -e build ]; then
|
||||||
|
echo "Clean"
|
||||||
|
rm -rf build/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Local.cmake ..
|
||||||
|
make
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.11)
|
cmake_minimum_required(VERSION 2.8.11)
|
||||||
|
|
||||||
SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
|
SET(UBUS_UNIX_SOCKET "/tmp/ubus.sock")
|
||||||
SET(UBUS_MAX_MSGLEN 1048576)
|
SET(UBUS_MAX_MSGLEN 1048576)
|
||||||
|
|
||||||
ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}")
|
ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}")
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ file(
|
|||||||
source_files
|
source_files
|
||||||
../../src/UBusCall.cpp
|
../../src/UBusCall.cpp
|
||||||
../../src/UBusObject.cpp
|
../../src/UBusObject.cpp
|
||||||
|
../../src/UBusTimer.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(
|
add_library(
|
||||||
|
|||||||
61
lib/ubuscpp/include/ubuscpp/UBusTimer.h
Normal file
61
lib/ubuscpp/include/ubuscpp/UBusTimer.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*!
|
||||||
|
* UbusTimer.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 _UBUS_TIMER_H
|
||||||
|
#define _UBUS_TIMER_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <libubox/uloop.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------- Dependencies --------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
|
class UBusTimer : public uloop_timeout {
|
||||||
|
|
||||||
|
// Disable copy construction and copy assignement
|
||||||
|
UBusTimer (const UBusTimer&);
|
||||||
|
UBusTimer &operator=(const UBusTimer&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
UBusTimer (void);
|
||||||
|
virtual ~UBusTimer (void);
|
||||||
|
|
||||||
|
virtual int Expire (void);
|
||||||
|
int Start (unsigned int aTimerValue, bool aRepeat = false);
|
||||||
|
int Tick (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mRepeat;
|
||||||
|
uint16_t mTimerValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _UBUS_TIMER_H */
|
||||||
113
lib/ubuscpp/src/UBusTimer.cpp
Normal file
113
lib/ubuscpp/src/UBusTimer.cpp
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*!
|
||||||
|
* UbusTimer.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 "ubuscpp/UBusTimer.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn timer_callback
|
||||||
|
*
|
||||||
|
* @brief Callback used when a Timer has expired.
|
||||||
|
*/
|
||||||
|
static void timer_callback (struct uloop_timeout *aTimeout)
|
||||||
|
{
|
||||||
|
UBusTimer *aTmp = static_cast<UBusTimer *>(aTimeout);
|
||||||
|
aTmp->Tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn UBusTimer
|
||||||
|
*
|
||||||
|
* @brief Constructor of the Timer UBUS Object.
|
||||||
|
*/
|
||||||
|
UBusTimer::UBusTimer (void)
|
||||||
|
{
|
||||||
|
// Uloop Timer Init.
|
||||||
|
cb = timer_callback;
|
||||||
|
pending = 0;
|
||||||
|
|
||||||
|
// UBus Timer.
|
||||||
|
mRepeat = false;
|
||||||
|
mTimerValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn ~UBusTimer
|
||||||
|
*
|
||||||
|
* @brief Destructor of the Timer UBUS Object.
|
||||||
|
*/
|
||||||
|
UBusTimer::~UBusTimer (void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Start the Timer
|
||||||
|
*
|
||||||
|
* @brief Start the Timer object.
|
||||||
|
*/
|
||||||
|
int UBusTimer::Start (unsigned int aTimerValue, bool aRepeat)
|
||||||
|
{
|
||||||
|
mTimerValue = aTimerValue;
|
||||||
|
mRepeat = aRepeat;
|
||||||
|
|
||||||
|
return uloop_timeout_set (this, mTimerValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Expire
|
||||||
|
*
|
||||||
|
* @brief Method Should be overrided.
|
||||||
|
*/
|
||||||
|
int UBusTimer::Expire (void)
|
||||||
|
{
|
||||||
|
//fprintf (stderr, "UBusTimer::Expire\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Tick
|
||||||
|
*
|
||||||
|
* @brief Method called when the Timer has expired.
|
||||||
|
*/
|
||||||
|
int UBusTimer::Tick (void)
|
||||||
|
{
|
||||||
|
//fprintf (stderr, "UBusTimer::Tick\n");
|
||||||
|
|
||||||
|
Expire ();
|
||||||
|
|
||||||
|
if (mRepeat == true)
|
||||||
|
uloop_timeout_set (this, mTimerValue);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ file(
|
|||||||
../../src/models/Devices.cpp
|
../../src/models/Devices.cpp
|
||||||
../../src/helpers/Tokenizer.cpp
|
../../src/helpers/Tokenizer.cpp
|
||||||
../../src/helpers/Strings.cpp
|
../../src/helpers/Strings.cpp
|
||||||
|
../../src/Timers.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable (
|
add_executable (
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ extern "C" {
|
|||||||
#include "ubus/capabilities_sprinklers.h"
|
#include "ubus/capabilities_sprinklers.h"
|
||||||
#include "ubus/speach_command.h"
|
#include "ubus/speach_command.h"
|
||||||
|
|
||||||
|
#include "timers/Timers.h"
|
||||||
#include "models/Devices.h"
|
#include "models/Devices.h"
|
||||||
|
|
||||||
/*--------------------------------- GLOBALS ---------------------------------*/
|
/*--------------------------------- GLOBALS ---------------------------------*/
|
||||||
@@ -85,11 +86,19 @@ static struct ubus_context *setupUbus (void)
|
|||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
int theRet = 0;
|
int theRet = 0;
|
||||||
|
char *theWritePath;
|
||||||
std::string thePath;
|
std::string thePath;
|
||||||
|
Timers theTimers;
|
||||||
struct ubus_context *theCtx = NULL;
|
struct ubus_context *theCtx = NULL;
|
||||||
|
|
||||||
thePath = getenv ("DOMO_WRITE_PATH");
|
theWritePath = getenv ("DOMO_WRITE_PATH");
|
||||||
|
if (theWritePath == NULL) {
|
||||||
|
|
||||||
|
fprintf (stderr, "you should export DOMO_WRITE_PATH. with the Path of data.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
thePath = theWritePath;
|
||||||
thePath += "/Devices.json";
|
thePath += "/Devices.json";
|
||||||
|
|
||||||
//printf ("DOMO PATH: %s\n", thePath.c_str());
|
//printf ("DOMO PATH: %s\n", thePath.c_str());
|
||||||
@@ -114,6 +123,9 @@ int main (void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Setup the Timers. */
|
||||||
|
theTimers.Setup ();
|
||||||
|
|
||||||
/* Add the UBus to the model exposed. */
|
/* Add the UBus to the model exposed. */
|
||||||
ubus_add_object (theCtx, &theCapabilities);
|
ubus_add_object (theCtx, &theCapabilities);
|
||||||
ubus_add_object (theCtx, &theCapLights);
|
ubus_add_object (theCtx, &theCapLights);
|
||||||
|
|||||||
78
src/domod/src/timers/Timers.cpp
Normal file
78
src/domod/src/timers/Timers.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*!
|
||||||
|
* 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 "timers/Timers.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Timers
|
||||||
|
*
|
||||||
|
* @brief Constructor of the Timers Managagers.
|
||||||
|
*/
|
||||||
|
Timers::Timers (void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Devices
|
||||||
|
*
|
||||||
|
* @brief Destructors of the Timer Managers.
|
||||||
|
*/
|
||||||
|
Timers::~Timers (void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Devices
|
||||||
|
*
|
||||||
|
* @brief Destructors of the Timer Managers.
|
||||||
|
*/
|
||||||
|
int Timers::Setup (void)
|
||||||
|
{
|
||||||
|
Start (2000, true);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn Expire
|
||||||
|
*
|
||||||
|
* @brief Method Call when the Timer has expired.
|
||||||
|
*/
|
||||||
|
int Timers::Expire (void)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Domo::Timers::Expire\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
48
src/domod/src/timers/Timers.h
Normal file
48
src/domod/src/timers/Timers.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*!
|
||||||
|
* 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 "ubuscpp/UBusTimer.h"
|
||||||
|
|
||||||
|
class Timers : public UBusTimer {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Timers (void);
|
||||||
|
~Timers (void);
|
||||||
|
|
||||||
|
int Expire (void);
|
||||||
|
|
||||||
|
int Setup (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UBusTimer mTest;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _TIMERS_H */
|
||||||
@@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 2.8.11)
|
|||||||
|
|
||||||
project(ui)
|
project(ui)
|
||||||
|
|
||||||
add_custom_target(ui ALL)
|
#add_custom_target(ui ALL)
|
||||||
|
add_custom_target(ui)
|
||||||
|
|
||||||
add_custom_command(TARGET ui PRE_BUILD
|
add_custom_command(TARGET ui PRE_BUILD
|
||||||
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/html
|
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/html
|
||||||
|
|||||||
Reference in New Issue
Block a user