Changed all the C++ comments to C comments using comment.sh script.

This commit is contained in:
skarg
2006-02-19 01:32:09 +00:00
parent c80d26a894
commit dee63d45bc
76 changed files with 1856 additions and 1856 deletions
+125 -125
View File
@@ -44,58 +44,58 @@ int npdu_encode_raw(uint8_t * npdu,
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
{
int len = 0; // return value - number of octets loaded in this function
int i = 0; // counter
int len = 0; /* return value - number of octets loaded in this function */
int i = 0; /* counter */
if (npdu && npdu_data) {
// Protocol Version
/* Protocol Version */
npdu[0] = 1;
// control octet
/* control octet */
npdu[1] = 0;
// Bit 7: 1 indicates that the NSDU conveys a network layer message.
// Message Type field is present.
// 0 indicates that the NSDU contains a BACnet APDU.
// Message Type field is absent.
/* Bit 7: 1 indicates that the NSDU conveys a network layer message. */
/* Message Type field is present. */
/* 0 indicates that the NSDU contains a BACnet APDU. */
/* Message Type field is absent. */
if (npdu_data->network_layer_message)
npdu[1] |= BIT7;
//Bit 6: Reserved. Shall be zero.
//Bit 5: Destination specifier where:
// 0 = DNET, DLEN, DADR, and Hop Count absent
// 1 = DNET, DLEN, and Hop Count present
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent
// DLEN > 0 specifies length of DADR field
/*Bit 6: Reserved. Shall be zero. */
/*Bit 5: Destination specifier where: */
/* 0 = DNET, DLEN, DADR, and Hop Count absent */
/* 1 = DNET, DLEN, and Hop Count present */
/* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
/* DLEN > 0 specifies length of DADR field */
if (dest && dest->net)
npdu[1] |= BIT5;
// Bit 4: Reserved. Shall be zero.
// Bit 3: Source specifier where:
// 0 = SNET, SLEN, and SADR absent
// 1 = SNET, SLEN, and SADR present
// SLEN = 0 Invalid
// SLEN > 0 specifies length of SADR field
/* Bit 4: Reserved. Shall be zero. */
/* Bit 3: Source specifier where: */
/* 0 = SNET, SLEN, and SADR absent */
/* 1 = SNET, SLEN, and SADR present */
/* SLEN = 0 Invalid */
/* SLEN > 0 specifies length of SADR field */
if (src && src->net)
npdu[1] |= BIT3;
// Bit 2: The value of this bit corresponds to the data_expecting_reply
// parameter in the N-UNITDATA primitives.
// 1 indicates that a BACnet-Confirmed-Request-PDU,
// a segment of a BACnet-ComplexACK-PDU,
// or a network layer message expecting a reply is present.
// 0 indicates that other than a BACnet-Confirmed-Request-PDU,
// a segment of a BACnet-ComplexACK-PDU,
// or a network layer message expecting a reply is present.
/* Bit 2: The value of this bit corresponds to the data_expecting_reply */
/* parameter in the N-UNITDATA primitives. */
/* 1 indicates that a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */
/* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */
if (npdu_data->data_expecting_reply)
npdu[1] |= BIT2;
// Bits 1,0: Network priority where:
// B'11' = Life Safety message
// B'10' = Critical Equipment message
// B'01' = Urgent message
// B'00' = Normal message
/* Bits 1,0: Network priority where: */
/* B'11' = Life Safety message */
/* B'10' = Critical Equipment message */
/* B'01' = Urgent message */
/* B'00' = Normal message */
npdu[1] |= (npdu_data->priority & 0x03);
len = 2;
if (dest && dest->net) {
len += encode_unsigned16(&npdu[len], dest->net);
npdu[len++] = dest->len;
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent
// DLEN > 0 specifies length of DADR field
/* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
/* DLEN > 0 specifies length of DADR field */
if (dest->len) {
for (i = 0; i < dest->len; i++) {
npdu[len++] = dest->adr[i];
@@ -105,17 +105,17 @@ int npdu_encode_raw(uint8_t * npdu,
if (src && src->net) {
len += encode_unsigned16(&npdu[len], src->net);
npdu[len++] = src->len;
// SLEN = 0 denotes broadcast MAC SADR and SADR field is absent
// SLEN > 0 specifies length of SADR field
/* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */
/* SLEN > 0 specifies length of SADR field */
if (src->len) {
for (i = 0; i < src->len; i++) {
npdu[len++] = src->adr[i];
}
}
}
// The Hop Count field shall be present only if the message is
// destined for a remote network, i.e., if DNET is present.
// This is a one-octet field that is initialized to a value of 0xff.
/* The Hop Count field shall be present only if the message is */
/* destined for a remote network, i.e., if DNET is present. */
/* This is a one-octet field that is initialized to a value of 0xff. */
if (dest && dest->net) {
npdu[len] = 0xFF;
len++;
@@ -123,8 +123,8 @@ int npdu_encode_raw(uint8_t * npdu,
if (npdu_data->network_layer_message) {
npdu[len] = npdu_data->network_message_type;
len++;
// Message Type field contains a value in the range 0x80 - 0xFF,
// then a Vendor ID field shall be present
/* Message Type field contains a value in the range 0x80 - 0xFF, */
/* then a Vendor ID field shall be present */
if (npdu_data->network_message_type >= 0x80)
len += encode_unsigned16(&npdu[len], npdu_data->vendor_id);
}
@@ -133,19 +133,19 @@ int npdu_encode_raw(uint8_t * npdu,
return len;
}
// encode the NPDU portion of the packet for an APDU
// This function does not handle the network messages, just APDUs.
int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, // true for confirmed messages
/* encode the NPDU portion of the packet for an APDU */
/* This function does not handle the network messages, just APDUs. */
int npdu_encode_apdu(uint8_t * npdu, BACNET_ADDRESS * dest, BACNET_ADDRESS * src, bool data_expecting_reply, /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority)
{
BACNET_NPDU_DATA npdu_data = { 0 };
npdu_data.data_expecting_reply = data_expecting_reply;
npdu_data.network_layer_message = false; // false if APDU
npdu_data.network_message_type = 0; // optional
npdu_data.vendor_id = 0; // optional, if net message type is > 0x80
npdu_data.network_layer_message = false; /* false if APDU */
npdu_data.network_message_type = 0; /* optional */
npdu_data.vendor_id = 0; /* optional, if net message type is > 0x80 */
npdu_data.priority = priority;
// call the real function...
/* call the real function... */
return npdu_encode_raw(npdu, dest, src, &npdu_data);
}
@@ -153,50 +153,50 @@ int npdu_decode(uint8_t * npdu,
BACNET_ADDRESS * dest,
BACNET_ADDRESS * src, BACNET_NPDU_DATA * npdu_data)
{
int len = 0; // return value - number of octets loaded in this function
int i = 0; // counter
int len = 0; /* return value - number of octets loaded in this function */
int i = 0; /* counter */
uint16_t src_net = 0;
uint16_t dest_net = 0;
uint8_t address_len = 0;
uint8_t mac_octet = 0;
if (npdu && npdu_data) {
// Protocol Version
/* Protocol Version */
npdu_data->protocol_version = npdu[0];
// control octet
// Bit 7: 1 indicates that the NSDU conveys a network layer message.
// Message Type field is present.
// 0 indicates that the NSDU contains a BACnet APDU.
// Message Type field is absent.
/* control octet */
/* Bit 7: 1 indicates that the NSDU conveys a network layer message. */
/* Message Type field is present. */
/* 0 indicates that the NSDU contains a BACnet APDU. */
/* Message Type field is absent. */
npdu_data->network_layer_message = (npdu[1] & BIT7) ? true : false;
//Bit 6: Reserved. Shall be zero.
// Bit 4: Reserved. Shall be zero.
// Bit 2: The value of this bit corresponds to the data_expecting_reply
// parameter in the N-UNITDATA primitives.
// 1 indicates that a BACnet-Confirmed-Request-PDU,
// a segment of a BACnet-ComplexACK-PDU,
// or a network layer message expecting a reply is present.
// 0 indicates that other than a BACnet-Confirmed-Request-PDU,
// a segment of a BACnet-ComplexACK-PDU,
// or a network layer message expecting a reply is present.
/*Bit 6: Reserved. Shall be zero. */
/* Bit 4: Reserved. Shall be zero. */
/* Bit 2: The value of this bit corresponds to the data_expecting_reply */
/* parameter in the N-UNITDATA primitives. */
/* 1 indicates that a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */
/* 0 indicates that other than a BACnet-Confirmed-Request-PDU, */
/* a segment of a BACnet-ComplexACK-PDU, */
/* or a network layer message expecting a reply is present. */
npdu_data->data_expecting_reply = (npdu[1] & BIT2) ? true : false;
// Bits 1,0: Network priority where:
// B'11' = Life Safety message
// B'10' = Critical Equipment message
// B'01' = Urgent message
// B'00' = Normal message
/* Bits 1,0: Network priority where: */
/* B'11' = Life Safety message */
/* B'10' = Critical Equipment message */
/* B'01' = Urgent message */
/* B'00' = Normal message */
npdu_data->priority = npdu[1] & 0x03;
// set the offset to where the optional stuff starts
/* set the offset to where the optional stuff starts */
len = 2;
//Bit 5: Destination specifier where:
// 0 = DNET, DLEN, DADR, and Hop Count absent
// 1 = DNET, DLEN, and Hop Count present
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent
// DLEN > 0 specifies length of DADR field
/*Bit 5: Destination specifier where: */
/* 0 = DNET, DLEN, DADR, and Hop Count absent */
/* 1 = DNET, DLEN, and Hop Count present */
/* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
/* DLEN > 0 specifies length of DADR field */
if (npdu[1] & BIT5) {
len += decode_unsigned16(&npdu[len], &dest_net);
// DLEN = 0 denotes broadcast MAC DADR and DADR field is absent
// DLEN > 0 specifies length of DADR field
/* DLEN = 0 denotes broadcast MAC DADR and DADR field is absent */
/* DLEN > 0 specifies length of DADR field */
address_len = npdu[len++];
if (dest) {
dest->net = dest_net;
@@ -210,7 +210,7 @@ int npdu_decode(uint8_t * npdu,
}
}
}
// zero out the destination address
/* zero out the destination address */
else if (dest) {
dest->net = 0;
dest->len = 0;
@@ -218,15 +218,15 @@ int npdu_decode(uint8_t * npdu,
dest->adr[i] = 0;
}
}
// Bit 3: Source specifier where:
// 0 = SNET, SLEN, and SADR absent
// 1 = SNET, SLEN, and SADR present
// SLEN = 0 Invalid
// SLEN > 0 specifies length of SADR field
/* Bit 3: Source specifier where: */
/* 0 = SNET, SLEN, and SADR absent */
/* 1 = SNET, SLEN, and SADR present */
/* SLEN = 0 Invalid */
/* SLEN > 0 specifies length of SADR field */
if (npdu[1] & BIT3) {
len += decode_unsigned16(&npdu[len], &src_net);
// SLEN = 0 denotes broadcast MAC SADR and SADR field is absent
// SLEN > 0 specifies length of SADR field
/* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */
/* SLEN > 0 specifies length of SADR field */
address_len = npdu[len++];
if (src) {
src->net = src_net;
@@ -246,19 +246,19 @@ int npdu_decode(uint8_t * npdu,
src->adr[i] = 0;
}
}
// The Hop Count field shall be present only if the message is
// destined for a remote network, i.e., if DNET is present.
// This is a one-octet field that is initialized to a value of 0xff.
/* The Hop Count field shall be present only if the message is */
/* destined for a remote network, i.e., if DNET is present. */
/* This is a one-octet field that is initialized to a value of 0xff. */
if (dest_net)
npdu_data->hop_count = npdu[len++];
else
npdu_data->hop_count = 0;
// Indicates that the NSDU conveys a network layer message.
// Message Type field is present.
/* Indicates that the NSDU conveys a network layer message. */
/* Message Type field is present. */
if (npdu_data->network_layer_message) {
npdu_data->network_message_type = npdu[len++];
// Message Type field contains a value in the range 0x80 - 0xFF,
// then a Vendor ID field shall be present
/* Message Type field contains a value in the range 0x80 - 0xFF, */
/* then a Vendor ID field shall be present */
if (npdu_data->network_message_type >= 0x80)
len +=
decode_unsigned16(&npdu[len], &npdu_data->vendor_id);
@@ -269,20 +269,20 @@ int npdu_decode(uint8_t * npdu,
return len;
}
void npdu_handler(BACNET_ADDRESS * src, // source address
uint8_t * pdu, // PDU data
uint16_t pdu_len) // length PDU
{
void npdu_handler(BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len)
{ /* length PDU */
int apdu_offset = 0;
BACNET_ADDRESS dest = { 0 };
BACNET_NPDU_DATA npdu_data = { 0 };
apdu_offset = npdu_decode(&pdu[0], // data to decode
&dest, // destination address - get the DNET/DLEN/DADR if in there
src, // source address - get the SNET/SLEN/SADR if in there
&npdu_data); // amount of data to decode
apdu_offset = npdu_decode(&pdu[0], /* data to decode */
&dest, /* destination address - get the DNET/DLEN/DADR if in there */
src, /* source address - get the SNET/SLEN/SADR if in there */
&npdu_data); /* amount of data to decode */
if (npdu_data.network_layer_message) {
//FIXME: network layer message received! Handle it!
/*FIXME: network layer message received! Handle it! */
} else {
apdu_handler(src,
npdu_data.data_expecting_reply,
@@ -306,21 +306,21 @@ void testNPDU2(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 };
int len = 0;
bool data_expecting_reply = false; // true for confirmed messages
bool data_expecting_reply = false; /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; // counter
int i = 0; /* counter */
int npdu_len = 0;
bool network_layer_message = false; // false if APDU
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; // optional
uint16_t vendor_id = 0; // optional, if net message type is > 0x80
bool network_layer_message = false; /* false if APDU */
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */
uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */
// mac_len = 0 if global address
/* mac_len = 0 if global address */
dest.mac_len = 6;
for (i = 0; i < dest.mac_len; i++) {
dest.mac[i] = i;
}
// DNET,DLEN,DADR
/* DNET,DLEN,DADR */
dest.net = 1;
dest.len = 6;
for (i = 0; i < dest.len; i++) {
@@ -330,7 +330,7 @@ void testNPDU2(Test * pTest)
for (i = 0; i < src.mac_len; i++) {
src.mac[i] = 0x80;
}
// SNET,SLEN,SADR
/* SNET,SLEN,SADR */
src.net = 2;
src.len = 1;
for (i = 0; i < src.len; i++) {
@@ -339,7 +339,7 @@ void testNPDU2(Test * pTest)
len = npdu_encode_apdu(&pdu[0],
&dest, &src, data_expecting_reply, priority);
ct_test(pTest, len != 0);
// can we get the info back?
/* can we get the info back? */
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
ct_test(pTest, npdu_len != 0);
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply);
@@ -348,13 +348,13 @@ void testNPDU2(Test * pTest)
ct_test(pTest, npdu_data.network_message_type == network_message_type);
ct_test(pTest, npdu_data.vendor_id == vendor_id);
ct_test(pTest, npdu_data.priority == priority);
// DNET,DLEN,DADR
/* DNET,DLEN,DADR */
ct_test(pTest, npdu_dest.net == dest.net);
ct_test(pTest, npdu_dest.len == dest.len);
for (i = 0; i < dest.len; i++) {
ct_test(pTest, npdu_dest.adr[i] == dest.adr[i]);
}
// SNET,SLEN,SADR
/* SNET,SLEN,SADR */
ct_test(pTest, npdu_src.net == src.net);
ct_test(pTest, npdu_src.len == src.len);
for (i = 0; i < src.len; i++) {
@@ -370,21 +370,21 @@ void testNPDU1(Test * pTest)
BACNET_ADDRESS npdu_dest = { 0 };
BACNET_ADDRESS npdu_src = { 0 };
int len = 0;
bool data_expecting_reply = false; // true for confirmed messages
bool data_expecting_reply = false; /* true for confirmed messages */
BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL;
BACNET_NPDU_DATA npdu_data = { 0 };
int i = 0; // counter
int i = 0; /* counter */
int npdu_len = 0;
bool network_layer_message = false; // false if APDU
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; // optional
uint16_t vendor_id = 0; // optional, if net message type is > 0x80
bool network_layer_message = false; /* false if APDU */
BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */
uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */
// mac_len = 0 if global address
/* mac_len = 0 if global address */
dest.mac_len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) {
dest.mac[i] = 0;
}
// DNET,DLEN,DADR
/* DNET,DLEN,DADR */
dest.net = 0;
dest.len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) {
@@ -394,7 +394,7 @@ void testNPDU1(Test * pTest)
for (i = 0; i < MAX_MAC_LEN; i++) {
src.mac[i] = 0;
}
// SNET,SLEN,SADR
/* SNET,SLEN,SADR */
src.net = 0;
src.len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) {
@@ -403,7 +403,7 @@ void testNPDU1(Test * pTest)
len = npdu_encode_apdu(&pdu[0],
&dest, &src, data_expecting_reply, priority);
ct_test(pTest, len != 0);
// can we get the info back?
/* can we get the info back? */
npdu_len = npdu_decode(&pdu[0], &npdu_dest, &npdu_src, &npdu_data);
ct_test(pTest, npdu_len != 0);
ct_test(pTest, npdu_data.data_expecting_reply == data_expecting_reply);
@@ -417,7 +417,7 @@ void testNPDU1(Test * pTest)
}
#ifdef TEST_NPDU
// dummy stub for testing
/* dummy stub for testing */
void tsm_free_invoke_id(uint8_t invokeID)
{
(void) invokeID;