Modified the server to work with MSTP datalink. Still in progress.
This commit is contained in:
@@ -10,7 +10,8 @@ BASEDIR = .
|
||||
# Configure the BACnet Datalink Layer
|
||||
#BACDL_DEFINE = -DBACDL_ETHERNET=1
|
||||
#BACDL_DEFINE = -DBACDL_ARCNET=1
|
||||
BACDL_DEFINE = -DBACDL_BIP=1 -DBIP_DEBUG
|
||||
BACDL_DEFINE = -DBACDL_MSTP=1
|
||||
#BACDL_DEFINE = -DBACDL_BIP=1 -DBIP_DEBUG
|
||||
BACNET_DEFINES = -DBACFILE=1 -DPRINT_ENABLED=1 -DBIG_ENDIAN=0
|
||||
DEFINES = $(BACNET_DEFINES) $(BACDL_DEFINE)
|
||||
|
||||
@@ -28,6 +29,10 @@ SRCS = main.c \
|
||||
$(BACNET_PORT)/bip-init.c \
|
||||
$(BACNET_PORT)/ethernet.c \
|
||||
$(BACNET_PORT)/arcnet.c \
|
||||
$(BACNET_PORT)/dlmstp.c \
|
||||
$(BACNET_PORT)/mstp.c \
|
||||
$(BACNET_PORT)/rs485.c \
|
||||
$(BACNET_ROOT)/crc.c \
|
||||
$(BACNET_ROOT)/bip.c \
|
||||
$(BACNET_HANDLER)/txbuf.c \
|
||||
$(BACNET_HANDLER)/noserv.c \
|
||||
@@ -83,7 +88,7 @@ OBJS = ${SRCS:.c=.o}
|
||||
all: ${TARGET}
|
||||
|
||||
${TARGET}: ${OBJS}
|
||||
${CC} -o $@ ${OBJS}
|
||||
${CC} -pthread -o $@ ${OBJS}
|
||||
|
||||
.c.o:
|
||||
${CC} -c ${CFLAGS} $*.c -o $@
|
||||
|
||||
@@ -107,6 +107,14 @@ int main(int argc, char *argv[])
|
||||
Network_Interface = argv[2];
|
||||
if (argc > 3)
|
||||
bip_set_port(strtol(argv[3], NULL, 0));
|
||||
#endif
|
||||
#if defined(BACDL_MSTP)
|
||||
if (argc > 2) {
|
||||
Network_Interface = argv[2];
|
||||
}
|
||||
if (argc > 3) {
|
||||
dlmstp_set_mac_address(strtol(argv[1], NULL, 0));
|
||||
}
|
||||
#endif
|
||||
printf("BACnet Server Demo\n"
|
||||
"BACnet Device ID: %u\r\n",
|
||||
|
||||
@@ -57,7 +57,7 @@ typedef struct dlmstp_packet {
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void dlmstp_init(void);
|
||||
bool dlmstp_init(char *ifname);
|
||||
void dlmstp_cleanup(void);
|
||||
void dlmstp_millisecond_timer(void);
|
||||
|
||||
@@ -80,8 +80,8 @@ extern "C" {
|
||||
/* nodes. This may be used to allocate more or less of the available link */
|
||||
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
|
||||
/* node, its value shall be 1. */
|
||||
void dlmstp_set_max_info_frames(unsigned max_info_frames);
|
||||
unsigned dlmstp_max_info_frames(void);
|
||||
void dlmstp_set_max_info_frames(uint8_t max_info_frames);
|
||||
uint8_t dlmstp_max_info_frames(void);
|
||||
|
||||
/* This parameter represents the value of the Max_Master property of the */
|
||||
/* node's Device object. The value of Max_Master specifies the highest */
|
||||
@@ -91,7 +91,10 @@ extern "C" {
|
||||
void dlmstp_set_max_master(uint8_t max_master);
|
||||
uint8_t dlmstp_max_master(void);
|
||||
|
||||
void dlmstp_set_my_address(uint8_t my_address);
|
||||
/* MAC address 0-127 */
|
||||
void dlmstp_set_mac_address(uint8_t my_address);
|
||||
uint8_t dlmstp_mac_address(void);
|
||||
|
||||
void dlmstp_get_my_address(BACNET_ADDRESS * my_address);
|
||||
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */
|
||||
|
||||
@@ -101,6 +104,8 @@ extern "C" {
|
||||
uint16_t pdu_len);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -77,7 +77,7 @@ static void *dlmstp_milliseconds_task(void *pArg)
|
||||
void dlmstp_reinit(void)
|
||||
{
|
||||
//RS485_Reinit();
|
||||
dlmstp_set_my_address(DEFAULT_MAC_ADDRESS);
|
||||
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
|
||||
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
|
||||
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
|
||||
}
|
||||
@@ -156,21 +156,39 @@ static void *dlmstp_master_fsm_task(void *pArg)
|
||||
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE) {
|
||||
while (MSTP_Master_Node_FSM(&MSTP_Port)) {
|
||||
sched_yield();
|
||||
};
|
||||
}
|
||||
/* see if there is a packet available, and a place
|
||||
to put the reply (if necessary) and process it */
|
||||
if (Receive_Buffer.ready && !MSTP_Port.TxReady) {
|
||||
if (Receive_Buffer.pdu_len) {
|
||||
MSTP_Packets++;
|
||||
npdu_handler(&Receive_Buffer.address,
|
||||
&Receive_Buffer.pdu[0], Receive_Buffer.pdu_len);
|
||||
}
|
||||
Receive_Buffer.ready = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* copy the packet if one is received.
|
||||
Return the length of the packet */
|
||||
uint16_t dlmstp_receive(
|
||||
BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
unsigned timeout) /* milliseconds to wait for a packet */
|
||||
{
|
||||
uint16_t len = 0;
|
||||
/* see if there is a packet available, and a place
|
||||
to put the reply (if necessary) and process it */
|
||||
if (Receive_Buffer.ready && !MSTP_Port.TxReady) {
|
||||
if (Receive_Buffer.pdu_len) {
|
||||
MSTP_Packets++;
|
||||
len = Receive_Buffer.pdu_len;
|
||||
memcpy(src,&Receive_Buffer.address,sizeof(Receive_Buffer.address));
|
||||
/* FIXME: check pdu_len and max_pdu */
|
||||
memcpy(pdu,&Receive_Buffer.pdu[0],len);
|
||||
}
|
||||
Receive_Buffer.ready = false;
|
||||
} else {
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -207,7 +225,7 @@ uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
void dlmstp_set_my_address(uint8_t mac_address)
|
||||
void dlmstp_set_mac_address(uint8_t mac_address)
|
||||
{
|
||||
/* Master Nodes can only have address 0-127 */
|
||||
if (mac_address <= 127) {
|
||||
@@ -250,7 +268,7 @@ void dlmstp_set_max_info_frames(uint8_t max_info_frames)
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned dlmstp_max_info_frames(void)
|
||||
uint8_t dlmstp_max_info_frames(void)
|
||||
{
|
||||
return MSTP_Port.Nmax_info_frames;
|
||||
}
|
||||
@@ -331,7 +349,7 @@ bool dlmstp_init(char *ifname)
|
||||
if (data <= 127)
|
||||
MSTP_Port.This_Station = data;
|
||||
else
|
||||
dlmstp_set_my_address(DEFAULT_MAC_ADDRESS);
|
||||
dlmstp_set_mac_address(DEFAULT_MAC_ADDRESS);
|
||||
if ((data <= 127) && (data >= MSTP_Port.This_Station))
|
||||
MSTP_Port.Nmax_master = data;
|
||||
else
|
||||
@@ -376,7 +394,7 @@ int main(int argc, char *argv[])
|
||||
RS485_Set_Interface(argv[1]);
|
||||
}
|
||||
RS485_Set_Baud_Rate(38400);
|
||||
dlmstp_set_my_address(0x05);
|
||||
dlmstp_set_mac_address(0x05);
|
||||
dlmstp_set_max_info_frames(DEFAULT_MAX_INFO_FRAMES);
|
||||
dlmstp_set_max_master(DEFAULT_MAX_MASTER);
|
||||
dlmstp_init();
|
||||
|
||||
@@ -194,7 +194,7 @@ struct mstp_port_struct_t {
|
||||
/* nodes. This may be used to allocate more or less of the available link */
|
||||
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
|
||||
/* node, its value shall be 1. */
|
||||
unsigned Nmax_info_frames;
|
||||
uint8_t Nmax_info_frames;
|
||||
|
||||
/* This parameter represents the value of the Max_Master property of the */
|
||||
/* node's Device object. The value of Max_Master specifies the highest */
|
||||
|
||||
Reference in New Issue
Block a user