Combined the interface set into the datalink_init for all the datalink layers. Changed all the demo programs to use datalink_init instead of specific datalink functions.

This commit is contained in:
skarg
2007-05-25 01:08:42 +00:00
parent 076ee5f3ca
commit 8026dc003b
29 changed files with 123 additions and 295 deletions
+7 -1
View File
@@ -1,4 +1,5 @@
all: readprop writeprop readfile writefile reinit server dcc whohas whois ucov timesync all: readprop writeprop readfile writefile reinit server dcc \
whohas whois ucov timesync epics
@echo "utilities are in the utils directory" @echo "utilities are in the utils directory"
clean: \ clean: \
@@ -10,6 +11,7 @@ clean: \
demo/dcc/Makefile \ demo/dcc/Makefile \
demo/whohas/Makefile \ demo/whohas/Makefile \
demo/timesync/Makefile \ demo/timesync/Makefile \
demo/epics/Makefile \
demo/whois/Makefile demo/whois/Makefile
( cd demo/readprop ; make clean ) ( cd demo/readprop ; make clean )
( cd demo/writeprop ; make clean ) ( cd demo/writeprop ; make clean )
@@ -20,6 +22,7 @@ clean: \
( cd demo/dcc ; make clean ) ( cd demo/dcc ; make clean )
( cd demo/whohas ; make clean ) ( cd demo/whohas ; make clean )
( cd demo/timesync ; make clean ) ( cd demo/timesync ; make clean )
( cd demo/epics ; make clean )
( cd demo/whois ; make clean ) ( cd demo/whois ; make clean )
readprop: demo/readprop/Makefile readprop: demo/readprop/Makefile
@@ -49,6 +52,9 @@ whohas: demo/whohas/Makefile
timesync: demo/timesync/Makefile timesync: demo/timesync/Makefile
( cd demo/timesync ; make clean ; make ; cp bacts ../../utils ) ( cd demo/timesync ; make clean ; make ; cp bacts ../../utils )
epics: demo/epics/Makefile
( cd demo/epics ; make clean ; make ; cp bacts ../../utils )
ucov: demo/ucov/Makefile ucov: demo/ucov/Makefile
( cd demo/ucov ; make clean ; make ; cp bacucov ../../utils ) ( cd demo/ucov ; make clean ; make ; cp bacucov ../../utils )
+15 -15
View File
@@ -51,10 +51,12 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* note: define init and cleanup in your ports section */ /* note: define init and cleanup in your ports section */
bool bip_init(void); /* on Linux, ifname is eth0, ath0, arc0, and others.
on Windows, ifname is the dotted ip address of the interface */
bool bip_init(char *ifname);
/* normal functions... */ /* normal functions... */
void bip_cleanup(void); void bip_cleanup(void);
void bip_set_socket(int sock_fd); void bip_set_socket(int sock_fd);
int bip_socket(void); int bip_socket(void);
@@ -62,37 +64,35 @@ extern "C" {
void bip_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */ void bip_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */
void bip_get_my_address(BACNET_ADDRESS * my_address); void bip_get_my_address(BACNET_ADDRESS * my_address);
/* function to send a packet out the BACnet/IP socket */ /* function to send a packet out the BACnet/IP socket */
/* returns zero on success, non-zero on failure */ /* returns zero on success, non-zero on failure */
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len); /* number of bytes of data */ unsigned pdu_len); /* number of bytes of data */
/* receives a BACnet/IP packet */ /* receives a BACnet/IP packet */
/* returns the number of octets in the PDU, or zero on failure */ /* returns the number of octets in the PDU, or zero on failure */
uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */ uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */ uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */ uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout); /* milliseconds to wait for a packet */ unsigned timeout); /* milliseconds to wait for a packet */
/* use host byte order for setting */ /* use host byte order for setting */
void bip_set_port(uint16_t port); void bip_set_port(uint16_t port);
/* returns host byte order */ /* returns host byte order */
uint16_t bip_get_port(void); uint16_t bip_get_port(void);
/* use network byte order for setting */ /* use network byte order for setting */
void bip_set_addr(uint32_t net_address); void bip_set_addr(uint32_t net_address);
/* returns host byte order */ /* returns host byte order */
uint32_t bip_get_addr(void); uint32_t bip_get_addr(void);
/* use network byte order for setting */ /* use network byte order for setting */
void bip_set_broadcast_addr(uint32_t net_address); void bip_set_broadcast_addr(uint32_t net_address);
/* returns host byte order */ /* returns host byte order */
uint32_t bip_get_broadcast_addr(void); uint32_t bip_get_broadcast_addr(void);
void bip_set_interface(char *ifname);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
+6 -1
View File
@@ -37,6 +37,7 @@
#if defined(BACDL_ETHERNET) #if defined(BACDL_ETHERNET)
#include "ethernet.h" #include "ethernet.h"
#define datalink_init ethernet_init
#define datalink_send_pdu ethernet_send_pdu #define datalink_send_pdu ethernet_send_pdu
#define datalink_receive ethernet_receive #define datalink_receive ethernet_receive
#define datalink_cleanup ethernet_cleanup #define datalink_cleanup ethernet_cleanup
@@ -46,6 +47,7 @@
#elif defined(BACDL_ARCNET) #elif defined(BACDL_ARCNET)
#include "arcnet.h" #include "arcnet.h"
#define datalink_init arcnet_init
#define datalink_send_pdu arcnet_send_pdu #define datalink_send_pdu arcnet_send_pdu
#define datalink_receive arcnet_receive #define datalink_receive arcnet_receive
#define datalink_cleanup arcnet_cleanup #define datalink_cleanup arcnet_cleanup
@@ -55,6 +57,7 @@
#elif defined(BACDL_MSTP) #elif defined(BACDL_MSTP)
#include "dlmstp.h" #include "dlmstp.h"
#define datalink_init dlmstp_init
#define datalink_send_pdu dlmstp_send_pdu #define datalink_send_pdu dlmstp_send_pdu
#define datalink_receive dlmstp_receive #define datalink_receive dlmstp_receive
#define datalink_cleanup dlmstp_cleanup #define datalink_cleanup dlmstp_cleanup
@@ -64,6 +67,7 @@
#elif defined(BACDL_BIP) #elif defined(BACDL_BIP)
#include "bip.h" #include "bip.h"
#define datalink_init bip_init
#define datalink_send_pdu bip_send_pdu #define datalink_send_pdu bip_send_pdu
#define datalink_receive bip_receive #define datalink_receive bip_receive
#define datalink_cleanup bip_cleanup #define datalink_cleanup bip_cleanup
@@ -79,7 +83,8 @@ extern uint16_t datalink_receive(BACNET_ADDRESS * src,
uint8_t * pdu, uint16_t max_pdu, unsigned timeout); uint8_t * pdu, uint16_t max_pdu, unsigned timeout);
extern void datalink_cleanup(void); extern void datalink_cleanup(void);
extern void datalink_get_broadcast_address(BACNET_ADDRESS * dest); extern void datalink_get_broadcast_address(BACNET_ADDRESS * dest);
extern void bip_get_my_address(BACNET_ADDRESS * my_address); extern void datalink_get_my_address(BACNET_ADDRESS * my_address);
extern void datalink_set_interface(char *ifname);
#endif #endif
+1 -38
View File
@@ -138,21 +138,6 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
for (i = 0; i < dest->mac_len; i++) {
printf("%02X", dest->mac[i]);
}
printf("\n");
}
}
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
BACNET_ADDRESS src = { 0 }; /* address where message came from */ BACNET_ADDRESS src = { 0 }; /* address where message came from */
@@ -165,9 +150,6 @@ int main(int argc, char *argv[])
time_t timeout_seconds = 0; time_t timeout_seconds = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool found = false; bool found = false;
#ifdef BIP_DEBUG
BACNET_ADDRESS my_address, broadcast_address;
#endif
if (argc < 3) { if (argc < 3) {
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
@@ -202,27 +184,8 @@ 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();
#ifdef BACDL_ETHERNET if (!datalink_init(NULL))
/* init the physical layer */
if (!ethernet_init("eth0"))
return 1; return 1;
#endif
#ifdef BACDL_BIP
bip_set_interface("eth0");
if (!bip_init())
return 1;
printf("bip: using port %hu\r\n", bip_get_port());
#ifdef BIP_DEBUG
datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address);
print_address("Address", &my_address);
#endif
#endif
#ifdef BACDL_ARCNET
if (!arcnet_init("arc0"))
return 1;
#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) *
+1 -21
View File
@@ -343,27 +343,7 @@ 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();
#if defined(BACDL_ETHERNET) datalink_init(Network_Interface);
/* init the physical layer */
if (!Network_Interface)
Network_Interface = "eth0";
if (!ethernet_init(Network_Interface))
return 1;
#elif defined(BACDL_BIP)
if (!Network_Interface)
Network_Interface = "eth0";
bip_set_interface(Network_Interface);
if (!bip_init())
return 1;
/* printf("bip: using port %hu\r\n", bip_get_port()); */
#elif defined(BACDL_ARCNET)
if (!Network_Interface)
Network_Interface = "arc0";
if (!arcnet_init(Network_Interface))
return 1;
#else
#error Define a datalink (BACDL_ETHERNET,BACDL_BIP, or BACDL_ARCNET)
#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) *
+1 -14
View File
@@ -230,21 +230,8 @@ 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();
#ifdef BACDL_ETHERNET if (!datalink_init(NULL))
/* init the physical layer */
if (!ethernet_init("eth0"))
return 1; return 1;
#endif
#ifdef BACDL_BIP
bip_set_interface("eth0");
if (!bip_init())
return 1;
printf("bip: using port %hu\r\n", bip_get_port());
#endif
#ifdef BACDL_ARCNET
if (!arcnet_init("arc0"))
return 1;
#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) *
+1 -1
View File
@@ -20,7 +20,7 @@ CFLAGS = -Wall -g $(INCLUDES) $(DEFINES)
TARGET = bacrp TARGET = bacrp
SRCS = readprop.c \ SRCS = main.c \
$(BACNET_PORT)/bip-init.c \ $(BACNET_PORT)/bip-init.c \
$(BACNET_PORT)/ethernet.c \ $(BACNET_PORT)/ethernet.c \
$(BACNET_PORT)/arcnet.c \ $(BACNET_PORT)/arcnet.c \
@@ -175,21 +175,8 @@ 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();
#if defined(BACDL_ETHERNET) if (!datalink_init(NULL))
/* init the physical layer */
if (!ethernet_init("eth0"))
return 1; 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 */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = (Device_APDU_Timeout() / 1000) * timeout_seconds = (Device_APDU_Timeout() / 1000) *
+1 -1
View File
@@ -17,7 +17,7 @@ PRODUCT_EXE = $(PRODUCT).exe
# Choose the Data Link Layer to Enable # Choose the Data Link Layer to Enable
DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0;PRINT_ENABLED=1 DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0;PRINT_ENABLED=1
SRCS = readprop.c \ SRCS = main.c \
..\..\ports\win32\bip-init.c \ ..\..\ports\win32\bip-init.c \
..\..\filename.c \ ..\..\filename.c \
..\..\bip.c \ ..\..\bip.c \
+6 -29
View File
@@ -133,21 +133,6 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
for (i = 0; i < dest->mac_len; i++) {
printf("%02X", dest->mac[i]);
}
printf("\n");
}
}
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
BACNET_ADDRESS src = { 0 }; /* address where message came from */ BACNET_ADDRESS src = { 0 }; /* address where message came from */
@@ -160,9 +145,6 @@ int main(int argc, char *argv[])
time_t timeout_seconds = 0; time_t timeout_seconds = 0;
uint8_t invoke_id = 0; uint8_t invoke_id = 0;
bool found = false; bool found = false;
#ifdef BIP_DEBUG
BACNET_ADDRESS my_address, broadcast_address;
#endif
if (argc < 3) { if (argc < 3) {
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
@@ -199,17 +181,8 @@ 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 (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
#ifdef BIP_DEBUG
datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address);
print_address("Address", &my_address);
#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) *
@@ -223,7 +196,11 @@ 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) {
+1 -14
View File
@@ -122,21 +122,8 @@ int main(int argc, char *argv[])
printf("BACnet Server Demo - Device #%u\r\n", printf("BACnet Server Demo - Device #%u\r\n",
Device_Object_Instance_Number()); Device_Object_Instance_Number());
Init_Service_Handlers(); Init_Service_Handlers();
#ifdef BACDL_ETHERNET if (!datalink_init(NULL))
/* init the physical layer */
if (!ethernet_init("eth0"))
return 1; return 1;
#endif
#ifdef BACDL_BIP
bip_set_interface("eth0");
if (!bip_init())
return 1;
printf("bip: using port %hu\r\n", bip_get_port());
#endif
#ifdef BACDL_ARCNET
if (!arcnet_init("arc0"))
return 1;
#endif
datalink_get_broadcast_address(&broadcast_address); datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address); print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
+2 -30
View File
@@ -103,21 +103,6 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
for (i = 0; i < dest->mac_len; i++) {
printf("%02X", dest->mac[i]);
}
printf("\n");
}
}
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
BACNET_ADDRESS src = { 0 }; /* address where message came from */ BACNET_ADDRESS src = { 0 }; /* address where message came from */
@@ -132,10 +117,6 @@ int main(int argc, char *argv[])
BACNET_DATE bdate; BACNET_DATE bdate;
BACNET_TIME btime; BACNET_TIME btime;
#ifdef BIP_DEBUG
BACNET_ADDRESS my_address, broadcast_address;
#endif
/* FIXME: we could send directed time sync, and how do we send UTC? */ /* FIXME: we could send directed time sync, and how do we send UTC? */
#if 0 #if 0
if (argc < 2) { if (argc < 2) {
@@ -164,17 +145,8 @@ int main(int argc, char *argv[])
/* setup my info */ /* setup my info */
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
Init_Service_Handlers(); Init_Service_Handlers();
/* configure standard BACnet/IP port */ if (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
#ifdef BIP_DEBUG
datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address);
print_address("Address", &my_address);
#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;
@@ -195,7 +167,7 @@ int main(int argc, char *argv[])
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
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) {
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
+1 -7
View File
@@ -202,19 +202,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "unable to parse the tag value\r\n"); fprintf(stderr, "unable to parse the tag value\r\n");
return 1; return 1;
} }
/* setup my info */ /* setup my info */
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
Init_Service_Handlers(); Init_Service_Handlers();
/* configure standard BACnet/IP port */ if (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
/* only one value in our value list */ /* only one value in our value list */
cov_data.listOfValues.next = NULL; cov_data.listOfValues.next = NULL;
ucov_notify_send(&Handler_Transmit_Buffer[0], &cov_data); ucov_notify_send(&Handler_Transmit_Buffer[0], &cov_data);
return 0; return 0;
+2 -29
View File
@@ -103,21 +103,6 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
for (i = 0; i < dest->mac_len; i++) {
printf("%02X", dest->mac[i]);
}
printf("\n");
}
}
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
BACNET_ADDRESS src = { 0 }; /* address where message came from */ BACNET_ADDRESS src = { 0 }; /* address where message came from */
@@ -127,9 +112,6 @@ int main(int argc, char *argv[])
time_t last_seconds = 0; time_t last_seconds = 0;
time_t current_seconds = 0; time_t current_seconds = 0;
time_t timeout_seconds = 0; time_t timeout_seconds = 0;
#ifdef BIP_DEBUG
BACNET_ADDRESS my_address, broadcast_address;
#endif
if (argc < 2) { if (argc < 2) {
/* note: priority 16 and 0 should produce the same end results... */ /* note: priority 16 and 0 should produce the same end results... */
@@ -166,17 +148,8 @@ int main(int argc, char *argv[])
/* setup my info */ /* setup my info */
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
Init_Service_Handlers(); Init_Service_Handlers();
/* configure standard BACnet/IP port */ if (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
#ifdef BIP_DEBUG
datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address);
print_address("Address", &my_address);
#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;
@@ -191,7 +164,7 @@ int main(int argc, char *argv[])
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
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) {
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
+2 -29
View File
@@ -99,21 +99,6 @@ static void Init_Service_Handlers(void)
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
#ifdef BIP_DEBUG
static void print_address(char *name, BACNET_ADDRESS * dest)
{ /* destination address */
int i = 0; /* counter */
if (dest) {
printf("%s: ", name);
for (i = 0; i < dest->mac_len; i++) {
printf("%02X", dest->mac[i]);
}
printf("\n");
}
}
#endif
static void print_address_cache(void) static void print_address_cache(void)
{ {
int i, j; int i, j;
@@ -144,9 +129,6 @@ int main(int argc, char *argv[])
time_t last_seconds = 0; time_t last_seconds = 0;
time_t current_seconds = 0; time_t current_seconds = 0;
time_t timeout_seconds = 0; time_t timeout_seconds = 0;
#ifdef BIP_DEBUG
BACNET_ADDRESS my_address, broadcast_address;
#endif
if (argc < 2) { if (argc < 2) {
printf printf
@@ -186,17 +168,8 @@ int main(int argc, char *argv[])
/* setup my info */ /* setup my info */
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
Init_Service_Handlers(); Init_Service_Handlers();
/* configure standard BACnet/IP port */ if (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
#ifdef BIP_DEBUG
datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address);
print_address("Address", &my_address);
#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;
@@ -207,7 +180,7 @@ int main(int argc, char *argv[])
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
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) {
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
+1 -1
View File
@@ -20,7 +20,7 @@ CFLAGS = -Wall -g $(INCLUDES) $(DEFINES)
TARGET = bacawf TARGET = bacawf
SRCS = writefile.c \ SRCS = main.c \
$(BACNET_PORT)/bip-init.c \ $(BACNET_PORT)/bip-init.c \
$(BACNET_ROOT)/bip.c \ $(BACNET_ROOT)/bip.c \
$(BACNET_HANDLER)/txbuf.c \ $(BACNET_HANDLER)/txbuf.c \
@@ -186,10 +186,7 @@ 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 (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
@@ -204,7 +201,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) {
+1 -1
View File
@@ -17,7 +17,7 @@ PRODUCT_EXE = $(PRODUCT).exe
# Choose the Data Link Layer to Enable # Choose the Data Link Layer to Enable
DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0;PRINT_ENABLED=1 DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0;PRINT_ENABLED=1
SRCS = writefile.c \ SRCS = main.c \
..\..\ports\win32\bip-init.c \ ..\..\ports\win32\bip-init.c \
..\..\bip.c \ ..\..\bip.c \
..\..\demo\handler\txbuf.c \ ..\..\demo\handler\txbuf.c \
+2 -5
View File
@@ -310,10 +310,7 @@ 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 (!datalink_init(NULL))
bip_set_interface("eth0"); /* for linux */
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
/* configure the timeout values */ /* configure the timeout values */
last_seconds = time(NULL); last_seconds = time(NULL);
@@ -328,7 +325,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) {
+14 -1
View File
@@ -8,7 +8,7 @@ BORLAND_DIR_Not_Defined:
!endif !endif
all: readprop writeprop readfile writefile server dcc reinit \ all: readprop writeprop readfile writefile server dcc reinit \
whois whohas timesync ucov whois whohas timesync ucov epics
@echo "demo utilities are in utils directory" @echo "demo utilities are in utils directory"
clean: \ clean: \
@@ -22,6 +22,7 @@ clean: \
demo/whois/makefile.b32 \ demo/whois/makefile.b32 \
demo/whohas/makefile.b32 \ demo/whohas/makefile.b32 \
demo/ucov/makefile.b32 \ demo/ucov/makefile.b32 \
demo/epics/makefile.b32 \
demo/timesync/makefile.b32 demo/timesync/makefile.b32
cd demo/readprop cd demo/readprop
make -i -f makefile.b32 clean make -i -f makefile.b32 clean
@@ -63,6 +64,10 @@ clean: \
make -i -f makefile.b32 clean make -i -f makefile.b32 clean
cd .. cd ..
cd .. cd ..
cd demo/epics
make -i -f makefile.b32 clean
cd ..
cd ..
cd demo/timesync cd demo/timesync
make -i -f makefile.b32 clean make -i -f makefile.b32 clean
cd .. cd ..
@@ -148,6 +153,14 @@ ucov: demo/ucov/makefile.b32
cd .. cd ..
cd .. cd ..
epics: demo/epics/makefile.b32
cd demo/epics
make -i -f makefile.b32 clean
make -f makefile.b32 all
make -f makefile.b32 install
cd ..
cd ..
timesync: demo/timesync/makefile.b32 timesync: demo/timesync/makefile.b32
cd demo/timesync cd demo/timesync
make -i -f makefile.b32 clean make -i -f makefile.b32 clean
+4 -1
View File
@@ -178,7 +178,10 @@ static int arcnet_bind(char *interface_name)
bool arcnet_init(char *interface_name) bool arcnet_init(char *interface_name)
{ {
ARCNET_Sock_FD = arcnet_bind(interface_name); if (interface_name)
ARCNET_Sock_FD = arcnet_bind(interface_name);
else
ARCNET_Sock_FD = arcnet_bind("arc0");
return arcnet_valid(); return arcnet_valid();
} }
+6 -2
View File
@@ -71,7 +71,9 @@ static int get_local_address_ioctl(char *ifname,
return rv; return rv;
} }
void bip_set_interface(char *ifname)
/* on Linux, ifname is eth0, ath0, arc0, and others. */
static void bip_set_interface(char *ifname)
{ {
struct in_addr local_address; struct in_addr local_address;
struct in_addr broadcast_address; struct in_addr broadcast_address;
@@ -91,13 +93,15 @@ void bip_set_interface(char *ifname)
#endif #endif
} }
bool bip_init(void) bool bip_init(char *ifname)
{ {
int status = 0; /* return from socket lib calls */ int status = 0; /* return from socket lib calls */
struct sockaddr_in sin; struct sockaddr_in sin;
int sockopt = 0; int sockopt = 0;
int sock_fd = -1; int sock_fd = -1;
if (ifname)
bip_set_interface(ifname);
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
bip_set_socket(sock_fd); bip_set_socket(sock_fd);
+7 -2
View File
@@ -170,8 +170,13 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac)
bool ethernet_init(char *interface_name) bool ethernet_init(char *interface_name)
{ {
get_local_hwaddr(interface_name, Ethernet_MAC_Address); if (interface_name) {
eth802_sockfd = ethernet_bind(&eth_addr, interface_name); get_local_hwaddr(interface_name, Ethernet_MAC_Address);
eth802_sockfd = ethernet_bind(&eth_addr, interface_name);
} else {
get_local_hwaddr("eth0", Ethernet_MAC_Address);
eth802_sockfd = ethernet_bind(&eth_addr, "eth0");
}
return ethernet_valid(); return ethernet_valid();
} }
+3 -7
View File
@@ -39,12 +39,6 @@
static int interface = SOCKET_ERROR; /* SOCKET_ERROR means no open interface */ static int interface = SOCKET_ERROR; /* SOCKET_ERROR means no open interface */
void bip_set_interface(char *ifname)
{
/*dummy function - to make the demos compile easier */
(void) ifname;
}
/*-----------------------------------*/ /*-----------------------------------*/
static void Error(const char *Msg) static void Error(const char *Msg)
{ {
@@ -244,7 +238,7 @@ static void set_broadcast_address(uint32_t net_address)
#endif #endif
} }
bool bip_init(void) bool bip_init(char *ifname)
{ {
int rv = 0; /* return from socket lib calls */ int rv = 0; /* return from socket lib calls */
struct sockaddr_in sin = { -1 }; struct sockaddr_in sin = { -1 };
@@ -252,6 +246,8 @@ bool bip_init(void)
int sock_fd = -1; int sock_fd = -1;
struct in_addr my_addr; struct in_addr my_addr;
(void)ifname;
NetInitialize(); NetInitialize();
RTIP_To_Network_Address(TargetIP, &my_addr); RTIP_To_Network_Address(TargetIP, &my_addr);
+2 -1
View File
@@ -42,8 +42,9 @@ static uint8_t PDU_Buffer[MAX_MPDU];
/* local MS/TP port data */ /* local MS/TP port data */
static volatile struct mstp_port_struct_t MSTP_Port; static volatile struct mstp_port_struct_t MSTP_Port;
void dlmstp_init(void) void dlmstp_init(char *ifname)
{ {
(void)ifname;
/* initialize buffer */ /* initialize buffer */
Receive_Buffer.ready = false; Receive_Buffer.ready = false;
Receive_Buffer.pdu_len = 0; Receive_Buffer.pdu_len = 0;
+1 -9
View File
@@ -140,18 +140,10 @@ int main(int argc, char *argv[])
Init_Service_Handlers(); Init_Service_Handlers();
RTOS_Initialize(); RTOS_Initialize();
/* init the physical layer */ /* init the physical layer */
#ifdef BACDL_BIP
if (!bip_init())
return 1;
#endif
#ifdef BACDL_ETHERNET
if (!ethernet_init(NULL))
return 1;
#endif
#ifdef BACDL_MSTP #ifdef BACDL_MSTP
dlmstp_set_my_address(0x05); dlmstp_set_my_address(0x05);
dlmstp_init();
#endif #endif
datalink_init(NULL);
iam_send(&Handler_Transmit_Buffer[0]); iam_send(&Handler_Transmit_Buffer[0]);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
+24 -3
View File
@@ -99,13 +99,32 @@ static void cleanup(void)
WSACleanup(); WSACleanup();
} }
/* on Windows, ifname is the dotted ip address of the interface */
void bip_set_interface(char *ifname) void bip_set_interface(char *ifname)
{ {
(void) ifname; struct in_addr address;
/* dummy function */
/* setup local address */
if (bip_get_addr() == 0) {
bip_set_addr(inet_addr(ifname));
}
#ifdef BIP_DEBUG
fprintf(stderr, "IP Address: %s\n", inet_ntoa(address));
#endif
/* setup local broadcast address */
if (bip_get_broadcast_addr() == 0) {
address.s_addr = htonl(bip_get_addr());
set_broadcast_address(address.s_addr);
}
#ifdef BIP_DEBUG
address.s_addr = htonl(bip_get_broadcast_addr());
fprintf(stderr, "Broadcast Address: %s\n",
inet_ntoa(address));
#endif
} }
bool bip_init(void) bool bip_init(char *ifname)
{ {
int rv = 0; /* return from socket lib calls */ int rv = 0; /* return from socket lib calls */
struct sockaddr_in sin = { -1 }; struct sockaddr_in sin = { -1 };
@@ -127,6 +146,8 @@ bool bip_init(void)
} }
atexit(cleanup); atexit(cleanup);
if (ifname)
bip_set_interface(ifname);
/* has address been set? */ /* has address been set? */
address.s_addr = htonl(bip_get_addr()); address.s_addr = htonl(bip_get_addr());
if (address.s_addr == 0) { if (address.s_addr == 0) {
+2 -7
View File
@@ -214,11 +214,8 @@ int main(int argc, char *argv[])
Device_Set_Object_Instance_Number(124); Device_Set_Object_Instance_Number(124);
Init_Service_Handlers(); Init_Service_Handlers();
/* init the data link layer */ /* init the data link layer */
/* configure standard BACnet/IP port */ if (!datalink_init(NULL))
bip_set_port(0xBAC0);
if (!bip_init())
return 1; return 1;
datalink_get_broadcast_address(&broadcast_address); datalink_get_broadcast_address(&broadcast_address);
print_address("Broadcast", &broadcast_address); print_address("Broadcast", &broadcast_address);
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
@@ -230,10 +227,8 @@ int main(int argc, char *argv[])
/* input */ /* input */
/* 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) {
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
} }