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

@@ -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<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;
}
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;
}
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;
AQH_MESSAGE *nodeMsg;
int rv;
GWEN_BUFFER *dbuf;
for (i=0;i<FLASH_TOOL_MAX_REPEAT;i++) {
AQH_MESSAGE *nodeMsg;
int rv;
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);
#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);
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;
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;
}
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;
}