/****************************************************************************
 * 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_H
#define AQH_MSG_NODE_H


#include <aqhome/api.h>

#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>


#define AQH_MAXMSGSIZE 24


#define AQH_MSG_OFFS_ALL_DEST_ADDRESS  0
#define AQH_MSG_OFFS_ALL_PAYLOAD_LEN   1
#define AQH_MSG_OFFS_ALL_PAYLOAD_BEGIN 2
#define AQH_MSG_OFFS_ALL_MSG_TYPE      2
#define AQH_MSG_OFFS_ALL_SRC_ADDRESS   3
#define AQH_MSG_OFFS_ALL_DATA_BEGIN    4


#define AQH_MSG_TYPE_PING          10
#define AQH_MSG_TYPE_PONG          11
#define AQH_MSG_TYPE_COMSENDSTATS  20
#define AQH_MSG_TYPE_COMRECVSTATS  21
#define AQH_MSG_TYPE_TWIBUSMEMBER  30
#define AQH_MSG_TYPE_DEBUG         40
#define AQH_MSG_TYPE_VALUE         50
#define AQH_MSG_TYPE_VALUE2        51
#define AQH_MSG_TYPE_NEED_ADDRESS  60
#define AQH_MSG_TYPE_HAVE_ADDRESS  61
#define AQH_MSG_TYPE_CLAIM_ADDRESS 62
#define AQH_MSG_TYPE_DENY_ADDRESS  63
#define AQH_MSG_TYPE_ADDRESS_RANGE 64

#define AQH_MSG_TYPE_DEVICE        80


/* internal msg types via NET interface */
#define AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS      200


#define AQH_MSG_TYPEGROUP_INFO    0x00000001
#define AQH_MSG_TYPEGROUP_VALUES  0x00000002
#define AQH_MSG_TYPEGROUP_ADDRESS 0x00000004
#define AQH_MSG_TYPEGROUP_FLASH   0x00000008
#define AQH_MSG_TYPEGROUP_ADMIN   0x00000010
#define AQH_MSG_TYPEGROUP_ALL     0xffffffff




AQHOME_API uint8_t AQH_NodeMsg_GetDestAddress(const GWEN_MSG *msg);
AQHOME_API uint8_t AQH_NodeMsg_GetMsgType(const GWEN_MSG *msg);
AQHOME_API uint8_t AQH_NodeMsg_GetSourceAddress(const GWEN_MSG *msg);
AQHOME_API uint8_t AQH_NodeMsg_GetMsgPayloadLen(const GWEN_MSG *msg);



AQHOME_API int AQH_NodeMsg_IsMsgComplete(const GWEN_MSG *msg);
AQHOME_API int AQH_NodeMsg_IsChecksumValid(const GWEN_MSG *msg);
AQHOME_API int AQH_NodeMsg_AddChecksum(GWEN_MSG *msg);

AQHOME_API uint32_t AQH_NodeMsg_GetUint32At(const GWEN_MSG *msg, int offs, int defaultValue);
AQHOME_API uint16_t AQH_NodeMsg_GetUint16At(const GWEN_MSG *msg, int offs, int defaultValue);
AQHOME_API uint8_t AQH_NodeMsg_GetUint8At(const GWEN_MSG *msg, int offs, int defaultValue);

AQHOME_API void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);

AQHOME_API uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType);




#endif
