indented per coding standard using indent.sh
This commit is contained in:
@@ -644,8 +644,7 @@ typedef enum {
|
|||||||
/* procedures and constraints described in Clause 23. */
|
/* procedures and constraints described in Clause 23. */
|
||||||
} BACNET_LIFE_SAFETY_STATE;
|
} BACNET_LIFE_SAFETY_STATE;
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
SILENCED_STATE_UNSILENCED = 0,
|
SILENCED_STATE_UNSILENCED = 0,
|
||||||
SILENCED_STATE_AUDIBLE_SILENCED = 1,
|
SILENCED_STATE_AUDIBLE_SILENCED = 1,
|
||||||
SILENCED_STATE_VISIBLE_SILENCED = 2,
|
SILENCED_STATE_VISIBLE_SILENCED = 2,
|
||||||
|
|||||||
+76
-133
@@ -43,14 +43,15 @@
|
|||||||
BACnet Broadcast Management Device,
|
BACnet Broadcast Management Device,
|
||||||
Broadcast Distribution Table, and
|
Broadcast Distribution Table, and
|
||||||
Foreign Device Registration */
|
Foreign Device Registration */
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* true if valid entry - false if not */
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
/* BACnet/IP address */
|
/* BACnet/IP address */
|
||||||
|
struct in_addr dest_address;
|
||||||
|
|
||||||
uint16_t dest_port;
|
uint16_t dest_port;
|
||||||
|
|
||||||
@@ -67,12 +68,13 @@ seconds remaining before the BBMD will purge the registrant's FDT
|
|||||||
/*Each device that registers as a foreign device shall be placed
|
/*Each device that registers as a foreign device shall be placed
|
||||||
in an entry in the BBMD's Foreign Device Table (FDT). Each
|
in an entry in the BBMD's Foreign Device Table (FDT). Each
|
||||||
entry shall consist of the 6-octet B/IP address of the registrant;
|
entry shall consist of the 6-octet B/IP address of the registrant;
|
||||||
typedef struct
|
the 2-octet Time-to-Live value supplied at the time of
|
||||||
{
|
|
||||||
registration; and a 2-octet value representing the number of
|
registration; and a 2-octet value representing the number of
|
||||||
|
seconds remaining before the BBMD will purge the registrant's FDT
|
||||||
entry if no re-registration occurs. This value will be initialized
|
entry if no re-registration occurs. This value will be initialized
|
||||||
to the 2-octet Time-to-Live value supplied at the time of
|
to the 2-octet Time-to-Live value supplied at the time of
|
||||||
registration.*/
|
registration.*/
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
||||||
bool valid;
|
bool valid;
|
||||||
@@ -80,11 +82,9 @@ typedef struct
|
|||||||
/* BACnet/IP address */
|
/* BACnet/IP address */
|
||||||
struct in_addr dest_address;
|
struct in_addr dest_address;
|
||||||
|
|
||||||
|
|
||||||
uint16_t dest_port;
|
uint16_t dest_port;
|
||||||
|
|
||||||
/* seconds for valid entry lifetime */
|
/* seconds for valid entry lifetime */
|
||||||
|
|
||||||
uint16_t time_to_live;
|
uint16_t time_to_live;
|
||||||
|
|
||||||
time_t seconds_remaining; /* includes 30 second grace period */
|
time_t seconds_remaining; /* includes 30 second grace period */
|
||||||
@@ -92,6 +92,7 @@ void bvlc_maintenance_timer(unsigned seconds)
|
|||||||
} FD_TABLE_ENTRY;
|
} FD_TABLE_ENTRY;
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_FD_ENTRIES 128
|
||||||
static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES];
|
||||||
|
|
||||||
|
|
||||||
@@ -102,133 +103,103 @@ void bvlc_maintenance_timer(unsigned seconds)
|
|||||||
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_FD_ENTRIES; i++) {
|
for (i = 0; i < MAX_FD_ENTRIES; i++) {
|
||||||
|
|
||||||
int bvlc_encode_bip_address(
|
|
||||||
uint8_t *pdu,
|
|
||||||
struct in_addr *address, /* in host format */
|
|
||||||
if (FD_Table[i].valid)
|
if (FD_Table[i].valid)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (FD_Table[i].seconds_remaining)
|
if (FD_Table[i].seconds_remaining)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (FD_Table[i].seconds_remaining < seconds)
|
if (FD_Table[i].seconds_remaining < seconds)
|
||||||
|
|
||||||
int bvlc_decode_bip_address(
|
|
||||||
uint8_t *pdu,
|
|
||||||
struct in_addr *address, /* in host format */
|
|
||||||
FD_Table[i].seconds_remaining = 0;
|
FD_Table[i].seconds_remaining = 0;
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
||||||
FD_Table[i].seconds_remaining -= seconds;
|
FD_Table[i].seconds_remaining -= seconds;
|
||||||
|
|
||||||
if (FD_Table[i].seconds_remaining == 0)
|
if (FD_Table[i].seconds_remaining == 0)
|
||||||
struct in_addr *address,
|
|
||||||
uint16_t port,
|
|
||||||
struct in_addr *mask)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
FD_Table[i].valid = false;
|
FD_Table[i].valid = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
uint8_t *pdu,
|
|
||||||
BACNET_BVLC_RESULT result_code)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_bip_address(
|
int bvlc_encode_bip_address(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
struct in_addr *address, /* in host format */
|
struct in_addr *address, /* in host format */
|
||||||
uint16_t port)
|
uint16_t port)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_write_bdt_init(
|
|
||||||
uint8_t *pdu,
|
|
||||||
unsigned entries)
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
|
|
||||||
len = encode_unsigned32(&pdu[0], address->s_addr);
|
len = encode_unsigned32(&pdu[0], address->s_addr);
|
||||||
|
|
||||||
len += encode_unsigned16(&pdu[len], port);
|
len += encode_unsigned16(&pdu[len], port);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int bvlc_decode_bip_address(
|
||||||
int bvlc_encode_read_bdt(
|
|
||||||
uint8_t *pdu)
|
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
struct in_addr *address, /* in host format */
|
struct in_addr *address, /* in host format */
|
||||||
|
|
||||||
uint16_t * port)
|
uint16_t * port)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* used for both read and write entries */
|
/* used for both read and write entries */
|
||||||
int bvlc_encode_address_entry(
|
int bvlc_encode_address_entry(
|
||||||
|
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
struct in_addr *address,
|
struct in_addr *address,
|
||||||
|
uint16_t port,
|
||||||
int bvlc_encode_read_bdt_ack_init(
|
|
||||||
uint8_t *pdu,
|
|
||||||
unsigned entries)
|
|
||||||
struct in_addr *mask)
|
struct in_addr *mask)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
len = bvlc_encode_bip_address(pdu, address, port);
|
len = bvlc_encode_bip_address(pdu, address, port);
|
||||||
|
|
||||||
len += encode_unsigned32(&pdu[len], mask->s_addr);
|
len += encode_unsigned32(&pdu[len], mask->s_addr);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t *npdu,
|
|
||||||
unsigned npdu_length)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_bvlc_result(
|
int bvlc_encode_bvlc_result(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
BACNET_BVLC_RESULT result_code)
|
BACNET_BVLC_RESULT result_code)
|
||||||
|
{
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
@@ -243,19 +214,16 @@ int bvlc_encode_forwarded_npdu(
|
|||||||
|
|
||||||
encode_unsigned16(&pdu[4], result_code);
|
encode_unsigned16(&pdu[4], result_code);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t *pdu,
|
return 6;
|
||||||
uint16_t time_to_live_seconds)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_write_bdt_init(
|
int bvlc_encode_write_bdt_init(
|
||||||
|
uint8_t * pdu,
|
||||||
unsigned entries)
|
unsigned entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -263,81 +231,67 @@ int bvlc_encode_register_foreign_device(
|
|||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
int bvlc_encode_read_fdt(
|
|
||||||
uint8_t *pdu)
|
|
||||||
pdu[1] = BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE;
|
pdu[1] = BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE;
|
||||||
|
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
|
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||||
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
|
}
|
||||||
int bvlc_encode_read_fdt_ack_init(
|
|
||||||
uint8_t *pdu,
|
|
||||||
unsigned entries)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_read_bdt(
|
int bvlc_encode_read_bdt(
|
||||||
uint8_t * pdu)
|
uint8_t * pdu)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
|
|
||||||
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE;
|
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE;
|
||||||
|
|
||||||
|
|
||||||
uint8_t *pdu,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
struct in_addr *address,
|
|
||||||
uint16_t port)
|
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
|
|
||||||
encode_unsigned16(&pdu[2], 4);
|
encode_unsigned16(&pdu[2], 4);
|
||||||
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_read_bdt_ack_init(
|
int bvlc_encode_read_bdt_ack_init(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
|
|
||||||
unsigned entries)
|
unsigned entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
uint8_t *pdu,
|
int len = 0;
|
||||||
uint8_t *npdu,
|
|
||||||
unsigned npdu_length)
|
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
|
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE_ACK;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
@@ -347,21 +301,17 @@ int bvlc_encode_distribute_broadcast_to_network(
|
|||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
uint8_t * pdu,
|
|
||||||
uint8_t * npdu,
|
|
||||||
unsigned npdu_length)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_forwarded_npdu(
|
int bvlc_encode_forwarded_npdu(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
|
uint8_t * npdu,
|
||||||
unsigned npdu_length)
|
unsigned npdu_length)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -371,21 +321,17 @@ int bvlc_encode_original_unicast_npdu(
|
|||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
|
|
||||||
uint8_t * pdu,
|
pdu[1] = BVLC_FORWARDED_NPDU;
|
||||||
uint8_t * npdu,
|
|
||||||
unsigned npdu_length)
|
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
|
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
encode_unsigned16(&pdu[2], 4 + 6 + npdu_length);
|
encode_unsigned16(&pdu[2], 4 + 6 + npdu_length);
|
||||||
|
|
||||||
|
len = 4;
|
||||||
|
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
|
|
||||||
@@ -395,19 +341,17 @@ int bvlc_encode_original_broadcast_npdu(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < npdu_length; i++) {
|
for (i = 0; i < npdu_length; i++) {
|
||||||
|
|
||||||
pdu[len] = npdu[i];
|
pdu[len] = npdu[i];
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
}
|
}
|
||||||
void bvlc_internet_to_bacnet_address(
|
|
||||||
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -416,19 +360,17 @@ void bvlc_internet_to_bacnet_address(
|
|||||||
int bvlc_encode_register_foreign_device(
|
int bvlc_encode_register_foreign_device(
|
||||||
uint8_t * pdu,
|
uint8_t * pdu,
|
||||||
uint16_t time_to_live_seconds)
|
uint16_t time_to_live_seconds)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
void bvlc_bacnet_to_internet_address(
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
struct sockaddr_in * sin, /* source internet address */
|
|
||||||
|
|
||||||
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
|
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
|
||||||
|
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
@@ -437,16 +379,14 @@ void bvlc_bacnet_to_internet_address(
|
|||||||
encode_unsigned16(&pdu[2], time_to_live_seconds);
|
encode_unsigned16(&pdu[2], time_to_live_seconds);
|
||||||
|
|
||||||
len = 6;
|
len = 6;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bvlc_bdt_forward_npdu(
|
|
||||||
struct sockaddr_in *sin, /* the source address */
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
uint8_t mtu[MAX_MPDU] = { 0 };
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_read_fdt(
|
int bvlc_encode_read_fdt(
|
||||||
uint8_t * pdu)
|
uint8_t * pdu)
|
||||||
@@ -455,53 +395,46 @@ void bvlc_bdt_forward_npdu(
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (pdu) {
|
||||||
mtu_len = bvlc_encode_forwarded_npdu(
|
|
||||||
&mtu[0],
|
|
||||||
sin,
|
|
||||||
npdu,
|
|
||||||
npdu_length);
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
encode_unsigned16(&pdu[2], 4);
|
encode_unsigned16(&pdu[2], 4);
|
||||||
|
|
||||||
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
htonl(((~BBMD_Table[i].broadcast_mask.s_addr) |
|
|
||||||
BBMD_Table[i].dest_address.s_addr));
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_read_fdt_ack_init(
|
int bvlc_encode_read_fdt_ack_init(
|
||||||
bytes_sent = sendto(bip_socket(), (char *) mtu, mtu_len, 0,
|
uint8_t * pdu,
|
||||||
|
unsigned entries)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
void bvlc_fdt_forward_npdu(
|
|
||||||
struct sockaddr_in *sin, /* the source address */
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t bvlc_handler(
|
|
||||||
BACNET_ADDRESS * src, /* returns the source address */
|
|
||||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE_ACK;
|
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE_ACK;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
uint8_t buf[MAX_MPDU] = { 0 }; /* data */
|
encode_unsigned16(&pdu[2], 4 + entries * 10);
|
||||||
|
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -528,11 +461,14 @@ uint16_t bvlc_handler(
|
|||||||
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0)
|
encode_unsigned16(&pdu[2], 10);
|
||||||
received_bytes = recvfrom(BIP_Socket,
|
|
||||||
(char *) &buf[0], MAX_MPDU, 0,
|
/* FDT Entry */
|
||||||
|
encode_unsigned32(&pdu[0], address->s_addr);
|
||||||
|
|
||||||
|
encode_unsigned16(&pdu[4], port);
|
||||||
|
|
||||||
len = 10;
|
len = 10;
|
||||||
|
|
||||||
@@ -549,8 +485,10 @@ uint16_t bvlc_handler(
|
|||||||
uint8_t * npdu,
|
uint8_t * npdu,
|
||||||
unsigned npdu_length)
|
unsigned npdu_length)
|
||||||
{
|
{
|
||||||
|
|
||||||
int len = 0; /* return value */
|
int len = 0; /* return value */
|
||||||
|
|
||||||
|
unsigned i; /* for loop counter */
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
@@ -558,6 +496,7 @@ uint16_t bvlc_handler(
|
|||||||
pdu[0] = BVLL_TYPE_BACNET_IP;
|
pdu[0] = BVLL_TYPE_BACNET_IP;
|
||||||
|
|
||||||
pdu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
|
pdu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
|
||||||
|
|
||||||
/* The 2-octet BVLC Length field is the length, in octets,
|
/* The 2-octet BVLC Length field is the length, in octets,
|
||||||
of the entire BVLL message, including the two octets of the
|
of the entire BVLL message, including the two octets of the
|
||||||
length field itself, most significant octet first. */
|
length field itself, most significant octet first. */
|
||||||
@@ -572,6 +511,7 @@ uint16_t bvlc_handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
@@ -606,14 +546,18 @@ uint16_t bvlc_handler(
|
|||||||
|
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int bvlc_encode_original_broadcast_npdu(
|
int bvlc_encode_original_broadcast_npdu(
|
||||||
|
uint8_t * pdu,
|
||||||
uint8_t * npdu,
|
uint8_t * npdu,
|
||||||
unsigned npdu_length)
|
unsigned npdu_length)
|
||||||
{
|
{
|
||||||
@@ -621,6 +565,7 @@ uint16_t bvlc_handler(
|
|||||||
int len = 0; /* return value */
|
int len = 0; /* return value */
|
||||||
|
|
||||||
unsigned i = 0; /* loop counter */
|
unsigned i = 0; /* loop counter */
|
||||||
|
|
||||||
|
|
||||||
if (pdu) {
|
if (pdu) {
|
||||||
|
|
||||||
@@ -635,13 +580,16 @@ uint16_t bvlc_handler(
|
|||||||
|
|
||||||
for (i = 0; i < npdu_length; i++) {
|
for (i = 0; i < npdu_length; i++) {
|
||||||
|
|
||||||
|
pdu[len] = npdu[i];
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,7 +597,6 @@ uint16_t bvlc_handler(
|
|||||||
|
|
||||||
/* copy the source internet address to the BACnet address */
|
/* copy the source internet address to the BACnet address */
|
||||||
/* FIXME: IPv6? */
|
/* FIXME: IPv6? */
|
||||||
|
|
||||||
/* FIXME: is sockaddr_in host or network order? */
|
/* FIXME: is sockaddr_in host or network order? */
|
||||||
void bvlc_internet_to_bacnet_address(
|
void bvlc_internet_to_bacnet_address(
|
||||||
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
BACNET_ADDRESS * src, /* returns the BACnet source address */
|
||||||
@@ -657,19 +604,15 @@ uint16_t bvlc_handler(
|
|||||||
{
|
{
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
void testBVLC(Test * pTest)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (src && sin)
|
if (src && sin)
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
len = encode_unsigned32(&src->mac[0], sin->sin_addr.s_addr);
|
len = encode_unsigned32(&src->mac[0], sin->sin_addr.s_addr);
|
||||||
|
|
||||||
|
|
||||||
|
len += encode_unsigned16(&src->mac[4], sin->sin_port);
|
||||||
|
|
||||||
src->mac_len = len;
|
src->mac_len = len;
|
||||||
|
|
||||||
@@ -679,8 +622,8 @@ int main(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
/* called from BACnet/IP handler */
|
/* called from BACnet/IP handler */
|
||||||
@@ -49,4 +50,4 @@ void bvlc_handler(uint8_t *buf, int len, struct sockaddr_in *sin);
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ unsigned Binary_Output_Instance_To_Index(uint32_t object_instance)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BACNET_BINARY_PV Binary_Output_Present_Value(uint32_t object_instance)
|
static BACNET_BINARY_PV Binary_Output_Present_Value(uint32_t
|
||||||
|
object_instance)
|
||||||
{
|
{
|
||||||
BACNET_BINARY_PV value = RELINQUISH_DEFAULT;
|
BACNET_BINARY_PV value = RELINQUISH_DEFAULT;
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
|
|||||||
@@ -548,8 +548,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
Local_Time.min = 0;
|
Local_Time.min = 0;
|
||||||
Local_Time.sec = 3;
|
Local_Time.sec = 3;
|
||||||
Local_Time.hundredths = 1;
|
Local_Time.hundredths = 1;
|
||||||
apdu_len =
|
apdu_len = encode_tagged_time(&apdu[0], &Local_Time);
|
||||||
encode_tagged_time(&apdu[0], &Local_Time);
|
|
||||||
break;
|
break;
|
||||||
/* FIXME: if you support time */
|
/* FIXME: if you support time */
|
||||||
case PROP_UTC_OFFSET:
|
case PROP_UTC_OFFSET:
|
||||||
@@ -566,7 +565,8 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
apdu_len = encode_tagged_date(&apdu[0], &Local_Date);
|
apdu_len = encode_tagged_date(&apdu[0], &Local_Date);
|
||||||
break;
|
break;
|
||||||
case PROP_DAYLIGHT_SAVINGS_STATUS:
|
case PROP_DAYLIGHT_SAVINGS_STATUS:
|
||||||
apdu_len = encode_tagged_boolean(&apdu[0], Daylight_Savings_Status);
|
apdu_len =
|
||||||
|
encode_tagged_boolean(&apdu[0], Daylight_Savings_Status);
|
||||||
break;
|
break;
|
||||||
case PROP_PROTOCOL_VERSION:
|
case PROP_PROTOCOL_VERSION:
|
||||||
apdu_len =
|
apdu_len =
|
||||||
@@ -681,8 +681,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
/* FIXME: encode the list here, if it exists */
|
/* FIXME: encode the list here, if it exists */
|
||||||
break;
|
break;
|
||||||
case PROP_DATABASE_REVISION:
|
case PROP_DATABASE_REVISION:
|
||||||
apdu_len =
|
apdu_len = encode_tagged_unsigned(&apdu[0], Database_Revision);
|
||||||
encode_tagged_unsigned(&apdu[0], Database_Revision);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ void Life_Safety_Point_Init(void)
|
|||||||
for (i = 0; i < MAX_LIFE_SAFETY_POINTS; i++) {
|
for (i = 0; i < MAX_LIFE_SAFETY_POINTS; i++) {
|
||||||
Life_Safety_Point_Mode[i] = LIFE_SAFETY_MODE_DEFAULT;
|
Life_Safety_Point_Mode[i] = LIFE_SAFETY_MODE_DEFAULT;
|
||||||
Life_Safety_Point_State[i] = LIFE_SAFETY_STATE_QUIET;
|
Life_Safety_Point_State[i] = LIFE_SAFETY_STATE_QUIET;
|
||||||
Life_Safety_Point_Silenced_State[i] = SILENCED_STATE_UNSILENCED;
|
Life_Safety_Point_Silenced_State[i] =
|
||||||
|
SILENCED_STATE_UNSILENCED;
|
||||||
Life_Safety_Point_Operation[i] = LIFE_SAFETY_OPERATION_NONE;
|
Life_Safety_Point_Operation[i] = LIFE_SAFETY_OPERATION_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,7 +113,8 @@ unsigned Life_Safety_Point_Instance_To_Index(uint32_t object_instance)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BACNET_LIFE_SAFETY_STATE Life_Safety_Point_Present_Value(uint32_t object_instance)
|
static BACNET_LIFE_SAFETY_STATE Life_Safety_Point_Present_Value(uint32_t
|
||||||
|
object_instance)
|
||||||
{
|
{
|
||||||
BACNET_LIFE_SAFETY_STATE present_value = LIFE_SAFETY_STATE_QUIET;
|
BACNET_LIFE_SAFETY_STATE present_value = LIFE_SAFETY_STATE_QUIET;
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
@@ -156,12 +158,12 @@ int Life_Safety_Point_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
unsigned object_index = 0;
|
unsigned object_index = 0;
|
||||||
bool state = false;
|
bool state = false;
|
||||||
BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED;
|
BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED;
|
||||||
|
|
||||||
|
|
||||||
(void) array_index; /* currently not used */
|
(void) array_index; /* currently not used */
|
||||||
Life_Safety_Point_Init();
|
Life_Safety_Point_Init();
|
||||||
switch (property) {
|
switch (property) {
|
||||||
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_LIFE_SAFETY_POINT,
|
case PROP_OBJECT_IDENTIFIER:
|
||||||
|
apdu_len =
|
||||||
encode_tagged_object_id(&apdu[0], OBJECT_LIFE_SAFETY_POINT,
|
encode_tagged_object_id(&apdu[0], OBJECT_LIFE_SAFETY_POINT,
|
||||||
object_instance);
|
object_instance);
|
||||||
break;
|
break;
|
||||||
@@ -190,7 +192,8 @@ int Life_Safety_Point_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
case PROP_EVENT_STATE:
|
case PROP_EVENT_STATE:
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], EVENT_STATE_NORMAL);
|
apdu_len = encode_tagged_enumerated(&apdu[0], EVENT_STATE_NORMAL);
|
||||||
break;
|
break;
|
||||||
object_index = Life_Safety_Point_Instance_To_Index(object_instance);
|
case PROP_OUT_OF_SERVICE:
|
||||||
|
object_index =
|
||||||
Life_Safety_Point_Instance_To_Index(object_instance);
|
Life_Safety_Point_Instance_To_Index(object_instance);
|
||||||
state = Life_Safety_Point_Out_Of_Service[object_index];
|
state = Life_Safety_Point_Out_Of_Service[object_index];
|
||||||
apdu_len = encode_tagged_boolean(&apdu[0], state);
|
apdu_len = encode_tagged_boolean(&apdu[0], state);
|
||||||
@@ -200,24 +203,27 @@ int Life_Safety_Point_Encode_Property_APDU(uint8_t * apdu,
|
|||||||
reliability = RELIABILITY_NO_FAULT_DETECTED;
|
reliability = RELIABILITY_NO_FAULT_DETECTED;
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], reliability);
|
apdu_len = encode_tagged_enumerated(&apdu[0], reliability);
|
||||||
break;
|
break;
|
||||||
object_index = Life_Safety_Point_Instance_To_Index(object_instance);
|
case PROP_MODE:
|
||||||
|
object_index =
|
||||||
Life_Safety_Point_Instance_To_Index(object_instance);
|
Life_Safety_Point_Instance_To_Index(object_instance);
|
||||||
mode = Life_Safety_Point_Mode[object_index];
|
mode = Life_Safety_Point_Mode[object_index];
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], mode);
|
apdu_len = encode_tagged_enumerated(&apdu[0], mode);
|
||||||
break;
|
break;
|
||||||
for (mode = MIN_LIFE_SAFETY_MODE; mode < MAX_LIFE_SAFETY_MODE; mode++)
|
case PROP_ACCEPTED_MODES:
|
||||||
{
|
for (mode = MIN_LIFE_SAFETY_MODE; mode < MAX_LIFE_SAFETY_MODE;
|
||||||
mode++) {
|
mode++) {
|
||||||
len = encode_tagged_enumerated(&apdu[apdu_len], mode);
|
len = encode_tagged_enumerated(&apdu[apdu_len], mode);
|
||||||
apdu_len += len;
|
apdu_len += len;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
object_index = Life_Safety_Point_Instance_To_Index(object_instance);
|
case PROP_SILENCED:
|
||||||
|
object_index =
|
||||||
Life_Safety_Point_Instance_To_Index(object_instance);
|
Life_Safety_Point_Instance_To_Index(object_instance);
|
||||||
silenced_state = Life_Safety_Point_Silenced_State[object_index];
|
silenced_state = Life_Safety_Point_Silenced_State[object_index];
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], silenced_state);
|
apdu_len = encode_tagged_enumerated(&apdu[0], silenced_state);
|
||||||
break;
|
break;
|
||||||
object_index = Life_Safety_Point_Instance_To_Index(object_instance);
|
case PROP_OPERATION_EXPECTED:
|
||||||
|
object_index =
|
||||||
Life_Safety_Point_Instance_To_Index(object_instance);
|
Life_Safety_Point_Instance_To_Index(object_instance);
|
||||||
operation = Life_Safety_Point_Operation[object_index];
|
operation = Life_Safety_Point_Operation[object_index];
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], operation);
|
apdu_len = encode_tagged_enumerated(&apdu[0], operation);
|
||||||
@@ -250,8 +256,11 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
case PROP_MODE:
|
case PROP_MODE:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
|
||||||
if ((wp_data->value.type.Enumerated >= MIN_LIFE_SAFETY_MODE) &&
|
if ((wp_data->value.type.Enumerated >= MIN_LIFE_SAFETY_MODE) &&
|
||||||
object_index = Life_Safety_Point_Instance_To_Index(wp_data->object_instance);
|
(wp_data->value.type.Enumerated <= MIN_LIFE_SAFETY_MODE)) {
|
||||||
Life_Safety_Point_Mode[object_index] = wp_data->value.type.Enumerated;
|
object_index =
|
||||||
|
Life_Safety_Point_Instance_To_Index(wp_data->
|
||||||
|
object_instance);
|
||||||
|
Life_Safety_Point_Mode[object_index] =
|
||||||
wp_data->value.type.Enumerated;
|
wp_data->value.type.Enumerated;
|
||||||
status = true;
|
status = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -265,7 +274,8 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
break;
|
break;
|
||||||
case PROP_OUT_OF_SERVICE:
|
case PROP_OUT_OF_SERVICE:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||||
Life_Safety_Point_Instance_To_Index(wp_data->object_instance);
|
object_index =
|
||||||
|
Life_Safety_Point_Instance_To_Index(wp_data->
|
||||||
object_instance);
|
object_instance);
|
||||||
Life_Safety_Point_Out_Of_Service[object_index] =
|
Life_Safety_Point_Out_Of_Service[object_index] =
|
||||||
wp_data->value.type.Boolean;
|
wp_data->value.type.Boolean;
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ extern "C" {
|
|||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
|
|
||||||
bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *
|
||||||
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
wp_data, BACNET_ERROR_CLASS * error_class,
|
||||||
|
BACNET_ERROR_CODE * error_code);
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user