aqhome-react: major rebuild of unit handling.
now nested networks are allowed to allow for complex networks.
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
|
||||
|
||||
|
||||
@@ -43,8 +43,7 @@ static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_
|
||||
AQHREACT_UNIT *AqHomeReact_UnitHighPass_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
AQHREACT_PARAM *param;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
@@ -52,17 +51,17 @@ AQHREACT_UNIT *AqHomeReact_UnitHighPass_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetDescription(unit, "Highpass filter for data");
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
param=AQHREACT_Param_new();
|
||||
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_HIGHPASS_PARAM_LIMIT);
|
||||
@@ -79,17 +78,22 @@ AQHREACT_UNIT *AqHomeReact_UnitHighPass_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT) {
|
||||
double data;
|
||||
double limit;
|
||||
double newValue;
|
||||
if (unit && port && dataObject && AQHREACT_Port_GetIdForUnit(port)==AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT) {
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
limit=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HIGHPASS_PARAM_LIMIT, data);
|
||||
newValue=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HIGHPASS_PARAM_NEWVALUE, data);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT, (data>=limit)?data:newValue);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT);
|
||||
if (outputPort) {
|
||||
double data;
|
||||
double limit;
|
||||
double newValue;
|
||||
|
||||
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
limit=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HIGHPASS_PARAM_LIMIT, data);
|
||||
newValue=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HIGHPASS_PARAM_NEWVALUE, data);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, outputPort, (data>=limit)?data:newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,27 +89,26 @@ AQHREACT_UNIT *AqHomeReact_UnitXor_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_UNIT *_unitLogical_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
AQHREACT_Unit_SetName(unit, "or");
|
||||
AQHREACT_Unit_SetDescription(unit, "Logical OR inputs");
|
||||
|
||||
AQHREACT_Unit_SetNextInputSlotId(unit, AQHOMEREACT_UNIT_LOGICAL_INSLOT_AUTOINPUT); /* for auto-gen multi-slots */
|
||||
AQHREACT_Unit_SetNextInputPortId(unit, AQHOMEREACT_UNIT_LOGICAL_INSLOT_AUTOINPUT); /* for auto-gen multi-slots */
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_LOGICAL_INSLOT_INPUT);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_InputSlot_AddFlags(inputSlot, AQHREACT_UNIT_FLAGS_MULTI);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_LOGICAL_INSLOT_INPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Port_AddFlags(port, AQHREACT_UNIT_FLAGS_MULTI);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
return unit;
|
||||
}
|
||||
@@ -119,41 +118,46 @@ AQHREACT_UNIT *_unitLogical_new(AQHOME_REACT *aqh)
|
||||
int _cbProcessOr(AQHREACT_UNIT *unit)
|
||||
{
|
||||
if (unit && AQHREACT_Unit_InputHasChanged(unit)) {
|
||||
AQHREACT_INPUT_SLOT_LIST *inputSlotList;
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
inputSlotList=AQHREACT_Unit_GetInputSlots(unit);
|
||||
if (inputSlotList) {
|
||||
const AQHREACT_INPUT_SLOT *inputSlot;
|
||||
int result=0;
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_List_First(inputSlotList);
|
||||
while(inputSlot) {
|
||||
const char *slotName;
|
||||
const AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
slotName=AQHREACT_InputSlot_GetName(inputSlot);
|
||||
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(inputSlot);
|
||||
if (dataObject) {
|
||||
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
||||
double d;
|
||||
|
||||
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (d>0.0)
|
||||
result|=1;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", slotName?slotName:"<unnamed>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", slotName?slotName:"<unnamed>");
|
||||
}
|
||||
inputSlot=AQHREACT_InputSlot_List_Next(inputSlot);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT);
|
||||
if (outputPort) {
|
||||
AQHREACT_PORT_LIST *portList;
|
||||
|
||||
portList=AQHREACT_Unit_GetInputPortList(unit);
|
||||
if (portList) {
|
||||
const AQHREACT_PORT *port;
|
||||
int result=0;
|
||||
|
||||
port=AQHREACT_Port_List_First(portList);
|
||||
while(port) {
|
||||
const char *portName;
|
||||
const AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
portName=AQHREACT_Port_GetName(port);
|
||||
dataObject=AQHREACT_Port_GetCurrentDataObject(port);
|
||||
if (dataObject) {
|
||||
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
||||
double d;
|
||||
|
||||
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (d>0.0)
|
||||
result|=1;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", portName?portName:"<unnamed>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", portName?portName:"<unnamed>");
|
||||
}
|
||||
port=AQHREACT_Port_List_Next(port);
|
||||
}
|
||||
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(unit);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, outputPort, result?1.0:0.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT, result?1.0:0.0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,41 +169,46 @@ int _cbProcessOr(AQHREACT_UNIT *unit)
|
||||
int _cbProcessAnd(AQHREACT_UNIT *unit)
|
||||
{
|
||||
if (unit && AQHREACT_Unit_InputHasChanged(unit)) {
|
||||
AQHREACT_INPUT_SLOT_LIST *inputSlotList;
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
inputSlotList=AQHREACT_Unit_GetInputSlots(unit);
|
||||
if (inputSlotList) {
|
||||
const AQHREACT_INPUT_SLOT *inputSlot;
|
||||
int result=1;
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_List_First(inputSlotList);
|
||||
while(inputSlot) {
|
||||
const char *slotName;
|
||||
const AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
slotName=AQHREACT_InputSlot_GetName(inputSlot);
|
||||
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(inputSlot);
|
||||
if (dataObject) {
|
||||
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
||||
double d;
|
||||
|
||||
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (!(d>0.0))
|
||||
result=0;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", slotName?slotName:"<unnamed>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", slotName?slotName:"<unnamed>");
|
||||
}
|
||||
inputSlot=AQHREACT_InputSlot_List_Next(inputSlot);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT);
|
||||
if (outputPort) {
|
||||
AQHREACT_PORT_LIST *portList;
|
||||
|
||||
portList=AQHREACT_Unit_GetInputPortList(unit);
|
||||
if (portList) {
|
||||
AQHREACT_PORT *port;
|
||||
int result=1;
|
||||
|
||||
port=AQHREACT_Port_List_First(portList);
|
||||
while(port) {
|
||||
const char *portName;
|
||||
const AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
portName=AQHREACT_Port_GetName(port);
|
||||
dataObject=AQHREACT_Port_GetCurrentDataObject(port);
|
||||
if (dataObject) {
|
||||
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
||||
double d;
|
||||
|
||||
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (!(d>0.0))
|
||||
result=0;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", portName?portName:"<unnamed>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", portName?portName:"<unnamed>");
|
||||
}
|
||||
port=AQHREACT_Port_List_Next(port);
|
||||
}
|
||||
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(unit);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, port, result?1.0:0.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT, result?1.0:0.0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,41 +220,46 @@ int _cbProcessAnd(AQHREACT_UNIT *unit)
|
||||
int _cbProcessXor(AQHREACT_UNIT *unit)
|
||||
{
|
||||
if (unit && AQHREACT_Unit_InputHasChanged(unit)) {
|
||||
AQHREACT_INPUT_SLOT_LIST *inputSlotList;
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
inputSlotList=AQHREACT_Unit_GetInputSlots(unit);
|
||||
if (inputSlotList) {
|
||||
const AQHREACT_INPUT_SLOT *inputSlot;
|
||||
int result=0;
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_List_First(inputSlotList);
|
||||
while(inputSlot) {
|
||||
const char *slotName;
|
||||
const AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
slotName=AQHREACT_InputSlot_GetName(inputSlot);
|
||||
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(inputSlot);
|
||||
if (dataObject) {
|
||||
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
||||
double d;
|
||||
|
||||
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (d>0.0)
|
||||
result^=1; /*only xor when >0.0, otherwise no change (x XOR 0 is still x) */
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", slotName?slotName:"<unnamed>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", slotName?slotName:"<unnamed>");
|
||||
}
|
||||
inputSlot=AQHREACT_InputSlot_List_Next(inputSlot);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT);
|
||||
if (outputPort) {
|
||||
AQHREACT_PORT_LIST *portList;
|
||||
|
||||
portList=AQHREACT_Unit_GetInputPortList(unit);
|
||||
if (portList) {
|
||||
AQHREACT_PORT *port;
|
||||
int result=0;
|
||||
|
||||
port=AQHREACT_Port_List_First(portList);
|
||||
while(port) {
|
||||
const char *portName;
|
||||
const AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
portName=AQHREACT_Port_GetName(port);
|
||||
dataObject=AQHREACT_Port_GetCurrentDataObject(port);
|
||||
if (dataObject) {
|
||||
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
||||
double d;
|
||||
|
||||
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (d>0.0)
|
||||
result^=1; /*only xor when >0.0, otherwise no change (x XOR 0 is still x) */
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", portName?portName:"<unnamed>");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", portName?portName:"<unnamed>");
|
||||
}
|
||||
port=AQHREACT_Port_List_Next(port);
|
||||
}
|
||||
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(unit);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, port, result?1.0:0.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_LOGICAL_OUTSLOT_RESULT, result?1.0:0.0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
|
||||
|
||||
|
||||
@@ -43,8 +43,7 @@ static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_
|
||||
AQHREACT_UNIT *AqHomeReact_UnitLowPass_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
AQHREACT_PARAM *param;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
@@ -52,17 +51,17 @@ AQHREACT_UNIT *AqHomeReact_UnitLowPass_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetDescription(unit, "Lowpass filter for data");
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_LOWPASS_OUTSLOT_OUTPUT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_LOWPASS_OUTSLOT_OUTPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_LOWPASS_INSLOT_INPUT);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_LOWPASS_INSLOT_INPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
param=AQHREACT_Param_new();
|
||||
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_LOWPASS_PARAM_LIMIT);
|
||||
@@ -79,17 +78,22 @@ AQHREACT_UNIT *AqHomeReact_UnitLowPass_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_LOWPASS_INSLOT_INPUT) {
|
||||
double data;
|
||||
double limit;
|
||||
double newValue;
|
||||
if (unit && port && dataObject && AQHREACT_Port_GetIdForUnit(port)==AQHOMEREACT_UNIT_LOWPASS_INSLOT_INPUT) {
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
limit=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_LOWPASS_PARAM_LIMIT, data);
|
||||
newValue=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_LOWPASS_PARAM_NEWVALUE, data);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_LOWPASS_OUTSLOT_OUTPUT, (data<=limit)?data:newValue);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_LOWPASS_OUTSLOT_OUTPUT);
|
||||
if (outputPort) {
|
||||
double data;
|
||||
double limit;
|
||||
double newValue;
|
||||
|
||||
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
limit=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_LOWPASS_PARAM_LIMIT, data);
|
||||
newValue=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_LOWPASS_PARAM_NEWVALUE, data);
|
||||
AQHREACT_Unit_OutputDoubleData(unit, outputPort, (data<=limit)?data:newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <gwenhywfar/xml.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
//TODO: set params
|
||||
//TODO: read modules
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -36,31 +36,43 @@ GWEN_LIST_FUNCTIONS(MODULE_PROXY_DESCR, ModuleProxyDescr);
|
||||
*/
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbOutputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static AQHREACT_PARAM *_cbGetParamByName(const AQHREACT_UNIT *unit, const char *paramName);
|
||||
static int _cbProcess(AQHREACT_UNIT *unit);
|
||||
|
||||
static void _readProxyFromXml(AQHREACT_UNIT *unit,
|
||||
GWEN_XMLNODE *xmlNode,
|
||||
static void _readProxyFromXml(GWEN_XMLNODE *xmlNode,
|
||||
MODULE_PROXY_DESCR_LIST *proxyDescrList,
|
||||
const char *mainGroupName,
|
||||
const char *groupName,
|
||||
const char *nameProperty,
|
||||
const char *targetObjectProperty,
|
||||
const char *targetNameProperty);
|
||||
static void _readInputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
||||
static void _readOutputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
||||
static int _finishInSlots(AQHREACT_UNIT *unit);
|
||||
static int _finishOutSlots(AQHREACT_UNIT *unit);
|
||||
static int _readInputPortsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
||||
static int _readOutputPortsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
||||
static int _finishParams(AQHREACT_UNIT *unit);
|
||||
static void _readUnitsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
||||
static AQHREACT_UNIT *_readOneUnitFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *parentUnit, GWEN_XMLNODE *xmlNode);
|
||||
static AQHREACT_UNIT *_readOneUnitFromXml(AQHOME_REACT *aqh, GWEN_XMLNODE *xmlNode);
|
||||
static int _readParamsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNodeUnit, const char *mainGroupName);
|
||||
static int _readParamFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *paramNode);
|
||||
static int _setParamDataFromString(AQHREACT_PARAM *param, const char *value);
|
||||
static int _readLinksFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode);
|
||||
static int _readLinkFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *linkNode);
|
||||
static int _linkFromThisModulesInput(AQHOME_REACT *aqh,
|
||||
AQHREACT_UNIT *unit,
|
||||
const char *emittingPortName,
|
||||
const char *receivingUnitName,
|
||||
const char *receivingPortName);
|
||||
static int _linkToModulesOutput(AQHOME_REACT *aqh,
|
||||
AQHREACT_UNIT *unit,
|
||||
const char *emittingUnitName,
|
||||
const char *emittingPortName,
|
||||
const char *receivingPortName);
|
||||
static int _linkBetweenUnits(AQHOME_REACT *aqh,
|
||||
AQHREACT_UNIT *unit,
|
||||
const char *emittingUnitName,
|
||||
const char *emittingPortName,
|
||||
const char *receivingUnitName,
|
||||
const char *receivingPortName);
|
||||
|
||||
|
||||
|
||||
@@ -138,12 +150,9 @@ AQHREACT_UNIT *AqHomeReact_UnitModule_new(AQHOME_REACT *aqh)
|
||||
GWEN_INHERIT_SETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit, xunit, _freeData);
|
||||
|
||||
xunit->paramProxyList=ModuleProxyDescr_List_new();
|
||||
xunit->inSlotProxyList=ModuleProxyDescr_List_new();
|
||||
xunit->outSlotProxyList=ModuleProxyDescr_List_new();
|
||||
xunit->unitList=AQHREACT_Unit_List_new();
|
||||
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
AQHREACT_Unit_SetOutputDataFn(unit, _cbOutputData);
|
||||
AQHREACT_Unit_SetGetParamByNameFn(unit, _cbGetParamByName);
|
||||
AQHREACT_Unit_SetProcessFn(unit, _cbProcess);
|
||||
|
||||
@@ -152,15 +161,13 @@ AQHREACT_UNIT *AqHomeReact_UnitModule_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _freeData(void *bp, void *p)
|
||||
void _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*) p;
|
||||
|
||||
AQHREACT_Unit_List_free(xunit->unitList);
|
||||
ModuleProxyDescr_List_free(xunit->outSlotProxyList);
|
||||
ModuleProxyDescr_List_free(xunit->inSlotProxyList);
|
||||
ModuleProxyDescr_List_free(xunit->paramProxyList);
|
||||
|
||||
GWEN_FREE_OBJECT(xunit);
|
||||
@@ -171,110 +178,67 @@ void _freeData(void *bp, void *p)
|
||||
AQHREACT_UNIT *AqHomeReact_UnitModule_fromXml(AQHOME_REACT *aqh, GWEN_XMLNODE *xmlNode)
|
||||
{
|
||||
const char *t;
|
||||
const char *id;
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
int rv;
|
||||
|
||||
t=GWEN_XMLNode_GetProperty(xmlNode, "type", NULL);
|
||||
if (t && *t) {
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
int rv;
|
||||
id=GWEN_XMLNode_GetProperty(xmlNode, "id", NULL);
|
||||
|
||||
unit=AqHomeReact_UnitModule_new(aqh);
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
AQHREACT_Unit_SetName(unit, t);
|
||||
unit=AqHomeReact_UnitModule_new(aqh);
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
AQHREACT_Unit_SetName(unit, t);
|
||||
AQHREACT_Unit_SetId(unit, id);
|
||||
|
||||
_readProxyFromXml(unit, xmlNode, xunit->paramProxyList, "paramdefs", "param", "name", "targetModule", "targetParam");
|
||||
_readProxyFromXml(xmlNode, xunit->paramProxyList, "paramdefs", "param", "name", "targetModule", "targetParam");
|
||||
|
||||
_readInputSlotsFromXml(aqh, unit, xmlNode);
|
||||
_readOutputSlotsFromXml(aqh, unit, xmlNode);
|
||||
|
||||
_readUnitsFromXml(aqh, unit, xmlNode);
|
||||
|
||||
rv=_finishInSlots(unit);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
rv=_finishOutSlots(unit);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv=_finishParams(unit);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv=_readParamsFromXml(unit, xmlNode, "paramDefs");
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv=_readLinksFromXml(aqh, unit, xmlNode);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return unit;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No \"type\" property in xml node for module");
|
||||
rv=_readInputPortsFromXml(unit, xmlNode);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv=_readOutputPortsFromXml(unit, xmlNode);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_readUnitsFromXml(aqh, unit, xmlNode);
|
||||
|
||||
rv=_finishParams(unit);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv=_readParamsFromXml(unit, xmlNode, "paramDefs");
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv=_readLinksFromXml(aqh, unit, xmlNode);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
AQHREACT_Unit_free(unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return unit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(GWEN_UNUSED AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
if (xunit) {
|
||||
AQHREACT_INPUT_SLOT *slot;
|
||||
|
||||
slot=AQHREACT_Unit_GetInputSlotByIdForUnit(unit, slotIdForUnit);
|
||||
if (slot) {
|
||||
const char *slotName;
|
||||
const MODULE_PROXY_DESCR *pd;
|
||||
|
||||
slotName=AQHREACT_InputSlot_GetName(slot);
|
||||
pd=ModuleProxyDescr_List_FindByName(xunit->inSlotProxyList, slotName);
|
||||
if (pd)
|
||||
AQHREACT_Unit_InputData(pd->targetObjectPtr, pd->targetIdForModule, dataObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _cbOutputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
if (xunit) {
|
||||
AQHREACT_OUTPUT_SLOT *slot;
|
||||
|
||||
slot=AQHREACT_Unit_GetOutputSlotByIdForUnit(unit, slotIdForUnit);
|
||||
if (slot) {
|
||||
const char *slotName;
|
||||
const MODULE_PROXY_DESCR *pd;
|
||||
|
||||
slotName=AQHREACT_OutputSlot_GetName(slot);
|
||||
pd=ModuleProxyDescr_List_FindByName(xunit->outSlotProxyList, slotName);
|
||||
if (pd)
|
||||
AQHREACT_Unit_OutputData(pd->targetObjectPtr, pd->targetIdForModule, dataObject);
|
||||
}
|
||||
}
|
||||
if (port)
|
||||
AQHREACT_Port_SendData(port, dataObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -322,8 +286,7 @@ int _cbProcess(AQHREACT_UNIT *unit)
|
||||
|
||||
|
||||
|
||||
void _readProxyFromXml(AQHREACT_UNIT *unit,
|
||||
GWEN_XMLNODE *xmlNode,
|
||||
void _readProxyFromXml(GWEN_XMLNODE *xmlNode,
|
||||
MODULE_PROXY_DESCR_LIST *proxyDescrList,
|
||||
const char *mainGroupName,
|
||||
const char *groupName,
|
||||
@@ -363,136 +326,42 @@ void _readProxyFromXml(AQHREACT_UNIT *unit,
|
||||
|
||||
|
||||
|
||||
void _readInputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
||||
int _readInputPortsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
GWEN_XMLNODE *nGroup;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
|
||||
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "inputSlots", NULL, NULL);
|
||||
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "inputPorts", NULL, NULL);
|
||||
if (nGroup) {
|
||||
GWEN_XMLNODE *n;
|
||||
|
||||
n=GWEN_XMLNode_FindFirstTag(nGroup, "inputSlot", NULL, NULL);
|
||||
n=GWEN_XMLNode_FindFirstTag(nGroup, "inputPort", NULL, NULL);
|
||||
while(n) {
|
||||
const char *name;
|
||||
const char *targetUnit;
|
||||
const char *targetSlot;
|
||||
int slotIdForUnit;
|
||||
int dataType;
|
||||
AQHREACT_PORT *port;
|
||||
|
||||
name=GWEN_XMLNode_GetProperty(n, "name", NULL);
|
||||
targetUnit=GWEN_XMLNode_GetProperty(n, "targetUnit", NULL);
|
||||
targetSlot=GWEN_XMLNode_GetProperty(n, "targetSlot", NULL);
|
||||
slotIdForUnit=GWEN_XMLNode_GetIntProperty(n, "idForUnit", 0);
|
||||
|
||||
if (name && targetUnit && targetSlot) {
|
||||
MODULE_PROXY_DESCR *pd;
|
||||
AQHREACT_INPUT_SLOT *slot;
|
||||
|
||||
pd=ModuleProxyDescr_new(name, targetUnit, targetSlot); /* set pd->targetObjectPtr later */
|
||||
ModuleProxyDescr_List_Add(pd, xunit->inSlotProxyList);
|
||||
|
||||
slot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(slot, name);
|
||||
AQHREACT_InputSlot_SetIdForUnit(slot, slotIdForUnit);
|
||||
AQHREACT_Unit_AddInputSlot(unit, slot);
|
||||
dataType=AQHREACT_DataObjectType_fromString(GWEN_XMLNode_GetProperty(n, "dataType", "double"));
|
||||
if (dataType==AQHREACT_DATAOBJECTTYPE_UNKNOWN) {
|
||||
DBG_ERROR(NULL, "Unknown dataType: %s", GWEN_XMLNode_GetProperty(n, "dataType", "double"));
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Incomplete input slot, ignoring");
|
||||
if (name==NULL) {
|
||||
DBG_ERROR(NULL, "Missing name in input port");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
n=GWEN_XMLNode_FindNextTag(n, "inputSlot", NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _readOutputSlotsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
GWEN_XMLNODE *nGroup;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
|
||||
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "outputSlots", NULL, NULL);
|
||||
if (nGroup) {
|
||||
GWEN_XMLNODE *n;
|
||||
|
||||
n=GWEN_XMLNode_FindFirstTag(nGroup, "outputSlot", NULL, NULL);
|
||||
while(n) {
|
||||
const char *name;
|
||||
const char *targetUnit;
|
||||
const char *targetSlot;
|
||||
int slotIdForUnit;
|
||||
|
||||
name=GWEN_XMLNode_GetProperty(n, "name", NULL);
|
||||
targetUnit=GWEN_XMLNode_GetProperty(n, "targetUnit", NULL);
|
||||
targetSlot=GWEN_XMLNode_GetProperty(n, "targetSlot", NULL);
|
||||
slotIdForUnit=GWEN_XMLNode_GetIntProperty(n, "idForUnit", 0);
|
||||
|
||||
if (name && targetUnit && targetSlot) {
|
||||
MODULE_PROXY_DESCR *pd;
|
||||
AQHREACT_OUTPUT_SLOT *slot;
|
||||
|
||||
pd=ModuleProxyDescr_new(name, targetUnit, targetSlot); /* set pd->targetObjectPtr later */
|
||||
ModuleProxyDescr_List_Add(pd, xunit->outSlotProxyList);
|
||||
|
||||
slot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(slot, name);
|
||||
AQHREACT_OutputSlot_SetIdForUnit(slot, slotIdForUnit);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, slot);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Incomplete output slot, ignoring");
|
||||
}
|
||||
n=GWEN_XMLNode_FindNextTag(n, "outputSlot", NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _finishInSlots(AQHREACT_UNIT *unit)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
MODULE_PROXY_DESCR *pd;
|
||||
const char *unitName;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
unitName=AQHREACT_Unit_GetName(unit);
|
||||
pd=ModuleProxyDescr_List_First(xunit->inSlotProxyList);
|
||||
while(pd) {
|
||||
AQHREACT_UNIT *subUnit;
|
||||
const AQHREACT_INPUT_SLOT *subUnitSlot;
|
||||
AQHREACT_INPUT_SLOT *moduleSlot;
|
||||
|
||||
subUnit=AQHREACT_Unit_List_GetById(xunit->unitList, pd->targetObject);
|
||||
if (subUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Subunit \"%s\" not found for input slot", pd->targetObject);
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
pd->targetObjectPtr=subUnit;
|
||||
|
||||
moduleSlot=AQHREACT_Unit_GetInputSlotByName(subUnit, pd->name);
|
||||
if (moduleSlot==NULL) {
|
||||
DBG_ERROR(NULL, "Unit %s: Input slot \"%s\" not defined", unitName, pd->targetName);
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
subUnitSlot=AQHREACT_Unit_GetInputSlotByName(subUnit, pd->targetName);
|
||||
if (subUnitSlot==NULL) {
|
||||
DBG_ERROR(NULL, "Unit %s: Input slot \"%s\" not found for subunit \"%s\"", unitName, pd->targetName, pd->targetObject);
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
AQHREACT_InputSlot_SetDescription(moduleSlot, AQHREACT_InputSlot_GetDescription(subUnitSlot));
|
||||
AQHREACT_InputSlot_SetFlags(moduleSlot, AQHREACT_InputSlot_GetFlags(subUnitSlot));
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(moduleSlot, AQHREACT_InputSlot_GetAcceptedDataType(subUnitSlot));
|
||||
|
||||
pd->targetIdForModule=AQHREACT_InputSlot_GetIdForUnit(subUnitSlot);
|
||||
|
||||
pd=ModuleProxyDescr_List_Next(pd);
|
||||
/* create input port */
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, name);
|
||||
AQHREACT_Port_SetIdForUnit(port, ++(xunit->lastPortId));
|
||||
AQHREACT_Port_SetDataType(port, dataType);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
n=GWEN_XMLNode_FindNextTag(n, "inputPort", NULL, NULL);
|
||||
} /* while */
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -500,46 +369,42 @@ int _finishInSlots(AQHREACT_UNIT *unit)
|
||||
|
||||
|
||||
|
||||
int _finishOutSlots(AQHREACT_UNIT *unit)
|
||||
int _readOutputPortsFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlNode)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
MODULE_PROXY_DESCR *pd;
|
||||
const char *unitName;
|
||||
GWEN_XMLNODE *nGroup;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
unitName=AQHREACT_Unit_GetName(unit);
|
||||
pd=ModuleProxyDescr_List_First(xunit->outSlotProxyList);
|
||||
while(pd) {
|
||||
AQHREACT_UNIT *subUnit;
|
||||
const AQHREACT_OUTPUT_SLOT *subUnitSlot;
|
||||
AQHREACT_OUTPUT_SLOT *moduleSlot;
|
||||
|
||||
subUnit=AQHREACT_Unit_List_GetById(xunit->unitList, pd->targetObject);
|
||||
if (subUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Subunit \"%s\" not found for output slot", pd->targetObject);
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
nGroup=GWEN_XMLNode_FindFirstTag(xmlNode, "outputPorts", NULL, NULL);
|
||||
if (nGroup) {
|
||||
GWEN_XMLNODE *n;
|
||||
|
||||
n=GWEN_XMLNode_FindFirstTag(nGroup, "outputPort", NULL, NULL);
|
||||
while(n) {
|
||||
const char *name;
|
||||
int dataType;
|
||||
AQHREACT_PORT *port;
|
||||
|
||||
name=GWEN_XMLNode_GetProperty(n, "name", NULL);
|
||||
dataType=AQHREACT_DataObjectType_fromString(GWEN_XMLNode_GetProperty(n, "dataType", "double"));
|
||||
if (dataType==AQHREACT_DATAOBJECTTYPE_UNKNOWN) {
|
||||
DBG_ERROR(NULL, "Unknown dataType: %s", GWEN_XMLNode_GetProperty(n, "dataType", "double"));
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
if (name==NULL) {
|
||||
DBG_ERROR(NULL, "Missing name in output port");
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
/* create input port */
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, name);
|
||||
AQHREACT_Port_SetIdForUnit(port, ++(xunit->lastPortId));
|
||||
AQHREACT_Port_SetDataType(port, dataType);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
n=GWEN_XMLNode_FindNextTag(n, "outputPort", NULL, NULL);
|
||||
}
|
||||
pd->targetObjectPtr=subUnit;
|
||||
|
||||
moduleSlot=AQHREACT_Unit_GetOutputSlotByName(subUnit, pd->name);
|
||||
if (moduleSlot==NULL) {
|
||||
DBG_ERROR(NULL, "Unit %s: Output slot \"%s\" not defined", unitName, pd->targetName);
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
subUnitSlot=AQHREACT_Unit_GetOutputSlotByName(subUnit, pd->targetName);
|
||||
if (subUnitSlot==NULL) {
|
||||
DBG_ERROR(NULL, "Unit %s: Output slot \"%s\" not found for subunit \"%s\"", unitName, pd->targetName, pd->targetObject);
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
AQHREACT_OutputSlot_SetDescription(moduleSlot, AQHREACT_OutputSlot_GetDescription(subUnitSlot));
|
||||
AQHREACT_OutputSlot_SetFlags(moduleSlot, AQHREACT_OutputSlot_GetFlags(subUnitSlot));
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(moduleSlot, AQHREACT_OutputSlot_GetEmittedDataType(subUnitSlot));
|
||||
|
||||
pd->targetIdForModule=AQHREACT_OutputSlot_GetIdForUnit(subUnitSlot);
|
||||
|
||||
pd=ModuleProxyDescr_List_Next(pd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -589,7 +454,7 @@ void _readUnitsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xml
|
||||
while(n) {
|
||||
AQHREACT_UNIT *subUnit;
|
||||
|
||||
subUnit=_readOneUnitFromXml(aqh, unit, n);
|
||||
subUnit=_readOneUnitFromXml(aqh, n);
|
||||
if (subUnit)
|
||||
AQHREACT_Unit_List_Add(subUnit, xunit->unitList);
|
||||
else {
|
||||
@@ -603,7 +468,7 @@ void _readUnitsFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xml
|
||||
|
||||
|
||||
|
||||
AQHREACT_UNIT *_readOneUnitFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *parentUnit, GWEN_XMLNODE *xmlNode)
|
||||
AQHREACT_UNIT *_readOneUnitFromXml(AQHOME_REACT *aqh, GWEN_XMLNODE *xmlNode)
|
||||
{
|
||||
const char *id;
|
||||
const char *t;
|
||||
@@ -750,63 +615,179 @@ int _readLinksFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *xmlN
|
||||
|
||||
int _readLinkFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *linkNode)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
const char *sourceUnitName;
|
||||
const char *sourceSlotName;
|
||||
const char *targetUnitName;
|
||||
const char *targetSlotName;
|
||||
AQHREACT_UNIT *sourceUnit;
|
||||
AQHREACT_UNIT *targetUnit;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_LINK *link;
|
||||
const char *emittingUnitName;
|
||||
const char *emittingPortName;
|
||||
const char *receivingUnitName;
|
||||
const char *receivingPortName;
|
||||
int rv;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
emittingUnitName=GWEN_XMLNode_GetProperty(linkNode, "sourceUnit", ".");
|
||||
emittingPortName=GWEN_XMLNode_GetProperty(linkNode, "sourcePort", NULL);
|
||||
receivingUnitName=GWEN_XMLNode_GetProperty(linkNode, "targetUnit", ".");
|
||||
receivingPortName=GWEN_XMLNode_GetProperty(linkNode, "targetPort", NULL);
|
||||
|
||||
sourceUnitName=GWEN_XMLNode_GetProperty(linkNode, "sourceUnit", NULL);
|
||||
sourceSlotName=GWEN_XMLNode_GetProperty(linkNode, "sourceSlot", NULL);
|
||||
targetUnitName=GWEN_XMLNode_GetProperty(linkNode, "targetUnit", NULL);
|
||||
targetSlotName=GWEN_XMLNode_GetProperty(linkNode, "targetSlot", NULL);
|
||||
|
||||
if (!(sourceUnitName && *sourceUnitName && sourceSlotName && *sourceSlotName &&
|
||||
targetUnitName && *targetUnitName && targetSlotName && *targetSlotName)) {
|
||||
if (!(emittingUnitName && *emittingUnitName && emittingPortName && *emittingPortName &&
|
||||
receivingUnitName && *receivingUnitName && receivingPortName && *receivingPortName)) {
|
||||
DBG_ERROR(NULL,
|
||||
"Link in net \"%s\" needs properties sourceUnit, sourceSlot, targetUnit and targetSlot",
|
||||
"Link in net \"%s\" needs properties sourceUnit, sourcePort, targetUnit and targetPort",
|
||||
AQHREACT_Unit_GetName(unit));
|
||||
return GWEN_ERROR_BAD_DATA;
|
||||
}
|
||||
|
||||
sourceUnit=AQHREACT_Unit_List_GetById(xunit->unitList, sourceUnitName);
|
||||
if (sourceUnit==NULL)
|
||||
sourceUnit=AqHomeReact_FindUnitByNetNameAndUnitId(aqh, NULL, sourceUnitName);
|
||||
if (sourceUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Source unit \"%s\" not found", sourceUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
if (strcasecmp(emittingUnitName, ".")==0)
|
||||
rv=_linkFromThisModulesInput(aqh, unit, emittingPortName, receivingUnitName, receivingPortName);
|
||||
else if (strcasecmp(receivingUnitName, ".")==0)
|
||||
rv=_linkToModulesOutput(aqh, unit, emittingUnitName, emittingPortName, receivingPortName);
|
||||
else
|
||||
rv=_linkBetweenUnits(aqh, unit, emittingUnitName, emittingPortName, receivingUnitName, receivingPortName);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error creating link: %s:%s -> %s:%s (%d)",
|
||||
emittingUnitName, emittingPortName, receivingUnitName, receivingPortName, rv);
|
||||
return rv;
|
||||
}
|
||||
outputSlot=AQHREACT_Unit_GetOutputSlotByName(sourceUnit, sourceSlotName);
|
||||
if (outputSlot==NULL) {
|
||||
DBG_ERROR(NULL, "Output slot \"%s\" not found for source unit \"%s\"", sourceSlotName, sourceUnitName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _linkFromThisModulesInput(AQHOME_REACT *aqh,
|
||||
AQHREACT_UNIT *unit,
|
||||
const char *emittingPortName,
|
||||
const char *receivingUnitName,
|
||||
const char *receivingPortName)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
AQHREACT_UNIT *receivingUnit;
|
||||
AQHREACT_PORT *receivingPort;
|
||||
AQHREACT_PORT *emittingPort;
|
||||
AQHREACT_LINK *link;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
|
||||
receivingUnit=AQHREACT_Unit_List_GetById(xunit->unitList, receivingUnitName);
|
||||
if (receivingUnit==NULL)
|
||||
receivingUnit=AqHomeReact_FindUnitByUnitId(aqh, receivingUnitName);
|
||||
if (receivingUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Target unit \"%s\" not found", receivingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
targetUnit=AQHREACT_Unit_List_GetById(xunit->unitList, targetUnitName);
|
||||
if (targetUnit==NULL)
|
||||
targetUnit=AqHomeReact_FindUnitByNetNameAndUnitId(aqh, NULL, targetUnitName);
|
||||
if (targetUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Target unit \"%s\" not found", targetUnitName);
|
||||
emittingPort=AQHREACT_Unit_GetInputPortByName(unit, emittingPortName); /* find in modules input port list! */
|
||||
if (emittingPort==NULL) {
|
||||
DBG_ERROR(NULL, "Target port \"%s\" not found for source unit \"%s\"", emittingPortName, AQHREACT_Unit_GetName(unit));
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
inputSlot=AQHREACT_Unit_GetOrCreateUnusedInputSlotByName(targetUnit, targetSlotName);
|
||||
if (inputSlot==NULL) {
|
||||
DBG_ERROR(NULL, "Input slot \"%s\" not found for target unit \"%s\"", targetSlotName, targetUnitName);
|
||||
|
||||
receivingPort=AQHREACT_Unit_GetInputPortByName(receivingUnit, receivingPortName);
|
||||
if (receivingPort==NULL) {
|
||||
DBG_ERROR(NULL, "Input port \"%s\" not found for target unit \"%s\"", receivingPortName, receivingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
link=AQHREACT_Link_new();
|
||||
AQHREACT_Link_SetTargetUnitId(link, targetUnitName);
|
||||
AQHREACT_Link_SetTargetUnit(link, targetUnit);
|
||||
AQHREACT_Link_SetTargetInputSlotIdForUnit(link, AQHREACT_InputSlot_GetIdForUnit(inputSlot));
|
||||
AQHREACT_OutputSlot_AddLink(outputSlot, link);
|
||||
AQHREACT_Link_SetTargetUnit(link, receivingUnit);
|
||||
AQHREACT_Link_SetTargetPort(link, receivingPort);
|
||||
AQHREACT_Port_AddLink(emittingPort, link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _linkToModulesOutput(AQHOME_REACT *aqh,
|
||||
AQHREACT_UNIT *unit,
|
||||
const char *emittingUnitName,
|
||||
const char *emittingPortName,
|
||||
const char *receivingPortName)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
AQHREACT_UNIT *receivingUnit;
|
||||
AQHREACT_PORT *receivingPort;
|
||||
AQHREACT_UNIT *emittingUnit;
|
||||
AQHREACT_PORT *emittingPort;
|
||||
AQHREACT_LINK *link;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
|
||||
emittingUnit=AQHREACT_Unit_List_GetById(xunit->unitList, emittingUnitName);
|
||||
if (emittingUnit==NULL)
|
||||
emittingUnit=AqHomeReact_FindUnitByUnitId(aqh, emittingUnitName);
|
||||
if (emittingUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Source unit \"%s\" not found", emittingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
receivingUnit=unit;
|
||||
|
||||
emittingPort=AQHREACT_Unit_GetOutputPortByName(emittingUnit, emittingPortName);
|
||||
if (emittingPort==NULL) {
|
||||
DBG_ERROR(NULL, "Output port \"%s\" not found", emittingPortName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
receivingPort=AQHREACT_Unit_GetOutputPortByName(unit, receivingPortName); /* find in modules output port list! */
|
||||
if (receivingPort==NULL) {
|
||||
DBG_ERROR(NULL, "Target port \"%s\" not found", receivingPortName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
link=AQHREACT_Link_new();
|
||||
AQHREACT_Link_SetTargetUnit(link, receivingUnit);
|
||||
AQHREACT_Link_SetTargetPort(link, receivingPort);
|
||||
AQHREACT_Port_AddLink(emittingPort, link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _linkBetweenUnits(AQHOME_REACT *aqh,
|
||||
AQHREACT_UNIT *unit,
|
||||
const char *emittingUnitName,
|
||||
const char *emittingPortName,
|
||||
const char *receivingUnitName,
|
||||
const char *receivingPortName)
|
||||
{
|
||||
AQHREACT_UNIT_MODULE *xunit;
|
||||
AQHREACT_UNIT *receivingUnit;
|
||||
AQHREACT_PORT *receivingPort;
|
||||
AQHREACT_UNIT *emittingUnit;
|
||||
AQHREACT_PORT *emittingPort;
|
||||
AQHREACT_LINK *link;
|
||||
|
||||
xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit);
|
||||
|
||||
emittingUnit=AQHREACT_Unit_List_GetById(xunit->unitList, emittingUnitName);
|
||||
if (emittingUnit==NULL)
|
||||
emittingUnit=AqHomeReact_FindUnitByUnitId(aqh, emittingUnitName);
|
||||
if (emittingUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Source unit \"%s\" not found", emittingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
receivingUnit=AQHREACT_Unit_List_GetById(xunit->unitList, receivingUnitName);
|
||||
if (receivingUnit==NULL)
|
||||
receivingUnit=AqHomeReact_FindUnitByUnitId(aqh, receivingUnitName);
|
||||
if (receivingUnit==NULL) {
|
||||
DBG_ERROR(NULL, "Target unit \"%s\" not found", receivingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
emittingPort=AQHREACT_Unit_GetOutputPortByName(emittingUnit, emittingPortName);
|
||||
if (emittingPort==NULL) {
|
||||
DBG_ERROR(NULL, "Output port \"%s\" not found for source unit \"%s\"", emittingPortName, emittingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
receivingPort=AQHREACT_Unit_GetOrCreateUnusedInputPortByName(receivingUnit, receivingPortName);
|
||||
if (receivingPort==NULL) {
|
||||
DBG_ERROR(NULL, "Input port \"%s\" not found for target unit \"%s\"", receivingPortName, receivingUnitName);
|
||||
return GWEN_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
link=AQHREACT_Link_new();
|
||||
AQHREACT_Link_SetTargetUnit(link, receivingUnit);
|
||||
AQHREACT_Link_SetTargetPort(link, receivingPort);
|
||||
AQHREACT_Port_AddLink(emittingPort, link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -814,4 +795,3 @@ int _readLinkFromXml(AQHOME_REACT *aqh, AQHREACT_UNIT *unit, GWEN_XMLNODE *linkN
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,10 +43,8 @@ static MODULE_PROXY_DESCR *ModuleProxyDescr_List_FindByName(const MODULE_PROXY_D
|
||||
|
||||
struct AQHREACT_UNIT_MODULE {
|
||||
MODULE_PROXY_DESCR_LIST *paramProxyList;
|
||||
MODULE_PROXY_DESCR_LIST *inSlotProxyList;
|
||||
MODULE_PROXY_DESCR_LIST *outSlotProxyList;
|
||||
|
||||
AQHREACT_UNIT_LIST *unitList;
|
||||
int lastPortId;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
|
||||
|
||||
|
||||
@@ -40,25 +40,24 @@ static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_
|
||||
AQHREACT_UNIT *AqHomeReact_UnitPassthrough_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
AQHREACT_Unit_SetName(unit, "passthrough");
|
||||
AQHREACT_Unit_SetDescription(unit, "Generic passthrough unit");
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
return unit;
|
||||
}
|
||||
@@ -66,10 +65,15 @@ AQHREACT_UNIT *AqHomeReact_UnitPassthrough_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_PASSTHROUGH_INSLOT_INPUT)
|
||||
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT, dataObject);
|
||||
if (unit && port && dataObject && AQHREACT_Port_GetIdForUnit(port)==AQHOMEREACT_UNIT_PASSTHROUGH_INSLOT_INPUT) {
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
if (outputPort)
|
||||
AQHREACT_Unit_OutputData(unit, outputPort, dataObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ AQHREACT_UNIT *AqHomeReact_UnitStabilize_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT_STABILIZE *xunit;
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
AQHREACT_PARAM *param;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
@@ -78,23 +77,23 @@ AQHREACT_UNIT *AqHomeReact_UnitStabilize_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetDescription(unit, "Stabilize signal changes (only propagate changes stable for some time)");
|
||||
AQHREACT_Unit_SetProcessFn(unit, _cbProcessFn);
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_STABILIZE_OUTSLOT_OUTPUT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_STABILIZE_OUTSLOT_OUTPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_STABILIZE_INSLOT_INPUT);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_STABILIZE_INSLOT_INPUT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "timer");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_STABILIZE_INSLOT_TIMER);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "timer");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_STABILIZE_INSLOT_TIMER);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
param=AQHREACT_Param_new();
|
||||
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_STABILIZE_PARAM_HOLDTIME_HIGH);
|
||||
@@ -111,7 +110,7 @@ AQHREACT_UNIT *AqHomeReact_UnitStabilize_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _freeData(void *bp, void *p)
|
||||
void _freeData(GWEN_UNUSED void *bp, void *p)
|
||||
{
|
||||
AQHREACT_UNIT_STABILIZE *xunit;
|
||||
|
||||
@@ -127,7 +126,7 @@ int _cbProcessFn(AQHREACT_UNIT *unit)
|
||||
int rv;
|
||||
|
||||
rv=_checkState(unit);
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
|
||||
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputPorts(unit);
|
||||
return rv;
|
||||
}
|
||||
return 0;
|
||||
@@ -142,13 +141,13 @@ int _checkState(AQHREACT_UNIT *unit)
|
||||
|
||||
xunit=GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_STABILIZE, unit);
|
||||
if (xunit) {
|
||||
AQHREACT_INPUT_SLOT *dataSlot;
|
||||
AQHREACT_PORT *port;
|
||||
|
||||
dataSlot=AQHREACT_Unit_GetInputSlotByIdForUnit(unit, AQHOMEREACT_UNIT_STABILIZE_INSLOT_INPUT);
|
||||
if (dataSlot) {
|
||||
port=AQHREACT_Unit_GetInputPortByIdForUnit(unit, AQHOMEREACT_UNIT_STABILIZE_INSLOT_INPUT);
|
||||
if (port) {
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(dataSlot);
|
||||
dataObject=AQHREACT_Port_GetCurrentDataObject(port);
|
||||
if (dataObject) {
|
||||
double doubleData;
|
||||
int newState;
|
||||
@@ -216,11 +215,16 @@ void _startTimer(AQHREACT_UNIT *unit, AQHREACT_UNIT_STABILIZE *xunit, int newSta
|
||||
|
||||
void _setOutput(AQHREACT_UNIT *unit, AQHREACT_UNIT_STABILIZE *xunit, int newState)
|
||||
{
|
||||
/* timeout, switch output */
|
||||
DBG_INFO(NULL, "Switch output to %s", newState?"ON":"OFF");
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_STABILIZE_OUTSLOT_OUTPUT, newState?1.0:0.0);
|
||||
xunit->currentOutState=newState;
|
||||
xunit->tsHoldUntil=0;
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_STABILIZE_OUTSLOT_OUTPUT);
|
||||
if (outputPort) {
|
||||
/* timeout, switch output */
|
||||
DBG_INFO(NULL, "Switch output to %s", newState?"ON":"OFF");
|
||||
AQHREACT_Unit_OutputDoubleData(unit, outputPort, newState?1.0:0.0);
|
||||
xunit->currentOutState=newState;
|
||||
xunit->tsHoldUntil=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,11 @@ AQHREACT_UNIT *AqHomeReact_UnitTimer_new(AQHOME_REACT *aqh)
|
||||
|
||||
void AqHomeReact_UnitTimer_GenerateTick(AQHREACT_UNIT *unit)
|
||||
{
|
||||
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT, 1.0);
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
if (outputPort)
|
||||
AQHREACT_Unit_OutputDoubleData(unit, outputPort, 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_
|
||||
AQHREACT_UNIT *AqHomeReact_UnitValueFilter_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
AQHREACT_PARAM *param;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
@@ -53,17 +52,17 @@ AQHREACT_UNIT *AqHomeReact_UnitValueFilter_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetDescription(unit, "Filter values received from unit VarChanges by value path");
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
param=AQHREACT_Param_new();
|
||||
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUEFILTER_PARAM_VALUENAME);
|
||||
@@ -75,22 +74,27 @@ AQHREACT_UNIT *AqHomeReact_UnitValueFilter_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE) {
|
||||
const char *sSystemValueId;
|
||||
if (unit && port && dataObject && AQHREACT_Port_GetIdForUnit(port)==AQHOMEREACT_UNIT_VALUEFILTER_INSLOT_VALUE) {
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
sSystemValueId=AQHREACT_DataObject_GetSystemValueId(dataObject);
|
||||
if (sSystemValueId && *sSystemValueId) {
|
||||
const char *sFilter;
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT);
|
||||
if (outputPort) {
|
||||
const char *sSystemValueId;
|
||||
|
||||
sFilter=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUEFILTER_PARAM_VALUENAME, NULL);
|
||||
if (sFilter && *sFilter && strcasecmp(sSystemValueId, sFilter)==0) {
|
||||
DBG_INFO(NULL, "Value \"%s\" matches", sSystemValueId);
|
||||
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_VALUEFILTER_OUTSLOT_RESULT, dataObject);
|
||||
}
|
||||
else {
|
||||
DBG_DEBUG(NULL, "Value \"%s\" does not match", sSystemValueId);
|
||||
sSystemValueId=AQHREACT_DataObject_GetSystemValueId(dataObject);
|
||||
if (sSystemValueId && *sSystemValueId) {
|
||||
const char *sFilter;
|
||||
|
||||
sFilter=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUEFILTER_PARAM_VALUENAME, NULL);
|
||||
if (sFilter && *sFilter && strcasecmp(sSystemValueId, sFilter)==0) {
|
||||
DBG_INFO(NULL, "Value \"%s\" matches", sSystemValueId);
|
||||
AQHREACT_Unit_OutputData(unit, outputPort, dataObject);
|
||||
}
|
||||
else {
|
||||
DBG_DEBUG(NULL, "Value \"%s\" does not match", sSystemValueId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static GWEN_MSG *_mkSetDataMsgString(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static GWEN_MSG *_mkSetDataMsgDouble(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static GWEN_MSG *_mkSetDataMsgString(const char *sValueName, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static GWEN_MSG *_mkSetDataMsgDouble(const char *sValueName, const AQHREACT_DATAOBJECT *dataObject);
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ static GWEN_MSG *_mkSetDataMsgDouble(AQHREACT_UNIT *unit, const char *sValueName
|
||||
AQHREACT_UNIT *AqHomeReact_UnitValueSet_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
AQHREACT_PARAM *param;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
@@ -56,11 +56,11 @@ AQHREACT_UNIT *AqHomeReact_UnitValueSet_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetDescription(unit, "Set value by value path");
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_VALUESET_INSLOT_VALUE);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_VALUESET_INSLOT_VALUE);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
param=AQHREACT_Param_new();
|
||||
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUENAME);
|
||||
@@ -72,9 +72,9 @@ AQHREACT_UNIT *AqHomeReact_UnitValueSet_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_VALUESET_INSLOT_VALUE) {
|
||||
if (unit && port && dataObject && AQHREACT_Port_GetIdForUnit(port)==AQHOMEREACT_UNIT_VALUESET_INSLOT_VALUE) {
|
||||
const char *sValueName;
|
||||
|
||||
sValueName=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUENAME, NULL);
|
||||
@@ -87,10 +87,10 @@ void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJ
|
||||
|
||||
switch(AQHREACT_DataObject_GetDataType(dataObject)) {
|
||||
case AQHREACT_DATAOBJECTTYPE_DOUBLE:
|
||||
msgOut=_mkSetDataMsgDouble(unit, sValueName, dataObject);
|
||||
msgOut=_mkSetDataMsgDouble(sValueName, dataObject);
|
||||
break;
|
||||
case AQHREACT_DATAOBJECTTYPE_STRING:
|
||||
msgOut=_mkSetDataMsgString(unit, sValueName, dataObject);
|
||||
msgOut=_mkSetDataMsgString(sValueName, dataObject);
|
||||
break;
|
||||
default:
|
||||
DBG_INFO(NULL, "Unhandled data type (%d)", AQHREACT_DataObject_GetDataType(dataObject));
|
||||
@@ -107,7 +107,7 @@ void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJ
|
||||
}
|
||||
|
||||
|
||||
GWEN_MSG *_mkSetDataMsgString(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject)
|
||||
GWEN_MSG *_mkSetDataMsgString(const char *sValueName, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
AQH_VALUE *v;
|
||||
@@ -122,7 +122,7 @@ GWEN_MSG *_mkSetDataMsgString(AQHREACT_UNIT *unit, const char *sValueName, const
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *_mkSetDataMsgDouble(AQHREACT_UNIT *unit, const char *sValueName, const AQHREACT_DATAOBJECT *dataObject)
|
||||
GWEN_MSG *_mkSetDataMsgDouble(const char *sValueName, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
AQH_VALUE *v;
|
||||
|
||||
@@ -32,17 +32,22 @@ AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh)
|
||||
|
||||
void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALUE *value, uint64_t timestamp, double data)
|
||||
{
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
DBG_DEBUG(NULL, "Value \"%s\" changed", AQH_Value_GetNameForSystem(value));
|
||||
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, AQH_Value_GetNameForSystem(value));
|
||||
AQHREACT_DataObject_SetValueId(dataObject, AQH_Value_GetId(value));
|
||||
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT, dataObject);
|
||||
AQHREACT_DataObject_free(dataObject);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT);
|
||||
if (outputPort) {
|
||||
AQHREACT_DATAOBJECT *dataObject;
|
||||
|
||||
DBG_DEBUG(NULL, "Value \"%s\" changed", AQH_Value_GetNameForSystem(value));
|
||||
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, AQH_Value_GetNameForSystem(value));
|
||||
AQHREACT_DataObject_SetValueId(dataObject, AQH_Value_GetId(value));
|
||||
AQHREACT_Unit_OutputData(unit, outputPort, dataObject);
|
||||
AQHREACT_DataObject_free(dataObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
||||
static void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject);
|
||||
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_
|
||||
AQHREACT_UNIT *AqHomeReact_UnitZeroPosNegString_new(AQHOME_REACT *aqh)
|
||||
{
|
||||
AQHREACT_UNIT *unit;
|
||||
AQHREACT_OUTPUT_SLOT *outputSlot;
|
||||
AQHREACT_INPUT_SLOT *inputSlot;
|
||||
AQHREACT_PORT *port;
|
||||
AQHREACT_PARAM *param;
|
||||
|
||||
unit=AQHREACT_Unit_new(aqh);
|
||||
@@ -53,17 +52,17 @@ AQHREACT_UNIT *AqHomeReact_UnitZeroPosNegString_new(AQHOME_REACT *aqh)
|
||||
AQHREACT_Unit_SetDescription(unit, "Translate double value into strings for zero, positive, negative values");
|
||||
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
||||
|
||||
outputSlot=AQHREACT_OutputSlot_new();
|
||||
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
||||
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT);
|
||||
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "output");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_STRING);
|
||||
AQHREACT_Unit_AddOutputPort(unit, port);
|
||||
|
||||
inputSlot=AQHREACT_InputSlot_new();
|
||||
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
||||
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_INSLOT_VALUE);
|
||||
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
||||
port=AQHREACT_Port_new();
|
||||
AQHREACT_Port_SetName(port, "input");
|
||||
AQHREACT_Port_SetIdForUnit(port, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_INSLOT_VALUE);
|
||||
AQHREACT_Port_SetDataType(port, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
||||
AQHREACT_Unit_AddInputPort(unit, port);
|
||||
|
||||
param=AQHREACT_Param_new();
|
||||
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_NEG);
|
||||
@@ -85,23 +84,28 @@ AQHREACT_UNIT *AqHomeReact_UnitZeroPosNegString_new(AQHOME_REACT *aqh)
|
||||
|
||||
|
||||
|
||||
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
||||
void _cbInputData(AQHREACT_UNIT *unit, GWEN_UNUSED AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject)
|
||||
{
|
||||
if (unit && dataObject) {
|
||||
const char *result=NULL;
|
||||
double data;
|
||||
AQHREACT_PORT *outputPort;
|
||||
|
||||
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (data>0.0)
|
||||
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_POS, NULL);
|
||||
else if (data<0.0)
|
||||
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_NEG, NULL);
|
||||
else
|
||||
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_ZERO, NULL);
|
||||
outputPort=AQHREACT_Unit_GetOutputPortByIdForUnit(unit, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT);
|
||||
if (outputPort) {
|
||||
const char *result=NULL;
|
||||
double data;
|
||||
|
||||
if (result && *result) {
|
||||
DBG_DEBUG(NULL, "Sending \"%s\" to output", result);
|
||||
AQHREACT_Unit_OutputStringData(unit, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT, result);
|
||||
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
||||
if (data>0.0)
|
||||
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_POS, NULL);
|
||||
else if (data<0.0)
|
||||
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_NEG, NULL);
|
||||
else
|
||||
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_ZERO, NULL);
|
||||
|
||||
if (result && *result) {
|
||||
DBG_DEBUG(NULL, "Sending \"%s\" to output", result);
|
||||
AQHREACT_Unit_OutputStringData(unit, outputPort, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user