diff --git a/bacnet-stack/abort.h b/bacnet-stack/abort.h index eca30632..9a6ff1dc 100644 --- a/bacnet-stack/abort.h +++ b/bacnet-stack/abort.h @@ -37,6 +37,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + int abort_encode_apdu( uint8_t *apdu, uint8_t invoke_id, @@ -59,5 +63,9 @@ int abort_decode_apdu( void testAbort(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/address.h b/bacnet-stack/address.h index 50e5391f..cfa36325 100644 --- a/bacnet-stack/address.h +++ b/bacnet-stack/address.h @@ -39,6 +39,10 @@ #include #include "bacdef.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + void address_init(void); void address_copy( @@ -80,4 +84,8 @@ void address_add_binding( unsigned max_apdu, BACNET_ADDRESS *src); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/ai.h b/bacnet-stack/ai.h index 4a2b5343..a004932b 100644 --- a/bacnet-stack/ai.h +++ b/bacnet-stack/ai.h @@ -29,6 +29,10 @@ #include #include "bacdef.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + bool Analog_Input_Valid_Instance(uint32_t object_instance); unsigned Analog_Input_Count(void); uint32_t Analog_Input_Index_To_Instance(unsigned index); @@ -46,4 +50,8 @@ int Analog_Input_Encode_Property_APDU( void testAnalogInput(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/ao.h b/bacnet-stack/ao.h index c57b57ff..db8de2ce 100644 --- a/bacnet-stack/ao.h +++ b/bacnet-stack/ao.h @@ -31,6 +31,10 @@ #include "bacerror.h" #include "wp.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + bool Analog_Output_Valid_Instance(uint32_t object_instance); unsigned Analog_Output_Count(void); uint32_t Analog_Output_Index_To_Instance(unsigned index); @@ -53,4 +57,8 @@ bool Analog_Output_Write_Property( void testAnalogOutput(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/apdu.h b/bacnet-stack/apdu.h index a4ae43cb..86dc8672 100644 --- a/bacnet-stack/apdu.h +++ b/bacnet-stack/apdu.h @@ -39,6 +39,10 @@ #include "bacdef.h" #include "bacenum.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + typedef struct _confirmed_service_data { bool segmented_message; @@ -139,4 +143,8 @@ void apdu_handler( uint8_t *apdu, // APDU data uint16_t pdu_len); // for confirmed messages +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/arf.h b/bacnet-stack/arf.h index af9a205f..d47540d7 100644 --- a/bacnet-stack/arf.h +++ b/bacnet-stack/arf.h @@ -64,8 +64,11 @@ typedef struct BACnet_Atomic_Read_File_Data bool endOfFile; } BACNET_ATOMIC_READ_FILE_DATA; -// Atomic Read File +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +// Atomic Read File // encode service int arf_encode_apdu( uint8_t *apdu, @@ -111,5 +114,9 @@ void test_AtomicReadFile(Test * pTest); void test_AtomicReadFileAck(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/awf.h b/bacnet-stack/awf.h index 7bd82efe..bcf1ef3d 100644 --- a/bacnet-stack/awf.h +++ b/bacnet-stack/awf.h @@ -62,8 +62,11 @@ typedef struct BACnet_Atomic_Write_File_Data unsigned fileDataLength; } BACNET_ATOMIC_WRITE_FILE_DATA; -// Atomic Write File +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +// Atomic Write File // encode service int awf_encode_apdu( uint8_t *apdu, @@ -108,5 +111,9 @@ void test_AtomicWriteFile(Test * pTest); void test_AtomicWriteFileAck(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/bacdcode.h b/bacnet-stack/bacdcode.h index 2382e987..d8bafedb 100644 --- a/bacnet-stack/bacdcode.h +++ b/bacnet-stack/bacdcode.h @@ -64,6 +64,10 @@ typedef struct BACnet_Time uint8_t hundredths; } BACNET_TIME; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // from clause 20.2.1 General Rules for Encoding BACnet Tags // returns the number of apdu bytes consumed int encode_tag(uint8_t * apdu, uint8_t tag_number, bool context_specific, @@ -212,4 +216,8 @@ int decode_max_apdu(uint8_t octet); int encode_simple_ack(uint8_t * apdu, uint8_t invoke_id, uint8_t service_choice); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/bacerror.h b/bacnet-stack/bacerror.h index 1684e09d..d93e01eb 100644 --- a/bacnet-stack/bacerror.h +++ b/bacnet-stack/bacerror.h @@ -38,6 +38,10 @@ #include #include "bacenum.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + int bacerror_encode_apdu( uint8_t *apdu, uint8_t invoke_id, @@ -66,5 +70,9 @@ int bacerror_decode_apdu( void testBACError(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/bacfile.h b/bacnet-stack/bacfile.h index a1bfe10f..3c83f990 100644 --- a/bacnet-stack/bacfile.h +++ b/bacnet-stack/bacfile.h @@ -41,6 +41,10 @@ #include "apdu.h" #include "arf.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + char *bacfile_name(uint32_t instance); bool bacfile_valid_instance(uint32_t object_instance); uint32_t bacfile_count(void); @@ -66,4 +70,8 @@ int bacfile_encode_property_apdu( BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CODE *error_code); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/bigend.h b/bacnet-stack/bigend.h index dc3a67f5..1d1ad2d6 100644 --- a/bacnet-stack/bigend.h +++ b/bacnet-stack/bigend.h @@ -1,6 +1,10 @@ #ifndef BIGEND_H #define BIGEND_H +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // Big-Endian systems save the most significant byte first. // Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. // for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. @@ -19,4 +23,8 @@ int big_endian(void); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/bip.c b/bacnet-stack/bip.c index 465c5954..5bddde1e 100644 --- a/bacnet-stack/bip.c +++ b/bacnet-stack/bip.c @@ -35,15 +35,15 @@ #include // for standard integer types uint8_t etc. #include // for the standard bool type. #include "bacdcode.h" -#include "bip.h" +#include "bip.h" #include "net.h" // custom per port static int BIP_Socket = -1; -/* port to use - stored in network byte order */ +/* port to use - stored in host byte order */ static uint16_t BIP_Port = 0; -/* IP Address - stored in network byte order */ +/* IP Address - stored in host byte order */ static struct in_addr BIP_Address; -/* Broadcast Address */ +/* Broadcast Address - stored in host byte order */ static struct in_addr BIP_Broadcast_Address; void bip_set_socket(int sock_fd) @@ -62,7 +62,7 @@ void bip_cleanup(void) close(BIP_Socket); BIP_Socket = -1; - return; + return; } static void set_network_address(struct in_addr *net_address, @@ -77,7 +77,7 @@ static void set_network_address(struct in_addr *net_address, long_data.byte[1] = octet2; long_data.byte[2] = octet3; long_data.byte[3] = octet4; - + net_address->s_addr = long_data.value; } @@ -90,18 +90,6 @@ void bip_set_address( set_network_address(&BIP_Address, octet1, octet2, octet3, octet4); } -// Win32 shortcut -void bip_set_addr(struct in_addr *net_address) -{ - BIP_Address.s_addr = htonl(net_address->s_addr); -} - -// Win32 shortcut -unsigned long bip_get_addr(void) -{ - return BIP_Address.s_addr; -} - void bip_set_broadcast_address( uint8_t octet1, uint8_t octet2, @@ -111,25 +99,44 @@ void bip_set_broadcast_address( set_network_address(&BIP_Broadcast_Address, octet1, octet2, octet3, octet4); } -// Win32 shortcut -void bip_set_ipv4_broadcast_s_addr( - unsigned long address) +// set using network byte order +void bip_set_addr(uint32_t net_address) { - BIP_Broadcast_Address.s_addr = address; + BIP_Address.s_addr = ntohl(net_address); } +// returns host byte order +uint32_t bip_get_addr(void) +{ + return BIP_Address.s_addr; +} + +// set using network byte order +void bip_set_broadcast_addr(uint32_t net_address) +{ + BIP_Broadcast_Address.s_addr = ntohl(net_address); +} + +// returns host byte order +uint32_t bip_get_broadcast_addr(void) +{ + return BIP_Broadcast_Address.s_addr; +} + +// set using host byte order void bip_set_port(uint16_t port) { - BIP_Port = htons(port); + BIP_Port = port; } +// returns host byte order uint16_t bip_get_port(void) { return BIP_Port; } -/* function to send a packet out the 802.2 socket */ -/* returns number of bytes sent on success, negative on failure */ +/* function to send a packet out the BACnet/IP socket (Annex J) */ +/* returns number of bytes sent on success, negative number on failure */ static int bip_send( struct sockaddr_in *bip_dest, uint8_t *pdu, // any data to be sent - may be null @@ -144,7 +151,7 @@ static int bip_send( return BIP_Socket; mtu[0] = 0x81; /* BVLL for BACnet/IP */ - if (bip_dest->sin_addr.s_addr == BIP_Broadcast_Address.s_addr) + if (bip_dest->sin_addr.s_addr == htonl(BIP_Broadcast_Address.s_addr)) mtu[1] = 0x0B; /* Original-Broadcast-NPDU */ else mtu[1] = 0x0A; /* Original-Unicast-NPDU */ @@ -157,12 +164,12 @@ static int bip_send( bytes_sent = sendto(BIP_Socket, (char *)mtu, mtu_len, 0, (struct sockaddr *)bip_dest, sizeof(struct sockaddr)); - + return bytes_sent; } /* function to send a packet out the BACnet/IP socket (Annex J) */ -/* returns number of bytes sent on success, negative on failure */ +/* returns number of bytes sent on success, negative number on failure */ int bip_send_pdu( BACNET_ADDRESS *dest, // destination address uint8_t *pdu, // any data to be sent - may be null @@ -181,8 +188,8 @@ int bip_send_pdu( /* broadcast */ else if (dest->mac_len == 0) { - bip_dest.sin_addr.s_addr = BIP_Broadcast_Address.s_addr; - bip_dest.sin_port = BIP_Port; + bip_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr); + bip_dest.sin_port = htons(BIP_Port); memset(&(bip_dest.sin_zero), '\0', 8); } else @@ -270,13 +277,14 @@ uint16_t bip_receive( sin.sin_port); // FIXME: check destination address // see if it is broadcast or for us - /* decode the length of the PDU - length is inclusive of BVLC */ (void)decode_unsigned16(&buf[2],&pdu_len); /* copy the buffer into the PDU */ pdu_len -= 4; /* BVLC header */ if (pdu_len < max_pdu) memmove(&pdu[0],&buf[4],pdu_len); + // ignore packets that are too large + // clients should check my max-apdu first else pdu_len = 0; } @@ -291,9 +299,9 @@ void bip_get_my_address(BACNET_ADDRESS *my_address) my_address->mac_len = 6; (void)encode_unsigned32(&my_address->mac[0], - BIP_Address.s_addr); + htonl(BIP_Address.s_addr)); (void)encode_unsigned16(&my_address->mac[4], - BIP_Port); + htons(BIP_Port)); my_address->net = 0; /* local only, no routing */ my_address->len = 0; /* no SLEN */ for (i = 0; i < MAX_MAC_LEN; i++) @@ -314,9 +322,9 @@ void bip_get_broadcast_address( { dest->mac_len = 6; (void)encode_unsigned32(&dest->mac[0], - BIP_Broadcast_Address.s_addr); + htonl(BIP_Broadcast_Address.s_addr)); (void)encode_unsigned16(&dest->mac[4], - BIP_Port); + htons(BIP_Port)); dest->net = BACNET_BROADCAST_NETWORK; dest->len = 0; /* no SLEN */ for (i = 0; i < MAX_MAC_LEN; i++) diff --git a/bacnet-stack/bip.h b/bacnet-stack/bip.h index 1a1b42c9..0b2eb02d 100644 --- a/bacnet-stack/bip.h +++ b/bacnet-stack/bip.h @@ -38,11 +38,16 @@ #include #include #include "bacdef.h" +#include "net.h" // specific defines for Ethernet #define MAX_HEADER (1 + 1 + 2) #define MAX_MPDU (MAX_HEADER+MAX_PDU) +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // note: define init and cleanup in your ports section bool bip_init(void); @@ -74,8 +79,25 @@ void bip_set_address(uint8_t octet1, uint8_t octet2, void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4); +// use host byte order for setting void bip_set_port(uint16_t port); +// returns host byte order uint16_t bip_get_port(void); + +// use network byte order for setting +void bip_set_addr(uint32_t net_address); +// returns host byte order +uint32_t bip_get_addr(void); + +// use network byte order for setting +void bip_set_broadcast_addr(uint32_t net_address); +// returns host byte order +uint32_t bip_get_broadcast_addr(void); + void bip_set_interface_name(char *ifname); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/crc.h b/bacnet-stack/crc.h index afc0d6d4..2fc221cd 100644 --- a/bacnet-stack/crc.h +++ b/bacnet-stack/crc.h @@ -38,7 +38,15 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue); uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/datalink.h b/bacnet-stack/datalink.h index 0a4182a3..eae7ec61 100644 --- a/bacnet-stack/datalink.h +++ b/bacnet-stack/datalink.h @@ -51,6 +51,10 @@ #include "bip.h" #endif +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + /* returns number of bytes sent on success, negative on failure */ int datalink_send_pdu( BACNET_ADDRESS *dest, // destination address @@ -70,4 +74,8 @@ void datalink_get_broadcast_address( void datalink_get_my_address( BACNET_ADDRESS *my_address); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/device.h b/bacnet-stack/device.h index 46282420..ce1c3a1f 100644 --- a/bacnet-stack/device.h +++ b/bacnet-stack/device.h @@ -40,6 +40,10 @@ #include "bacenum.h" #include "wp.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + uint32_t Device_Object_Instance_Number(void); void Device_Set_Object_Instance_Number(uint32_t object_id); bool Device_Valid_Object_Instance_Number(uint32_t object_id); @@ -96,5 +100,9 @@ bool Device_Write_Property( BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CODE *error_code); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/dlmstp.h b/bacnet-stack/dlmstp.h index 9c3ca1ae..6790bb47 100644 --- a/bacnet-stack/dlmstp.h +++ b/bacnet-stack/dlmstp.h @@ -44,6 +44,10 @@ #define MAX_HEADER (2+1+1+1+2+1+2+1) #define MAX_MPDU (MAX_HEADER+MAX_PDU) +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + /* returns number of bytes sent on success, negative on failure */ int dlmstp_send_pdu( BACNET_ADDRESS *dest, // destination address @@ -62,4 +66,8 @@ void dlmstp_get_my_address(BACNET_ADDRESS *my_address); void dlmstp_get_broadcast_address( BACNET_ADDRESS *dest); // destination address +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/ethernet.h b/bacnet-stack/ethernet.h index 3fdc3b29..9d11db4a 100644 --- a/bacnet-stack/ethernet.h +++ b/bacnet-stack/ethernet.h @@ -43,6 +43,10 @@ #define MAX_HEADER (6+6+2+1+1+1) #define MAX_MPDU (MAX_HEADER+MAX_PDU) +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + bool ethernet_valid(void); void ethernet_cleanup(void); bool ethernet_init(char *interface_name); @@ -75,4 +79,8 @@ void ethernet_get_my_address(BACNET_ADDRESS *my_address); void ethernet_get_broadcast_address( BACNET_ADDRESS *dest); // destination address +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/handlers.h b/bacnet-stack/handlers.h index 5be29ec0..f00451fa 100644 --- a/bacnet-stack/handlers.h +++ b/bacnet-stack/handlers.h @@ -36,6 +36,10 @@ extern bool I_Am_Request; // flag to send a global Who-Is extern bool Who_Is_Request; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + void UnrecognizedServiceHandler( uint8_t *service_request, uint16_t service_len, @@ -87,4 +91,8 @@ void AtomicReadFileAckHandler( BACNET_ADDRESS *src, BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/iam.h b/bacnet-stack/iam.h index 1cadf969..2691f136 100644 --- a/bacnet-stack/iam.h +++ b/bacnet-stack/iam.h @@ -38,6 +38,10 @@ #include #include "bacdef.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + int iam_encode_apdu( uint8_t *apdu, uint32_t device_id, @@ -71,4 +75,8 @@ int iam_send(uint8_t *buffer); void testIAm(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/mstp.h b/bacnet-stack/mstp.h index 12c1dd4a..b6c51f85 100644 --- a/bacnet-stack/mstp.h +++ b/bacnet-stack/mstp.h @@ -204,6 +204,10 @@ struct mstp_port_struct_t // At 9600 baud, 40 bit times would be about 4.166 milliseconds #define Tturnaround 40; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + void MSTP_Init( volatile struct mstp_port_struct_t *mstp_port, uint8_t this_station_mac); @@ -211,4 +215,8 @@ void MSTP_Millisecond_Timer(volatile struct mstp_port_struct_t *mstp_port); void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port); void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/npdu.h b/bacnet-stack/npdu.h index 1239bec2..df5516a3 100644 --- a/bacnet-stack/npdu.h +++ b/bacnet-stack/npdu.h @@ -53,6 +53,10 @@ typedef struct bacnet_npdu_data_t uint8_t hop_count; } BACNET_NPDU_DATA; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + uint8_t npdu_encode_max_seg_max_apdu(int max_segs, int max_apdu); int npdu_encode_raw( uint8_t *npdu, @@ -78,4 +82,8 @@ void npdu_handler( uint8_t *pdu, // PDU data uint16_t pdu_len); // length PDU +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/ports/linux/bip-init.c b/bacnet-stack/ports/linux/bip-init.c index 51bc21de..5d8ac0b2 100644 --- a/bacnet-stack/ports/linux/bip-init.c +++ b/bacnet-stack/ports/linux/bip-init.c @@ -74,7 +74,7 @@ bool bip_init(void) // bind the socket to the local port number and IP address sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); - sin.sin_port = bip_get_port(); + sin.sin_port = htons(bip_get_port()); memset(&(sin.sin_zero), '\0', 8); status = bind(sock_fd, (const struct sockaddr*)&sin, sizeof(struct sockaddr)); diff --git a/bacnet-stack/ports/linux/main.c b/bacnet-stack/ports/linux/main.c index 459d599b..791a6f01 100644 --- a/bacnet-stack/ports/linux/main.c +++ b/bacnet-stack/ports/linux/main.c @@ -81,43 +81,19 @@ static int get_local_address_ioctl( return rv; } -static void decode_network_address(struct in_addr *net_address, - uint8_t *octet1, uint8_t *octet2, uint8_t *octet3, uint8_t *octet4) -{ - union { - uint8_t byte[4]; - uint32_t value; - } long_data = {{0}}; - - long_data.value = net_address->s_addr; - - *octet1 = long_data.byte[0]; - *octet2 = long_data.byte[1]; - *octet3 = long_data.byte[2]; - *octet4 = long_data.byte[3]; -} - static void Init_Network(char *ifname) { struct in_addr local_address; struct in_addr broadcast_address; - uint8_t octet1; - uint8_t octet2; - uint8_t octet3; - uint8_t octet4; /* setup local address */ get_local_address_ioctl(ifname, &local_address, SIOCGIFADDR); - decode_network_address(&local_address, &octet1, &octet2, &octet3, &octet4); - bip_set_address(octet1, octet2, octet3, octet4); - fprintf(stderr,"IP Address: %d.%d.%d.%d\n", - (int)octet1, (int)octet2, (int)octet3, (int)octet4); + bip_set_addr(local_address.s_addr); + fprintf(stderr,"IP Address: %s\n",inet_ntoa(local_address)); /* setup local broadcast address */ get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR); - decode_network_address(&broadcast_address, &octet1, &octet2, &octet3, &octet4); - bip_set_broadcast_address(octet1, octet2, octet3, octet4); - fprintf(stderr,"Broadcast Address: %d.%d.%d.%d\n", - (int)octet1, (int)octet2, (int)octet3, (int)octet4); + bip_set_broadcast_addr(broadcast_address.s_addr); + fprintf(stderr,"Broadcast Address: %s\n",inet_ntoa(broadcast_address)); } #endif @@ -360,7 +336,7 @@ int main(int argc, char *argv[]) { case 1: // used for testing, but kind of noisy on the network - //Read_Properties(); + Read_Properties(); break; case 2: break; diff --git a/bacnet-stack/ports/rtos32/bip-init.c b/bacnet-stack/ports/rtos32/bip-init.c index 5d85fdc2..5acba4c0 100644 --- a/bacnet-stack/ports/rtos32/bip-init.c +++ b/bacnet-stack/ports/rtos32/bip-init.c @@ -50,7 +50,7 @@ bool bip_init(void) // bind the socket to the local port number and IP address sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); - sin.sin_port = BIP_Port; + sin.sin_port = htons(bip_get_port()); memset(&(sin.sin_zero), '\0', 8); rv = bind(BIP_Socket, (const struct sockaddr*)&sin, sizeof(struct sockaddr)); diff --git a/bacnet-stack/ports/win32/bip-init.c b/bacnet-stack/ports/win32/bip-init.c index 2ac9aed6..fc0d86a3 100644 --- a/bacnet-stack/ports/win32/bip-init.c +++ b/bacnet-stack/ports/win32/bip-init.c @@ -79,7 +79,7 @@ bool bip_init(void) // bind the socket to the local port number and IP address sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); - sin.sin_port = bip_get_port(); + sin.sin_port = htons(bip_get_port()); memset(&(sin.sin_zero), '\0', 8); rv = bind(sock_fd, (const struct sockaddr*)&sin, sizeof(struct sockaddr)); diff --git a/bacnet-stack/ports/win32/main.c b/bacnet-stack/ports/win32/main.c index 9b68d41c..7b2ef23a 100644 --- a/bacnet-stack/ports/win32/main.c +++ b/bacnet-stack/ports/win32/main.c @@ -205,9 +205,9 @@ static void NetInitialize(void) exit(1); } address.s_addr = gethostaddr(); - bip_set_addr(&address); + bip_set_addr(address.s_addr); /* local broadcast address */ - bip_set_ipv4_broadcast_s_addr(INADDR_BROADCAST); + bip_set_broadcast_addr(INADDR_BROADCAST); /* configure standard BACnet/IP port */ bip_set_port(0xBAC0); } diff --git a/bacnet-stack/ports/win32/net.h b/bacnet-stack/ports/win32/net.h index 09e589c2..7432ffa2 100644 --- a/bacnet-stack/ports/win32/net.h +++ b/bacnet-stack/ports/win32/net.h @@ -26,6 +26,9 @@ #ifndef NET_H #define NET_H +#define WIN32_LEAN_AND_MEAN +#define STRICT + #include #define close closesocket diff --git a/bacnet-stack/reject.h b/bacnet-stack/reject.h index 99bb76ed..27b66e5b 100644 --- a/bacnet-stack/reject.h +++ b/bacnet-stack/reject.h @@ -37,6 +37,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + int reject_encode_apdu( uint8_t *apdu, uint8_t invoke_id, @@ -58,5 +62,9 @@ int reject_decode_apdu( void testReject(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/ringbuf.h b/bacnet-stack/ringbuf.h index dccd4f16..38f4cb50 100644 --- a/bacnet-stack/ringbuf.h +++ b/bacnet-stack/ringbuf.h @@ -52,16 +52,24 @@ struct ring_buffer_t }; typedef struct ring_buffer_t RING_BUFFER; -extern bool Ringbuf_Empty(RING_BUFFER const *b); -extern char *Ringbuf_Get_Front(RING_BUFFER const *b); -extern char *Ringbuf_Pop_Front(RING_BUFFER *b); -extern bool Ringbuf_Put( +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +bool Ringbuf_Empty(RING_BUFFER const *b); +char *Ringbuf_Get_Front(RING_BUFFER const *b); +char *Ringbuf_Pop_Front(RING_BUFFER *b); +bool Ringbuf_Put( RING_BUFFER *b, // ring buffer structure char *data_element); // one element to add to the ring -extern void Ringbuf_Init( +void Ringbuf_Init( RING_BUFFER *b, // ring buffer structure char *data, // data block or array of data unsigned element_size, // size of one element in the data block unsigned element_count); // number of elements in the data block +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/rp.h b/bacnet-stack/rp.h index 2ba876d4..a52f9aa2 100644 --- a/bacnet-stack/rp.h +++ b/bacnet-stack/rp.h @@ -47,6 +47,10 @@ typedef struct BACnet_Read_Property_Data int application_data_len; } BACNET_READ_PROPERTY_DATA; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // encode service int rp_encode_apdu( uint8_t *apdu, @@ -89,5 +93,9 @@ void test_ReadProperty(Test * pTest); void test_ReadPropertyAck(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/rpm.h b/bacnet-stack/rpm.h index e6cd721f..c41ccf9e 100644 --- a/bacnet-stack/rpm.h +++ b/bacnet-stack/rpm.h @@ -53,6 +53,10 @@ typedef struct BACnet_Read_Property_Multiple_Data unsigned property_list_len; } BACNET_READ_PROPERTY_MULTIPLE_DATA; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // encode service int rpm_encode_apdu( uint8_t *apdu, @@ -95,5 +99,9 @@ void test_ReadProperty(Test * pTest); void test_ReadPropertyAck(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/rs485.h b/bacnet-stack/rs485.h index aba982b9..49185796 100644 --- a/bacnet-stack/rs485.h +++ b/bacnet-stack/rs485.h @@ -39,6 +39,10 @@ #include #include "mstp.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + void RS485_Initialize(void); void RS485_Send_Frame( @@ -51,4 +55,8 @@ void RS485_Check_UART_Data( void RS485_Process_Tx_Message(void); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/tsm.h b/bacnet-stack/tsm.h index 7d4e8c99..4d4a6595 100644 --- a/bacnet-stack/tsm.h +++ b/bacnet-stack/tsm.h @@ -84,6 +84,10 @@ typedef struct BACnet_TSM_Data unsigned pdu_len; } BACNET_TSM_DATA; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + bool tsm_transaction_available(void); uint8_t tsm_transaction_idle_count(void); void tsm_timer_milliseconds(uint16_t milliseconds); @@ -104,5 +108,9 @@ bool tsm_get_transaction_pdu( uint8_t *pdu, uint16_t *pdu_len); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/whois.h b/bacnet-stack/whois.h index f00371ae..97cdf584 100644 --- a/bacnet-stack/whois.h +++ b/bacnet-stack/whois.h @@ -37,6 +37,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // encode service - use -1 for limit if you want unlimited int whois_encode_apdu( uint8_t *apdu, @@ -59,5 +63,9 @@ int whois_decode_apdu( void testWhoIs(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif diff --git a/bacnet-stack/wp.h b/bacnet-stack/wp.h index 07acb13c..33b4012c 100644 --- a/bacnet-stack/wp.h +++ b/bacnet-stack/wp.h @@ -75,6 +75,10 @@ typedef struct BACnet_Write_Property_Data uint8_t priority; // use 0 if not setting the priority } BACNET_WRITE_PROPERTY_DATA; +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + // encode service int wp_encode_apdu( uint8_t *apdu, @@ -100,5 +104,9 @@ void test_ReadProperty(Test * pTest); void test_ReadPropertyAck(Test * pTest); #endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif