aqhome: Improved serial port handling, added parsers for different msg types.

This commit is contained in:
Martin Preuss
2023-02-04 00:58:28 +01:00
parent 4587dfb9dd
commit 2874e18048
14 changed files with 1117 additions and 211 deletions

99
aqhome/msg_sendstats.c Normal file
View File

@@ -0,0 +1,99 @@
/****************************************************************************
* 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_sendstats.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
uint32_t AQH_MsgSendStats_GetTimestamp(const AQH_MSG *msg)
{
if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_TIMESTAMP;
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
}
return 0;
}
uint16_t AQH_MsgSendStats_GetPacketsOut(const AQH_MSG *msg)
{
if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_PACKETSOUT;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return 0;
}
uint16_t AQH_MsgSendStats_GetCollisions(const AQH_MSG *msg)
{
if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_COLLISIONS;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return 0;
}
uint16_t AQH_MsgSendStats_GetAborted(const AQH_MSG *msg)
{
if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return 0;
}
void AQH_MsgSendStats_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SENDSTATS %s (timestamp=0x%08x, out=%d, collisions=%d, aborted=%d)\n",
AQH_Msg_GetSourceAddress(msg),
AQH_Msg_GetDestAddress(msg),
sText,
(unsigned int) AQH_MsgSendStats_GetTimestamp(msg),
AQH_MsgSendStats_GetPacketsOut(msg),
AQH_MsgSendStats_GetCollisions(msg),
AQH_MsgSendStats_GetAborted(msg));
}
}