avr: added flash-related messages.

This commit is contained in:
Martin Preuss
2023-04-20 00:43:07 +02:00
parent 5b9fe3d0cd
commit c65bd60bc5
15 changed files with 545 additions and 9 deletions

View File

@@ -64,6 +64,10 @@
msg_value2.h
msg_device.h
msg_flashready.h
msg_flashstart.h
msg_flashresponse.h
msg_flashend.h
msg_flashdata.h
</headers>
@@ -98,6 +102,10 @@
msg_value2.c
msg_device.c
msg_flashready.c
msg_flashstart.c
msg_flashresponse.c
msg_flashend.c
msg_flashdata.c
</sources>

View File

@@ -28,6 +28,10 @@
#include "aqhome/msg/msg_denyaddr.h"
#include "aqhome/msg/msg_device.h"
#include "aqhome/msg/msg_flashready.h"
#include "aqhome/msg/msg_flashstart.h"
#include "aqhome/msg/msg_flashresponse.h"
#include "aqhome/msg/msg_flashend.h"
#include "aqhome/msg/msg_flashdata.h"
#include <gwenhywfar/list.h>
#include <gwenhywfar/inherit.h>
@@ -141,6 +145,10 @@ void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
case AQH_MSG_TYPE_MEMSTATS: AQH_MemStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_SYSSTATS: AQH_SysStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_READY: AQH_FlashReadyMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_START: AQH_FlashStartMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_RSP: AQH_FlashResponseMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_END: AQH_FlashEndMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_FLASH_DATA: AQH_FlashDataMsg_DumpToBuffer(msg, dbuf, "received"); break;
default: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
}
}

111
aqhome/msg/msg_flashdata.c Normal file
View File

@@ -0,0 +1,111 @@
/****************************************************************************
* 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_flashdata.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_FLASHDATA_ADDRESS 0 /* 4 bytes */
#define AQH_MSG_OFFS_FLASHDATA_DATA 4 /* x bytes */
#define AQH_MSG_FLASHEND_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA)
GWEN_MSG *AQH_FlashDataMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr,
const uint8_t *dataPtr, uint32_t dataLen)
{
GWEN_MSG *msg;
uint8_t *ptr;
int rv;
uint32_t i;
msg=AQH_NodeMsg_new(destAddr, srcAddr, code, dataLen+4, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_ADDRESS;
*(ptr++)=addr & 0xff;
*(ptr++)=(addr>>8) & 0xff;
*(ptr++)=(addr>>16) & 0xff;
*(ptr++)=(addr>>24) & 0xff;
for (i=0; i<dataLen; i++) {
*(ptr++)=*(dataPtr);
}
rv=AQH_NodeMsg_AddChecksum(msg);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Msg_free(msg);
return NULL;
}
return msg;
}
uint32_t AQH_FlashDataMsg_GetAddress(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_ADDRESS, 0);
}
uint8_t AQH_FlashDataMsg_GetDataLen(const GWEN_MSG *msg)
{
uint8_t msgDataLen;
msgDataLen=GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_PAYLOAD_LEN, 0);
if (msgDataLen>AQH_MSG_FLASHEND_MINSIZE)
return msgDataLen-AQH_MSG_OFFS_ALL_DATA_BEGIN-AQH_MSG_OFFS_FLASHDATA_DATA;
return 0;
}
const uint8_t *AQH_FlashDataMsg_GetDataPtr(const GWEN_MSG *msg)
{
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg);
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE)
return ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA;
return NULL;
}
void AQH_FlashDataMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_FLASH_READY) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE)) {
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHDATA %s (data address=0x%04x, data length=%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
AQH_FlashDataMsg_GetAddress(msg),
AQH_FlashDataMsg_GetDataLen(msg));
}
}

View File

