From 58bc39c2fbcb5812cceb0162af250ac6d937c75d Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 11 Mar 2025 23:00:02 +0100 Subject: [PATCH] aqhome-tool: Decreased verbosity, fixed flash handling. --- apps/aqhome-tool/client.c | 4 +- apps/aqhome-tool/nodes/flash.c | 118 ++++++++++++++---------------- apps/aqhome-tool/nodes/getnodes.c | 71 +++++++++++------- 3 files changed, 99 insertions(+), 94 deletions(-) diff --git a/apps/aqhome-tool/client.c b/apps/aqhome-tool/client.c index 971808f..406f903 100644 --- a/apps/aqhome-tool/client.c +++ b/apps/aqhome-tool/client.c @@ -397,7 +397,7 @@ int _exchangeConnectMsgs(AQH_TOOL_CLIENT *xo, uint32_t flags) userId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "userId", 0, NULL); passw=GWEN_DB_GetCharValue(xo->dbLocalArgs, "password", 0, NULL); - DBG_ERROR(NULL, "Sending connect message for proto=%d.%d", xo->protoId, xo->protoVer); + DBG_INFO(NULL, "Sending connect message for proto=%d.%d", xo->protoId, xo->protoVer); msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint); msgOut=AQH_IpcMessageConnect_new(xo->protoId, xo->protoVer, AQH_MSGTYPE_IPC_CONNECT_REQ, @@ -577,7 +577,7 @@ int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId) return 3; } else if (rv==1) { - DBG_ERROR(NULL, "Done."); + DBG_INFO(NULL, "Done."); return 0; } } diff --git a/apps/aqhome-tool/nodes/flash.c b/apps/aqhome-tool/nodes/flash.c index 40068fc..a08aef6 100644 --- a/apps/aqhome-tool/nodes/flash.c +++ b/apps/aqhome-tool/nodes/flash.c @@ -44,8 +44,10 @@ #define A_CHAR GWEN_ArgsType_Char #define A_INT GWEN_ArgsType_Int -#define FLASH_TOOL_MAX_REPEAT 16 -#define FLASH_TOOL_DEFAULT_TIMEOUTINSECS 5 + +#define FLASH_TOOL_MAX_REPEAT 16 +#define FLASH_TOOL_DEFAULT_TIMEOUTINSECS 5 +#define FLASH_TOOL_WAITFORFLASHREADY_INSECS 30 @@ -68,6 +70,9 @@ static int _flashRecord(AQH_OBJECT *o, int timeoutInSeconds); static int _flashData(AQH_OBJECT *o, uint32_t address, const uint8_t *ptr, uint32_t len, int timeoutInSeconds); static int _flashEnd(AQH_OBJECT *o, int reason, int timeoutInSeconds); + +/** frees msg! */ +static int _trySendMsgAndWaitForFlasgResponse(AQH_OBJECT *o, AQH_MESSAGE *msg, const char *msgInfo, int timeoutInSeconds); static int _waitForFlashResponse(AQH_OBJECT *o, int timeoutInSeconds); static AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename); @@ -90,7 +95,7 @@ int AQH_Tool_Flash(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv) { A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL}, { A_ARG, A_CHAR, "userId", 0, 1, "u", "userid", I18S("Specify user id"), NULL}, { A_ARG, A_CHAR, "password", 0, 1, "p", "password", I18S("Specify service password"), NULL}, - { A_ARG, A_CHAR, "uid", 1, 1, "u", "uid", I18S("Specify UID of the node to flash"),NULL}, + { A_ARG, A_CHAR, "uid", 1, 1, "U", "uid", I18S("Specify UID of the node to flash"),NULL}, { A_ARG, A_CHAR, "hexFilename", 1, 1, "H", NULL, I18S("Specify hexfile to flash"), NULL}, { 0, A_INT, "reboot", 0, 1, "R", NULL, I18S("Request node reboot before trying to flash"), NULL}, { A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL} @@ -164,6 +169,7 @@ int doFlash(AQH_OBJECT *o) rv=_rebootNode(o, uid, timeoutInSeconds); if (rv<0) { DBG_INFO(NULL, "here (%d)", rv); + fprintf(stderr, "No REBOOT response received.\n"); return 3; } fprintf(stdout, "Reboot in progress\n"); @@ -171,9 +177,10 @@ int doFlash(AQH_OBJECT *o) /* wait for FLASH_READY message */ fprintf(stdout, "Waiting for node to become ready for flashing\n"); - msg=AQH_ToolClient_WaitForNodeMsg(o, 0, AQH_MSG_TYPE_FLASH_READY, timeoutInSeconds); + msg=AQH_ToolClient_WaitForNodeMsg(o, 0, AQH_MSG_TYPE_FLASH_READY, FLASH_TOOL_WAITFORFLASHREADY_INSECS); if (msg==NULL) { DBG_INFO(NULL, "No FLASH_READY message received."); + fprintf(stderr, "No FLASH_READY received.\n"); return 3; } DBG_INFO(NULL, "FLASH_READY message received"); @@ -263,31 +270,14 @@ int _performFlashProcedure(AQH_OBJECT *o, int _flashStart(AQH_OBJECT *o, unsigned int uid, int timeoutInSeconds) { - int i; + AQH_MESSAGE *nodeMsg; - for (i=0; i #include #include +#include #include @@ -44,6 +45,8 @@ #define A_CHAR GWEN_ArgsType_Char #define A_INT GWEN_ArgsType_Int +#define LAST1H (60*60) + /* ------------------------------------------------------------------------------------------------ @@ -53,7 +56,7 @@ static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId); static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first); -static void _printNode(const AQH_NODE_INFO *ni); +static void _printNode(const AQH_NODE_INFO *ni, int printAll); static void _printUintAsTextOrHex(uint32_t u, int bits); @@ -74,6 +77,7 @@ int AQH_Tool_GetNodes(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv) { A_ARG, A_INT, "tcpPort", 0, 1, "P", "tcpport", I18S("TCP port to connect to"), NULL}, { A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL}, { 0, A_INT, "printHeader", 0, 1, "H", "printheader", I18S("Print header if given"), NULL}, + { 0, A_INT, "printAll", 0, 1, "a", "printall", I18S("Print all devices (not only last seen)"), NULL}, { A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL} }; @@ -104,11 +108,13 @@ AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, uint32_t msgId) int _handleResponseMessage(GWEN_UNUSED AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first) { uint16_t code; - //GWEN_DB_NODE *dbArgs; + GWEN_DB_NODE *dbArgs; //int printHeader; + int printAll; - //dbArgs=AQH_ToolClient_GetDbLocalArgs(o); + dbArgs=AQH_ToolClient_GetDbLocalArgs(o); //printHeader=first?GWEN_DB_GetIntValue(dbArgs, "printHeader", 0, 0):0; + printAll=GWEN_DB_GetIntValue(dbArgs, "printAll", 0, 0); code=AQH_IpcMessage_GetCode(msg); if (code==AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP) { @@ -116,7 +122,7 @@ int _handleResponseMessage(GWEN_UNUSED AQH_OBJECT *o, const AQH_MESSAGE *msg, co ni=AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(tagList); if (ni) - _printNode(ni); + _printNode(ni, printAll); if (AQH_IpcnMessageGetDevicesRsp_GetFlags(tagList) & AQH_MSGNODE_GETDEVICES_RSP_FLAGS_LASTMSG) { DBG_INFO(NULL, "Last message received"); @@ -135,35 +141,44 @@ int _handleResponseMessage(GWEN_UNUSED AQH_OBJECT *o, const AQH_MESSAGE *msg, co -void _printNode(const AQH_NODE_INFO *ni) +void _printNode(const AQH_NODE_INFO *ni, int printAll) { - uint32_t u; const GWEN_TIMESTAMP *ts; + time_t now; + time_t tLastSeen=0; + int timeSinceLastSeen; - fprintf(stdout, "- node: addr=%3d, uid=0x%08x, device=", - AQH_NodeInfo_GetBusAddress(ni), - (unsigned int) AQH_NodeInfo_GetUid(ni)); + now=time(NULL); ts=AQH_NodeInfo_GetTimestampLastChange(ni); + tLastSeen=ts?GWEN_Timestamp_toTimeT(ts):now; + timeSinceLastSeen=(int) (now-tLastSeen); + if (printAll || timeSinceLastSeen>8) & 0xff, u & 0xff); - u=AQH_NodeInfo_GetFirmwareVersion(ni); - fprintf(stdout, ", firmware=%d.%d.%d (%d), ", - (u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff); - if (ts) - fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts)); - fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n", - AQH_NodeInfo_GetStatsPacketsOut(ni), - AQH_NodeInfo_GetStatsPacketsIn(ni), - AQH_NodeInfo_GetStatsCollisions(ni), - AQH_NodeInfo_GetStatsBusy(ni), - AQH_NodeInfo_GetStatsCrcErrors(ni), - AQH_NodeInfo_GetStatsIoErrors(ni)); + fprintf(stdout, "- node: addr=%3d, uid=0x%08x, device=", + AQH_NodeInfo_GetBusAddress(ni), + (unsigned int) AQH_NodeInfo_GetUid(ni)); + + u=AQH_NodeInfo_GetManufacturer(ni); + _printUintAsTextOrHex(u, 32); + fprintf(stdout, ":"); + u=AQH_NodeInfo_GetDeviceType(ni); + _printUintAsTextOrHex(u, 16); + u=AQH_NodeInfo_GetDeviceVersion(ni); + fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff); + u=AQH_NodeInfo_GetFirmwareVersion(ni); + fprintf(stdout, ", firmware=%d.%d.%d (%d), ", + (u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff); + if (ts) + fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts)); + fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n", + AQH_NodeInfo_GetStatsPacketsOut(ni), + AQH_NodeInfo_GetStatsPacketsIn(ni), + AQH_NodeInfo_GetStatsCollisions(ni), + AQH_NodeInfo_GetStatsBusy(ni), + AQH_NodeInfo_GetStatsCrcErrors(ni), + AQH_NodeInfo_GetStatsIoErrors(ni)); + } }