made the datalink generic while adding datalink for MS/TP
This commit is contained in:
@@ -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 \
|
||||
|
||||
+40
-10
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+1
-4
@@ -40,10 +40,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user