indented per coding standard using indent.sh

This commit is contained in:
skarg
2006-05-24 19:57:35 +00:00
parent 500d324b0f
commit 648af404d6
12 changed files with 673 additions and 719 deletions
+1 -2
View File
@@ -644,8 +644,7 @@ typedef enum {
/* procedures and constraints described in Clause 23. */
} BACNET_LIFE_SAFETY_STATE;
typedef enum
{
typedef enum {
SILENCED_STATE_UNSILENCED = 0,
SILENCED_STATE_AUDIBLE_SILENCED = 1,
SILENCED_STATE_VISIBLE_SILENCED = 2,
+76 -133
View File
@@ -43,14 +43,15 @@
BACnet Broadcast Management Device,
Broadcast Distribution Table, and
Foreign Device Registration */
typedef struct
typedef struct
{
{
/* true if valid entry - false if not */
bool valid;
/* BACnet/IP address */
struct in_addr dest_address;
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
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;
typedef struct
{
the 2-octet Time-to-Live value supplied at the time 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
to the 2-octet Time-to-Live value supplied at the time of
registration.*/
typedef struct
{
bool valid;
@@ -80,11 +82,9 @@ typedef struct
/* BACnet/IP address */
struct in_addr dest_address;
uint16_t dest_port;
/* seconds for valid entry lifetime */
uint16_t time_to_live;
time_t seconds_remaining; /* includes 30 second grace period */
@@ -92,6 +92,7 @@ void bvlc_maintenance_timer(unsigned seconds)
} FD_TABLE_ENTRY;
#define MAX_FD_ENTRIES 128
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++) {
int bvlc_encode_bip_address(
uint8_t *pdu,
struct in_addr *address, /* in host format */
if (FD_Table[i].valid)
{
if (FD_Table[i].seconds_remaining)
{
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;
else
FD_Table[i].seconds_remaining -= seconds;
if (FD_Table[i].seconds_remaining == 0)
struct in_addr *address,
uint16_t port,
struct in_addr *mask)
{
FD_Table[i].valid = false;
}
}
}
uint8_t *pdu,
BACNET_BVLC_RESULT result_code)
}
}
int bvlc_encode_bip_address(
uint8_t * pdu,
struct in_addr *address, /* in host format */
uint16_t port)
{
int len = 0;
int bvlc_encode_write_bdt_init(
uint8_t *pdu,
unsigned entries)
if (pdu) {
len = encode_unsigned32(&pdu[0], address->s_addr);
len += encode_unsigned16(&pdu[len], port);
}
return len;
}
int bvlc_encode_read_bdt(
uint8_t *pdu)
int bvlc_decode_bip_address(
uint8_t * pdu,
struct in_addr *address, /* in host format */
uint16_t * port)
{
}
/* used for both read and write entries */
int bvlc_encode_address_entry(
uint8_t * pdu,
struct in_addr *address,
int bvlc_encode_read_bdt_ack_init(
uint8_t *pdu,
unsigned entries)
uint16_t port,
struct in_addr *mask)
{
int len = 0;
if (pdu) {
len = bvlc_encode_bip_address(pdu, address, port);
len += encode_unsigned32(&pdu[len], mask->s_addr);
}
return len;
BACNET_ADDRESS *src,
uint8_t *npdu,
unsigned npdu_length)
}
int bvlc_encode_bvlc_result(
uint8_t * pdu,
BACNET_BVLC_RESULT result_code)
{
if (pdu) {
@@ -243,19 +214,16 @@ int bvlc_encode_forwarded_npdu(
encode_unsigned16(&pdu[4], result_code);
}
uint8_t *pdu,
uint16_t time_to_live_seconds)
return 6;
}
int bvlc_encode_write_bdt_init(
uint8_t * pdu,
unsigned entries)
{
@@ -263,81 +231,67 @@ int bvlc_encode_register_foreign_device(
if (pdu) {
pdu[0] = BVLL_TYPE_BACNET_IP;
int bvlc_encode_read_fdt(
uint8_t *pdu)
pdu[1] = BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE;
/* 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. */
encode_unsigned16(&pdu[2], 4 + entries * 10);
len = 4;
}
return len;
int bvlc_encode_read_fdt_ack_init(
uint8_t *pdu,
unsigned entries)
}
int bvlc_encode_read_bdt(
uint8_t * pdu)
{
int len = 0;
if (pdu) {
pdu[0] = BVLL_TYPE_BACNET_IP;
pdu[1] = BVLC_READ_BROADCAST_DISTRIBUTION_TABLE;
uint8_t *pdu,
struct in_addr *address,
uint16_t port)
/* 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. */
encode_unsigned16(&pdu[2], 4);
len = 4;
}
return len;
}
int bvlc_encode_read_bdt_ack_init(
uint8_t * pdu,
unsigned entries)
{
uint8_t *pdu,
uint8_t *npdu,
unsigned npdu_length)
int len = 0;
if (pdu) {
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,
of the entire BVLL message, including the two octets of the
@@ -347,21 +301,17 @@ int bvlc_encode_distribute_broadcast_to_network(
len = 4;
}
return len;
uint8_t * pdu,
uint8_t * npdu,
unsigned npdu_length)
}
int bvlc_encode_forwarded_npdu(
uint8_t * pdu,
BACNET_ADDRESS * src,
uint8_t * npdu,
unsigned npdu_length)
{
@@ -371,21 +321,17 @@ int bvlc_encode_original_unicast_npdu(
if (pdu) {
pdu[0] = BVLL_TYPE_BACNET_IP;
uint8_t * pdu,
uint8_t * npdu,
unsigned npdu_length)
pdu[1] = BVLC_FORWARDED_NPDU;
/* 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. */
encode_unsigned16(&pdu[2], 4 + 6 + npdu_length);
len = 4;
for (i = 0; i < 6; i++) {
@@ -395,19 +341,17 @@ int bvlc_encode_original_broadcast_npdu(
}
for (i = 0; i < npdu_length; i++) {
pdu[len] = npdu[i];
len++;
}
void bvlc_internet_to_bacnet_address(
BACNET_ADDRESS * src, /* returns the BACnet source address */
}
return len;
}
@@ -416,19 +360,17 @@ void bvlc_internet_to_bacnet_address(
int bvlc_encode_register_foreign_device(
uint8_t * pdu,
uint16_t time_to_live_seconds)
{
int len = 0;
if (pdu) {
void bvlc_bacnet_to_internet_address(
struct sockaddr_in * sin, /* source internet address */
pdu[0] = BVLL_TYPE_BACNET_IP;
pdu[1] = BVLC_REGISTER_FOREIGN_DEVICE;
/* 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. */
@@ -437,16 +379,14 @@ void bvlc_bacnet_to_internet_address(
encode_unsigned16(&pdu[2], time_to_live_seconds);
len = 6;
}
void bvlc_bdt_forward_npdu(
struct sockaddr_in *sin, /* the source address */
return len;
uint8_t mtu[MAX_MPDU] = { 0 };
}
int bvlc_encode_read_fdt(
uint8_t * pdu)
@@ -455,53 +395,46 @@ void bvlc_bdt_forward_npdu(
int len = 0;
mtu_len = bvlc_encode_forwarded_npdu(
&mtu[0],
sin,
npdu,
npdu_length);
if (pdu) {
pdu[0] = BVLL_TYPE_BACNET_IP;
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
/* 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. */
encode_unsigned16(&pdu[2], 4);
len = 4;
}
return len;
htonl(((~BBMD_Table[i].broadcast_mask.s_addr) |
BBMD_Table[i].dest_address.s_addr));
}
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;
void bvlc_fdt_forward_npdu(
struct sockaddr_in *sin, /* the source address */
if (pdu) {
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;
/* 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. */
uint8_t buf[MAX_MPDU] = { 0 }; /* data */
encode_unsigned16(&pdu[2], 4 + entries * 10);
len = 4;
}
@@ -528,11 +461,14 @@ uint16_t bvlc_handler(
pdu[1] = BVLC_READ_FOREIGN_DEVICE_TABLE;
/* 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. */
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0)
received_bytes = recvfrom(BIP_Socket,
(char *) &buf[0], MAX_MPDU, 0,
encode_unsigned16(&pdu[2], 10);
/* FDT Entry */
encode_unsigned32(&pdu[0], address->s_addr);
encode_unsigned16(&pdu[4], port);
len = 10;
@@ -549,8 +485,10 @@ uint16_t bvlc_handler(
uint8_t * npdu,
unsigned npdu_length)
{
int len = 0; /* return value */
unsigned i; /* for loop counter */
if (pdu) {
@@ -558,6 +496,7 @@ uint16_t bvlc_handler(
pdu[0] = BVLL_TYPE_BACNET_IP;
pdu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
/* 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. */
@@ -572,6 +511,7 @@ uint16_t bvlc_handler(
}
}
return len;
@@ -606,14 +546,18 @@ uint16_t bvlc_handler(
len++;
}
}
return len;
}
int bvlc_encode_original_broadcast_npdu(
uint8_t * pdu,
uint8_t * npdu,
unsigned npdu_length)
{
@@ -621,6 +565,7 @@ uint16_t bvlc_handler(
int len = 0; /* return value */
unsigned i = 0; /* loop counter */
if (pdu) {
@@ -635,13 +580,16 @@ uint16_t bvlc_handler(
for (i = 0; i < npdu_length; i++) {
pdu[len] = npdu[i];
len++;
}
}
return len;
}
@@ -649,7 +597,6 @@ uint16_t bvlc_handler(
/* copy the source internet address to the BACnet address */
/* FIXME: IPv6? */
/* FIXME: is sockaddr_in host or network order? */
void bvlc_internet_to_bacnet_address(
BACNET_ADDRESS * src, /* returns the BACnet source address */
@@ -657,19 +604,15 @@ uint16_t bvlc_handler(
{
int len = 0;
void testBVLC(Test * pTest)
{
if (src && sin)
int main(void)
{
{
len = encode_unsigned32(&src->mac[0], sin->sin_addr.s_addr);
len += encode_unsigned16(&src->mac[4], sin->sin_port);
src->mac_len = len;
@@ -679,8 +622,8 @@ int main(void)
}
return;
}
+2 -1
View File
@@ -40,6 +40,7 @@
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* called from BACnet/IP handler */
@@ -49,4 +50,4 @@ void bvlc_handler(uint8_t *buf, int len, struct sockaddr_in *sin);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+2 -1
View File
@@ -104,7 +104,8 @@ unsigned Binary_Output_Instance_To_Index(uint32_t object_instance)
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;
unsigned index = 0;
+4 -5
View File
@@ -548,8 +548,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
Local_Time.min = 0;
Local_Time.sec = 3;
Local_Time.hundredths = 1;
apdu_len =
encode_tagged_time(&apdu[0], &Local_Time);
apdu_len = encode_tagged_time(&apdu[0], &Local_Time);
break;
/* FIXME: if you support time */
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);
break;
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;
case PROP_PROTOCOL_VERSION:
apdu_len =
@@ -681,8 +681,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu,
/* FIXME: encode the list here, if it exists */
break;
case PROP_DATABASE_REVISION:
apdu_len =
encode_tagged_unsigned(&apdu[0], Database_Revision);
apdu_len = encode_tagged_unsigned(&apdu[0], Database_Revision);
break;
default:
*error_class = ERROR_CLASS_PROPERTY;
+23 -13
View File
@@ -61,7 +61,8 @@ void Life_Safety_Point_Init(void)
for (i = 0; i < MAX_LIFE_SAFETY_POINTS; i++) {
Life_Safety_Point_Mode[i] = LIFE_SAFETY_MODE_DEFAULT;
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;
}
}
@@ -112,7 +113,8 @@ unsigned Life_Safety_Point_Instance_To_Index(uint32_t object_instance)
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;
unsigned index = 0;
@@ -156,12 +158,12 @@ int Life_Safety_Point_Encode_Property_APDU(uint8_t * apdu,
unsigned object_index = 0;
bool state = false;
BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED;
(void) array_index; /* currently not used */
Life_Safety_Point_Init();
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,
object_instance);
break;
@@ -190,7 +192,8 @@ int Life_Safety_Point_Encode_Property_APDU(uint8_t * apdu,
case PROP_EVENT_STATE:
apdu_len = encode_tagged_enumerated(&apdu[0], EVENT_STATE_NORMAL);
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);
state = Life_Safety_Point_Out_Of_Service[object_index];
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;
apdu_len = encode_tagged_enumerated(&apdu[0], reliability);
break;
object_index = Life_Safety_Point_Instance_To_Index(object_instance);
case PROP_MODE:
object_index =
Life_Safety_Point_Instance_To_Index(object_instance);
mode = Life_Safety_Point_Mode[object_index];
apdu_len = encode_tagged_enumerated(&apdu[0], mode);
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++) {
len = encode_tagged_enumerated(&apdu[apdu_len], mode);
apdu_len += len;
}
break;
object_index = Life_Safety_Point_Instance_To_Index(object_instance);
case PROP_SILENCED:
object_index =
Life_Safety_Point_Instance_To_Index(object_instance);
silenced_state = Life_Safety_Point_Silenced_State[object_index];
apdu_len = encode_tagged_enumerated(&apdu[0], silenced_state);
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);
operation = Life_Safety_Point_Operation[object_index];
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:
if (wp_data->value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
if ((wp_data->value.type.Enumerated >= MIN_LIFE_SAFETY_MODE) &&
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 <= MIN_LIFE_SAFETY_MODE)) {
object_index =
Life_Safety_Point_Instance_To_Index(wp_data->
object_instance);
Life_Safety_Point_Mode[object_index] =
wp_data->value.type.Enumerated;
status = true;
} else {
@@ -265,7 +274,8 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
break;
case PROP_OUT_OF_SERVICE:
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);
Life_Safety_Point_Out_Of_Service[object_index] =
wp_data->value.type.Boolean;
+3 -2
View File
@@ -46,8 +46,9 @@ extern "C" {
int32_t array_index,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *
wp_data, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code);
#ifdef TEST
#include "ctest.h"