included ethernet and arcnet in demo for readprop and server on Linux. Corrected the ethernet length. Corrected warnings in s_rp and s_whois.

This commit is contained in:
skarg
2006-08-13 16:53:15 +00:00
parent 3560e3d06f
commit 05abf5be23
5 changed files with 28 additions and 13 deletions
+1
View File
@@ -25,6 +25,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include "config.h" #include "config.h"
#include "config.h" #include "config.h"
#include "txbuf.h" #include "txbuf.h"
+1
View File
@@ -25,6 +25,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include "config.h" #include "config.h"
#include "config.h" #include "config.h"
#include "txbuf.h" #include "txbuf.h"
+6 -4
View File
@@ -6,10 +6,10 @@ BASEDIR = .
#CFLAGS = -Wall -I. -O2 -g #CFLAGS = -Wall -I. -O2 -g
# Note: you can strip out symbols using the strip command # Note: you can strip out symbols using the strip command
# to get an idea of how big the compile really is. # to get an idea of how big the compile really is.
#DEFINES = -DBACFILE=1 -DBACDL_ETHERNET=1 #DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 -DBACDL_ETHERNET=1
#DEFINES = -DBACFILE=1 -DBACDL_ARCNET=1 #DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=1 -DBACDL_ARCNET=1
#DEFINES = -DBACFILE=1 -DBACDL_MSTP=1 #DEFINES = -DBACFILE=1 -DTSM_ENABLED=1 -DBIG_ENDIAN=0 -DPRINT_ENABLED=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_BIP=1
BACNET_PORT = ../../ports/linux BACNET_PORT = ../../ports/linux
BACNET_OBJECT = ../object BACNET_OBJECT = ../object
BACNET_HANDLER = ../handler BACNET_HANDLER = ../handler
@@ -22,6 +22,8 @@ TARGET = bacrp
SRCS = readprop.c \ SRCS = readprop.c \
$(BACNET_PORT)/bip-init.c \ $(BACNET_PORT)/bip-init.c \
$(BACNET_PORT)/ethernet.c \
$(BACNET_PORT)/arcnet.c \
$(BACNET_ROOT)/bip.c \ $(BACNET_ROOT)/bip.c \
$(BACNET_HANDLER)/txbuf.c \ $(BACNET_HANDLER)/txbuf.c \
$(BACNET_HANDLER)/noserv.c \ $(BACNET_HANDLER)/noserv.c \
+14 -4
View File
@@ -174,11 +174,21 @@ int main(int argc, char *argv[])
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
address_init(); address_init();
Init_Service_Handlers(); Init_Service_Handlers();
/* configure standard BACnet/IP port */ #if defined(BACDL_ETHERNET)
bip_set_interface("eth0"); /* for linux */ /* init the physical layer */
bip_set_port(0xBAC0); if (!ethernet_init("eth0"))
return 1;
#elif defined(BACDL_BIP)
bip_set_interface("eth0");
if (!bip_init()) if (!bip_init())
return 1; 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 */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
@@ -192,7 +202,7 @@ int main(int argc, char *argv[])
current_seconds = time(NULL); current_seconds = time(NULL);
/* returns 0 bytes on timeout */ /* 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 */ /* process */
if (pdu_len) { if (pdu_len) {
+6 -5
View File
@@ -188,8 +188,9 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_ADDRESS src = { 0 }; /* source address for npdu*/ BACNET_ADDRESS src = { 0 }; /* source address for npdu*/
uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */ uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */
int mtu_len = 0; int mtu_len = 0;
int len = 0; int npdu_len = 0;
/* load the BACnet address for NPDU data */
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
src.mac[i] = Ethernet_MAC_Address[i]; src.mac[i] = Ethernet_MAC_Address[i];
src.mac_len++; src.mac_len++;
@@ -223,16 +224,16 @@ int ethernet_send_pdu(BACNET_ADDRESS * dest, /* destination address */
mtu[14] = 0x82; /* DSAP for BACnet */ mtu[14] = 0x82; /* DSAP for BACnet */
mtu[15] = 0x82; /* SSAP for BACnet */ mtu[15] = 0x82; /* SSAP for BACnet */
mtu[16] = 0x03; /* Control byte in header */ mtu[16] = 0x03; /* Control byte in header */
len = npdu_encode_pdu(&mtu[17], dest, &src, npdu_data); npdu_len = npdu_encode_pdu(&mtu[17], dest, &src, npdu_data);
mtu_len = 17 + len; mtu_len = 17 + npdu_len;
if ((mtu_len + pdu_len) > MAX_MPDU) { if ((mtu_len + pdu_len) > MAX_MPDU) {
fprintf(stderr, "ethernet: PDU is too big to send!\n"); fprintf(stderr, "ethernet: PDU is too big to send!\n");
return -4; return -4;
} }
memcpy(&mtu[mtu_len], pdu, pdu_len); memcpy(&mtu[mtu_len], pdu, pdu_len);
mtu_len += pdu_len; mtu_len += pdu_len;
/* packet length */ /* packet length - only the logical portion, not the address */
encode_unsigned16(&mtu[12],mtu_len); encode_unsigned16(&mtu[12], 3 + npdu_len + pdu_len);
/* Send the packet */ /* Send the packet */
bytes = bytes =