aqhome-tool: Decreased verbosity, fixed flash handling.

This commit is contained in:
Martin Preuss
2025-03-11 23:00:02 +01:00
parent fecaaaf341
commit 58bc39c2fb
3 changed files with 99 additions and 94 deletions

View File

@@ -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;
}
}

View File

@@ -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_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;
for (i=0; i<FLASH_TOOL_MAX_REPEAT; i++) {
AQH_MESSAGE *nodeMsg;
int rv;
if (i)
fprintf(stdout, "- sending FLASH_START (retry %d)\n", i);
else
fprintf(stdout, "- sending FLASH_START\n");
/* send FLASH_START message */
DBG_INFO(NULL, "Sending FLASH START message (%d)", i);
nodeMsg=AQH_FlashStartMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_START, uid);
if (nodeMsg==NULL) {
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
rv=_waitForFlashResponse(o, timeoutInSeconds);
if (rv==0) {
return 0;
}
}
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
return GWEN_ERROR_GENERIC;
return _trySendMsgAndWaitForFlasgResponse(o, nodeMsg, "FLASH_START", timeoutInSeconds);
}
@@ -328,40 +318,41 @@ int _flashRecord(AQH_OBJECT *o,
int _flashData(AQH_OBJECT *o, uint32_t address, const uint8_t *ptr, uint32_t len, int timeoutInSeconds)
{
int i;
for (i=0;i<FLASH_TOOL_MAX_REPEAT;i++) {
AQH_MESSAGE *nodeMsg;
int rv;
GWEN_BUFFER *dbuf;
#ifdef DEBUG_FLASH
DBG_ERROR(NULL, " Sending message: addr=%04x, data len=%d, pagesize=%d", address, len, pageSize);
GWEN_Text_LogString((const char*) ptr, len, NULL, GWEN_LoggerLevel_Error);
#endif
if (i)
fprintf(stdout, "- send data: dest addr=%04x, len=%d bytes (retry %d)\n", address, len, i);
else
fprintf(stdout, "- send data: dest addr=%04x, len=%d bytes\n", address, len);
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendString(dbuf, "FLASH_DATA (");
GWEN_Buffer_AppendArgs(dbuf, "addr=%04x, data len=%d)", address, len);
nodeMsg=AQH_FlashDataMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_DATA, address, ptr, len);
if (nodeMsg==NULL) {
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
rv=_waitForFlashResponse(o, timeoutInSeconds);
if (rv==0)
return 0;
} /* for */
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
return GWEN_ERROR_GENERIC;
rv=_trySendMsgAndWaitForFlasgResponse(o, nodeMsg, GWEN_Buffer_GetStart(dbuf), timeoutInSeconds);
GWEN_Buffer_free(dbuf);
return rv;
}
int _flashEnd(AQH_OBJECT *o, int reason, int timeoutInSeconds)
{
AQH_MESSAGE *nodeMsg;
nodeMsg=AQH_FlashEndMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_END, reason);
if (nodeMsg==NULL) {
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
return _trySendMsgAndWaitForFlasgResponse(o, nodeMsg, "FLASH_END", timeoutInSeconds);
}
int _trySendMsgAndWaitForFlasgResponse(AQH_OBJECT *o, AQH_MESSAGE *msg, const char *msgInfo, int timeoutInSeconds)
{
int i;
@@ -370,22 +361,21 @@ int _flashEnd(AQH_OBJECT *o, int reason, int timeoutInSeconds)
int rv;
if (i)
fprintf(stdout, "- sending FLASH_END (retry %d)\n", i);
else
fprintf(stdout, "- sending FLASH_END\n");
fprintf(stdout, " - retry sending %s (retry %d)\n", msgInfo, i);
/* send FLASH_START message */
DBG_INFO(NULL, "Sending FLASH END message (%d)", i);
nodeMsg=AQH_FlashEndMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_END, reason);
if (nodeMsg==NULL) {
DBG_ERROR(NULL, "Error creating message");
return GWEN_ERROR_GENERIC;
}
nodeMsg=AQH_Message_dup(msg);
DBG_INFO(NULL, "Sending %s message (%d)", msgInfo, i);
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
rv=_waitForFlashResponse(o, timeoutInSeconds);
if (rv==0)
if (rv==0) {
AQH_Message_free(msg);
return 0;
}
}
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
fprintf(stderr, "No FLASH_RESPONSE received.\n");
AQH_Message_free(msg);
return GWEN_ERROR_GENERIC;
}

View File

@@ -26,6 +26,7 @@
#include <gwenhywfar/i18n.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/timestamp.h>
#include <ctype.h>
@@ -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,15 +141,23 @@ 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;
now=time(NULL);
ts=AQH_NodeInfo_GetTimestampLastChange(ni);
tLastSeen=ts?GWEN_Timestamp_toTimeT(ts):now;
timeSinceLastSeen=(int) (now-tLastSeen);
if (printAll || timeSinceLastSeen<LAST1H) {
uint32_t u;
fprintf(stdout, "- node: addr=%3d, uid=0x%08x, device=",
AQH_NodeInfo_GetBusAddress(ni),
(unsigned int) AQH_NodeInfo_GetUid(ni));
ts=AQH_NodeInfo_GetTimestampLastChange(ni);
u=AQH_NodeInfo_GetManufacturer(ni);
_printUintAsTextOrHex(u, 32);
@@ -164,6 +178,7 @@ void _printNode(const AQH_NODE_INFO *ni)
AQH_NodeInfo_GetStatsBusy(ni),
AQH_NodeInfo_GetStatsCrcErrors(ni),
AQH_NodeInfo_GetStatsIoErrors(ni));
}
}