aqhome-nodes: send heartbeat message to interface every 2mins.

e02 now expects this message. If for at least 10mins no such msg is
received the USB interface is reset.
This commit is contained in:
Martin Preuss
2026-04-27 16:01:12 +02:00
parent a0360d5373
commit 0ac20ba82c
12 changed files with 217 additions and 26 deletions

View File

@@ -64,6 +64,7 @@
m_flashresponse.h
m_range.h
m_time.h
m_heartbeat.h
</headers>
@@ -93,6 +94,7 @@
m_flashresponse.c
m_range.c
m_time.c
m_heartbeat.c
</sources>

View File

@@ -0,0 +1,55 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2026 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/node/m_heartbeat.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_HEARTBEAT_TIMESTAMP 0 /* 4 bytes */
AQH_MESSAGE *AQH_HeartbeatMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t timestamp)
{
uint32_t payload;
payload=GWEN_ENDIAN_HTOLE32(timestamp);
return AQH_NodeMessage_new(destAddr, srcAddr, code, sizeof(payload), (const uint8_t*)&payload);
}
uint32_t AQH_HeartbeatMessage_GetTimestamp(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HEARTBEAT_TIMESTAMP, 0);
}
void AQH_HeartbeatMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: HEARTBEAT(%s) %s (uid=0x%08x)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_HeartbeatMessage_GetTimestamp(msg));
}

View File

@@ -0,0 +1,28 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2026 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_M_HEARTBEAT_H
#define AQH_M_HEARTBEAT_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_HeartbeatMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t timestamp);
AQHOME_API uint32_t AQH_HeartbeatMessage_GetTimestamp(const AQH_MESSAGE *msg);
AQHOME_API void AQH_HeartbeatMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -21,6 +21,7 @@
#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_heartbeat.h"
#include "aqhome/msg/node/m_reboot.h"
#include "aqhome/msg/node/m_value.h"
#include "aqhome/msg/node/m_flashstart.h"
@@ -29,6 +30,7 @@
#include "aqhome/msg/node/m_flashready.h"
#include "aqhome/msg/node/m_flashresponse.h"
#include "aqhome/msg/node/m_range.h"
#include "aqhome/msg/node/m_time.h"
#include <gwenhywfar/text.h>
@@ -202,6 +204,7 @@ const char *AQH_NodeMessage_MsgTypeToChar(uint8_t i)
switch(i) {
case AQH_MSG_TYPE_PING: return "Ping";
case AQH_MSG_TYPE_PONG: return "Pong";
case AQH_MSG_TYPE_HEARTBEAT: return "Heartbeat";
case AQH_MSG_TYPE_COMSENDSTATS: return "SendStats";
case AQH_MSG_TYPE_COMRECVSTATS: return "RecvStats";
case AQH_MSG_TYPE_TWIBUSMEMBER: return "TwiBusMember";
@@ -245,6 +248,7 @@ void AQH_NodeMessage_DumpSpecificToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *d
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_HEARTBEAT: AQH_HeartbeatMessage_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_NEED_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;

View File

@@ -29,6 +29,7 @@
#define AQH_MSG_TYPE_PING 10
#define AQH_MSG_TYPE_PONG 11
#define AQH_MSG_TYPE_HEARTBEAT 12
#define AQH_MSG_TYPE_COMSENDSTATS 22
#define AQH_MSG_TYPE_COMRECVSTATS 23
#define AQH_MSG_TYPE_TWIBUSMEMBER 30