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:
@@ -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"
|
||||
|
||||
clean: \
|
||||
@@ -10,6 +11,7 @@ clean: \
|
||||
demo/dcc/Makefile \
|
||||
demo/whohas/Makefile \
|
||||
demo/timesync/Makefile \
|
||||
demo/epics/Makefile \
|
||||
demo/whois/Makefile
|
||||
( cd demo/readprop ; make clean )
|
||||
( cd demo/writeprop ; make clean )
|
||||
@@ -20,6 +22,7 @@ clean: \
|
||||
( cd demo/dcc ; make clean )
|
||||
( cd demo/whohas ; make clean )
|
||||
( cd demo/timesync ; make clean )
|
||||
( cd demo/epics ; make clean )
|
||||
( cd demo/whois ; make clean )
|
||||
|
||||
readprop: demo/readprop/Makefile
|
||||
@@ -49,6 +52,9 @@ whohas: demo/whohas/Makefile
|
||||
timesync: demo/timesync/Makefile
|
||||
( 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
|
||||
( cd demo/ucov ; make clean ; make ; cp bacucov ../../utils )
|
||||
|
||||
|
||||
+15
-15
@@ -51,10 +51,12 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* note: define init and cleanup in your ports section */
|
||||
bool bip_init(void);
|
||||
/* note: define init and cleanup in your ports section */
|
||||
/* 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_set_socket(int sock_fd);
|
||||
int bip_socket(void);
|
||||
@@ -62,37 +64,35 @@ extern "C" {
|
||||
void bip_get_broadcast_address(BACNET_ADDRESS * dest); /* destination address */
|
||||
void bip_get_my_address(BACNET_ADDRESS * my_address);
|
||||
|
||||
/* function to send a packet out the BACnet/IP socket */
|
||||
/* returns zero on success, non-zero on failure */
|
||||
/* function to send a packet out the BACnet/IP socket */
|
||||
/* returns zero on success, non-zero on failure */
|
||||
int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */
|
||||
BACNET_NPDU_DATA * npdu_data, /* network information */
|
||||
uint8_t * pdu, /* any data to be sent - may be null */
|
||||
unsigned pdu_len); /* number of bytes of data */
|
||||
|
||||
/* receives a BACnet/IP packet */
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
/* receives a BACnet/IP packet */
|
||||
/* returns the number of octets in the PDU, or zero on failure */
|
||||
uint16_t bip_receive(BACNET_ADDRESS * src, /* source address */
|
||||
uint8_t * pdu, /* PDU data */
|
||||
uint16_t max_pdu, /* amount of space available in the PDU */
|
||||
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);
|
||||
/* returns host byte order */
|
||||
/* returns host byte order */
|
||||
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);
|
||||
/* returns host byte order */
|
||||
/* returns host byte order */
|
||||
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);
|
||||
/* returns host byte order */
|
||||
/* returns host byte order */
|
||||
uint32_t bip_get_broadcast_addr(void);
|
||||
|
||||
void bip_set_interface(char *ifname);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#if defined(BACDL_ETHERNET)
|
||||
#include "ethernet.h"
|
||||
|
||||
#define datalink_init ethernet_init
|
||||
#define datalink_send_pdu ethernet_send_pdu
|
||||
#define datalink_receive ethernet_receive
|
||||
#define datalink_cleanup ethernet_cleanup
|
||||
@@ -46,6 +47,7 @@
|
||||
#elif defined(BACDL_ARCNET)
|
||||
#include "arcnet.h"
|
||||
|
||||
#define datalink_init arcnet_init
|
||||
#define datalink_send_pdu arcnet_send_pdu
|
||||
#define datalink_receive arcnet_receive
|
||||
#define datalink_cleanup arcnet_cleanup
|
||||
@@ -55,6 +57,7 @@
|
||||
#elif defined(BACDL_MSTP)
|
||||
#include "dlmstp.h"
|
||||
|
||||
#define datalink_init dlmstp_init
|
||||
#define datalink_send_pdu dlmstp_send_pdu
|
||||
#define datalink_receive dlmstp_receive
|
||||
#define datalink_cleanup dlmstp_cleanup
|
||||
@@ -64,6 +67,7 @@
|
||||
#elif defined(BACDL_BIP)
|
||||
#include "bip.h"
|
||||
|
||||
#define datalink_init bip_init
|
||||
#define datalink_send_pdu bip_send_pdu
|
||||
#define datalink_receive bip_receive
|
||||
#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);
|
||||
extern void datalink_cleanup(void);
|
||||
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
|
||||
|
||||
|
||||
@@ -138,21 +138,6 @@ static void Init_Service_Handlers(void)
|
||||
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[])
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
||||
@@ -165,9 +150,6 @@ int main(int argc, char *argv[])
|
||||
time_t timeout_seconds = 0;
|
||||
uint8_t invoke_id = 0;
|
||||
bool found = false;
|
||||
#ifdef BIP_DEBUG
|
||||
BACNET_ADDRESS my_address, broadcast_address;
|
||||
#endif
|
||||
|
||||
if (argc < 3) {
|
||||
/* 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);
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
#ifdef BACDL_ETHERNET
|
||||
/* init the physical layer */
|
||||
if (!ethernet_init("eth0"))
|
||||
if (!datalink_init(NULL))
|
||||
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 */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
||||
|
||||
@@ -342,28 +342,8 @@ int main(int argc, char *argv[])
|
||||
/* setup my info */
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
#if defined(BACDL_ETHERNET)
|
||||
/* 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
|
||||
Init_Service_Handlers();
|
||||
datalink_init(Network_Interface);
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
||||
|
||||
@@ -230,21 +230,8 @@ int main(int argc, char *argv[])
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
#ifdef BACDL_ETHERNET
|
||||
/* init the physical layer */
|
||||
if (!ethernet_init("eth0"))
|
||||
if (!datalink_init(NULL))
|
||||
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 */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
||||
|
||||
@@ -20,7 +20,7 @@ CFLAGS = -Wall -g $(INCLUDES) $(DEFINES)
|
||||
|
||||
TARGET = bacrp
|
||||
|
||||
SRCS = readprop.c \
|
||||
SRCS = main.c \
|
||||
$(BACNET_PORT)/bip-init.c \
|
||||
$(BACNET_PORT)/ethernet.c \
|
||||
$(BACNET_PORT)/arcnet.c \
|
||||
|
||||
@@ -175,21 +175,8 @@ int main(int argc, char *argv[])
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
#if defined(BACDL_ETHERNET)
|
||||
/* init the physical layer */
|
||||
if (!ethernet_init("eth0"))
|
||||
if (!datalink_init(NULL))
|
||||
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) *
|
||||
@@ -17,7 +17,7 @@ PRODUCT_EXE = $(PRODUCT).exe
|
||||
# Choose the Data Link Layer to Enable
|
||||
DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0;PRINT_ENABLED=1
|
||||
|
||||
SRCS = readprop.c \
|
||||
SRCS = main.c \
|
||||
..\..\ports\win32\bip-init.c \
|
||||
..\..\filename.c \
|
||||
..\..\bip.c \
|
||||
|
||||
@@ -133,21 +133,6 @@ static void Init_Service_Handlers(void)
|
||||
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[])
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
||||
@@ -160,9 +145,6 @@ int main(int argc, char *argv[])
|
||||
time_t timeout_seconds = 0;
|
||||
uint8_t invoke_id = 0;
|
||||
bool found = false;
|
||||
#ifdef BIP_DEBUG
|
||||
BACNET_ADDRESS my_address, broadcast_address;
|
||||
#endif
|
||||
|
||||
if (argc < 3) {
|
||||
/* 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);
|
||||
address_init();
|
||||
Init_Service_Handlers();
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_interface("eth0"); /* for linux */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
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 */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
||||
@@ -223,7 +196,11 @@ 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) {
|
||||
|
||||
@@ -122,21 +122,8 @@ int main(int argc, char *argv[])
|
||||
printf("BACnet Server Demo - Device #%u\r\n",
|
||||
Device_Object_Instance_Number());
|
||||
Init_Service_Handlers();
|
||||
#ifdef BACDL_ETHERNET
|
||||
/* init the physical layer */
|
||||
if (!ethernet_init("eth0"))
|
||||
if (!datalink_init(NULL))
|
||||
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);
|
||||
print_address("Broadcast", &broadcast_address);
|
||||
datalink_get_my_address(&my_address);
|
||||
|
||||
@@ -103,21 +103,6 @@ static void Init_Service_Handlers(void)
|
||||
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[])
|
||||
{
|
||||
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
||||
@@ -132,10 +117,6 @@ int main(int argc, char *argv[])
|
||||
BACNET_DATE bdate;
|
||||
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? */
|
||||
#if 0
|
||||
if (argc < 2) {
|
||||
@@ -164,17 +145,8 @@ int main(int argc, char *argv[])
|
||||
/* setup my info */
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_interface("eth0"); /* for linux */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
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 */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = Device_APDU_Timeout() / 1000;
|
||||
@@ -195,7 +167,7 @@ int main(int argc, char *argv[])
|
||||
/* increment timer - exit if timed out */
|
||||
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) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
|
||||
@@ -202,19 +202,13 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "unable to parse the tag value\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* setup my info */
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_interface("eth0"); /* for linux */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
return 1;
|
||||
|
||||
Init_Service_Handlers();
|
||||
if (!datalink_init(NULL))
|
||||
return 1;
|
||||
/* only one value in our value list */
|
||||
cov_data.listOfValues.next = NULL;
|
||||
|
||||
ucov_notify_send(&Handler_Transmit_Buffer[0], &cov_data);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -103,21 +103,6 @@ static void Init_Service_Handlers(void)
|
||||
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[])
|
||||
{
|
||||
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 current_seconds = 0;
|
||||
time_t timeout_seconds = 0;
|
||||
#ifdef BIP_DEBUG
|
||||
BACNET_ADDRESS my_address, broadcast_address;
|
||||
#endif
|
||||
|
||||
if (argc < 2) {
|
||||
/* note: priority 16 and 0 should produce the same end results... */
|
||||
@@ -166,17 +148,8 @@ int main(int argc, char *argv[])
|
||||
/* setup my info */
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_interface("eth0"); /* for linux */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
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 */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = Device_APDU_Timeout() / 1000;
|
||||
@@ -191,7 +164,7 @@ int main(int argc, char *argv[])
|
||||
/* increment timer - exit if timed out */
|
||||
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) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
|
||||
@@ -99,21 +99,6 @@ static void Init_Service_Handlers(void)
|
||||
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)
|
||||
{
|
||||
int i, j;
|
||||
@@ -144,9 +129,6 @@ int main(int argc, char *argv[])
|
||||
time_t last_seconds = 0;
|
||||
time_t current_seconds = 0;
|
||||
time_t timeout_seconds = 0;
|
||||
#ifdef BIP_DEBUG
|
||||
BACNET_ADDRESS my_address, broadcast_address;
|
||||
#endif
|
||||
|
||||
if (argc < 2) {
|
||||
printf
|
||||
@@ -186,17 +168,8 @@ int main(int argc, char *argv[])
|
||||
/* setup my info */
|
||||
Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE);
|
||||
Init_Service_Handlers();
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_interface("eth0"); /* for linux */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
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 */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = Device_APDU_Timeout() / 1000;
|
||||
@@ -207,7 +180,7 @@ int main(int argc, char *argv[])
|
||||
/* increment timer - exit if timed out */
|
||||
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) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
|
||||
@@ -20,7 +20,7 @@ CFLAGS = -Wall -g $(INCLUDES) $(DEFINES)
|
||||
|
||||
TARGET = bacawf
|
||||
|
||||
SRCS = writefile.c \
|
||||
SRCS = main.c \
|
||||
$(BACNET_PORT)/bip-init.c \
|
||||
$(BACNET_ROOT)/bip.c \
|
||||
$(BACNET_HANDLER)/txbuf.c \
|
||||
|
||||
@@ -186,10 +186,7 @@ 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 (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
return 1;
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
@@ -204,7 +201,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) {
|
||||
@@ -17,7 +17,7 @@ PRODUCT_EXE = $(PRODUCT).exe
|
||||
# Choose the Data Link Layer to Enable
|
||||
DEFINES = -DBACDL_BIP=1;TSM_ENABLED=1;BIG_ENDIAN=0;PRINT_ENABLED=1
|
||||
|
||||
SRCS = writefile.c \
|
||||
SRCS = main.c \
|
||||
..\..\ports\win32\bip-init.c \
|
||||
..\..\bip.c \
|
||||
..\..\demo\handler\txbuf.c \
|
||||
|
||||
@@ -310,11 +310,8 @@ 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 (!bip_init())
|
||||
return 1;
|
||||
if (!datalink_init(NULL))
|
||||
return 1;
|
||||
/* configure the timeout values */
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
||||
@@ -328,7 +325,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) {
|
||||
|
||||
@@ -8,7 +8,7 @@ BORLAND_DIR_Not_Defined:
|
||||
!endif
|
||||
|
||||
all: readprop writeprop readfile writefile server dcc reinit \
|
||||
whois whohas timesync ucov
|
||||
whois whohas timesync ucov epics
|
||||
@echo "demo utilities are in utils directory"
|
||||
|
||||
clean: \
|
||||
@@ -22,6 +22,7 @@ clean: \
|
||||
demo/whois/makefile.b32 \
|
||||
demo/whohas/makefile.b32 \
|
||||
demo/ucov/makefile.b32 \
|
||||
demo/epics/makefile.b32 \
|
||||
demo/timesync/makefile.b32
|
||||
cd demo/readprop
|
||||
make -i -f makefile.b32 clean
|
||||
@@ -63,6 +64,10 @@ clean: \
|
||||
make -i -f makefile.b32 clean
|
||||
cd ..
|
||||
cd ..
|
||||
cd demo/epics
|
||||
make -i -f makefile.b32 clean
|
||||
cd ..
|
||||
cd ..
|
||||
cd demo/timesync
|
||||
make -i -f makefile.b32 clean
|
||||
cd ..
|
||||
@@ -148,6 +153,14 @@ ucov: demo/ucov/makefile.b32
|
||||
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
|
||||
cd demo/timesync
|
||||
make -i -f makefile.b32 clean
|
||||
|
||||
@@ -178,7 +178,10 @@ static int arcnet_bind(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();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ static int get_local_address_ioctl(char *ifname,
|
||||
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 broadcast_address;
|
||||
@@ -91,13 +93,15 @@ void bip_set_interface(char *ifname)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
bool bip_init(char *ifname)
|
||||
{
|
||||
int status = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin;
|
||||
int sockopt = 0;
|
||||
int sock_fd = -1;
|
||||
|
||||
if (ifname)
|
||||
bip_set_interface(ifname);
|
||||
/* assumes that the driver has already been initialized */
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
bip_set_socket(sock_fd);
|
||||
|
||||
@@ -170,8 +170,13 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac)
|
||||
|
||||
bool ethernet_init(char *interface_name)
|
||||
{
|
||||
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
||||
eth802_sockfd = ethernet_bind(ð_addr, interface_name);
|
||||
if (interface_name) {
|
||||
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
||||
eth802_sockfd = ethernet_bind(ð_addr, interface_name);
|
||||
} else {
|
||||
get_local_hwaddr("eth0", Ethernet_MAC_Address);
|
||||
eth802_sockfd = ethernet_bind(ð_addr, "eth0");
|
||||
}
|
||||
|
||||
return ethernet_valid();
|
||||
}
|
||||
|
||||
@@ -39,12 +39,6 @@
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -244,7 +238,7 @@ static void set_broadcast_address(uint32_t net_address)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bip_init(void)
|
||||
bool bip_init(char *ifname)
|
||||
{
|
||||
int rv = 0; /* return from socket lib calls */
|
||||
struct sockaddr_in sin = { -1 };
|
||||
@@ -252,6 +246,8 @@ bool bip_init(void)
|
||||
int sock_fd = -1;
|
||||
struct in_addr my_addr;
|
||||
|
||||
(void)ifname;
|
||||
|
||||
NetInitialize();
|
||||
|
||||
RTIP_To_Network_Address(TargetIP, &my_addr);
|
||||
|
||||
@@ -42,8 +42,9 @@ static uint8_t PDU_Buffer[MAX_MPDU];
|
||||
/* local MS/TP port data */
|
||||
static volatile struct mstp_port_struct_t MSTP_Port;
|
||||
|
||||
void dlmstp_init(void)
|
||||
{
|
||||
void dlmstp_init(char *ifname)
|
||||
{
|
||||
(void)ifname;
|
||||
/* initialize buffer */
|
||||
Receive_Buffer.ready = false;
|
||||
Receive_Buffer.pdu_len = 0;
|
||||
|
||||
@@ -140,18 +140,10 @@ int main(int argc, char *argv[])
|
||||
Init_Service_Handlers();
|
||||
RTOS_Initialize();
|
||||
/* 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
|
||||
dlmstp_set_my_address(0x05);
|
||||
dlmstp_init();
|
||||
#endif
|
||||
datalink_init(NULL);
|
||||
iam_send(&Handler_Transmit_Buffer[0]);
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
|
||||
@@ -99,13 +99,32 @@ static void cleanup(void)
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
/* on Windows, ifname is the dotted ip address of the interface */
|
||||
void bip_set_interface(char *ifname)
|
||||
{
|
||||
(void) ifname;
|
||||
/* dummy function */
|
||||
struct in_addr address;
|
||||
|
||||
/* 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 */
|
||||
struct sockaddr_in sin = { -1 };
|
||||
@@ -126,7 +145,9 @@ bool bip_init(void)
|
||||
exit(1);
|
||||
}
|
||||
atexit(cleanup);
|
||||
|
||||
|
||||
if (ifname)
|
||||
bip_set_interface(ifname);
|
||||
/* has address been set? */
|
||||
address.s_addr = htonl(bip_get_addr());
|
||||
if (address.s_addr == 0) {
|
||||
|
||||
@@ -214,11 +214,8 @@ int main(int argc, char *argv[])
|
||||
Device_Set_Object_Instance_Number(124);
|
||||
Init_Service_Handlers();
|
||||
/* init the data link layer */
|
||||
/* configure standard BACnet/IP port */
|
||||
bip_set_port(0xBAC0);
|
||||
if (!bip_init())
|
||||
if (!datalink_init(NULL))
|
||||
return 1;
|
||||
|
||||
datalink_get_broadcast_address(&broadcast_address);
|
||||
print_address("Broadcast", &broadcast_address);
|
||||
datalink_get_my_address(&my_address);
|
||||
@@ -230,10 +227,8 @@ int main(int argc, char *argv[])
|
||||
/* input */
|
||||
|
||||
/* 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) {
|
||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user