Added externs declarations to header files to handle C++ compilation.
Cleaned up BACnet/IP API a little.
This commit is contained in:
@@ -37,6 +37,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
#include <stdbool.h>
|
||||
#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
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
#include <stdint.h>
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+8
-1
@@ -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
|
||||
|
||||
|
||||
+8
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#include <stdbool.h>
|
||||
#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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+43
-35
@@ -35,15 +35,15 @@
|
||||
#include <stdint.h> // for standard integer types uint8_t etc.
|
||||
#include <stdbool.h> // 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++)
|
||||
|
||||
@@ -38,11 +38,16 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#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
|
||||
|
||||
@@ -38,7 +38,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
#include <stdbool.h>
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#ifndef NET_H
|
||||
#define NET_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define STRICT
|
||||
|
||||
#include <winsock2.h>
|
||||
|
||||
#define close closesocket
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
+13
-5
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
#include <stdint.h>
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user