diff --git a/projects/rpi_domo/configs/buildroot_defconfig b/projects/rpi_domo/configs/buildroot_defconfig index 3fc638bf..02fcdeb8 100644 --- a/projects/rpi_domo/configs/buildroot_defconfig +++ b/projects/rpi_domo/configs/buildroot_defconfig @@ -7,12 +7,11 @@ BR2_PACKAGE_OVERRIDE_FILE="$(BOARD)/local.mk" BR2_GLOBAL_PATCH_DIR="$(BR2_EXTERNAL)/patches" BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y -BR2_TOOLCHAIN_EXTERNAL_URL="http://serveur.nadal-fr.com/buildroot/toolchain_rpi-5_4_0-glibc-2_23-2.tar.bz2" +BR2_TOOLCHAIN_EXTERNAL_URL="http://serveur.nadal-fr.com/buildroot/toolchain_rpi-5_4_0-glibc.tar.bz2" BR2_TOOLCHAIN_EXTERNAL_GCC_5=y BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_4=y BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y BR2_TOOLCHAIN_EXTERNAL_CXX=y -BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY=y BR2_TARGET_GENERIC_HOSTNAME="rpi_Domo" BR2_TARGET_GENERIC_ISSUE="Welcome to Domo" BR2_INIT_NONE=y @@ -60,4 +59,3 @@ BR2_PACKAGE_UHTTPD_REST_API_PLUGIN=y BR2_PACKAGE_CHACOND=y BR2_PACKAGE_SPRINKLERD=y BR2_PACKAGE_DOMOD=y -BR2_PACKAGE_DASHBOARD=y diff --git a/src/prog/sprinklerd/builders/cmake/CMakeLists.txt b/src/prog/sprinklerd/builders/cmake/CMakeLists.txt index dccf916e..ec6591bf 100644 --- a/src/prog/sprinklerd/builders/cmake/CMakeLists.txt +++ b/src/prog/sprinklerd/builders/cmake/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable (sprinklerd ${source_files}) target_link_libraries (sprinklerd LINK_PUBLIC ubus-cpp - json-cpp + jsonc ubox ubus blobmsg_json diff --git a/src/prog/sprinklerd/src/main.cpp b/src/prog/sprinklerd/src/main.cpp index 978d2215..d1bf114d 100644 --- a/src/prog/sprinklerd/src/main.cpp +++ b/src/prog/sprinklerd/src/main.cpp @@ -1,5 +1,4 @@ /*! - * main.c * * Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -28,7 +27,8 @@ #include #include -extern "C" { +extern "C" +{ #include } @@ -38,83 +38,83 @@ extern "C" { /*--------------------------------- GLOBALS ---------------------------------*/ - - /*! ---------------------------------------------------------------------------- * @fn setupUbus * * @brief Setup the UBus Mechanism. */ -extern "C" { -static struct ubus_context *setupUbus (void) +extern "C" { - ubus_context *theCtx; + static struct ubus_context *setupUbus(void) + { + ubus_context *theCtx; - if (uloop_init () !=0) { + if (uloop_init() != 0) + { + fprintf(stderr, "Failed to init Uloop.\n"); + return NULL; + } - 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; } - - 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 main(void) { int theRet = 0; SprinkerModel theSprinklersModel; - + struct ubus_context *theCtx = NULL; - if (setuid (0)) { - - perror ("setuid"); + if (setuid(0)) + { + perror("setuid"); return 1; } /* Setup the Ubus context. */ - theCtx = setupUbus (); - if (theCtx == NULL) { + theCtx = setupUbus(); + if (theCtx == NULL) + { return -1; } /* Setup the sprinklers. */ - theRet = sprinklers_setup (); - if (theRet != 0) { - - fprintf (stderr, "Impossible to Setup the Sprinkers.\n"); + theRet = sprinklers_setup(); + if (theRet != 0) + { + + fprintf(stderr, "Impossible to Setup the Sprinkers.\n"); return theRet; } /* Add the UBus to the model exposed. */ - ubus_add_object (theCtx, &theSprinklersModel); - - /* Main Event Loop. */ - uloop_run (); + ubus_add_object(theCtx, &theSprinklersModel); - ubus_free (theCtx); - - uloop_done (); + /* Main Event Loop. */ + uloop_run(); + + ubus_free(theCtx); + + uloop_done(); return theRet; } diff --git a/src/prog/sprinklerd/src/sprinklers.cpp b/src/prog/sprinklerd/src/sprinklers.cpp index d72052b4..d030a55c 100644 --- a/src/prog/sprinklerd/src/sprinklers.cpp +++ b/src/prog/sprinklerd/src/sprinklers.cpp @@ -1,5 +1,4 @@ /*! - * sprinklers.c * * Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -29,152 +28,153 @@ #include #include -#include +#include #include -#include +#include #include "sprinklers.h" /*-------------------------------- GLOBALES ---------------------------------*/ - /*! ---------------------------------------------------------------------------- * @fn sprinklers_setup * * @brief this function setup the OSPI environement. */ -int sprinklers_setup (void) +int sprinklers_setup(void) { UBusCall theCmd; std::string theResult; int theIDVal; - fprintf (stderr, "Setup the Gpios used by the Sprinklers.\n"); - - if (theCmd.Exec ("domo.capabilities.sprinklers", "get", "", theResult) == 0){ +#if 0 + fprintf(stderr, "Setup the Gpios used by the Sprinklers.\n"); + if (theCmd.Exec("domo.capabilities.sprinklers", "get", "", theResult) == 0) + { // We get the the sprinklers. Get the IDs. Json::Reader theReader; Json::Value theRoot; Json::Value theElement; - if (!theReader.parse (theResult, theRoot)) { + if (!theReader.parse(theResult, theRoot)) + { - fprintf (stderr, "Failed parse the List of Sprinklers.\n"); - return -1; - } + fprintf(stderr, "Failed parse the List of Sprinklers.\n"); + return -1; + } - for (const Json::Value& theElement : theRoot["Sprinklers"]) { + for (const Json::Value &theElement : theRoot["Sprinklers"]) + { theIDVal = theElement["id"].asInt(); - sprinkler_setup_station (theIDVal); + sprinkler_setup_station(theIDVal); } } - +#endif return 0; } - /*! ---------------------------------------------------------------------------- * @fn sprinkler_setup_station * * @brief This function change the State of an Ospi Station. */ -int sprinkler_setup_station (int aStation) +int sprinkler_setup_station(int a_station) { char theCommand[255]; - - printf (" Setup the Station: %d\n", aStation); +#if 0 + printf(" Setup the Station: %d\n", aStation); // Activate the Gpio - sprintf (theCommand, "echo %d > /sys/class/gpio/export", aStation); - system (theCommand); + sprintf(theCommand, "echo %d > /sys/class/gpio/export", aStation); + system(theCommand); // Select the Direction of the Gpio - sprintf (theCommand, "echo out > /sys/class/gpio/gpio%d/direction", aStation); - system (theCommand); + sprintf(theCommand, "echo out > /sys/class/gpio/gpio%d/direction", aStation); + system(theCommand); // Select the Direction of the Gpio - sprintf (theCommand, "echo 1 > /sys/class/gpio/gpio%d/value", aStation); - system (theCommand); - + sprintf(theCommand, "echo 1 > /sys/class/gpio/gpio%d/value", aStation); + system(theCommand); +#endif return 0; } - /*! ---------------------------------------------------------------------------- * @fn sprinkler_set_station * * @brief This function change the State of an Ospi Station. */ -int sprinklers_set_station (uint32_t aStation, bool aState) +int sprinklers_set_station(uint32_t a_station, bool a_state) { FILE *theFp; char theGpioPath[255]; - - sprintf (theGpioPath, "/sys/class/gpio/gpio%d/value", aStation); - - theFp = fopen (theGpioPath, "w"); +#if 0 + sprintf(theGpioPath, "/sys/class/gpio/gpio%d/value", aStation); - if (theFp == NULL) { + theFp = fopen(theGpioPath, "w"); - fprintf (stderr, "Impossible to open: <%s>\n", theGpioPath); + if (theFp == NULL) + { + fprintf(stderr, "Impossible to open: <%s>\n", theGpioPath); return -1; } - if (aState) { - - fwrite ("0", 1, 1, theFp); + if (aState) + { + fwrite("0", 1, 1, theFp); + } + else + { + fwrite("1", 1, 1, theFp); } - else { - - fwrite ("1", 1, 1, theFp); - } - - fclose (theFp); + fclose(theFp); +#endif return 0; } - /*! ---------------------------------------------------------------------------- * @fn sprinkler_get_station * * @brief This function change the State of an Ospi Station. */ -int sprinklers_get_station (uint32_t aStation, bool &aState) +int sprinklers_get_station(uint32_t a_station, bool &a_state) { +#if 0 FILE *theFp; char theGpioPath[255]; char theData[5]; - fprintf (stdout, "get station state (%d)\n", aStation); + fprintf(stdout, "get station state (%d)\n", aStation); - sprintf (theGpioPath, "/sys/class/gpio/gpio%d/value", aStation); + sprintf(theGpioPath, "/sys/class/gpio/gpio%d/value", aStation); - theFp = fopen (theGpioPath, "r"); + theFp = fopen(theGpioPath, "r"); - if (theFp == NULL) { + if (theFp == NULL) + { - fprintf (stderr, "Impossible to open: <%s>\n", theGpioPath); + fprintf(stderr, "Impossible to open: <%s>\n", theGpioPath); return -1; } - fread (theData, 1, 1, theFp); + fread(theData, 1, 1, theFp); //printf ("theData: %s\n", theData); - if (theData[0] == '0') { + if (theData[0] == '0') + { aState = true; } - else { + else + { aState = false; } - fclose (theFp); - + fclose(theFp); +#endif return 0; } - - diff --git a/src/prog/sprinklerd/src/sprinklers.h b/src/prog/sprinklerd/src/sprinklers.h index 770f1a18..b9d6b747 100644 --- a/src/prog/sprinklerd/src/sprinklers.h +++ b/src/prog/sprinklerd/src/sprinklers.h @@ -1,5 +1,4 @@ /*! - * sprinklers.h * * Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -29,14 +28,14 @@ /*-------------------------------- INCLUDES ---------------------------------*/ #include - + /*-------------------------------- METHODS ---------------------------------*/ -int sprinklers_setup (void); +int sprinklers_setup(void); -int sprinkler_setup_station (int aStation); +int sprinkler_setup_station(int a_station); -int sprinklers_set_station (uint32_t aStation, bool aState); -int sprinklers_get_station (uint32_t aStation, bool &aState); +int sprinklers_set_station(uint32_t a_station, bool a_state); +int sprinklers_get_station(uint32_t a_station, bool &a_state); #endif /* __SPRINKLERS_H */ diff --git a/src/prog/sprinklerd/src/ubus-sprinkler-model.cpp b/src/prog/sprinklerd/src/ubus-sprinkler-model.cpp index 65c05a98..224d4d18 100644 --- a/src/prog/sprinklerd/src/ubus-sprinkler-model.cpp +++ b/src/prog/sprinklerd/src/ubus-sprinkler-model.cpp @@ -1,5 +1,4 @@ /*! - * UBusSprinkerModel.cpp * * Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -23,16 +22,16 @@ * */ - /*-------------------------------- INCLUDES ---------------------------------*/ #include #include -#include +#include -#include +// #include -extern "C" { +extern "C" +{ #include } @@ -40,50 +39,47 @@ extern "C" { #include "ubus-sprinkler-model.h" -namespace { +namespace +{ using namespace UBus; static ObjectType gSprinklerModelUbus_types( "sprinklers", - Method("get", UBUS_CPP(SprinkerModel, Get)), - Method("set", UBUS_CPP(SprinkerModel, Set)) -); + Method("get", UBUS_CPP(SprinkerModel, get)), + Method("set", UBUS_CPP(SprinkerModel, set))); -} +} // namespace /*! ---------------------------------------------------------------------------- * @fn SprinkerModel * * @brief Constructor of the UBus Mixer Volume. */ -SprinkerModel::SprinkerModel (void) : - UBusObject (gSprinklerModelUbus_types, "sprinklers") +SprinkerModel::SprinkerModel(void) : UBusObject(gSprinklerModelUbus_types, "sprinklers") { } - /*! ---------------------------------------------------------------------------- * @fn ~SprinkerModel * * @brief Destructor of the UBus Mixer Volume. */ -SprinkerModel::~SprinkerModel (void) -{ +SprinkerModel::~SprinkerModel(void) +{ } - /*! ---------------------------------------------------------------------------- - * @fn Get + * @fn get * * @brief Get the State of a Sprinkler Station. */ -int SprinkerModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, - struct blob_attr *aMsg) +int SprinkerModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) { - int theResult = 0; + int the_result = 0; +#if 0 struct blob_buf theBuf = {0}; - char *theString = blobmsg_format_json (aMsg, true); + char *theString = blobmsg_format_json(aMsg, true); Json::Reader theReader; Json::StyledWriter theWriter; Json::Value theRoot; @@ -91,81 +87,86 @@ int SprinkerModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aRe uint32_t theStation = 0; bool theState = false; - if (!theReader.parse (theString, theRoot)) { + if (!theReader.parse(theString, theRoot)) + { - fprintf (stderr, "Failed parse the parameters.\n"); + fprintf(stderr, "Failed parse the parameters.\n"); return UBUS_STATUS_INVALID_ARGUMENT; - } + } theStation = theRoot["station"].asInt(); - if (theStation == 0) { + if (theStation == 0) + { - fprintf (stderr, "Station ID is missing.\n"); + fprintf(stderr, "Station ID is missing.\n"); return UBUS_STATUS_INVALID_ARGUMENT; } - theResult = sprinklers_get_station (theStation, theState); + theResult = sprinklers_get_station(theStation, theState); - if (theResult != 0) { + if (theResult != 0) + { - fprintf (stderr, "Wrong Station ID (%d).\n", theStation); + fprintf(stderr, "Wrong Station ID (%d).\n", theStation); return UBUS_STATUS_INVALID_ARGUMENT; } - printf ("aState: %d\n", theState); - theOutput ["station"] = theStation; - theOutput ["state"] = theState; + printf("aState: %d\n", theState); + theOutput["station"] = theStation; + theOutput["state"] = theState; - 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); + blob_buf_init(&theBuf, 0); - return theResult; + blobmsg_add_json_from_string(&theBuf, theWriter.write(theOutput).c_str()); + + theResult = ubus_send_reply(aCtx, aReq, theBuf.head); + + blob_buf_free(&theBuf); +#endif + return the_result; } - /*! ---------------------------------------------------------------------------- - * @fn Set + * @fn set * * @brief Set a new State for a Sprinkler Station. */ -int SprinkerModel::Set (struct ubus_context *aCtx, struct ubus_request_data *aReq, - struct blob_attr *aMsg) +int SprinkerModel::set(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) { - int theResult; - char *theString = blobmsg_format_json (aMsg, true); + int the_result = 0; +#if 0 + char *theString = blobmsg_format_json(aMsg, true); Json::Reader theReader; Json::Value theRoot; uint32_t theStation = 0; bool theState = false; - if (!theReader.parse (theString, theRoot)) { + if (!theReader.parse(theString, theRoot)) + { - fprintf (stderr, "Failed parse the parameters.\n"); + fprintf(stderr, "Failed parse the parameters.\n"); return UBUS_STATUS_INVALID_ARGUMENT; - } + } theStation = theRoot["station"].asInt(); theState = theRoot["state"].asBool(); - if (theStation == 0) { + if (theStation == 0) + { - fprintf (stderr, "Station ID is missing.\n"); + fprintf(stderr, "Station ID is missing.\n"); return UBUS_STATUS_INVALID_ARGUMENT; } - theResult = sprinklers_set_station (theStation, theState); + theResult = sprinklers_set_station(theStation, theState); - if (theResult != 0) { + if (theResult != 0) + { - fprintf (stderr, "Wrong Station ID (%d).\n", theStation); + fprintf(stderr, "Wrong Station ID (%d).\n", theStation); return UBUS_STATUS_INVALID_ARGUMENT; } - - return theResult; +#endif + return the_result; } diff --git a/src/prog/sprinklerd/src/ubus-sprinkler-model.h b/src/prog/sprinklerd/src/ubus-sprinkler-model.h index 42becdf8..c87c2b2a 100644 --- a/src/prog/sprinklerd/src/ubus-sprinkler-model.h +++ b/src/prog/sprinklerd/src/ubus-sprinkler-model.h @@ -1,5 +1,4 @@ /*! - * UBusModel.h * * Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -30,20 +29,20 @@ #include -#include +#include /*--------------------------------- Define ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/ -class SprinkerModel : public UBusObject { +class SprinkerModel : public UBusObject +{ + public: + SprinkerModel(void); + ~SprinkerModel(void); -public: - SprinkerModel (void); - ~SprinkerModel (void); - - int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*); - int Set (struct ubus_context*, struct ubus_request_data*, struct blob_attr*); + int get(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); + int set(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); }; #endif /* _UBUS_SPRINKLER_MODEL_H */