@@ -0,0 +1,34 @@
/****************************************************************************
* 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_FLASHDATA_H
#define AQH_MSG_FLASHDATA_H
#include <aqhome/api.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
AQHOME_API GWEN_MSG *AQH_FlashDataMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr,
const uint8_t *dataPtr, uint32_t dataLen);
AQHOME_API uint32_t AQH_FlashDataMsg_GetAddress(const GWEN_MSG *msg);
AQHOME_API uint8_t AQH_FlashDataMsg_GetDataLen(const GWEN_MSG *msg);
AQHOME_API const uint8_t *AQH_FlashDataMsg_GetDataPtr(const GWEN_MSG *msg);
AQHOME_API void AQH_FlashDataMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

76
aqhome/msg/msg_flashend.c Normal file
View File

@@ -0,0 +1,76 @@
/****************************************************************************
* 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_flashend.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_FLASHEND_REASON 0 /* 1 byte */
#define AQH_MSG_FLASHEND_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON+1)
GWEN_MSG *AQH_FlashEndMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason)
{
GWEN_MSG *msg;
uint8_t *ptr;
int rv;
msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 5, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON;
*(ptr++)=reason & 0xff; /* reason */
GWEN_Msg_IncCurrentPos(msg, 5);
rv=AQH_NodeMsg_AddChecksum(msg);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Msg_free(msg);
return NULL;
}
return msg;
}
uint8_t AQH_FlashEndMsg_GetReason(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON, 0);
}
void AQH_FlashEndMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_FLASH_READY) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE)) {
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHEND %s (reason=%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
AQH_FlashEndMsg_GetReason(msg));
}
}

31
aqhome/msg/msg_flashend.h Normal file
View File

@@ -0,0 +1,31 @@
/****************************************************************************
* 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_FLASHEND_H
#define AQH_MSG_FLASHEND_H
#include <aqhome/api.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
AQHOME_API GWEN_MSG *AQH_FlashEndMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason);
AQHOME_API uint8_t AQH_FlashEndMsg_GetReason(const GWEN_MSG *msg);
AQHOME_API void AQH_FlashEndMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -20,7 +20,7 @@
AQHOME_API uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg);
AQHOME_API uint16_t AQH_FlashReadyMsg_GetFirmwareType(const GWEN_MSG *msg);
AQHOME_API uint16_t AQH_FlashReadyMsg_GetFirmwareVersion(const GWEN_MSG *msg);
AQHOME_API uint16_t AQH_FlashReadyMsg_GetModules(const GWEN_MSG *msg);
AQHOME_API uint16_t AQH_FlashReadyMsg_GetPagesize(const GWEN_MSG *msg);
AQHOME_API void AQH_FlashReadyMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);

View File

@@ -0,0 +1,50 @@
/****************************************************************************
* 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_flashresponse.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_FLASHRESPONSE_CODE 0 /* 1 byte */
#define AQH_MSG_FLASHRESPONSE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE+1)
uint8_t AQH_FlashResponseMsg_GetCode(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE, 0);
}
void AQH_FlashResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHRESPONSE_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHRESPONSE %s (code=%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
AQH_FlashResponseMsg_GetCode(msg));
}
}

View File

@@ -0,0 +1,28 @@
/****************************************************************************
* 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_FLASHRESPONSE_H
#define AQH_MSG_FLASHRESPONSE_H
#include <aqhome/api.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
AQHOME_API uint8_t AQH_FlashResponseMsg_GetCode(const GWEN_MSG *msg);
AQHOME_API void AQH_FlashResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

107
aqhome/msg/msg_flashstart.c Normal file
View File

@@ -0,0 +1,107 @@
/****************************************************************************
* 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_flashstart.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_FLASHSTART_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_FLASHSTART_FWTYPE 4 /* 2 bytes */
#define AQH_MSG_OFFS_FLASHSTART_FWVER 6 /* 2 bytes */
#define AQH_MSG_FLASHSTART_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_FWVER+2)
GWEN_MSG *AQH_FlashStartMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code,
uint32_t uid, uint16_t firmwareType, uint16_t firmwareVersion)
{
GWEN_MSG *msg;
uint8_t *ptr;
int rv;
msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 8, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID;
*(ptr++)=uid & 0xff; /* uid */
*(ptr++)=(uid>>8) & 0xff;
*(ptr++)=(uid>>16) & 0xff;
*(ptr++)=(uid>>24) & 0xff;
*(ptr++)=firmwareType & 0xff; /* fw type */
*(ptr++)=(firmwareType>>8) & 0xff;
*(ptr++)=firmwareVersion & 0xff; /* fw ver */
*(ptr++)=(firmwareVersion>>8) & 0xff;
rv=AQH_NodeMsg_AddChecksum(msg);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Msg_free(msg);
return NULL;
}
return msg;
}
uint32_t AQH_FlashStartMsg_GetUid(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID, 0);
}
uint16_t AQH_FlashStartMsg_GetFirmwareType(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_FWTYPE, 0);
}
uint16_t AQH_FlashStartMsg_GetFirmwareVersion(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_FWVER, 0);
}
void AQH_FlashStartMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHSTART_MINSIZE) {
uint16_t fwVersion;
fwVersion=AQH_FlashStartMsg_GetFirmwareVersion(msg);
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHSTART %s (uid=0x%08x, fw type=%d, fw ver=%d.%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
(unsigned int) AQH_FlashStartMsg_GetUid(msg),
AQH_FlashStartMsg_GetFirmwareType(msg),
(fwVersion>>8) & 0xff,
fwVersion & 0xff);
}
}

