diff --git a/bacnet-stack/demo/handler/s_rp.c b/bacnet-stack/demo/handler/s_rp.c index 9c58d9e3..932e4670 100644 --- a/bacnet-stack/demo/handler/s_rp.c +++ b/bacnet-stack/demo/handler/s_rp.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "config.h" #include "config.h" #include "txbuf.h" diff --git a/bacnet-stack/demo/handler/s_whois.c b/bacnet-stack/demo/handler/s_whois.c index afc4caeb..52ddd525 100644 --- a/bacnet-stack/demo/handler/s_whois.c +++ b/bacnet-stack/demo/handler/s_whois.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "config.h" #include "config.h" #include "txbuf.h" diff --git a/bacnet-stack/demo/readprop/Makefile b/bacnet-stack/demo/readprop/Makefile index be25c704..189c65af 100644 --- a/bacnet-stack/demo/readprop/Makefile +++ b/bacnet-stack/demo/readprop/Makefile @@ -6,10 +6,10 @@ 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. -#DEFINES = -DBACFILE=1 -DBACDL_ETHERNET=1 -#DEFINES = -DBACFILE=1 -DBACDL_ARCNET=1 -#DEFINES = -DBACFILE=1 -DBACDL_MSTP=1 -DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBACDL_BIP=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 +#DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 -DBACDL_ETHERNET=1 +#DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 -DBACDL_ARCNET=1 +#DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 -DBACDL_MSTP=1 +DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 -DBACDL_BIP=1 BACNET_PORT = ../../ports/linux BACNET_OBJECT = ../object BACNET_HANDLER = ../handler @@ -22,6 +22,8 @@ TARGET = bacrp SRCS = readprop.c \ $(BACNET_PORT)/bip-init.c \ + $(BACNET_PORT)/ethernet.c \ + $(BACNET_PORT)/arcnet.c \ $(BACNET_ROOT)/bip.c \ $(BACNET_HANDLER)/txbuf.c \ $(BACNET_HANDLER)/noserv.c \ diff --git a/bacnet-stack/demo/readprop/readprop.c b/bacnet-stack/demo/readprop/readprop.c index cb064d8f..9daeac22 100644 --- a/bacnet-stack/demo/readprop/readprop.c +++ b/bacnet-stack/demo/readprop/readprop.c @@ -174,11 +174,21 @@ int main(int argc, char *argv[]) Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); address_init(); Init_Service_Handlers(); - /* configure standard BACnet/IP port */ - bip_set_interface("eth0"); /* for linux */ - bip_set_port(0xBAC0); +#if defined(BACDL_ETHERNET) + /* init the physical layer */ + if (!ethernet_init("eth0")) + return 1; +#elif defined(BACDL_BIP) + bip_set_interface("eth0"); if (!bip_init()) return 1; + printf("bip: using port %hu\r\n", bip_get_port()); +#elif defined(BACDL_ARCNET) + if (!arcnet_init("arc0")) + return 1; +#else + #error Datalink (BACDL_ETHERNET,BACDL_BIP, or BACDL_ARCNET) undefined +#endif /* configure the timeout values */ last_seconds = time(NULL); timeout_seconds = (Device_APDU_Timeout() / 1000) * @@ -192,7 +202,7 @@ int main(int argc, char *argv[]) current_seconds = time(NULL); /* returns 0 bytes on timeout */ - pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); + pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); /* process */ if (pdu_len) { diff --git a/bacnet-stack/ports/linux/ethernet.c b/bacnet-stack/ports/linux/ethernet.c index 52141e1b..27454268 100644 --- a/bacnet-stack/ports/linux/ethernet.c +++ b/bacnet-stack/ports/linux/ethernet.c @@ -188,8 +188,9 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */ BACNET_ADDRESS src = { 0 }; /* source address for npdu*/ uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */ int mtu_len = 0; - int len = 0; + int npdu_len = 0; + /* load the BACnet address for NPDU data */ for (i = 0; i < 6; i++) { src.mac[i] = Ethernet_MAC_Address[i]; src.mac_len++; @@ -223,16 +224,16 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */ mtu[14] = 0x82; /* DSAP for BACnet */ mtu[15] = 0x82; /* SSAP for BACnet */ mtu[16] = 0x03; /* Control byte in header */ - len = npdu_encode_pdu(&mtu[17], dest, &src, npdu_data); - mtu_len = 17 + len; + npdu_len = npdu_encode_pdu(&mtu[17], dest, &src, npdu_data); + mtu_len = 17 + npdu_len; if ((mtu_len + pdu_len) > MAX_MPDU) { fprintf(stderr, "ethernet: PDU is too big to send!\n"); return -4; } memcpy(&mtu[mtu_len], pdu, pdu_len); mtu_len += pdu_len; - /* packet length */ - encode_unsigned16(&mtu[12],mtu_len); + /* packet length - only the logical portion, not the address */ + encode_unsigned16(&mtu[12], 3 + npdu_len + pdu_len); /* Send the packet */ bytes =