Files
aqhomecontrol/aqhome/msg/msg_sendstats.c
2023-04-07 23:22:40 +02:00

89 lines
2.6 KiB
C

/****************************************************************************
* 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_sendstats.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_SENDSTATS_UID 0
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6
#define AQH_MSG_OFFS_SENDSTATS_ABORTED 8
#define AQH_MSG_OFFS_SENDSTATS_NOBUFFER 10
#define AQH_MSG_SENDSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED+2)
uint32_t AQH_SendStatsMsg_GetUid(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_UID, 0);
}
uint16_t AQH_SendStatsMsg_GetPacketsOut(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_PACKETSOUT, 0);
}
uint16_t AQH_SendStatsMsg_GetCollisions(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_COLLISIONS, 0);
}
uint16_t AQH_SendStatsMsg_GetAborted(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED, 0);
}
uint16_t AQH_SendStatsMsg_GetNoBufferErrors(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_NOBUFFER, 0);
}
void AQH_SendStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, aborted=%d, no buffer=%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
(unsigned int) AQH_SendStatsMsg_GetUid(msg),
AQH_SendStatsMsg_GetPacketsOut(msg),
AQH_SendStatsMsg_GetCollisions(msg),
AQH_SendStatsMsg_GetAborted(msg),
AQH_SendStatsMsg_GetNoBufferErrors(msg));
}
}