Feature/mstp extended frames (#529)

* added MSTP extended frames to bacnet/datalink/mstp.c module. Thank you, Simon!

* auto-size some FIFO buffers for MSTP

* add COBS library to MSTP builds

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-11-08 15:54:18 -06:00
committed by GitHub
parent 2536d5a350
commit 1372e52aa7
22 changed files with 109 additions and 32 deletions
+13 -1
View File
@@ -80,7 +80,7 @@
/* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */
/* This is used in constructing messages and to tell others our limits */
/* 50 is the minimum; adjust to your memory and physical layer constraints */
/* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476, BACnet/IP=1476 */
/* Lon=206, MS/TP=480 or 1476, ARCNET=480, Ethernet=1476, BACnet/IP=1476 */
#if !defined(MAX_APDU)
/* #define MAX_APDU 50 */
/* #define MAX_APDU 1476 */
@@ -96,6 +96,18 @@
#else
#define MAX_APDU 1476
#endif
#elif defined (BACDL_ARCNET)
#if defined(BACNET_SECURITY)
#define MAX_APDU 412
#else
#define MAX_APDU 480
#endif
#elif defined (BACDL_MSTP)
#if defined(BACNET_SECURITY)
#define MAX_APDU 412
#else
#define MAX_APDU 1476
#endif
#else
#if defined(BACNET_SECURITY)
#define MAX_APDU 412
+2
View File
@@ -483,6 +483,8 @@ void dlenv_maintenance_timer(uint16_t elapsed_seconds)
BBMD_Timer_Seconds = (uint16_t)BBMD_TTL_Seconds;
}
}
#else
(void)elapsed_seconds;
#endif
}
+39 -12
View File
@@ -56,6 +56,7 @@
#include "rs485.h"
#include "bacnet/datalink/mstptext.h"
#include "bacnet/npdu.h"
#include "bacnet/datalink/cobs.h"
#ifndef DEBUG_ENABLED
#define DEBUG_ENABLED 0
@@ -532,30 +533,56 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->DataCRC = CRC_Calc_Data(
mstp_port->DataRegister, mstp_port->DataCRC);
mstp_port->DataCRCActualMSB = mstp_port->DataRegister;
mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister;
mstp_port->Index++;
/* SKIP_DATA or DATA - no change in state */
} else if (mstp_port->Index == (mstp_port->DataLength + 1)) {
/* CRC2 */
mstp_port->InputBuffer[mstp_port->Index] =
mstp_port->DataRegister;
mstp_port->DataCRC = CRC_Calc_Data(
mstp_port->DataRegister, mstp_port->DataCRC);
mstp_port->DataCRCActualLSB = mstp_port->DataRegister;
printf_receive_data("%s",
mstptext_frame_type((unsigned)mstp_port->FrameType));
/* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */
if (mstp_port->DataCRC == 0xF0B8) {
if (mstp_port->receive_state ==
MSTP_RECEIVE_STATE_DATA) {
/* ForUs */
mstp_port->ReceivedValidFrame = true;
if ((mstp_port->FrameType ==
FRAME_TYPE_BACNET_EXTENDED_DATA_EXPECTING_REPLY) ||
(mstp_port->FrameType ==
FRAME_TYPE_BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY)) {
if (cobs_frame_decode(
&mstp_port->InputBuffer[mstp_port->Index + 1],
mstp_port->InputBufferSize,
mstp_port->InputBuffer, mstp_port->Index + 1)) {
if (mstp_port->receive_state ==
MSTP_RECEIVE_STATE_DATA) {
/* ForUs */
mstp_port->ReceivedValidFrame = true;
} else {
/* NotForUs */
mstp_port->ReceivedValidFrameNotForUs = true;
}
} else {
/* NotForUs */
mstp_port->ReceivedValidFrameNotForUs = true;
mstp_port->ReceivedInvalidFrame = true;
}
} else {
mstp_port->ReceivedInvalidFrame = true;
printf_receive_error("MSTP: Rx Data: BadCRC [%02X]\n",
mstp_port->DataRegister);
/* STATE DATA CRC - no need for new state */
/* indicate the complete reception of a valid frame */
if (mstp_port->DataCRC == 0xF0B8) {
if (mstp_port->receive_state ==
MSTP_RECEIVE_STATE_DATA) {
/* ForUs */
mstp_port->ReceivedValidFrame = true;
} else {
/* NotForUs */
mstp_port->ReceivedValidFrameNotForUs = true;
}
} else {
mstp_port->ReceivedInvalidFrame = true;
printf_receive_error(
"MSTP: Rx Data: BadCRC [%02X]\n",
mstp_port->DataRegister);
}
}
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
} else {
+6 -1
View File
@@ -75,7 +75,12 @@ static INDTEXT_DATA mstp_frame_type_text[] = { { FRAME_TYPE_TOKEN, "TOKEN" },
{ FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY, "BACNET_DATA_EXPECTING_REPLY" },
{ FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY,
"BACNET_DATA_NOT_EXPECTING_REPLY" },
{ FRAME_TYPE_REPLY_POSTPONED, "REPLY_POSTPONED" }, { 0, NULL } };
{ FRAME_TYPE_REPLY_POSTPONED, "REPLY_POSTPONED" },
{ FRAME_TYPE_BACNET_EXTENDED_DATA_EXPECTING_REPLY,
"BACNET_EXTENDED_DATA_EXPECTING_REPLY" },
{ FRAME_TYPE_BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY,
"BACNET_EXTENDED_DATA_NOT_EXPECTING_REPLY" },
{ FRAME_TYPE_IPV6_ENCAPSULATION, "IPV6_ENCAPSULATION" }, { 0, NULL } };
const char *mstptext_frame_type(unsigned index)
{