From e486a7e69de2ffa84a61cf0a241c59eebedc333e Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 18 Apr 2024 22:40:13 +0200 Subject: [PATCH] aqhome-react: finish new network reading code, improved debugging helper code. --- apps/aqhome-react/net_read.c | 46 ++++++++++++++++---------- apps/aqhome-react/types/link.c | 49 +++++++--------------------- apps/aqhome-react/types/link.h | 6 ---- apps/aqhome-react/types/link_p.h | 3 -- apps/aqhome-react/types/param.c | 4 +-- apps/aqhome-react/types/port.c | 25 ++++---------- apps/aqhome-react/types/unit.c | 28 +++++++++++++--- apps/aqhome-react/types/unit.h | 2 ++ apps/aqhome-react/types/unit_p.h | 1 + apps/aqhome-react/units/u_module.c | 24 ++++++++++++-- apps/aqhome-react/units/u_valueset.c | 7 ++++ 11 files changed, 103 insertions(+), 92 deletions(-) diff --git a/apps/aqhome-react/net_read.c b/apps/aqhome-react/net_read.c index 9bf4508..a5a7583 100644 --- a/apps/aqhome-react/net_read.c +++ b/apps/aqhome-react/net_read.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -91,29 +92,38 @@ int AQHomeReact_ReadUnitNetFiles(AQHOME_REACT *aqh) AQHREACT_UNIT *AQHomeReact_FindAndReadDataDirNetwork(AQHOME_REACT *aqh, const char *networkName) { - AQHREACT_UNIT *unit; - GWEN_BUFFER *bufFilename; - GWEN_BUFFER *bufPath; + if (aqh && networkName) { + AQHREACT_UNIT *unit; + GWEN_BUFFER *bufFilename; + GWEN_BUFFER *bufPath; + const char *s; - bufFilename=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendArgs(bufFilename, "aqhome/react/networks/%s.xml", networkName); - bufPath=AQH_FindPathOfDataFile(GWEN_Buffer_GetStart(bufFilename)); - if (bufPath==NULL) { - DBG_ERROR(NULL, "Network file \"%s\" not found in data folders", GWEN_Buffer_GetStart(bufFilename)); + bufFilename=GWEN_Buffer_new(0, 256, 0, 1); + GWEN_Buffer_AppendString(bufFilename, "aqhome/react/networks/"); + s=networkName; + while(*s) + GWEN_Buffer_AppendByte(bufFilename, tolower((unsigned char) *(s++))); + GWEN_Buffer_AppendString(bufFilename, ".xml"); + + bufPath=AQH_FindPathOfDataFile(GWEN_Buffer_GetStart(bufFilename)); + if (bufPath==NULL) { + DBG_ERROR(NULL, "Network file \"%s\" not found in data folders", GWEN_Buffer_GetStart(bufFilename)); + GWEN_Buffer_free(bufFilename); + return NULL; + } GWEN_Buffer_free(bufFilename); - return NULL; - } - GWEN_Buffer_free(bufFilename); - unit=_readNetworkFromFile(aqh, GWEN_Buffer_GetStart(bufPath)); - if (unit==NULL) { - DBG_ERROR(NULL, "Error reading network from file \"%s\"", GWEN_Buffer_GetStart(bufPath)); + unit=_readNetworkFromFile(aqh, GWEN_Buffer_GetStart(bufPath)); + if (unit==NULL) { + DBG_ERROR(NULL, "Error reading network from file \"%s\"", GWEN_Buffer_GetStart(bufPath)); + GWEN_Buffer_free(bufPath); + return NULL; + } + GWEN_Buffer_free(bufPath); - return NULL; + return unit; } - - GWEN_Buffer_free(bufPath); - return unit; + return NULL; } diff --git a/apps/aqhome-react/types/link.c b/apps/aqhome-react/types/link.c index 57c5843..ab337c2 100644 --- a/apps/aqhome-react/types/link.c +++ b/apps/aqhome-react/types/link.c @@ -25,7 +25,6 @@ AQHREACT_LINK *AQHREACT_Link_new() GWEN_NEW_OBJECT(AQHREACT_LINK, lnk); GWEN_LIST_INIT(AQHREACT_LINK, lnk); - lnk->targetInputSlotIdForUnit=-1; return lnk; } @@ -36,45 +35,12 @@ void AQHREACT_Link_free(AQHREACT_LINK *lnk) { if (lnk) { GWEN_LIST_FINI(AQHREACT_LINK, lnk); - free(lnk->targetUnitId); GWEN_FREE_OBJECT(lnk); } } -const char *AQHREACT_Link_GetTargetUnitId(const AQHREACT_LINK *lnk) -{ - return lnk?lnk->targetUnitId:NULL; -} - - - -void AQHREACT_Link_SetTargetUnitId(AQHREACT_LINK *lnk, const char *s) -{ - if (lnk) { - free(lnk->targetUnitId); - lnk->targetUnitId=s?strdup(s):NULL; - } -} - - - -int AQHREACT_Link_GetTargetInputSlotIdForUnit(const AQHREACT_LINK *lnk) -{ - return lnk?lnk->targetInputSlotIdForUnit:-1; -} - - - -void AQHREACT_Link_SetTargetInputSlotIdForUnit(AQHREACT_LINK *lnk, int i) -{ - if (lnk) - lnk->targetInputSlotIdForUnit=i; -} - - - AQHREACT_UNIT *AQHREACT_Link_GetTargetUnit(const AQHREACT_LINK *lnk) { return lnk?lnk->targetUnit:NULL; @@ -108,12 +74,19 @@ void AQHREACT_Link_SetTargetPort(AQHREACT_LINK *lnk, AQHREACT_PORT *port) void AQHREACT_Link_Dump(const AQHREACT_LINK *lnk, GWEN_BUFFER *buf, int indent) { if (lnk && buf) { + const char *unitName; + const char *unitId; + const char *portName; + + unitName=(lnk->targetUnit)?AQHREACT_Unit_GetName(lnk->targetUnit):NULL; + unitId=(lnk->targetUnit)?AQHREACT_Unit_GetId(lnk->targetUnit):NULL; + portName=(lnk->targetPort)?AQHREACT_Port_GetName(lnk->targetPort):NULL; if (indent) GWEN_Buffer_FillWithBytes(buf, ' ', indent); - GWEN_Buffer_AppendArgs(buf, "target unit id: %s (%s), target slot id: %d\n", - (lnk->targetUnitId)?(lnk->targetUnitId):"", - (lnk->targetUnit)?"set":"not set", - lnk->targetInputSlotIdForUnit); + GWEN_Buffer_AppendArgs(buf, "- target unit id: %s (%s), target slot name: %s\n", + unitId?unitId:"", + unitName?unitName:"", + portName?portName:""); } } diff --git a/apps/aqhome-react/types/link.h b/apps/aqhome-react/types/link.h index d7e5cd0..04add2b 100644 --- a/apps/aqhome-react/types/link.h +++ b/apps/aqhome-react/types/link.h @@ -25,12 +25,6 @@ AQHREACT_LINK *AQHREACT_Link_new(); void AQHREACT_Link_free(AQHREACT_LINK *lnk); -const char *AQHREACT_Link_GetTargetUnitId(const AQHREACT_LINK *lnk); -void AQHREACT_Link_SetTargetUnitId(AQHREACT_LINK *lnk, const char *s); - -int AQHREACT_Link_GetTargetInputSlotIdForUnit(const AQHREACT_LINK *lnk); -void AQHREACT_Link_SetTargetInputSlotIdForUnit(AQHREACT_LINK *lnk, int i); - AQHREACT_UNIT *AQHREACT_Link_GetTargetUnit(const AQHREACT_LINK *lnk); void AQHREACT_Link_SetTargetUnit(AQHREACT_LINK *lnk, AQHREACT_UNIT *unit); diff --git a/apps/aqhome-react/types/link_p.h b/apps/aqhome-react/types/link_p.h index dfb8a6b..062fb2b 100644 --- a/apps/aqhome-react/types/link_p.h +++ b/apps/aqhome-react/types/link_p.h @@ -16,9 +16,6 @@ struct AQHREACT_LINK { GWEN_LIST_ELEMENT(AQHREACT_LINK) - char *targetUnitId; - int targetInputSlotIdForUnit; - AQHREACT_UNIT *targetUnit; AQHREACT_PORT *targetPort; }; diff --git a/apps/aqhome-react/types/param.c b/apps/aqhome-react/types/param.c index 083eb98..59d5264 100644 --- a/apps/aqhome-react/types/param.c +++ b/apps/aqhome-react/types/param.c @@ -259,10 +259,10 @@ void AQHREACT_Param_Dump(const AQHREACT_PARAM *param, GWEN_BUFFER *buf, int inde switch(param->dataType) { case AQHREACT_DATAOBJECTTYPE_DOUBLE: - GWEN_Buffer_AppendArgs(buf, "%s = %f [DOUBLE]\n", (param->name)?(param->name):"", param->doubleValue); + GWEN_Buffer_AppendArgs(buf, "- %s = %f [DOUBLE]\n", (param->name)?(param->name):"", param->doubleValue); break; case AQHREACT_DATAOBJECTTYPE_STRING: - GWEN_Buffer_AppendArgs(buf, "%s = %s [STRING]\n", (param->name)?(param->name):"", param->stringValue); + GWEN_Buffer_AppendArgs(buf, "- %s = %s [STRING]\n", (param->name)?(param->name):"", param->stringValue); break; default: DBG_ERROR(NULL, "Unhandled data type %d", param->dataType); diff --git a/apps/aqhome-react/types/port.c b/apps/aqhome-react/types/port.c index 635f49b..a4292d2 100644 --- a/apps/aqhome-react/types/port.c +++ b/apps/aqhome-react/types/port.c @@ -263,21 +263,12 @@ void AQHREACT_Port_Dump(const AQHREACT_PORT *port, GWEN_BUFFER *buf, int indent) if (port && buf) { if (indent) GWEN_Buffer_FillWithBytes(buf, ' ', indent); - GWEN_Buffer_AppendArgs(buf, "name........: %s\n", (port->name)?(port->name):""); - - if (indent) - GWEN_Buffer_FillWithBytes(buf, ' ', indent); - GWEN_Buffer_AppendArgs(buf, "description.: %s\n", (port->description)?(port->description):""); - - if (indent) - GWEN_Buffer_FillWithBytes(buf, ' ', indent); - GWEN_Buffer_AppendArgs(buf, "data type...: %s\n", AQHREACT_DataObjectType_toString(port->dataType)); - - if (indent) - GWEN_Buffer_FillWithBytes(buf, ' ', indent); - GWEN_Buffer_AppendArgs(buf, "flags.......: %08x\n", port->flags); - - AQHREACT_Link_List_Dump(port->linkList, buf, indent, "Link List:"); + GWEN_Buffer_AppendArgs(buf, "- \"%s\" (%s, %08x)\n", + (port->name)?(port->name):"", + AQHREACT_DataObjectType_toString(port->dataType), + port->flags); + if (port->linkList && AQHREACT_Link_List_GetCount(port->linkList)) + AQHREACT_Link_List_Dump(port->linkList, buf, indent+2, "Link List:"); } } @@ -294,9 +285,7 @@ void AQHREACT_Port_List_Dump(const AQHREACT_PORT_LIST *portList, GWEN_BUFFER *bu port=AQHREACT_Port_List_First(portList); while(port) { - GWEN_Buffer_FillWithBytes(buf, ' ', indent+2); - GWEN_Buffer_AppendString(buf, "Port:\n"); - AQHREACT_Port_Dump(port, buf, indent+4); + AQHREACT_Port_Dump(port, buf, indent+2); port=AQHREACT_Port_List_Next(port); } } diff --git a/apps/aqhome-react/types/unit.c b/apps/aqhome-react/types/unit.c index ba4c921..71b0426 100644 --- a/apps/aqhome-react/types/unit.c +++ b/apps/aqhome-react/types/unit.c @@ -442,6 +442,20 @@ AQHREACT_UNIT_PROCESS_FN AQHREACT_Unit_SetProcessFn(AQHREACT_UNIT *unit, AQHREAC +AQHREACT_UNIT_DUMP_FN AQHREACT_Unit_SetDumpFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_DUMP_FN f) +{ + if (unit) { + AQHREACT_UNIT_DUMP_FN oldFn; + + oldFn=unit->dumpFn; + unit->dumpFn=f; + return oldFn; + } + return NULL; +} + + + void AQHREACT_Unit_OutputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject) { if (unit && port) { @@ -589,7 +603,7 @@ void AQHREACT_Unit_Dump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent) if (indent) GWEN_Buffer_FillWithBytes(buf, ' ', indent); - GWEN_Buffer_AppendArgs(buf, "name.......: %s\n", (unit->name)?(unit->name):""); + GWEN_Buffer_AppendArgs(buf, "type.......: %s\n", (unit->name)?(unit->name):""); if (indent) GWEN_Buffer_FillWithBytes(buf, ' ', indent); @@ -599,9 +613,15 @@ void AQHREACT_Unit_Dump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent) GWEN_Buffer_FillWithBytes(buf, ' ', indent); GWEN_Buffer_AppendArgs(buf, "flags......: %08x\n", unit->flags); - AQHREACT_Param_List_Dump(unit->paramList, buf, indent, "Unit Parameter List:"); - AQHREACT_Port_List_Dump(unit->inputPortList, buf, indent, "Input Port List:"); - AQHREACT_Port_List_Dump(unit->outputPortList, buf, indent, "Output Port List:"); + if (unit->paramList && AQHREACT_Param_List_GetCount(unit->paramList)) + AQHREACT_Param_List_Dump(unit->paramList, buf, indent, "Unit Parameter List:"); + if (unit->inputPortList && AQHREACT_Port_List_GetCount(unit->inputPortList)) + AQHREACT_Port_List_Dump(unit->inputPortList, buf, indent, "Input Port List:"); + if (unit->outputPortList && AQHREACT_Port_List_GetCount(unit->outputPortList)) + AQHREACT_Port_List_Dump(unit->outputPortList, buf, indent, "Output Port List:"); + + if (unit->dumpFn) + unit->dumpFn(unit, buf, indent+2); } } diff --git a/apps/aqhome-react/types/unit.h b/apps/aqhome-react/types/unit.h index b7f6579..24b668c 100644 --- a/apps/aqhome-react/types/unit.h +++ b/apps/aqhome-react/types/unit.h @@ -34,6 +34,7 @@ typedef void (*AQHREACT_UNIT_INPUTDATA_FN)(AQHREACT_UNIT *unit, AQHREACT_PORT *p typedef void (*AQHREACT_UNIT_OUTPUTDATA_FN)(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAOBJECT *dataObject); typedef AQHREACT_PARAM* (*AQHREACT_UNIT_GETPARAMBYNAME_FN)(const AQHREACT_UNIT *unit, const char *paramName); typedef int (*AQHREACT_UNIT_PROCESS_FN)(AQHREACT_UNIT *unit); +typedef void (*AQHREACT_UNIT_DUMP_FN)(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent); @@ -107,6 +108,7 @@ AQHREACT_UNIT_INPUTDATA_FN AQHREACT_Unit_SetInputDataFn(AQHREACT_UNIT *unit, AQH AQHREACT_UNIT_OUTPUTDATA_FN AQHREACT_Unit_SetOutputDataFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_OUTPUTDATA_FN f); AQHREACT_UNIT_GETPARAMBYNAME_FN AQHREACT_Unit_SetGetParamByNameFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_GETPARAMBYNAME_FN f); AQHREACT_UNIT_PROCESS_FN AQHREACT_Unit_SetProcessFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_PROCESS_FN f); +AQHREACT_UNIT_DUMP_FN AQHREACT_Unit_SetDumpFn(AQHREACT_UNIT *unit, AQHREACT_UNIT_DUMP_FN f); AQHREACT_UNIT *AQHREACT_Unit_List_GetById(const AQHREACT_UNIT_LIST *unitList, const char *id); diff --git a/apps/aqhome-react/types/unit_p.h b/apps/aqhome-react/types/unit_p.h index 2bc1079..be26176 100644 --- a/apps/aqhome-react/types/unit_p.h +++ b/apps/aqhome-react/types/unit_p.h @@ -36,6 +36,7 @@ struct AQHREACT_UNIT { AQHREACT_UNIT_OUTPUTDATA_FN outputDataFn; AQHREACT_UNIT_GETPARAMBYNAME_FN getParamByNameFn; AQHREACT_UNIT_PROCESS_FN processFn; + AQHREACT_UNIT_DUMP_FN dumpFn; }; diff --git a/apps/aqhome-react/units/u_module.c b/apps/aqhome-react/units/u_module.c index a8c5b25..3a7bc5e 100644 --- a/apps/aqhome-react/units/u_module.c +++ b/apps/aqhome-react/units/u_module.c @@ -39,6 +39,7 @@ static void GWENHYWFAR_CB _freeData(void *bp, void *p); 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 _cbDump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent); static void _readProxyFromXml(GWEN_XMLNODE *xmlNode, MODULE_PROXY_DESCR_LIST *proxyDescrList, @@ -155,6 +156,7 @@ AQHREACT_UNIT *AqHomeReact_UnitModule_new(AQHOME_REACT *aqh) AQHREACT_Unit_SetInputDataFn(unit, _cbInputData); AQHREACT_Unit_SetGetParamByNameFn(unit, _cbGetParamByName); AQHREACT_Unit_SetProcessFn(unit, _cbProcess); + AQHREACT_Unit_SetDumpFn(unit, _cbDump); return unit; } @@ -243,13 +245,18 @@ AQHREACT_PARAM *_cbGetParamByName(const AQHREACT_UNIT *unit, const char *paramNa { AQHREACT_UNIT_MODULE *xunit; + DBG_INFO(NULL, "Looking for param \"%s\" in proxy descr of module \"%s\"", paramName, AQHREACT_Unit_GetName(unit)); xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit); if (xunit) { const MODULE_PROXY_DESCR *pd; pd=ModuleProxyDescr_List_FindByName(xunit->paramProxyList, paramName); - if (pd) - AQHREACT_Unit_GetParamByName(pd->targetObjectPtr, pd->targetName); + if (pd) { + DBG_INFO(NULL, "Found proxydescr for param (-> %s:%s)", + (pd->targetObjectPtr)?AQHREACT_Unit_GetName(pd->targetObjectPtr):"", + (pd->targetName)?(pd->targetName):""); + return AQHREACT_Unit_GetParamByName(pd->targetObjectPtr, pd->targetName); + } } return NULL; } @@ -282,6 +289,17 @@ int _cbProcess(AQHREACT_UNIT *unit) +void _cbDump(const AQHREACT_UNIT *unit, GWEN_BUFFER *buf, int indent) +{ + AQHREACT_UNIT_MODULE *xunit; + + xunit=(AQHREACT_UNIT_MODULE*)GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_MODULE, unit); + if (xunit) + AQHREACT_Unit_List_Dump(xunit->unitList, buf, indent, "Sub Units:"); +} + + + void _readProxyFromXml(GWEN_XMLNODE *xmlNode, MODULE_PROXY_DESCR_LIST *proxyDescrList, const char *mainGroupName, @@ -543,7 +561,7 @@ int _readParamFromXml(AQHREACT_UNIT *unit, GWEN_XMLNODE *paramNode) } /* if value */ } else { - DBG_ERROR(NULL, "No param name \"%s\" in unit", paramName); + DBG_ERROR(NULL, "No param name \"%s\" in unit \"%s\"", paramName, AQHREACT_Unit_GetName(unit)); return GWEN_ERROR_BAD_DATA; } } diff --git a/apps/aqhome-react/units/u_valueset.c b/apps/aqhome-react/units/u_valueset.c index fff15f1..c792da7 100644 --- a/apps/aqhome-react/units/u_valueset.c +++ b/apps/aqhome-react/units/u_valueset.c @@ -19,6 +19,8 @@ #include +#define DEBUG_DRY_RUN 1 /* don't actually set value if "1" */ + /* ------------------------------------------------------------------------------------------------ * defines @@ -98,8 +100,13 @@ void _cbInputData(AQHREACT_UNIT *unit, AQHREACT_PORT *port, const AQHREACT_DATAO break; } if (msgOut) { +#if DEBUG_DRY_RUN + DBG_ERROR(NULL, "Would send data for value \"%s\"", sValueName); + GWEN_Msg_free(msgOut); +#else DBG_INFO(NULL, "Sending data for value \"%s\"", sValueName); GWEN_MsgEndpoint_AddSendMessage(brokerEndpoint, msgOut); +#endif } } }