From ff1dbe83b0607f8eb253ef36476f6bdd6c9064c6 Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 30 Jun 2005 21:31:00 +0000 Subject: [PATCH] made the datalink generic while adding datalink for MS/TP --- bacnet-stack/Makefile | 4 ++- bacnet-stack/datalink.c | 50 ++++++++++++++++++++++++++------- bacnet-stack/datalink.h | 9 +++++- bacnet-stack/mstp.h | 5 +--- bacnet-stack/ports/linux/main.c | 18 ++---------- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/bacnet-stack/Makefile b/bacnet-stack/Makefile index 6ea12893..7749fd5c 100644 --- a/bacnet-stack/Makefile +++ b/bacnet-stack/Makefile @@ -6,12 +6,14 @@ BASEDIR = . #CFLAGS = -Wall -I. -O2 -g # Note: you can strip out symbols using the strip command # to get an idea of how big the compile really is. -#CFLAGS = -Wall -I. -g -DBACDL_ETHERNET=1 +#CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_MSTP=1 +#CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_ETHERNET=1 CFLAGS = -Wall -I. -Iports/linux -g -DBACDL_BIP=1 SRCS = ports/linux/main.c \ ports/linux/ethernet.c \ ports/linux/bip.c \ + dlmstp.c \ handlers.c \ bacdcode.c \ bigend.c \ diff --git a/bacnet-stack/datalink.c b/bacnet-stack/datalink.c index ed093c30..4b46c397 100644 --- a/bacnet-stack/datalink.c +++ b/bacnet-stack/datalink.c @@ -46,14 +46,14 @@ int datalink_send_pdu( uint8_t *pdu, // any data to be sent - may be null unsigned pdu_len) // number of bytes of data { -#ifdef BACDL_ETHERNET - return ethernet_send_pdu( +#ifdef BACDL_MSTP + return dlmstp_send_pdu( dest, pdu, pdu_len); #endif -#ifdef BACDL_MSTP - return mstp_send_pdu( +#ifdef BACDL_ETHERNET + return ethernet_send_pdu( dest, pdu, pdu_len); @@ -66,15 +66,45 @@ int datalink_send_pdu( #endif } +// returns the number of octets in the PDU, or zero on failure +uint16_t datalink_receive( + BACNET_ADDRESS *src, // source address + uint8_t *pdu, // PDU data + uint16_t max_pdu, // amount of space available in the PDU + unsigned timeout) // number of milliseconds to wait for a packet +{ + #ifdef BACDL_MSTP + return dlmstp_receive( + src, + pdu, + max_pdu, + timeout); + #endif + #ifdef BACDL_ETHERNET + return ethernet_receive( + src, + pdu, + max_pdu, + timeout); + #endif + #ifdef BACDL_BIP + return bip_receive( + src, + pdu, + max_pdu, + timeout); + #endif +} + void datalink_get_broadcast_address( BACNET_ADDRESS *dest) // destination address { +#ifdef BACDL_MSTP + dlmstp_get_broadcast_address(dest); +#endif #ifdef BACDL_ETHERNET ethernet_get_broadcast_address(dest); #endif -#ifdef BACDL_MSTP - mstp_get_broadcast_address(dest); -#endif #ifdef BACDL_BIP bip_get_broadcast_address(dest); #endif @@ -83,12 +113,12 @@ void datalink_get_broadcast_address( void datalink_get_my_address( BACNET_ADDRESS *my_address) { +#ifdef BACDL_MSTP + dlmstp_get_my_address(my_address); +#endif #ifdef BACDL_ETHERNET ethernet_get_my_address(my_address); #endif -#ifdef BACDL_MSTP - mstp_get_my_address(my_address); -#endif #ifdef BACDL_BIP bip_get_my_address(my_address); #endif diff --git a/bacnet-stack/datalink.h b/bacnet-stack/datalink.h index 54665fcd..0a4182a3 100644 --- a/bacnet-stack/datalink.h +++ b/bacnet-stack/datalink.h @@ -44,7 +44,7 @@ #endif #ifdef BACDL_MSTP -#include "mstp.h" +#include "dlmstp.h" #endif #ifdef BACDL_BIP @@ -57,6 +57,13 @@ int datalink_send_pdu( uint8_t *pdu, // any data to be sent - may be null unsigned pdu_len); // number of bytes of data +// returns the number of octets in the PDU, or zero on failure +uint16_t datalink_receive( + BACNET_ADDRESS *src, // source address + uint8_t *pdu, // PDU data + uint16_t max_pdu, // amount of space available in the PDU + unsigned timeout); // number of milliseconds to wait for a packet + void datalink_get_broadcast_address( BACNET_ADDRESS *dest); // destination address diff --git a/bacnet-stack/mstp.h b/bacnet-stack/mstp.h index 86d92350..12c1dd4a 100644 --- a/bacnet-stack/mstp.h +++ b/bacnet-stack/mstp.h @@ -40,10 +40,7 @@ #include #include #include "bacdef.h" - -// defines specific to MS/TP -#define MAX_HEADER (2+1+1+1+2+1+2+1) -#define MAX_MPDU (MAX_HEADER+MAX_PDU) +#include "dlmstp.h" // The value 255 is used to denote broadcast when used as a // destination address but is not allowed as a value for a station. diff --git a/bacnet-stack/ports/linux/main.c b/bacnet-stack/ports/linux/main.c index 984ab245..f1c87148 100644 --- a/bacnet-stack/ports/linux/main.c +++ b/bacnet-stack/ports/linux/main.c @@ -39,12 +39,7 @@ #include "tsm.h" #include "device.h" #include "bacfile.h" -#ifdef BACDL_ETHERNET - #include "ethernet.h" -#endif -#ifdef BACDL_BIP - #include "bip.h" -#endif +#include "datalink.h" #include "net.h" // This is an example application using the BACnet Stack on Linux @@ -329,20 +324,11 @@ int main(int argc, char *argv[]) // input new_time = time(NULL); // returns 0 bytes on timeout - #ifdef BACDL_ETHERNET - pdu_len = ethernet_receive( + pdu_len = datalink_receive( &src, &Rx_Buf[0], MAX_MPDU, timeout); - #endif - #ifdef BACDL_BIP - pdu_len = bip_receive( - &src, - &Rx_Buf[0], - MAX_MPDU, - timeout); - #endif // process if (pdu_len)