aqhome: Prepared reorganizing IPC and nodes code around built-in event2 api.

This commit is contained in:
Martin Preuss
2025-02-26 00:49:33 +01:00
parent cf8edbbd5f
commit f63079af11
54 changed files with 2390 additions and 202 deletions

View File

@@ -10,9 +10,25 @@
# include <config.h>
#endif
#include "aqhome/msg/node/m_node.h"
#include "aqhome/msg/node/m_device.h"
#include "aqhome/msg/node/m_recvstats.h"
#include "aqhome/msg/node/m_sendstats.h"
#include "aqhome/msg/node/m_memstats.h"
#include "aqhome/msg/node/m_sysstats.h"
#include "aqhome/msg/node/m_addr.h"
#include "aqhome/msg/node/m_needaddr.h"
#include "aqhome/msg/node/m_ping.h"
#include "aqhome/msg/node/m_pong.h"
#include "aqhome/msg/node/m_reboot.h"
#include "aqhome/msg/node/m_value.h"
#include "aqhome/msg/node/m_flashstart.h"
#include "aqhome/msg/node/m_flashdata.h"
#include "aqhome/msg/node/m_flashend.h"
#include "aqhome/msg/node/m_flashready.h"
#include "aqhome/msg/node/m_flashresponse.h"
#include <gwenhywfar/text.h>
@@ -49,7 +65,7 @@ AQH_MESSAGE *AQH_NodeMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code
if (payloadLen && payload)
memmove(ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN, payload, payloadLen);
AQH_Message_SetUsedSize(msg, len);
AQH_Message_SetUsedSize(msg, len-1);
AQH_NodeMessage_AddChecksum(msg);
return msg;
@@ -57,6 +73,29 @@ AQH_MESSAGE *AQH_NodeMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code
AQH_MESSAGE *AQH_NodeMessage_prepare(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen)
{
AQH_MESSAGE *msg;
uint8_t *ptr;
uint32_t len;
len=AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen+1; /* dest, len, code, src, payload, crc8 */
msg=AQH_Message_new();
AQH_Message_SetData(msg, NULL, len); /* auto-malloc len bytes */
ptr=AQH_Message_GetMsgPointer(msg);
ptr[AQH_MSG_OFFS_ALL_DEST_ADDRESS]=destAddr & 0xff;
ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]=payloadLen+2; /* code, src, payload */
ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]=code;
ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]=srcAddr;
AQH_Message_SetUsedSize(msg, len-1);
return msg;
}
AQH_MESSAGE *AQH_NodeMessage_fromBuffer(const uint8_t *ptr, uint32_t len)
{
if (ptr && len) {
@@ -191,6 +230,42 @@ const char *AQH_NodeMessage_MsgTypeToChar(uint8_t i)
void AQH_NodeMessage_DumpSpecificToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (msg && dbuf) {
switch(AQH_NodeMessage_GetMsgType(msg)) {
case AQH_MSG_TYPE_PING: AQH_PingMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_PONG: AQH_PongMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_COMSENDSTATS: AQH_SendStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_COMRECVSTATS: AQH_RecvStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_VALUE: AQH_ValueMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_NEED_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_HAVE_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_CLAIM_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_DENY_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_START: AQH_FlashStartMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_END: AQH_FlashEndMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_READY: AQH_FlashReadyMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_DATA: AQH_FlashDataMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_RSP: AQH_FlashResponseMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_DEVICE: AQH_DeviceMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_MEMSTATS: AQH_MemStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_SYSSTATS: AQH_SysStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_REBOOT_REQ: AQH_RebootMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_REBOOT_RSP: AQH_RebootMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_DEBUG:
case AQH_MSG_TYPE_TWIBUSMEMBER:
case AQH_MSG_TYPE_ADDRESS_RANGE:
default: AQH_NodeMessage_DumpToBuffer(msg, dbuf, sText); break;
}
}
}
uint32_t AQH_NodeMessage_GetMsgGroup(uint8_t msgType)
{
switch(msgType) {