View File

@@ -0,0 +1,33 @@
/****************************************************************************
* 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_FLASHSTART_H
#define AQH_MSG_FLASHSTART_H
#include <aqhome/api.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
AQHOME_API GWEN_MSG *AQH_FlashStartMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code,
uint32_t uid, uint16_t firmwareType, uint16_t firmwareVersion);
AQHOME_API uint32_t AQH_FlashStartMsg_GetUid(const GWEN_MSG *msg);
AQHOME_API uint16_t AQH_FlashStartMsg_GetFirmwareType(const GWEN_MSG *msg);
AQHOME_API uint16_t AQH_FlashStartMsg_GetFirmwareVersion(const GWEN_MSG *msg);
AQHOME_API void AQH_FlashStartMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -42,7 +42,7 @@ GWEN_MSG *AQH_NodeMsg_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8
ptr=GWEN_Msg_GetBuffer(msg);
ptr[AQH_MSG_OFFS_ALL_DEST_ADDRESS]=destAddr & 0xff;
ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]=6;
ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]=payloadLen+2;
ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]=code;
ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]=srcAddr;
@@ -123,8 +123,10 @@ int AQH_NodeMsg_IsMsgComplete(const GWEN_MSG *msg)
ptr=GWEN_Msg_GetConstBuffer(msg);
len=ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]+AQH_MSG_OFFS_ALL_PAYLOAD_BEGIN+1;
if (len>AQH_MAXMSGSIZE)
return -1;
if (len>AQH_MAXMSGSIZE) {
DBG_ERROR(AQH_LOGDOMAIN, "Total length > max length (%d > %d)", len, AQH_MAXMSGSIZE);
return -1;
}
else if (msgLen>=len)
return 1;
}
@@ -259,5 +261,35 @@ uint8_t _calcXorChecksum(const uint8_t *ptr, uint8_t len)
const char *AQH_NodeMsg_MsgTypeToChar(uint8_t i)
{
switch(i) {
case AQH_MSG_TYPE_PING: return "Ping";
case AQH_MSG_TYPE_PONG: return "Pong";
case AQH_MSG_TYPE_COMSENDSTATS: return "SendStats";
case AQH_MSG_TYPE_COMRECVSTATS: return "RecvStats";
case AQH_MSG_TYPE_TWIBUSMEMBER: return "TwiBusMember";
case AQH_MSG_TYPE_DEBUG: return "Debug";
case AQH_MSG_TYPE_VALUE: return "Value";
case AQH_MSG_TYPE_VALUE2: return "Value2";
case AQH_MSG_TYPE_NEED_ADDRESS: return "NeedAddress";
case AQH_MSG_TYPE_HAVE_ADDRESS: return "HaveAddress";
case AQH_MSG_TYPE_CLAIM_ADDRESS: return "ClaimAddress";
case AQH_MSG_TYPE_DENY_ADDRESS: return "DenyAddress";
case AQH_MSG_TYPE_ADDRESS_RANGE: return "Range";
case AQH_MSG_TYPE_FLASH_START: return "FlashStart";
case AQH_MSG_TYPE_FLASH_END: return "FlashEnd";
case AQH_MSG_TYPE_FLASH_READY: return "FlashReady";
case AQH_MSG_TYPE_FLASH_DATA: return "FlashData";
case AQH_MSG_TYPE_FLASH_RSP: return "FlashResponse";
case AQH_MSG_TYPE_DEVICE: return "Device";
case AQH_MSG_TYPE_MEMSTATS: return "MemStats";
case AQH_MSG_TYPE_SYSSTATS: return "SysStats";
default: return "(unknown)";
}
}

View File

@@ -92,7 +92,7 @@ AQHOME_API void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf,
AQHOME_API uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType);
AQHOME_API const char *AQH_NodeMsg_MsgTypeToChar(uint8_t i);
#endif

View File

@@ -41,8 +41,6 @@ GWEN_MSG *AQH_PingMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code)
*(ptr++)=0;
*ptr=0;
GWEN_Msg_IncCurrentPos(msg, 4);
rv=AQH_NodeMsg_AddChecksum(msg);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);