aqhome-react, aqhome: added units/functions for handling local variables.
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user