Refactor/mstp zero config state machine (#676)
* Changed MS/TP master node self destination checks to be located in receive FSM * Changed MSTP zero configuration: modified comments for state transition names; modified next station increment; refactored the UUID rand() to not be required by common zero config implementation; added more unit tests. * Added another context to MS/TP user data to allow additional user data
This commit is contained in:
@@ -77,7 +77,7 @@ static struct my_object_functions {
|
||||
properties that are writable or that may change.
|
||||
The properties that are constant can be hard coded
|
||||
into the read-property encoding. */
|
||||
static uint32_t Object_Instance_Number = 103;
|
||||
static uint32_t Object_Instance_Number = BACNET_MAX_INSTANCE;
|
||||
static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL;
|
||||
static BACNET_CHARACTER_STRING My_Object_Name;
|
||||
static uint32_t Database_Revision;
|
||||
@@ -453,9 +453,8 @@ void Device_Init(object_functions_t *object_table)
|
||||
pObject++;
|
||||
}
|
||||
dcc_set_status_duration(COMMUNICATION_ENABLE, 0);
|
||||
if (Object_Instance_Number >= BACNET_MAX_INSTANCE) {
|
||||
Object_Instance_Number = 103;
|
||||
srand(Object_Instance_Number);
|
||||
if (Object_Instance_Number > BACNET_MAX_INSTANCE) {
|
||||
Object_Instance_Number = BACNET_MAX_INSTANCE;
|
||||
}
|
||||
characterstring_init_ansi(&My_Object_Name, "stm32-design-challenge-103");
|
||||
}
|
||||
|
||||
+10
-2
@@ -25,11 +25,13 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "hardware.h"
|
||||
#include "bacnet/basic/sys/mstimer.h"
|
||||
#include "bacnet/datalink/datalink.h"
|
||||
#include "bacnet/datalink/dlmstp.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
#include "bacnet/basic/object/device.h"
|
||||
#include "rs485.h"
|
||||
#include "led.h"
|
||||
#include "bacnet.h"
|
||||
@@ -38,7 +40,7 @@
|
||||
char *BACnet_Version = "1.0";
|
||||
/* MS/TP port */
|
||||
static struct mstp_port_struct_t MSTP_Port;
|
||||
static struct dlmstp_rs485_driver RS485_Driver = {
|
||||
static struct dlmstp_rs485_driver RS485_Driver = {
|
||||
.init = rs485_init,
|
||||
.send = rs485_bytes_send,
|
||||
.read = rs485_byte_available,
|
||||
@@ -46,7 +48,7 @@ static struct dlmstp_rs485_driver RS485_Driver = {
|
||||
.baud_rate = rs485_baud_rate,
|
||||
.baud_rate_set = rs485_baud_rate_set,
|
||||
.silence_milliseconds = rs485_silence_milliseconds,
|
||||
.silence_reset = rs485_silence_reset
|
||||
.silence_reset = rs485_silence_reset
|
||||
};
|
||||
static struct dlmstp_user_data_t MSTP_User_Data;
|
||||
static uint8_t Input_Buffer[DLMSTP_MPDU_MAX];
|
||||
@@ -144,6 +146,7 @@ static void mstp_configure(void)
|
||||
/* user data */
|
||||
MSTP_Port.ZeroConfigEnabled = true;
|
||||
MSTP_Port.SlaveNodeEnabled = false;
|
||||
MSTP_Zero_Config_UUID_Init(&MSTP_Port);
|
||||
MSTP_User_Data.RS485_Driver = &RS485_Driver;
|
||||
MSTP_Port.UserData = &MSTP_User_Data;
|
||||
dlmstp_init((char *)&MSTP_Port);
|
||||
@@ -163,6 +166,7 @@ static void mstp_configure(void)
|
||||
int main(void)
|
||||
{
|
||||
struct mstimer Blink_Timer;
|
||||
uint32_t Object_Instance_Number = 103;
|
||||
|
||||
/*At this stage the microcontroller clock setting is already configured,
|
||||
this is done through SystemInit() function which is called from startup
|
||||
@@ -178,6 +182,10 @@ int main(void)
|
||||
mstimer_init();
|
||||
lse_init();
|
||||
led_init();
|
||||
/* FIXME: get device instance from EEPROM */
|
||||
(void)Device_Set_Object_Instance_Number(Object_Instance_Number);
|
||||
/* seed libc random number generator */
|
||||
srand(Object_Instance_Number);
|
||||
/* initialize MSTP datalink layer */
|
||||
mstp_configure();
|
||||
/* initialize application layer*/
|
||||
|
||||
Reference in New Issue
Block a user