Reduced MS/TP MAX_APDU to use 480 by default in examples (#683)

* Reduced MS/TP MAX_APDU to 480 from 1476 so that devices not use new MS/TP extended frame types which older routers do not understand.

* Added extra objects to STM32F4xx example to elicit edge cases in object-list for testing.
This commit is contained in:
Steve Karg
2024-07-02 12:47:15 -05:00
committed by GitHub
parent d5b0060d8a
commit cb4f675e39
18 changed files with 242 additions and 48 deletions
+13 -1
View File
@@ -151,6 +151,16 @@ set(BACNET_PROJECT_SOURCE
${CMAKE_SOURCE_DIR}/device.c
${CMAKE_SOURCE_DIR}/netport.c
${LIBRARY_BACNET_BASIC}/object/ai.c
${LIBRARY_BACNET_BASIC}/object/ao.c
${LIBRARY_BACNET_BASIC}/object/av.c
${LIBRARY_BACNET_BASIC}/object/bi.c
${LIBRARY_BACNET_BASIC}/object/bo.c
${LIBRARY_BACNET_BASIC}/object/bv.c
${LIBRARY_BACNET_BASIC}/object/ms-input.c
${LIBRARY_BACNET_BASIC}/object/mso.c
${LIBRARY_BACNET_BASIC}/object/msv.c
${LIBRARY_BACNET_BASIC}/service/h_dcc.c
${LIBRARY_BACNET_BASIC}/service/h_apdu.c
${LIBRARY_BACNET_BASIC}/npdu/h_npdu.c
@@ -167,6 +177,7 @@ set(BACNET_PROJECT_SOURCE
${LIBRARY_BACNET_BASIC}/sys/debug.c
${LIBRARY_BACNET_BASIC}/sys/ringbuf.c
${LIBRARY_BACNET_BASIC}/sys/fifo.c
${LIBRARY_BACNET_BASIC}/sys/keylist.c
${LIBRARY_BACNET_BASIC}/sys/mstimer.c
${LIBRARY_BACNET_CORE}/abort.c
@@ -273,8 +284,9 @@ target_link_options(${EXECUTABLE} PRIVATE
# Create hex and bin files
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.hex
)
# Print executable size
+13 -2
View File
@@ -34,6 +34,15 @@ PLATFORM_SRC = \
BASIC_SRC = \
$(BACNET_BASIC)/npdu/h_npdu.c \
$(BACNET_BASIC)/object/ai.c \
$(BACNET_BASIC)/object/ao.c \
$(BACNET_BASIC)/object/av.c \
$(BACNET_BASIC)/object/bi.c \
$(BACNET_BASIC)/object/bo.c \
$(BACNET_BASIC)/object/bv.c \
$(BACNET_BASIC)/object/ms-input.c \
$(BACNET_BASIC)/object/mso.c \
$(BACNET_BASIC)/object/msv.c \
$(BACNET_BASIC)/service/h_apdu.c \
$(BACNET_BASIC)/service/h_dcc.c \
$(BACNET_BASIC)/service/h_rd.c \
@@ -48,6 +57,7 @@ BASIC_SRC = \
$(BACNET_BASIC)/sys/debug.c \
$(BACNET_BASIC)/sys/ringbuf.c \
$(BACNET_BASIC)/sys/fifo.c \
$(BACNET_BASIC)/sys/keylist.c \
$(BACNET_BASIC)/sys/mstimer.c \
$(BACNET_BASIC)/tsm/tsm.c
@@ -149,8 +159,9 @@ MCU_FLAGS += -DUSE_STDPERIPH_DRIVER
OPTIMIZE_FLAGS := -Os -ggdb
OPTIMIZE_FLAGS += -DNDEBUG
BACNET_FLAGS = -DBACDL_MSTP=1
BACNET_FLAGS += -DMAX_APDU=1476
BACNET_FLAGS = -DBACDL_MSTP=
# note: MS/TP extended frames can be up to MAX_APDU=1476 bytes
BACNET_FLAGS += -DMAX_APDU=480
BACNET_FLAGS += -DBIG_ENDIAN=0
BACNET_FLAGS += -DMAX_TSM_TRANSACTIONS=0
BACNET_FLAGS += -DMAX_CHARACTER_STRING_BYTES=64
+65 -2
View File
@@ -37,7 +37,15 @@
#include "bacnet/iam.h"
/* BACnet objects */
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/ai.h"
#include "bacnet/basic/object/ao.h"
#include "bacnet/basic/object/av.h"
#include "bacnet/basic/object/bi.h"
#include "bacnet/basic/object/bo.h"
#include "bacnet/basic/object/bv.h"
#include "bacnet/basic/object/ms-input.h"
#include "bacnet/basic/object/mso.h"
#include "bacnet/basic/object/msv.h"
/* me */
#include "bacnet.h"
@@ -47,14 +55,69 @@ static struct mstimer DCC_Timer;
/* Device ID to track changes */
static uint32_t Device_ID = 0xFFFFFFFF;
#ifndef BACNET_ANALOG_INPUTS_MAX
#define BACNET_ANALOG_INPUTS_MAX 12
#endif
#ifndef BACNET_ANALOG_OUTPUTS_MAX
#define BACNET_ANALOG_OUTPUTS_MAX 12
#endif
#ifndef BACNET_ANALOG_VALUES_MAX
#define BACNET_ANALOG_VALUES_MAX 12
#endif
#ifndef BACNET_BINARY_INPUTS_MAX
#define BACNET_BINARY_INPUTS_MAX 12
#endif
#ifndef BACNET_BINARY_OUTPUTS_MAX
#define BACNET_BINARY_OUTPUTS_MAX 12
#endif
#ifndef BACNET_BINARY_VALUES_MAX
#define BACNET_BINARY_VALUES_MAX 12
#endif
#ifndef BACNET_MULTISTATE_INPUTS_MAX
#define BACNET_MULTISTATE_INPUTS_MAX 12
#endif
#ifndef BACNET_MULTISTATE_OUTPUTS_MAX
#define BACNET_MULTISTATE_OUTPUTS_MAX 12
#endif
#ifndef BACNET_MULTISTATE_VALUES_MAX
#define BACNET_MULTISTATE_VALUES_MAX 12
#endif
/**
* @brief Initialize the BACnet device object, the service handlers, and timers
*/
void bacnet_init(void)
{
{
uint32_t instance;
/* initialize objects */
Device_Init(NULL);
for (instance = 1; instance <= BACNET_ANALOG_INPUTS_MAX; instance++) {
Analog_Input_Create(instance);
}
for (instance = 1; instance <= BACNET_ANALOG_OUTPUTS_MAX; instance++) {
Analog_Output_Create(instance);
}
for (instance = 1; instance <= BACNET_ANALOG_VALUES_MAX; instance++) {
Analog_Value_Create(instance);
}
for (instance = 1; instance <= BACNET_BINARY_INPUTS_MAX; instance++) {
Binary_Input_Create(instance);
}
for (instance = 1; instance <= BACNET_BINARY_OUTPUTS_MAX; instance++) {
Binary_Output_Create(instance);
}
for (instance = 1; instance <= BACNET_BINARY_VALUES_MAX; instance++) {
Binary_Value_Create(instance);
}
for (instance = 1; instance <= BACNET_MULTISTATE_INPUTS_MAX; instance++) {
Multistate_Input_Create(instance);
}
for (instance = 1; instance <= BACNET_MULTISTATE_OUTPUTS_MAX; instance++) {
Multistate_Output_Create(instance);
}
for (instance = 1; instance <= BACNET_MULTISTATE_VALUES_MAX; instance++) {
Multistate_Value_Create(instance);
}
/* set up our confirmed service unrecognized service handler - required! */
apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service);
/* we need to handle who-is to support dynamic device binding */
+34 -1
View File
@@ -224,7 +224,7 @@
<state>USE_STDPERIPH_DRIVER</state>
<state>STM32F4XX</state>
<state>BACDL_MSTP</state>
<state>MAX_APDU=1476</state>
<state>MAX_APDU=480</state>
<state>BIG_ENDIAN=0</state>
<state>MAX_TSM_TRANSACTIONS=1</state>
<state>BACAPP_MINIMAL</state>
@@ -1164,6 +1164,36 @@
<name>$PROJ_DIR$\..\..\src\bacnet\basic\npdu\h_npdu.c</name>
</file>
</group>
<group>
<name>BACnet Basic Objects</name>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\ai.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\ao.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\av.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\bi.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\bo.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\bv.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\ms-input.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\mso.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\object\msv.c</name>
</file>
</group>
<group>
<name>BACnet Basic Services</name>
<file>
@@ -1211,6 +1241,9 @@
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\sys\fifo.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\sys\keylist.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\basic\sys\mstimer.c</name>
</file>
+49
View File
@@ -40,11 +40,22 @@
#include "bacnet/version.h"
#include "bacnet/basic/services.h"
/* objects */
#include "bacnet/basic/object/ai.h"
#include "bacnet/basic/object/ao.h"
#include "bacnet/basic/object/av.h"
#include "bacnet/basic/object/bi.h"
#include "bacnet/basic/object/bo.h"
#include "bacnet/basic/object/bv.h"
#include "bacnet/basic/object/ms-input.h"
#include "bacnet/basic/object/mso.h"
#include "bacnet/basic/object/msv.h"
#if (BACNET_PROTOCOL_REVISION >= 17)
#include "bacnet/basic/object/netport.h"
#endif
#include "bacnet/basic/object/device.h"
/* clang-format off */
static struct my_object_functions {
BACNET_OBJECT_TYPE Object_Type;
object_init_function Object_Init;
@@ -60,6 +71,43 @@ static struct my_object_functions {
Device_Valid_Object_Instance_Number,
Device_Object_Name, Device_Read_Property_Local,
Device_Write_Property_Local, Device_Property_Lists },
{ OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count,
Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance,
Analog_Input_Object_Name, Analog_Input_Read_Property,
Analog_Input_Write_Property, Analog_Input_Property_Lists},
{ OBJECT_ANALOG_OUTPUT, Analog_Output_Init, Analog_Output_Count,
Analog_Output_Index_To_Instance, Analog_Output_Valid_Instance,
Analog_Output_Object_Name, Analog_Output_Read_Property,
Analog_Output_Write_Property, Analog_Output_Property_Lists},
{ OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count,
Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance,
Analog_Value_Object_Name, Analog_Value_Read_Property,
Analog_Value_Write_Property, Analog_Value_Property_Lists},
{ OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count,
Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance,
Binary_Input_Object_Name, Binary_Input_Read_Property,
Binary_Input_Write_Property, Binary_Input_Property_Lists},
{ OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count,
Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance,
Binary_Output_Object_Name, Binary_Output_Read_Property,
Binary_Output_Write_Property, Binary_Output_Property_Lists},
{ OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count,
Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance,
Binary_Value_Object_Name, Binary_Value_Read_Property,
Binary_Value_Write_Property, Binary_Value_Property_Lists},
{ OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count,
Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance,
Multistate_Input_Object_Name, Multistate_Input_Read_Property,
Multistate_Input_Write_Property, Multistate_Input_Property_Lists},
{ OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init,
Multistate_Output_Count, Multistate_Output_Index_To_Instance,
Multistate_Output_Valid_Instance, Multistate_Output_Object_Name,
Multistate_Output_Read_Property, Multistate_Output_Write_Property,
Multistate_Output_Property_Lists},
{ OBJECT_MULTI_STATE_VALUE, Multistate_Value_Init, Multistate_Value_Count,
Multistate_Value_Index_To_Instance, Multistate_Value_Valid_Instance,
Multistate_Value_Object_Name, Multistate_Value_Read_Property,
Multistate_Value_Write_Property, Multistate_Value_Property_Lists},
#if (BACNET_PROTOCOL_REVISION >= 17)
{ OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count,
Network_Port_Index_To_Instance, Network_Port_Valid_Instance,
@@ -68,6 +116,7 @@ static struct my_object_functions {
#endif
{ MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL } };
/* clang-format on */
/* note: you really only need to define variables for
properties that are writable or that may change.
+39 -17
View File
@@ -4,6 +4,16 @@ MEMORY
flash (RX) : ORIGIN = 0x08000000, LENGTH = 512k
}
_estack = 0x20000000 + 128k - 4; /* End of SRAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 48K;
/* Analysis from MAP file and Stack Usage (su) +
adjust _Min_Heap_Size until linker error: sram overflowed by x bytes
_Min_Heap_Size = _Min_Heap_Size - x
*/
_Min_Stack_Size = 16K;
SECTIONS
{
.text :
@@ -22,11 +32,10 @@ SECTIONS
*(.gnu.linkonce.r.*)
. = ALIGN(4);
_etext = .;
_sidata = _etext;
_sidata = _etext;
PROVIDE(etext = .);
_fini = . ;
*(.fini)
_fini = . ;
*(.fini)
} >flash
.data : AT (_etext)
@@ -40,20 +49,20 @@ SECTIONS
_edata = .;
} >sram
.ARM.extab :
{
*(.ARM.extab*)
} >sram
.ARM.extab :
{
*(.ARM.extab*)
} >sram
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx*)
} >sram
__exidx_end = .;
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx*)
} >sram
__exidx_end = .;
.bss (NOLOAD) : {
. = ALIGN(4);
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .;
*(.bss .bss.*)
@@ -63,6 +72,19 @@ SECTIONS
_ebss = .;
} >sram
end = .;
PROVIDE( _estack = 0x20010000 );
PROVIDE ( end = _ebss );
PROVIDE ( _end = _ebss );
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
. = . + _Min_Heap_Size;
_user_heap_end = .;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >sram
PROVIDE(_heap_limit = _user_heap_end);
PROVIDE(_stack_limit = _estack);
}