aqhome-react, aqhome: added units/functions for handling local variables.
This commit is contained in:
@@ -15,11 +15,13 @@
|
|||||||
#include "aqhome-react/units/u_logical.h"
|
#include "aqhome-react/units/u_logical.h"
|
||||||
#include "aqhome-react/units/u_valuefilter.h"
|
#include "aqhome-react/units/u_valuefilter.h"
|
||||||
#include "aqhome-react/units/u_valueset.h"
|
#include "aqhome-react/units/u_valueset.h"
|
||||||
|
#include "aqhome-react/units/u_varset.h"
|
||||||
#include "aqhome-react/units/u_stabilize.h"
|
#include "aqhome-react/units/u_stabilize.h"
|
||||||
#include "aqhome-react/units/u_lowpass.h"
|
#include "aqhome-react/units/u_lowpass.h"
|
||||||
#include "aqhome-react/units/u_highpass.h"
|
#include "aqhome-react/units/u_highpass.h"
|
||||||
#include "aqhome-react/units/u_zeroposnegstring.h"
|
#include "aqhome-react/units/u_zeroposnegstring.h"
|
||||||
#include "aqhome-react/units/u_suntime.h"
|
#include "aqhome-react/units/u_suntime.h"
|
||||||
|
#include "aqhome-react/units/u_varchanges.h"
|
||||||
|
|
||||||
|
|
||||||
#include <gwenhywfar/misc.h>
|
#include <gwenhywfar/misc.h>
|
||||||
@@ -114,9 +116,9 @@ AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh)
|
AQHREACT_UNIT *AqHomeReact_GetServerVarChangeUnit(const AQHOME_REACT *aqh)
|
||||||
{
|
{
|
||||||
return aqh?aqh->varChangeUnit:NULL;
|
return aqh?aqh->serverVarChangeUnit:NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -147,6 +149,73 @@ void AqHomeReact_AddUnit(AQHOME_REACT *aqh, AQHREACT_UNIT *unit)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_VARS *AqHomeReact_GetLocalVars(const AQHOME_REACT *aqh)
|
||||||
|
{
|
||||||
|
return aqh?aqh->localVars:NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AqHomeReact_SetCharValue(AQHOME_REACT *aqh, const char *path, const char *value)
|
||||||
|
{
|
||||||
|
if (aqh && aqh->localVars && path && *path) {
|
||||||
|
int rv;
|
||||||
|
uint64_t timestamp;
|
||||||
|
|
||||||
|
timestamp=(uint64_t) time(NULL);
|
||||||
|
rv=AQH_Vars_SetCharValue(aqh->localVars, AQH_VARS_PATHFLAGS_OVERWRITE_VARS, path, value);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
AqHomeReact_UnitVarChanges_StringVarUpdated(aqh->localVarChangeUnit, path, timestamp, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char *AqHomeReact_GetCharValue(AQHOME_REACT *aqh, const char *path, int idx, const char *defaultValue)
|
||||||
|
{
|
||||||
|
if (aqh && aqh->localVars && path && *path) {
|
||||||
|
return AQH_Vars_GetCharValue(aqh->localVars, path, idx, defaultValue);
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AqHomeReact_SetDoubleValue(AQHOME_REACT *aqh, const char *path, double value)
|
||||||
|
{
|
||||||
|
if (aqh && aqh->localVars && path && *path) {
|
||||||
|
int rv;
|
||||||
|
uint64_t timestamp;
|
||||||
|
|
||||||
|
timestamp=(uint64_t) time(NULL);
|
||||||
|
rv=AQH_Vars_SetDoubleValue(aqh->localVars, AQH_VARS_PATHFLAGS_OVERWRITE_VARS, path, value);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
AqHomeReact_UnitVarChanges_DoubleVarUpdated(aqh->localVarChangeUnit, path, timestamp, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double AqHomeReact_GetDoubleValue(AQHOME_REACT *aqh, const char *path, int idx, double defaultValue)
|
||||||
|
{
|
||||||
|
if (aqh && aqh->localVars && path && *path) {
|
||||||
|
return AQH_Vars_GetDoubleValue(aqh->localVars, path, idx, defaultValue);
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType)
|
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType)
|
||||||
{
|
{
|
||||||
/* this does not include u_timer and u_varchanges, because those are only created once globally in init.c */
|
/* this does not include u_timer and u_varchanges, because those are only created once globally in init.c */
|
||||||
@@ -161,6 +230,8 @@ AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitT
|
|||||||
return AqHomeReact_UnitValueFilter_new(aqh);
|
return AqHomeReact_UnitValueFilter_new(aqh);
|
||||||
else if (strcasecmp(unitType, "valueSet")==0)
|
else if (strcasecmp(unitType, "valueSet")==0)
|
||||||
return AqHomeReact_UnitValueSet_new(aqh);
|
return AqHomeReact_UnitValueSet_new(aqh);
|
||||||
|
else if (strcasecmp(unitType, "varSet")==0)
|
||||||
|
return AqHomeReact_UnitVarSet_new(aqh);
|
||||||
else if (strcasecmp(unitType, "stabilize")==0)
|
else if (strcasecmp(unitType, "stabilize")==0)
|
||||||
return AqHomeReact_UnitStabilize_new(aqh);
|
return AqHomeReact_UnitStabilize_new(aqh);
|
||||||
else if (strcasecmp(unitType, "lowPass")==0)
|
else if (strcasecmp(unitType, "lowPass")==0)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
typedef struct AQHOME_REACT AQHOME_REACT;
|
typedef struct AQHOME_REACT AQHOME_REACT;
|
||||||
|
|
||||||
#include "aqhome-react/types/unit.h"
|
#include "aqhome-react/types/unit.h"
|
||||||
|
#include "aqhome/data/vars.h"
|
||||||
|
|
||||||
|
|
||||||
AQHOME_REACT *AqHomeReact_new();
|
AQHOME_REACT *AqHomeReact_new();
|
||||||
@@ -34,13 +35,21 @@ void AqHomeReact_SetLatestNetworkFileTime(AQHOME_REACT *aqh, time_t t);
|
|||||||
|
|
||||||
|
|
||||||
AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh);
|
AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh);
|
||||||
AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh);
|
AQHREACT_UNIT *AqHomeReact_GetServerVarChangeUnit(const AQHOME_REACT *aqh);
|
||||||
|
AQHREACT_UNIT *AqHomeReact_GetLocalVarChangeUnit(const AQHOME_REACT *aqh);
|
||||||
|
|
||||||
AQHREACT_UNIT *AqHomeReact_FindUnitByUnitId(const AQHOME_REACT *aqh, const char *unitId);
|
AQHREACT_UNIT *AqHomeReact_FindUnitByUnitId(const AQHOME_REACT *aqh, const char *unitId);
|
||||||
void AqHomeReact_AddUnit(AQHOME_REACT *aqh, AQHREACT_UNIT *unit);
|
void AqHomeReact_AddUnit(AQHOME_REACT *aqh, AQHREACT_UNIT *unit);
|
||||||
|
|
||||||
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType);
|
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType);
|
||||||
|
|
||||||
|
AQH_VARS *AqHomeReact_GetLocalVars(const AQHOME_REACT *aqh);
|
||||||
|
|
||||||
|
int AqHomeReact_SetCharValue(AQHOME_REACT *aqh, const char *path, const char *value);
|
||||||
|
const char *AqHomeReact_GetCharValue(AQHOME_REACT *aqh, const char *path, int idx, const char *defaultValue);
|
||||||
|
|
||||||
|
int AqHomeReact_SetDoubleValue(AQHOME_REACT *aqh, const char *path, double value);
|
||||||
|
double AqHomeReact_GetDoubleValue(AQHOME_REACT *aqh, const char *path, int idx, double defaultValue);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,12 @@ struct AQHOME_REACT {
|
|||||||
int timeout; /* timeout for run e.g. inside valgrind */
|
int timeout; /* timeout for run e.g. inside valgrind */
|
||||||
|
|
||||||
AQHREACT_UNIT *timerUnit;
|
AQHREACT_UNIT *timerUnit;
|
||||||
AQHREACT_UNIT *varChangeUnit;
|
AQHREACT_UNIT *serverVarChangeUnit;
|
||||||
|
AQHREACT_UNIT *localVarChangeUnit;
|
||||||
AQHREACT_UNIT_LIST *unitList;
|
AQHREACT_UNIT_LIST *unitList;
|
||||||
|
|
||||||
|
AQH_VARS *localVars;
|
||||||
|
|
||||||
time_t latestNetworkFileTime;
|
time_t latestNetworkFileTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -50,10 +50,13 @@ int AqHomeReact_Fini(AQHOME_REACT *aqh)
|
|||||||
|
|
||||||
AQHREACT_Unit_List_Clear(aqh->unitList);
|
AQHREACT_Unit_List_Clear(aqh->unitList);
|
||||||
aqh->timerUnit=NULL;
|
aqh->timerUnit=NULL;
|
||||||
aqh->varChangeUnit=NULL;
|
aqh->serverVarChangeUnit=NULL;
|
||||||
|
aqh->localVarChangeUnit=NULL;
|
||||||
|
|
||||||
if (aqh->pidFile)
|
if (aqh->pidFile)
|
||||||
remove(aqh->pidFile);
|
remove(aqh->pidFile);
|
||||||
|
|
||||||
|
AQH_Vars_free(aqh->localVars);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ int AqHomeReact_Init(AQHOME_REACT *aqh, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aqh->localVars=AQH_Vars_CreateGroup("localVars");
|
||||||
|
|
||||||
rv=AqHomeReact_ReloadUnitNets(aqh);
|
rv=AqHomeReact_ReloadUnitNets(aqh);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_ERROR(NULL, "Error reading unit network files (%d)", rv);
|
DBG_ERROR(NULL, "Error reading unit network files (%d)", rv);
|
||||||
@@ -126,7 +128,7 @@ int AqHomeReact_ReloadUnitNets(AQHOME_REACT *aqh)
|
|||||||
|
|
||||||
AQHREACT_Unit_List_Clear(aqh->unitList);
|
AQHREACT_Unit_List_Clear(aqh->unitList);
|
||||||
aqh->timerUnit=NULL;
|
aqh->timerUnit=NULL;
|
||||||
aqh->varChangeUnit=NULL;
|
aqh->serverVarChangeUnit=NULL;
|
||||||
|
|
||||||
_setupBuiltinUnits(aqh);
|
_setupBuiltinUnits(aqh);
|
||||||
|
|
||||||
@@ -238,7 +240,12 @@ void _setupBuiltinUnits(AQHOME_REACT *aqh)
|
|||||||
unit=AqHomeReact_UnitVarChanges_new(aqh);
|
unit=AqHomeReact_UnitVarChanges_new(aqh);
|
||||||
AQHREACT_Unit_SetId(unit, ".updatedValue");
|
AQHREACT_Unit_SetId(unit, ".updatedValue");
|
||||||
AQHREACT_Unit_List_Add(unit, aqh->unitList);
|
AQHREACT_Unit_List_Add(unit, aqh->unitList);
|
||||||
aqh->varChangeUnit=unit;
|
aqh->serverVarChangeUnit=unit;
|
||||||
|
|
||||||
|
unit=AqHomeReact_UnitVarChanges_new(aqh);
|
||||||
|
AQHREACT_Unit_SetId(unit, ".updatedVar");
|
||||||
|
AQHREACT_Unit_List_Add(unit, aqh->unitList);
|
||||||
|
aqh->localVarChangeUnit=unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void AqHomeReact_IoLoop(AQHOME_REACT *aqh, int timeoutInMilliSecs)
|
|||||||
code=GWEN_IpcMsg_GetCode(msg);
|
code=GWEN_IpcMsg_GetCode(msg);
|
||||||
if (code==AQH_MSGTYPE_IPC_DATA_DATACHANGED) {
|
if (code==AQH_MSGTYPE_IPC_DATA_DATACHANGED) {
|
||||||
DBG_DEBUG(NULL, "Received expected IPC message");
|
DBG_DEBUG(NULL, "Received expected IPC message");
|
||||||
_handleDataResponse(aqh->varChangeUnit, msg);
|
_handleDataResponse(aqh->serverVarChangeUnit, msg);
|
||||||
}
|
}
|
||||||
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||||
DBG_INFO(NULL, "Received IPC result message, ignoring");
|
DBG_INFO(NULL, "Received IPC result message, ignoring");
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
u_highpass.h
|
u_highpass.h
|
||||||
u_stabilize.h
|
u_stabilize.h
|
||||||
u_valueset.h
|
u_valueset.h
|
||||||
|
u_varset.h
|
||||||
u_zeroposnegstring.h
|
u_zeroposnegstring.h
|
||||||
u_module.h
|
u_module.h
|
||||||
u_module_p.h
|
u_module_p.h
|
||||||
@@ -66,6 +67,7 @@
|
|||||||
u_highpass.c
|
u_highpass.c
|
||||||
u_stabilize.c
|
u_stabilize.c
|
||||||
u_valueset.c
|
u_valueset.c
|
||||||
|
u_varset.c
|
||||||
u_zeroposnegstring.c
|
u_zeroposnegstring.c
|
||||||
u_module.c
|
u_module.c
|
||||||
u_suntime.c
|
u_suntime.c
|
||||||
|
|||||||
@@ -52,6 +52,48 @@ void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALU
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AqHomeReact_UnitVarChanges_DoubleVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, double data)
|
||||||
|
{
|
||||||
|
AQHREACT_PORT *outputPort;
|
||||||
|
|
||||||
|
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||||
|
if (outputPort) {
|
||||||
|
AQHREACT_DATAOBJECT *dataObject;
|
||||||
|
|
||||||
|
DBG_DEBUG(NULL, "Variable \"%s\" changed (double)", varName);
|
||||||
|
dataObject=AQHREACT_DataObject_new();
|
||||||
|
AQHREACT_DataObject_SetDataType(dataObject, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||||
|
AQHREACT_DataObject_SetTimestamp(dataObject, timestamp);
|
||||||
|
AQHREACT_DataObject_SetDoubleData(dataObject, data);
|
||||||
|
AQHREACT_DataObject_SetSystemValueId(dataObject, varName);
|
||||||
|
AQHREACT_Unit_OutputData(unit, outputPort, dataObject);
|
||||||
|
AQHREACT_DataObject_free(dataObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AqHomeReact_UnitVarChanges_StringVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, const char *data)
|
||||||
|
{
|
||||||
|
AQHREACT_PORT *outputPort;
|
||||||
|
|
||||||
|
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||||
|
if (outputPort) {
|
||||||
|
AQHREACT_DATAOBJECT *dataObject;
|
||||||
|
|
||||||
|
DBG_DEBUG(NULL, "Variable \"%s\" changed (string)", varName);
|
||||||
|
dataObject=AQHREACT_DataObject_new();
|
||||||
|
AQHREACT_DataObject_SetDataType(dataObject, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||||
|
AQHREACT_DataObject_SetTimestamp(dataObject, timestamp);
|
||||||
|
AQHREACT_DataObject_SetStringData(dataObject, data);
|
||||||
|
AQHREACT_DataObject_SetSystemValueId(dataObject, varName);
|
||||||
|
AQHREACT_Unit_OutputData(unit, outputPort, dataObject);
|
||||||
|
AQHREACT_DataObject_free(dataObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,22 @@
|
|||||||
|
|
||||||
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh);
|
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from AqHomeReact when a value on the server changed.
|
||||||
|
*/
|
||||||
void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALUE *value, uint64_t timestamp, double data);
|
void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALUE *value, uint64_t timestamp, double data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from AqHomeReact when a local variable changed (see @ref AqHomeReact_SetDoubleValue).
|
||||||
|
*/
|
||||||
|
void AqHomeReact_UnitVarChanges_DoubleVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, double data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from AqHomeReact when a local variable changed (see @ref AqHomeReact_SetCharValue).
|
||||||
|
*/
|
||||||
|
void AqHomeReact_UnitVarChanges_StringVarUpdated(AQHREACT_UNIT *unit, const char *varName, uint64_t timestamp, const char *data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
128
apps/aqhome-react/units/u_varset.c
Normal file
128
apps/aqhome-react/units/u_varset.c
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
|
||||||
|
*
|
||||||
|
* The license for this file can be found in the file COPYING which you
|
||||||
|
* should have received along with this file.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "./u_varset.h"
|
||||||
|
|
||||||
|
#include "aqhome/ipc/data/msg_data_set.h"
|
||||||
|
#include "aqhome/ipc/data/ipc_data.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
#include <gwenhywfar/text.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define DEBUG_DRY_RUN 1 /* don't actually set value if "1" */
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* defines
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define AQHOMEREACT_UNIT_VARSET_INSLOT_VALUE 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* forward declarations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||||
|
static void _setDoubleValue(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject);
|
||||||
|
static void _setStringValue(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* implementations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
AQHREACT_UNIT *AqHomeReact_UnitVarSet_new(AQHOME_REACT *aqh)
|
||||||
|
{
|
||||||
|
AQHREACT_UNIT *unit;
|
||||||
|
AQHREACT_PORT *port;
|
||||||
|
AQHREACT_PARAM *param;
|
||||||
|
|
||||||
|
unit=AQHREACT_Unit_new(aqh);
|
||||||
|
AQHREACT_Unit_SetTypeName(unit, "varset");
|
||||||
|
AQHREACT_Unit_SetDescription(unit, "Set variable");
|
||||||
|
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||||
|
|
||||||
|
port=AQHREACT_Port_new();
|
||||||
|
AQHREACT_Port_SetName(port, "input");
|
||||||
|
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VARSET_INSLOT_VALUE);
|
||||||
|
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||||
|
AQHREACT_Unit_AddInputPort(unit, port);
|
||||||
|
|
||||||
|
param=AQHREACT_Param_new();
|
||||||
|
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VARSET_PARAM_VALUENAME);
|
||||||
|
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||||
|
AQHREACT_Unit_AddParam(unit, param);
|
||||||
|
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||||
|
{
|
||||||
|
if (unit && port && dataObject && AQHREACT_Port_GetIdForUnit(port)==AQHOMEREACT_UNIT_VARSET_INSLOT_VALUE) {
|
||||||
|
const char *sValueName;
|
||||||
|
|
||||||
|
sValueName=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VARSET_PARAM_VALUENAME, NULL);
|
||||||
|
if (sValueName && *sValueName) {
|
||||||
|
switch(AQHREACT_DataObject_GetDataType(dataObject)) {
|
||||||
|
case AQHREACT_DATAOBJECTTYPE_DOUBLE:
|
||||||
|
_setDoubleValue(unit, sValueName, dataObject);
|
||||||
|
break;
|
||||||
|
case AQHREACT_DATAOBJECTTYPE_STRING:
|
||||||
|
_setStringValue(unit, sValueName, dataObject);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DBG_INFO(NULL, "Unhandled data type (%d)", AQHREACT_DataObject_GetDataType(dataObject));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void _setDoubleValue(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject)
|
||||||
|
{
|
||||||
|
AQHOME_REACT *aqh;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
aqh=AQHREACT_Unit_GetAqHomeReact(unit);
|
||||||
|
rv=AqHomeReact_SetDoubleValue(aqh, sValueName, AQHREACT_DataObject_GetDoubleData(dataObject));
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void _setStringValue(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject)
|
||||||
|
{
|
||||||
|
AQHOME_REACT *aqh;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
aqh=AQHREACT_Unit_GetAqHomeReact(unit);
|
||||||
|
rv=AqHomeReact_SetCharValue(aqh, sValueName, AQHREACT_DataObject_GetStringData(dataObject));
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
26
apps/aqhome-react/units/u_varset.h
Normal file
26
apps/aqhome-react/units/u_varset.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
|
||||||
|
*
|
||||||
|
* The license for this file can be found in the file COPYING which you
|
||||||
|
* should have received along with this file.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef AQHOMEREACT_U_VARSET_H
|
||||||
|
#define AQHOMEREACT_U_VARSET_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "aqhome-react/aqhome_react.h"
|
||||||
|
#include "aqhome-react/types/unit.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define AQHOMEREACT_UNIT_VARSET_PARAM_VALUENAME "varName"
|
||||||
|
|
||||||
|
|
||||||
|
AQHREACT_UNIT *AqHomeReact_UnitVarSet_new(AQHOME_REACT *aqh);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +87,36 @@ void _releaseData(AQH_VARS *vt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_VARS *_dupData(const AQH_VARS *vt)
|
||||||
|
{
|
||||||
|
if (vt) {
|
||||||
|
AQH_VARS *vtCopy;
|
||||||
|
|
||||||
|
vtCopy=_newData();
|
||||||
|
vtCopy->dataType=vt->dataType;
|
||||||
|
switch(vt->dataType) {
|
||||||
|
case AQH_Vars_DataType_Unknown:
|
||||||
|
break;
|
||||||
|
case AQH_Vars_DataType_Group:
|
||||||
|
case AQH_Vars_DataType_Variable:
|
||||||
|
case AQH_Vars_DataType_ValueString:
|
||||||
|
vtCopy->data.dataString=(vt->data.dataString)?strdup(vt->data.dataString):NULL;
|
||||||
|
break;
|
||||||
|
case AQH_Vars_DataType_ValueInt:
|
||||||
|
vtCopy->data.dataInt=vt->data.dataInt;
|
||||||
|
break;
|
||||||
|
case AQH_Vars_DataType_ValueDouble:
|
||||||
|
vtCopy->data.dataDouble=vt->data.dataDouble;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vtCopy;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AQH_Vars_free(AQH_VARS *vt)
|
void AQH_Vars_free(AQH_VARS *vt)
|
||||||
{
|
{
|
||||||
if (vt) {
|
if (vt) {
|
||||||
@@ -98,6 +128,24 @@ void AQH_Vars_free(AQH_VARS *vt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_VARS *AQH_Vars_dup(const AQH_VARS *vt)
|
||||||
|
{
|
||||||
|
AQH_VARS *vtCopy;
|
||||||
|
AQH_VARS *vtChild;
|
||||||
|
|
||||||
|
vtCopy=_dupData(vt);
|
||||||
|
vtChild=AQH_Vars_Tree2_GetFirstChild(vt);
|
||||||
|
while(vtChild) {
|
||||||
|
AQH_Vars_Tree2_AddChild(vtCopy, _dupData(vtChild));
|
||||||
|
vtChild=AQH_Vars_Tree2_GetNext(vtChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vtCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_VARS *AQH_Vars_CreateGroup(const char *s)
|
AQH_VARS *AQH_Vars_CreateGroup(const char *s)
|
||||||
{
|
{
|
||||||
return _newStringElement(s?strdup(s):NULL, AQH_Vars_DataType_Group);
|
return _newStringElement(s?strdup(s):NULL, AQH_Vars_DataType_Group);
|
||||||
@@ -266,6 +314,13 @@ AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_VARS *AQH_Vars_GetGroup(AQH_VARS *vt, const char *path, uint32_t flags)
|
||||||
|
{
|
||||||
|
return vt?_getPath(vt, path, (flags & ~AQH_PATH_FLAGS_VARIABLE)):NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value)
|
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value)
|
||||||
{
|
{
|
||||||
if (vt) {
|
if (vt) {
|
||||||
@@ -404,8 +459,6 @@ AQH_VARS *_getValueNodeByIdx(const AQH_VARS *vt, int idx)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags)
|
AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags)
|
||||||
{
|
{
|
||||||
return (AQH_VARS *)AQH_Path_Handle(s, (void*) vt, flags, "/", _pathHandlerFn);
|
return (AQH_VARS *)AQH_Path_Handle(s, (void*) vt, flags, "/", _pathHandlerFn);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#ifndef AQH_VARS_H
|
#ifndef AQH_VARS_H
|
||||||
#define AQH_VARS_H
|
#define AQH_VARS_H
|
||||||
|
|
||||||
|
#include <aqhome/api.h>
|
||||||
|
|
||||||
#include <gwenhywfar/tree2.h>
|
#include <gwenhywfar/tree2.h>
|
||||||
|
|
||||||
@@ -30,43 +31,53 @@ typedef enum {
|
|||||||
|
|
||||||
|
|
||||||
typedef struct AQH_VARS AQH_VARS;
|
typedef struct AQH_VARS AQH_VARS;
|
||||||
GWEN_TREE2_FUNCTION_DEFS(AQH_VARS, AQH_Vars);
|
GWEN_TREE2_FUNCTION_LIB_DEFS(AQH_VARS, AQH_Vars, AQHOME_API);
|
||||||
|
|
||||||
|
|
||||||
AQH_VARS *AQH_Vars_CreateGroup(const char *s);
|
AQHOME_API AQH_VARS *AQH_Vars_CreateGroup(const char *s);
|
||||||
AQH_VARS *AQH_Vars_CreateVariable(const char *s);
|
AQHOME_API AQH_VARS *AQH_Vars_CreateVariable(const char *s);
|
||||||
AQH_VARS *AQH_Vars_CreateStringValue(char *s);
|
AQHOME_API AQH_VARS *AQH_Vars_CreateStringValue(char *s);
|
||||||
AQH_VARS *AQH_Vars_CreateIntValue(int d);
|
AQHOME_API AQH_VARS *AQH_Vars_CreateIntValue(int d);
|
||||||
AQH_VARS *AQH_Vars_CreateDoubleValue(double d);
|
AQHOME_API AQH_VARS *AQH_Vars_CreateDoubleValue(double d);
|
||||||
|
|
||||||
void AQH_Vars_free(AQH_VARS *vt);
|
AQHOME_API AQH_VARS *AQH_Vars_dup(const AQH_VARS *vt);
|
||||||
|
|
||||||
|
AQHOME_API void AQH_Vars_free(AQH_VARS *vt);
|
||||||
|
|
||||||
|
|
||||||
AQH_VARS_DATATYPE AQH_Vars_GetDataType(const AQH_VARS *vt);
|
AQHOME_API AQH_VARS_DATATYPE AQH_Vars_GetDataType(const AQH_VARS *vt);
|
||||||
uint32_t AQH_Vars_GetFlags(const AQH_VARS *vt);
|
AQHOME_API uint32_t AQH_Vars_GetFlags(const AQH_VARS *vt);
|
||||||
|
|
||||||
const char *AQH_Vars_GetStringData(const AQH_VARS *vt, const char *defValue);
|
AQHOME_API const char *AQH_Vars_GetStringData(const AQH_VARS *vt, const char *defValue);
|
||||||
void AQH_Vars_SetStringData(AQH_VARS *vt, char *s);
|
AQHOME_API void AQH_Vars_SetStringData(AQH_VARS *vt, char *s);
|
||||||
|
|
||||||
int AQH_Vars_GetIntData(const AQH_VARS *vt, int defValue);
|
AQHOME_API int AQH_Vars_GetIntData(const AQH_VARS *vt, int defValue);
|
||||||
void AQH_Vars_SetIntData(AQH_VARS *vt, int d);
|
AQHOME_API void AQH_Vars_SetIntData(AQH_VARS *vt, int d);
|
||||||
|
|
||||||
double AQH_Vars_GetDoubleData(const AQH_VARS *vt, double defValue);
|
AQHOME_API double AQH_Vars_GetDoubleData(const AQH_VARS *vt, double defValue);
|
||||||
void AQH_Vars_SetDoubleData(AQH_VARS *vt, double d);
|
AQHOME_API void AQH_Vars_SetDoubleData(AQH_VARS *vt, double d);
|
||||||
|
|
||||||
|
|
||||||
AQH_VARS *AQH_Vars_GetFirstChildByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt);
|
AQHOME_API AQH_VARS *AQH_Vars_GetFirstChildByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt);
|
||||||
AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt);
|
AQHOME_API AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt);
|
||||||
|
|
||||||
|
|
||||||
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value);
|
|
||||||
const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const char *defaultValue);
|
|
||||||
|
|
||||||
int AQH_Vars_SetIntValue(AQH_VARS *vt, uint32_t flags, const char *path, int value);
|
/**
|
||||||
int AQH_Vars_GetIntValue(AQH_VARS *vt, const char *path, int idx, int defaultValue);
|
* @name Functions Using Paths
|
||||||
|
*/
|
||||||
|
/*@{*/
|
||||||
|
AQHOME_API AQH_VARS *AQH_Vars_GetGroup(AQH_VARS *vt, const char *path, uint32_t flags);
|
||||||
|
|
||||||
int AQH_Vars_SetDoubleValue(AQH_VARS *vt, uint32_t flags, const char *path, double value);
|
AQHOME_API int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value);
|
||||||
double AQH_Vars_GetDoubleValue(AQH_VARS *vt, const char *path, int idx, double defaultValue);
|
AQHOME_API const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const char *defaultValue);
|
||||||
|
|
||||||
|
AQHOME_API int AQH_Vars_SetIntValue(AQH_VARS *vt, uint32_t flags, const char *path, int value);
|
||||||
|
AQHOME_API int AQH_Vars_GetIntValue(AQH_VARS *vt, const char *path, int idx, int defaultValue);
|
||||||
|
|
||||||
|
AQHOME_API int AQH_Vars_SetDoubleValue(AQH_VARS *vt, uint32_t flags, const char *path, double value);
|
||||||
|
AQHOME_API double AQH_Vars_GetDoubleValue(AQH_VARS *vt, const char *path, int idx, double defaultValue);
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user