aqhome-react, aqhome: added units/functions for handling local variables.
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
u_highpass.h
|
||||
u_stabilize.h
|
||||
u_valueset.h
|
||||
u_varset.h
|
||||
u_zeroposnegstring.h
|
||||
u_module.h
|
||||
u_module_p.h
|
||||
@@ -66,6 +67,7 @@
|
||||
u_highpass.c
|
||||
u_stabilize.c
|
||||
u_valueset.c
|
||||
u_varset.c
|
||||
u_zeroposnegstring.c
|
||||
u_module.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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user