Rebooting and flashing a node now works!
This commit is contained in:
@@ -68,6 +68,7 @@
|
||||
msg_flashresponse.h
|
||||
msg_flashend.h
|
||||
msg_flashdata.h
|
||||
msg_reboot.h
|
||||
</headers>
|
||||
|
||||
|
||||
@@ -106,6 +107,7 @@
|
||||
msg_flashresponse.c
|
||||
msg_flashend.c
|
||||
msg_flashdata.c
|
||||
msg_reboot.c
|
||||
</sources>
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "aqhome/msg/msg_flashresponse.h"
|
||||
#include "aqhome/msg/msg_flashend.h"
|
||||
#include "aqhome/msg/msg_flashdata.h"
|
||||
#include "aqhome/msg/msg_reboot.h"
|
||||
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/inherit.h>
|
||||
@@ -149,6 +150,8 @@ void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
||||
case AQH_MSG_TYPE_FLASH_RSP: AQH_FlashResponseMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_FLASH_END: AQH_FlashEndMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_FLASH_DATA: AQH_FlashDataMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_REBOOT_REQ: AQH_RebootRequestMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_REBOOT_RSP: AQH_RebootResponseMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
default: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,23 +199,30 @@ uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType)
|
||||
case AQH_MSG_TYPE_MEMSTATS:
|
||||
case AQH_MSG_TYPE_SYSSTATS:
|
||||
return AQH_MSG_TYPEGROUP_INFO;
|
||||
|
||||
case AQH_MSG_TYPE_VALUE:
|
||||
case AQH_MSG_TYPE_VALUE2:
|
||||
return AQH_MSG_TYPEGROUP_VALUES;
|
||||
|
||||
case AQH_MSG_TYPE_NEED_ADDRESS:
|
||||
case AQH_MSG_TYPE_HAVE_ADDRESS:
|
||||
case AQH_MSG_TYPE_CLAIM_ADDRESS:
|
||||
case AQH_MSG_TYPE_DENY_ADDRESS:
|
||||
case AQH_MSG_TYPE_ADDRESS_RANGE:
|
||||
return AQH_MSG_TYPEGROUP_ADDRESS;
|
||||
|
||||
case AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS:
|
||||
return AQH_MSG_TYPEGROUP_ADMIN;
|
||||
|
||||
case AQH_MSG_TYPE_FLASH_START:
|
||||
case AQH_MSG_TYPE_FLASH_END:
|
||||
case AQH_MSG_TYPE_FLASH_READY:
|
||||
case AQH_MSG_TYPE_FLASH_DATA:
|
||||
case AQH_MSG_TYPE_FLASH_RSP:
|
||||
case AQH_MSG_TYPE_REBOOT_REQ:
|
||||
case AQH_MSG_TYPE_REBOOT_RSP:
|
||||
return AQH_MSG_TYPEGROUP_FLASH;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -287,6 +294,8 @@ const char *AQH_NodeMsg_MsgTypeToChar(uint8_t i)
|
||||
case AQH_MSG_TYPE_DEVICE: return "Device";
|
||||
case AQH_MSG_TYPE_MEMSTATS: return "MemStats";
|
||||
case AQH_MSG_TYPE_SYSSTATS: return "SysStats";
|
||||
case AQH_MSG_TYPE_REBOOT_REQ: return "RebootRequest";
|
||||
case AQH_MSG_TYPE_REBOOT_RSP: return "RebootResponse";
|
||||
default: return "(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@
|
||||
#define AQH_MSG_TYPE_MEMSTATS 81
|
||||
#define AQH_MSG_TYPE_SYSSTATS 82
|
||||
|
||||
#define AQH_MSG_TYPE_REBOOT_REQ 90
|
||||
#define AQH_MSG_TYPE_REBOOT_RSP 91
|
||||
|
||||
|
||||
/* internal msg types via NET interface */
|
||||
#define AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS 200
|
||||
|
||||
135
aqhome/msg/msg_reboot.c
Normal file
135
aqhome/msg/msg_reboot.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "aqhome/msg/msg_reboot.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/error.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_REBOOT_UID 0 /* 4 bytes */
|
||||
|
||||
#define AQH_MSG_REBOOT_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID+4)
|
||||
|
||||
|
||||
|
||||
static GWEN_MSG *_rebootMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid);
|
||||
static uint32_t _getUid(const GWEN_MSG *msg);
|
||||
static void _rebootMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText, const char *cmd);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *AQH_RebootRequestMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid)
|
||||
{
|
||||
return _rebootMsg_new(srcAddr, destAddr, code, uid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_RebootRequestMsg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
return _getUid(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_RebootRequestMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
_rebootMsg_DumpToBuffer(msg, dbuf, sText, "REBOOT_REQUEST");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *AQH_RebootResponseMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid)
|
||||
{
|
||||
return _rebootMsg_new(srcAddr, destAddr, code, uid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_RebootResponseMsg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
return _getUid(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_RebootResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
_rebootMsg_DumpToBuffer(msg, dbuf, sText, "REBOOT_RESPONSE");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *_rebootMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
uint8_t *ptr;
|
||||
int rv;
|
||||
|
||||
msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 4, NULL);
|
||||
ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID;
|
||||
|
||||
*(ptr++)=uid & 0xff; /* uid */
|
||||
*(ptr++)=(uid>>8) & 0xff;
|
||||
*(ptr++)=(uid>>16) & 0xff;
|
||||
*(ptr++)=(uid>>24) & 0xff;
|
||||
|
||||
|
||||
rv=AQH_NodeMsg_AddChecksum(msg);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Msg_free(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t _getUid(const GWEN_MSG *msg)
|
||||
{
|
||||
return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _rebootMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText, const char *cmd)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_REBOOT_MINSIZE) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: %s %s (uid=0x%08x)\n",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
cmd,
|
||||
sText,
|
||||
_getUid(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
aqhome/msg/msg_reboot.h
Normal file
39
aqhome/msg/msg_reboot.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AQH_MSG_NODE_REBOOT_H
|
||||
#define AQH_MSG_NODE_REBOOT_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/msg/msg_node.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_RebootRequestMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid);
|
||||
|
||||
AQHOME_API uint32_t AQH_RebootRequestMsg_GetUid(const GWEN_MSG *msg);
|
||||
|
||||
AQHOME_API void AQH_RebootRequestMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_RebootResponseMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid);
|
||||
|
||||
AQHOME_API uint32_t AQH_RebootResponseMsg_GetUid(const GWEN_MSG *msg);
|
||||
|
||||
AQHOME_API void AQH_RebootResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user