Fix sprinkler build.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -25,7 +25,7 @@ add_executable (sprinklerd ${source_files})
|
||||
target_link_libraries (sprinklerd
|
||||
LINK_PUBLIC
|
||||
ubus-cpp
|
||||
json-cpp
|
||||
jsonc
|
||||
ubox
|
||||
ubus
|
||||
blobmsg_json
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*!
|
||||
* main.c
|
||||
*
|
||||
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -28,7 +27,8 @@
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#include <libubus.h>
|
||||
}
|
||||
|
||||
@@ -38,20 +38,19 @@ extern "C" {
|
||||
|
||||
/*--------------------------------- GLOBALS ---------------------------------*/
|
||||
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn setupUbus
|
||||
*
|
||||
* @brief Setup the UBus Mechanism.
|
||||
*/
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -60,8 +59,8 @@ static struct ubus_context *setupUbus (void)
|
||||
|
||||
theCtx = ubus_connect(NULL);
|
||||
|
||||
if (!theCtx) {
|
||||
|
||||
if (!theCtx)
|
||||
{
|
||||
fprintf(stderr, "Failed to connect to ubus\n");
|
||||
return NULL;
|
||||
}
|
||||
@@ -72,7 +71,6 @@ static struct ubus_context *setupUbus (void)
|
||||
}
|
||||
} // SetupUbus.
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn main
|
||||
*
|
||||
@@ -85,22 +83,24 @@ int main (void)
|
||||
|
||||
struct ubus_context *theCtx = NULL;
|
||||
|
||||
if (setuid (0)) {
|
||||
|
||||
if (setuid(0))
|
||||
{
|
||||
perror("setuid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Setup the Ubus context. */
|
||||
theCtx = setupUbus();
|
||||
if (theCtx == NULL) {
|
||||
if (theCtx == NULL)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Setup the sprinklers. */
|
||||
theRet = sprinklers_setup();
|
||||
if (theRet != 0) {
|
||||
if (theRet != 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Impossible to Setup the Sprinkers.\n");
|
||||
return theRet;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*!
|
||||
* sprinklers.c
|
||||
*
|
||||
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -29,16 +28,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
#include <json-c/json.h>
|
||||
#include <string>
|
||||
|
||||
#include <ubus-cpp/UBusCall.h>
|
||||
#include <ubus-cpp/ubus-call.h>
|
||||
|
||||
#include "sprinklers.h"
|
||||
|
||||
/*-------------------------------- GLOBALES ---------------------------------*/
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn sprinklers_setup
|
||||
*
|
||||
@@ -50,41 +48,43 @@ int sprinklers_setup (void)
|
||||
std::string theResult;
|
||||
int theIDVal;
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "Setup the Gpios used by the Sprinklers.\n");
|
||||
|
||||
if (theCmd.Exec ("domo.capabilities.sprinklers", "get", "", theResult) == 0){
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
for (const Json::Value& theElement : theRoot["Sprinklers"]) {
|
||||
for (const Json::Value &theElement : theRoot["Sprinklers"])
|
||||
{
|
||||
|
||||
theIDVal = theElement["id"].asInt();
|
||||
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];
|
||||
|
||||
#if 0
|
||||
printf(" Setup the Station: %d\n", aStation);
|
||||
|
||||
// Activate the Gpio
|
||||
@@ -98,53 +98,52 @@ int sprinkler_setup_station (int aStation)
|
||||
// Select the Direction of the Gpio
|
||||
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];
|
||||
|
||||
#if 0
|
||||
sprintf(theGpioPath, "/sys/class/gpio/gpio%d/value", aStation);
|
||||
|
||||
theFp = fopen(theGpioPath, "w");
|
||||
|
||||
if (theFp == NULL) {
|
||||
|
||||
if (theFp == NULL)
|
||||
{
|
||||
fprintf(stderr, "Impossible to open: <%s>\n", theGpioPath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (aState) {
|
||||
|
||||
if (aState)
|
||||
{
|
||||
fwrite("0", 1, 1, theFp);
|
||||
}
|
||||
else {
|
||||
|
||||
else
|
||||
{
|
||||
fwrite("1", 1, 1, 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];
|
||||
@@ -155,7 +154,8 @@ int sprinklers_get_station (uint32_t aStation, bool &aState)
|
||||
|
||||
theFp = fopen(theGpioPath, "r");
|
||||
|
||||
if (theFp == NULL) {
|
||||
if (theFp == NULL)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Impossible to open: <%s>\n", theGpioPath);
|
||||
return -1;
|
||||
@@ -165,16 +165,16 @@ int sprinklers_get_station (uint32_t aStation, bool &aState)
|
||||
|
||||
//printf ("theData: %s\n", theData);
|
||||
|
||||
if (theData[0] == '0') {
|
||||
if (theData[0] == '0')
|
||||
{
|
||||
aState = true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
aState = false;
|
||||
}
|
||||
|
||||
fclose(theFp);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*!
|
||||
* sprinklers.h
|
||||
*
|
||||
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -34,9 +33,9 @@
|
||||
|
||||
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 */
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*!
|
||||
* UBusSprinkerModel.cpp
|
||||
*
|
||||
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -23,16 +22,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
// #include <jsoncpp/json.h>
|
||||
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#include <libubox/blobmsg_json.h>
|
||||
}
|
||||
|
||||
@@ -40,29 +39,27 @@ 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
|
||||
*
|
||||
@@ -72,16 +69,15 @@ 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);
|
||||
Json::Reader theReader;
|
||||
@@ -91,7 +87,8 @@ 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");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
@@ -99,7 +96,8 @@ int SprinkerModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aRe
|
||||
|
||||
theStation = theRoot["station"].asInt();
|
||||
|
||||
if (theStation == 0) {
|
||||
if (theStation == 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Station ID is missing.\n");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
@@ -107,7 +105,8 @@ int SprinkerModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aRe
|
||||
|
||||
theResult = sprinklers_get_station(theStation, theState);
|
||||
|
||||
if (theResult != 0) {
|
||||
if (theResult != 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Wrong Station ID (%d).\n", theStation);
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
@@ -124,27 +123,27 @@ int SprinkerModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aRe
|
||||
theResult = ubus_send_reply(aCtx, aReq, theBuf.head);
|
||||
|
||||
blob_buf_free(&theBuf);
|
||||
|
||||
return theResult;
|
||||
#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;
|
||||
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");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
@@ -153,7 +152,8 @@ int SprinkerModel::Set (struct ubus_context *aCtx, struct ubus_request_data *aRe
|
||||
theStation = theRoot["station"].asInt();
|
||||
theState = theRoot["state"].asBool();
|
||||
|
||||
if (theStation == 0) {
|
||||
if (theStation == 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Station ID is missing.\n");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
@@ -161,11 +161,12 @@ int SprinkerModel::Set (struct ubus_context *aCtx, struct ubus_request_data *aRe
|
||||
|
||||
theResult = sprinklers_set_station(theStation, theState);
|
||||
|
||||
if (theResult != 0) {
|
||||
if (theResult != 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Wrong Station ID (%d).\n", theStation);
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
return the_result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*!
|
||||
* UBusModel.h
|
||||
*
|
||||
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -30,20 +29,20 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <ubus-cpp/UBusObject.h>
|
||||
#include <ubus-cpp/ubus-object.h>
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class SprinkerModel : public UBusObject {
|
||||
|
||||
class SprinkerModel : public UBusObject
|
||||
{
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user