From 16145d6ddeea9ce1765c2de12d54f66ab1c592a7 Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Tue, 17 May 2016 23:44:23 +0200 Subject: [PATCH] Add UBusTimer Object. And Add a Test of it into Domo program. --- build.local.sh | 9 ++ cmake-modules/libubus.cmake | 2 +- lib/ubuscpp/builders/cmake/CMakeLists.txt | 1 + lib/ubuscpp/include/ubuscpp/UBusTimer.h | 61 ++++++++++++ lib/ubuscpp/src/UBusTimer.cpp | 113 ++++++++++++++++++++++ src/domod/builders/cmake/CMakeLists.txt | 1 + src/domod/src/main.cpp | 16 ++- src/domod/src/timers/Timers.cpp | 78 +++++++++++++++ src/domod/src/timers/Timers.h | 48 +++++++++ src/ui/Domo/builders/cmake/CMakeLists.txt | 3 +- 10 files changed, 328 insertions(+), 4 deletions(-) create mode 100755 build.local.sh create mode 100644 lib/ubuscpp/include/ubuscpp/UBusTimer.h create mode 100644 lib/ubuscpp/src/UBusTimer.cpp create mode 100644 src/domod/src/timers/Timers.cpp create mode 100644 src/domod/src/timers/Timers.h diff --git a/build.local.sh b/build.local.sh new file mode 100755 index 00000000..ec5dd328 --- /dev/null +++ b/build.local.sh @@ -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 diff --git a/cmake-modules/libubus.cmake b/cmake-modules/libubus.cmake index e4881b9b..9108325d 100644 --- a/cmake-modules/libubus.cmake +++ b/cmake-modules/libubus.cmake @@ -1,6 +1,6 @@ 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) ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}") diff --git a/lib/ubuscpp/builders/cmake/CMakeLists.txt b/lib/ubuscpp/builders/cmake/CMakeLists.txt index 3a5fb333..ddea941b 100644 --- a/lib/ubuscpp/builders/cmake/CMakeLists.txt +++ b/lib/ubuscpp/builders/cmake/CMakeLists.txt @@ -11,6 +11,7 @@ file( source_files ../../src/UBusCall.cpp ../../src/UBusObject.cpp + ../../src/UBusTimer.cpp ) add_library( diff --git a/lib/ubuscpp/include/ubuscpp/UBusTimer.h b/lib/ubuscpp/include/ubuscpp/UBusTimer.h new file mode 100644 index 00000000..8f9fd135 --- /dev/null +++ b/lib/ubuscpp/include/ubuscpp/UBusTimer.h @@ -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 + +extern "C" { +#include +} + +/*----------------------------- 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 */ diff --git a/lib/ubuscpp/src/UBusTimer.cpp b/lib/ubuscpp/src/UBusTimer.cpp new file mode 100644 index 00000000..5411abb9 --- /dev/null +++ b/lib/ubuscpp/src/UBusTimer.cpp @@ -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 + +#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(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; +} diff --git a/src/domod/builders/cmake/CMakeLists.txt b/src/domod/builders/cmake/CMakeLists.txt index af93acf1..88db6cef 100644 --- a/src/domod/builders/cmake/CMakeLists.txt +++ b/src/domod/builders/cmake/CMakeLists.txt @@ -23,6 +23,7 @@ file( ../../src/models/Devices.cpp ../../src/helpers/Tokenizer.cpp ../../src/helpers/Strings.cpp + ../../src/Timers.cpp ) add_executable ( diff --git a/src/domod/src/main.cpp b/src/domod/src/main.cpp index 6f5689a9..1f9f88d5 100644 --- a/src/domod/src/main.cpp +++ b/src/domod/src/main.cpp @@ -38,6 +38,7 @@ extern "C" { #include "ubus/capabilities_sprinklers.h" #include "ubus/speach_command.h" +#include "timers/Timers.h" #include "models/Devices.h" /*--------------------------------- GLOBALS ---------------------------------*/ @@ -85,11 +86,19 @@ static struct ubus_context *setupUbus (void) int main (void) { int theRet = 0; + char *theWritePath; std::string thePath; - + Timers theTimers; 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"; //printf ("DOMO PATH: %s\n", thePath.c_str()); @@ -114,6 +123,9 @@ int main (void) return -1; } + /* Setup the Timers. */ + theTimers.Setup (); + /* Add the UBus to the model exposed. */ ubus_add_object (theCtx, &theCapabilities); ubus_add_object (theCtx, &theCapLights); diff --git a/src/domod/src/timers/Timers.cpp b/src/domod/src/timers/Timers.cpp new file mode 100644 index 00000000..acd0a06b --- /dev/null +++ b/src/domod/src/timers/Timers.cpp @@ -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 + +#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; +} diff --git a/src/domod/src/timers/Timers.h b/src/domod/src/timers/Timers.h new file mode 100644 index 00000000..e64867cb --- /dev/null +++ b/src/domod/src/timers/Timers.h @@ -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 */ diff --git a/src/ui/Domo/builders/cmake/CMakeLists.txt b/src/ui/Domo/builders/cmake/CMakeLists.txt index 0028ec07..425358ba 100644 --- a/src/ui/Domo/builders/cmake/CMakeLists.txt +++ b/src/ui/Domo/builders/cmake/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 2.8.11) project(ui) -add_custom_target(ui ALL) +#add_custom_target(ui ALL) +add_custom_target(ui) add_custom_command(TARGET ui PRE_BUILD COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/html