Added externs declarations to header files to handle C++ compilation.

Cleaned up BACnet/IP API a little.
This commit is contained in:
skarg
2005-08-13 14:10:21 +00:00
parent fdbe2eab1e
commit 2e87236e9b
36 changed files with 307 additions and 76 deletions
+8
View File
@@ -37,6 +37,10 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int abort_encode_apdu( int abort_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
uint8_t invoke_id, uint8_t invoke_id,
@@ -59,5 +63,9 @@ int abort_decode_apdu(
void testAbort(Test * pTest); void testAbort(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -39,6 +39,10 @@
#include <stdbool.h> #include <stdbool.h>
#include "bacdef.h" #include "bacdef.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void address_init(void); void address_init(void);
void address_copy( void address_copy(
@@ -80,4 +84,8 @@ void address_add_binding(
unsigned max_apdu, unsigned max_apdu,
BACNET_ADDRESS *src); BACNET_ADDRESS *src);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -29,6 +29,10 @@
#include <stdint.h> #include <stdint.h>
#include "bacdef.h" #include "bacdef.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool Analog_Input_Valid_Instance(uint32_t object_instance); bool Analog_Input_Valid_Instance(uint32_t object_instance);
unsigned Analog_Input_Count(void); unsigned Analog_Input_Count(void);
uint32_t Analog_Input_Index_To_Instance(unsigned index); uint32_t Analog_Input_Index_To_Instance(unsigned index);
@@ -46,4 +50,8 @@ int Analog_Input_Encode_Property_APDU(
void testAnalogInput(Test * pTest); void testAnalogInput(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -31,6 +31,10 @@
#include "bacerror.h" #include "bacerror.h"
#include "wp.h" #include "wp.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool Analog_Output_Valid_Instance(uint32_t object_instance); bool Analog_Output_Valid_Instance(uint32_t object_instance);
unsigned Analog_Output_Count(void); unsigned Analog_Output_Count(void);
uint32_t Analog_Output_Index_To_Instance(unsigned index); uint32_t Analog_Output_Index_To_Instance(unsigned index);
@@ -53,4 +57,8 @@ bool Analog_Output_Write_Property(
void testAnalogOutput(Test * pTest); void testAnalogOutput(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -39,6 +39,10 @@
#include "bacdef.h" #include "bacdef.h"
#include "bacenum.h" #include "bacenum.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _confirmed_service_data typedef struct _confirmed_service_data
{ {
bool segmented_message; bool segmented_message;
@@ -139,4 +143,8 @@ void apdu_handler(
uint8_t *apdu, // APDU data uint8_t *apdu, // APDU data
uint16_t pdu_len); // for confirmed messages uint16_t pdu_len); // for confirmed messages
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8 -1
View File
@@ -64,8 +64,11 @@ typedef struct BACnet_Atomic_Read_File_Data
bool endOfFile; bool endOfFile;
} BACNET_ATOMIC_READ_FILE_DATA; } BACNET_ATOMIC_READ_FILE_DATA;
// Atomic Read File #ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Atomic Read File
// encode service // encode service
int arf_encode_apdu( int arf_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
@@ -111,5 +114,9 @@ void test_AtomicReadFile(Test * pTest);
void test_AtomicReadFileAck(Test * pTest); void test_AtomicReadFileAck(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8 -1
View File
@@ -62,8 +62,11 @@ typedef struct BACnet_Atomic_Write_File_Data
unsigned fileDataLength; unsigned fileDataLength;
} BACNET_ATOMIC_WRITE_FILE_DATA; } BACNET_ATOMIC_WRITE_FILE_DATA;
// Atomic Write File #ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Atomic Write File
// encode service // encode service
int awf_encode_apdu( int awf_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
@@ -108,5 +111,9 @@ void test_AtomicWriteFile(Test * pTest);
void test_AtomicWriteFileAck(Test * pTest); void test_AtomicWriteFileAck(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -64,6 +64,10 @@ typedef struct BACnet_Time
uint8_t hundredths; uint8_t hundredths;
} BACNET_TIME; } BACNET_TIME;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// from clause 20.2.1 General Rules for Encoding BACnet Tags // from clause 20.2.1 General Rules for Encoding BACnet Tags
// returns the number of apdu bytes consumed // returns the number of apdu bytes consumed
int encode_tag(uint8_t * apdu, uint8_t tag_number, bool context_specific, 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, int encode_simple_ack(uint8_t * apdu, uint8_t invoke_id,
uint8_t service_choice); uint8_t service_choice);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -38,6 +38,10 @@
#include <stdbool.h> #include <stdbool.h>
#include "bacenum.h" #include "bacenum.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int bacerror_encode_apdu( int bacerror_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
uint8_t invoke_id, uint8_t invoke_id,
@@ -66,5 +70,9 @@ int bacerror_decode_apdu(
void testBACError(Test * pTest); void testBACError(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -41,6 +41,10 @@
#include "apdu.h" #include "apdu.h"
#include "arf.h" #include "arf.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
char *bacfile_name(uint32_t instance); char *bacfile_name(uint32_t instance);
bool bacfile_valid_instance(uint32_t object_instance); bool bacfile_valid_instance(uint32_t object_instance);
uint32_t bacfile_count(void); uint32_t bacfile_count(void);
@@ -66,4 +70,8 @@ int bacfile_encode_property_apdu(
BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code); BACNET_ERROR_CODE *error_code);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -1,6 +1,10 @@
#ifndef BIGEND_H #ifndef BIGEND_H
#define BIGEND_H #define BIGEND_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Big-Endian systems save the most significant byte first. // Big-Endian systems save the most significant byte first.
// Sun and Motorola processors, IBM-370s and PDP-10s are big-endian. // Sun and Motorola processors, IBM-370s and PDP-10s are big-endian.
// for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal. // for example, a 4 byte integer 67305985 is 0x04030201 in hexidecimal.
@@ -19,4 +23,8 @@
int big_endian(void); int big_endian(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+39 -31
View File
@@ -39,11 +39,11 @@
#include "net.h" // custom per port #include "net.h" // custom per port
static int BIP_Socket = -1; 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; 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; static struct in_addr BIP_Address;
/* Broadcast Address */ /* Broadcast Address - stored in host byte order */
static struct in_addr BIP_Broadcast_Address; static struct in_addr BIP_Broadcast_Address;
void bip_set_socket(int sock_fd) void bip_set_socket(int sock_fd)
@@ -90,18 +90,6 @@ void bip_set_address(
set_network_address(&BIP_Address, octet1, octet2, octet3, octet4); 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( void bip_set_broadcast_address(
uint8_t octet1, uint8_t octet1,
uint8_t octet2, uint8_t octet2,
@@ -111,25 +99,44 @@ void bip_set_broadcast_address(
set_network_address(&BIP_Broadcast_Address, octet1, octet2, octet3, octet4); set_network_address(&BIP_Broadcast_Address, octet1, octet2, octet3, octet4);
} }
// Win32 shortcut // set using network byte order
void bip_set_ipv4_broadcast_s_addr( void bip_set_addr(uint32_t net_address)
unsigned long 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) void bip_set_port(uint16_t port)
{ {
BIP_Port = htons(port); BIP_Port = port;
} }
// returns host byte order
uint16_t bip_get_port(void) uint16_t bip_get_port(void)
{ {
return BIP_Port; return BIP_Port;
} }
/* function to send a packet out the 802.2 socket */ /* 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 */
static int bip_send( static int bip_send(
struct sockaddr_in *bip_dest, struct sockaddr_in *bip_dest,
uint8_t *pdu, // any data to be sent - may be null uint8_t *pdu, // any data to be sent - may be null
@@ -144,7 +151,7 @@ static int bip_send(
return BIP_Socket; return BIP_Socket;
mtu[0] = 0x81; /* BVLL for BACnet/IP */ 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 */ mtu[1] = 0x0B; /* Original-Broadcast-NPDU */
else else
mtu[1] = 0x0A; /* Original-Unicast-NPDU */ mtu[1] = 0x0A; /* Original-Unicast-NPDU */
@@ -162,7 +169,7 @@ static int bip_send(
} }
/* function to send a packet out the BACnet/IP socket (Annex J) */ /* 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( int bip_send_pdu(
BACNET_ADDRESS *dest, // destination address BACNET_ADDRESS *dest, // destination address
uint8_t *pdu, // any data to be sent - may be null uint8_t *pdu, // any data to be sent - may be null
@@ -181,8 +188,8 @@ int bip_send_pdu(
/* broadcast */ /* broadcast */
else if (dest->mac_len == 0) else if (dest->mac_len == 0)
{ {
bip_dest.sin_addr.s_addr = BIP_Broadcast_Address.s_addr; bip_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr);
bip_dest.sin_port = BIP_Port; bip_dest.sin_port = htons(BIP_Port);
memset(&(bip_dest.sin_zero), '\0', 8); memset(&(bip_dest.sin_zero), '\0', 8);
} }
else else
@@ -270,13 +277,14 @@ uint16_t bip_receive(
sin.sin_port); sin.sin_port);
// FIXME: check destination address // FIXME: check destination address
// see if it is broadcast or for us // see if it is broadcast or for us
/* decode the length of the PDU - length is inclusive of BVLC */ /* decode the length of the PDU - length is inclusive of BVLC */
(void)decode_unsigned16(&buf[2],&pdu_len); (void)decode_unsigned16(&buf[2],&pdu_len);
/* copy the buffer into the PDU */ /* copy the buffer into the PDU */
pdu_len -= 4; /* BVLC header */ pdu_len -= 4; /* BVLC header */
if (pdu_len < max_pdu) if (pdu_len < max_pdu)
memmove(&pdu[0],&buf[4],pdu_len); memmove(&pdu[0],&buf[4],pdu_len);
// ignore packets that are too large
// clients should check my max-apdu first
else else
pdu_len = 0; pdu_len = 0;
} }
@@ -291,9 +299,9 @@ void bip_get_my_address(BACNET_ADDRESS *my_address)
my_address->mac_len = 6; my_address->mac_len = 6;
(void)encode_unsigned32(&my_address->mac[0], (void)encode_unsigned32(&my_address->mac[0],
BIP_Address.s_addr); htonl(BIP_Address.s_addr));
(void)encode_unsigned16(&my_address->mac[4], (void)encode_unsigned16(&my_address->mac[4],
BIP_Port); htons(BIP_Port));
my_address->net = 0; /* local only, no routing */ my_address->net = 0; /* local only, no routing */
my_address->len = 0; /* no SLEN */ my_address->len = 0; /* no SLEN */
for (i = 0; i < MAX_MAC_LEN; i++) for (i = 0; i < MAX_MAC_LEN; i++)
@@ -314,9 +322,9 @@ void bip_get_broadcast_address(
{ {
dest->mac_len = 6; dest->mac_len = 6;
(void)encode_unsigned32(&dest->mac[0], (void)encode_unsigned32(&dest->mac[0],
BIP_Broadcast_Address.s_addr); htonl(BIP_Broadcast_Address.s_addr));
(void)encode_unsigned16(&dest->mac[4], (void)encode_unsigned16(&dest->mac[4],
BIP_Port); htons(BIP_Port));
dest->net = BACNET_BROADCAST_NETWORK; dest->net = BACNET_BROADCAST_NETWORK;
dest->len = 0; /* no SLEN */ dest->len = 0; /* no SLEN */
for (i = 0; i < MAX_MAC_LEN; i++) for (i = 0; i < MAX_MAC_LEN; i++)
+22
View File
@@ -38,11 +38,16 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "bacdef.h" #include "bacdef.h"
#include "net.h"
// specific defines for Ethernet // specific defines for Ethernet
#define MAX_HEADER (1 + 1 + 2) #define MAX_HEADER (1 + 1 + 2)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// note: define init and cleanup in your ports section // note: define init and cleanup in your ports section
bool bip_init(void); 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, void bip_set_broadcast_address(uint8_t octet1, uint8_t octet2,
uint8_t octet3, uint8_t octet4); uint8_t octet3, uint8_t octet4);
// use host byte order for setting
void bip_set_port(uint16_t port); void bip_set_port(uint16_t port);
// returns host byte order
uint16_t bip_get_port(void); 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); void bip_set_interface_name(char *ifname);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -38,7 +38,15 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue); uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue);
uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue); uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -51,6 +51,10 @@
#include "bip.h" #include "bip.h"
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int datalink_send_pdu( int datalink_send_pdu(
BACNET_ADDRESS *dest, // destination address BACNET_ADDRESS *dest, // destination address
@@ -70,4 +74,8 @@ void datalink_get_broadcast_address(
void datalink_get_my_address( void datalink_get_my_address(
BACNET_ADDRESS *my_address); BACNET_ADDRESS *my_address);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -40,6 +40,10 @@
#include "bacenum.h" #include "bacenum.h"
#include "wp.h" #include "wp.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
uint32_t Device_Object_Instance_Number(void); uint32_t Device_Object_Instance_Number(void);
void Device_Set_Object_Instance_Number(uint32_t object_id); void Device_Set_Object_Instance_Number(uint32_t object_id);
bool Device_Valid_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_CLASS *error_class,
BACNET_ERROR_CODE *error_code); BACNET_ERROR_CODE *error_code);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -44,6 +44,10 @@
#define MAX_HEADER (2+1+1+1+2+1+2+1) #define MAX_HEADER (2+1+1+1+2+1+2+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int dlmstp_send_pdu( int dlmstp_send_pdu(
BACNET_ADDRESS *dest, // destination address BACNET_ADDRESS *dest, // destination address
@@ -62,4 +66,8 @@ void dlmstp_get_my_address(BACNET_ADDRESS *my_address);
void dlmstp_get_broadcast_address( void dlmstp_get_broadcast_address(
BACNET_ADDRESS *dest); // destination address BACNET_ADDRESS *dest); // destination address
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -43,6 +43,10 @@
#define MAX_HEADER (6+6+2+1+1+1) #define MAX_HEADER (6+6+2+1+1+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU) #define MAX_MPDU (MAX_HEADER+MAX_PDU)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool ethernet_valid(void); bool ethernet_valid(void);
void ethernet_cleanup(void); void ethernet_cleanup(void);
bool ethernet_init(char *interface_name); bool ethernet_init(char *interface_name);
@@ -75,4 +79,8 @@ void ethernet_get_my_address(BACNET_ADDRESS *my_address);
void ethernet_get_broadcast_address( void ethernet_get_broadcast_address(
BACNET_ADDRESS *dest); // destination address BACNET_ADDRESS *dest); // destination address
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -36,6 +36,10 @@ extern bool I_Am_Request;
// flag to send a global Who-Is // flag to send a global Who-Is
extern bool Who_Is_Request; extern bool Who_Is_Request;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void UnrecognizedServiceHandler( void UnrecognizedServiceHandler(
uint8_t *service_request, uint8_t *service_request,
uint16_t service_len, uint16_t service_len,
@@ -87,4 +91,8 @@ void AtomicReadFileAckHandler(
BACNET_ADDRESS *src, BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data); BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -38,6 +38,10 @@
#include <stdbool.h> #include <stdbool.h>
#include "bacdef.h" #include "bacdef.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int iam_encode_apdu( int iam_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
uint32_t device_id, uint32_t device_id,
@@ -71,4 +75,8 @@ int iam_send(uint8_t *buffer);
void testIAm(Test * pTest); void testIAm(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -204,6 +204,10 @@ struct mstp_port_struct_t
// At 9600 baud, 40 bit times would be about 4.166 milliseconds // At 9600 baud, 40 bit times would be about 4.166 milliseconds
#define Tturnaround 40; #define Tturnaround 40;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void MSTP_Init( void MSTP_Init(
volatile struct mstp_port_struct_t *mstp_port, volatile struct mstp_port_struct_t *mstp_port,
uint8_t this_station_mac); 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_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port);
void MSTP_Master_Node_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 #endif
+8
View File
@@ -53,6 +53,10 @@ typedef struct bacnet_npdu_data_t
uint8_t hop_count; uint8_t hop_count;
} BACNET_NPDU_DATA; } BACNET_NPDU_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
uint8_t npdu_encode_max_seg_max_apdu(int max_segs, int max_apdu); uint8_t npdu_encode_max_seg_max_apdu(int max_segs, int max_apdu);
int npdu_encode_raw( int npdu_encode_raw(
uint8_t *npdu, uint8_t *npdu,
@@ -78,4 +82,8 @@ void npdu_handler(
uint8_t *pdu, // PDU data uint8_t *pdu, // PDU data
uint16_t pdu_len); // length PDU uint16_t pdu_len); // length PDU
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+1 -1
View File
@@ -74,7 +74,7 @@ bool bip_init(void)
// bind the socket to the local port number and IP address // bind the socket to the local port number and IP address
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY); 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); memset(&(sin.sin_zero), '\0', 8);
status = bind(sock_fd, status = bind(sock_fd,
(const struct sockaddr*)&sin, sizeof(struct sockaddr)); (const struct sockaddr*)&sin, sizeof(struct sockaddr));
+5 -29
View File
@@ -81,43 +81,19 @@ static int get_local_address_ioctl(
return rv; 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) static void Init_Network(char *ifname)
{ {
struct in_addr local_address; struct in_addr local_address;
struct in_addr broadcast_address; struct in_addr broadcast_address;
uint8_t octet1;
uint8_t octet2;
uint8_t octet3;
uint8_t octet4;
/* setup local address */ /* setup local address */
get_local_address_ioctl(ifname, &local_address, SIOCGIFADDR); get_local_address_ioctl(ifname, &local_address, SIOCGIFADDR);
decode_network_address(&local_address, &octet1, &octet2, &octet3, &octet4); bip_set_addr(local_address.s_addr);
bip_set_address(octet1, octet2, octet3, octet4); fprintf(stderr,"IP Address: %s\n",inet_ntoa(local_address));
fprintf(stderr,"IP Address: %d.%d.%d.%d\n",
(int)octet1, (int)octet2, (int)octet3, (int)octet4);
/* setup local broadcast address */ /* setup local broadcast address */
get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR); get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR);
decode_network_address(&broadcast_address, &octet1, &octet2, &octet3, &octet4); bip_set_broadcast_addr(broadcast_address.s_addr);
bip_set_broadcast_address(octet1, octet2, octet3, octet4); fprintf(stderr,"Broadcast Address: %s\n",inet_ntoa(broadcast_address));
fprintf(stderr,"Broadcast Address: %d.%d.%d.%d\n",
(int)octet1, (int)octet2, (int)octet3, (int)octet4);
} }
#endif #endif
@@ -360,7 +336,7 @@ int main(int argc, char *argv[])
{ {
case 1: case 1:
// used for testing, but kind of noisy on the network // used for testing, but kind of noisy on the network
//Read_Properties(); Read_Properties();
break; break;
case 2: case 2:
break; break;
+1 -1
View File
@@ -50,7 +50,7 @@ bool bip_init(void)
// bind the socket to the local port number and IP address // bind the socket to the local port number and IP address
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY); 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); memset(&(sin.sin_zero), '\0', 8);
rv = bind(BIP_Socket, rv = bind(BIP_Socket,
(const struct sockaddr*)&sin, sizeof(struct sockaddr)); (const struct sockaddr*)&sin, sizeof(struct sockaddr));
+1 -1
View File
@@ -79,7 +79,7 @@ bool bip_init(void)
// bind the socket to the local port number and IP address // bind the socket to the local port number and IP address
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY); 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); memset(&(sin.sin_zero), '\0', 8);
rv = bind(sock_fd, rv = bind(sock_fd,
(const struct sockaddr*)&sin, sizeof(struct sockaddr)); (const struct sockaddr*)&sin, sizeof(struct sockaddr));
+2 -2
View File
@@ -205,9 +205,9 @@ static void NetInitialize(void)
exit(1); exit(1);
} }
address.s_addr = gethostaddr(); address.s_addr = gethostaddr();
bip_set_addr(&address); bip_set_addr(address.s_addr);
/* local broadcast address */ /* local broadcast address */
bip_set_ipv4_broadcast_s_addr(INADDR_BROADCAST); bip_set_broadcast_addr(INADDR_BROADCAST);
/* configure standard BACnet/IP port */ /* configure standard BACnet/IP port */
bip_set_port(0xBAC0); bip_set_port(0xBAC0);
} }
+3
View File
@@ -26,6 +26,9 @@
#ifndef NET_H #ifndef NET_H
#define NET_H #define NET_H
#define WIN32_LEAN_AND_MEAN
#define STRICT
#include <winsock2.h> #include <winsock2.h>
#define close closesocket #define close closesocket
+8
View File
@@ -37,6 +37,10 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int reject_encode_apdu( int reject_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
uint8_t invoke_id, uint8_t invoke_id,
@@ -58,5 +62,9 @@ int reject_decode_apdu(
void testReject(Test * pTest); void testReject(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+13 -5
View File
@@ -52,16 +52,24 @@ struct ring_buffer_t
}; };
typedef struct ring_buffer_t RING_BUFFER; typedef struct ring_buffer_t RING_BUFFER;
extern bool Ringbuf_Empty(RING_BUFFER const *b); #ifdef __cplusplus
extern char *Ringbuf_Get_Front(RING_BUFFER const *b); extern "C" {
extern char *Ringbuf_Pop_Front(RING_BUFFER *b); #endif /* __cplusplus */
extern bool Ringbuf_Put(
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 RING_BUFFER *b, // ring buffer structure
char *data_element); // one element to add to the ring char *data_element); // one element to add to the ring
extern void Ringbuf_Init( void Ringbuf_Init(
RING_BUFFER *b, // ring buffer structure RING_BUFFER *b, // ring buffer structure
char *data, // data block or array of data char *data, // data block or array of data
unsigned element_size, // size of one element in the data block unsigned element_size, // size of one element in the data block
unsigned element_count); // number of elements in the data block unsigned element_count); // number of elements in the data block
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -47,6 +47,10 @@ typedef struct BACnet_Read_Property_Data
int application_data_len; int application_data_len;
} BACNET_READ_PROPERTY_DATA; } BACNET_READ_PROPERTY_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// encode service // encode service
int rp_encode_apdu( int rp_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
@@ -89,5 +93,9 @@ void test_ReadProperty(Test * pTest);
void test_ReadPropertyAck(Test * pTest); void test_ReadPropertyAck(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -53,6 +53,10 @@ typedef struct BACnet_Read_Property_Multiple_Data
unsigned property_list_len; unsigned property_list_len;
} BACNET_READ_PROPERTY_MULTIPLE_DATA; } BACNET_READ_PROPERTY_MULTIPLE_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// encode service // encode service
int rpm_encode_apdu( int rpm_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
@@ -95,5 +99,9 @@ void test_ReadProperty(Test * pTest);
void test_ReadPropertyAck(Test * pTest); void test_ReadPropertyAck(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -39,6 +39,10 @@
#include <stdint.h> #include <stdint.h>
#include "mstp.h" #include "mstp.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void RS485_Initialize(void); void RS485_Initialize(void);
void RS485_Send_Frame( void RS485_Send_Frame(
@@ -51,4 +55,8 @@ void RS485_Check_UART_Data(
void RS485_Process_Tx_Message(void); void RS485_Process_Tx_Message(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -84,6 +84,10 @@ typedef struct BACnet_TSM_Data
unsigned pdu_len; unsigned pdu_len;
} BACNET_TSM_DATA; } BACNET_TSM_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bool tsm_transaction_available(void); bool tsm_transaction_available(void);
uint8_t tsm_transaction_idle_count(void); uint8_t tsm_transaction_idle_count(void);
void tsm_timer_milliseconds(uint16_t milliseconds); void tsm_timer_milliseconds(uint16_t milliseconds);
@@ -104,5 +108,9 @@ bool tsm_get_transaction_pdu(
uint8_t *pdu, uint8_t *pdu,
uint16_t *pdu_len); uint16_t *pdu_len);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -37,6 +37,10 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// encode service - use -1 for limit if you want unlimited // encode service - use -1 for limit if you want unlimited
int whois_encode_apdu( int whois_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
@@ -59,5 +63,9 @@ int whois_decode_apdu(
void testWhoIs(Test * pTest); void testWhoIs(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+8
View File
@@ -75,6 +75,10 @@ typedef struct BACnet_Write_Property_Data
uint8_t priority; // use 0 if not setting the priority uint8_t priority; // use 0 if not setting the priority
} BACNET_WRITE_PROPERTY_DATA; } BACNET_WRITE_PROPERTY_DATA;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// encode service // encode service
int wp_encode_apdu( int wp_encode_apdu(
uint8_t *apdu, uint8_t *apdu,
@@ -100,5 +104,9 @@ void test_ReadProperty(Test * pTest);
void test_ReadPropertyAck(Test * pTest); void test_ReadPropertyAck(Test * pTest);
#endif #endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif