Add ifdef to bit definitions to avoid conflicts with other libraries. Refactor BITx to use BIT macro. (#45)
This commit is contained in:
+20
-20
@@ -216,7 +216,7 @@ int encode_tag(uint8_t *apdu,
|
||||
|
||||
apdu[0] = 0;
|
||||
if (context_specific) {
|
||||
apdu[0] = BIT3;
|
||||
apdu[0] = BIT(3);
|
||||
}
|
||||
|
||||
/* additional tag byte after this byte */
|
||||
@@ -256,7 +256,7 @@ int encode_opening_tag(uint8_t *apdu, uint8_t tag_number)
|
||||
int len = 1;
|
||||
|
||||
/* set class field to context specific */
|
||||
apdu[0] = BIT3;
|
||||
apdu[0] = BIT(3);
|
||||
/* additional tag byte after this byte for extended tag byte */
|
||||
if (tag_number <= 14) {
|
||||
apdu[0] |= (tag_number << 4);
|
||||
@@ -278,7 +278,7 @@ int encode_closing_tag(uint8_t *apdu, uint8_t tag_number)
|
||||
int len = 1;
|
||||
|
||||
/* set class field to context specific */
|
||||
apdu[0] = BIT3;
|
||||
apdu[0] = BIT(3);
|
||||
/* additional tag byte after this byte for extended tag byte */
|
||||
if (tag_number <= 14) {
|
||||
apdu[0] |= (tag_number << 4);
|
||||
@@ -595,29 +595,29 @@ static uint8_t byte_reverse_bits(uint8_t in_byte)
|
||||
{
|
||||
uint8_t out_byte = 0;
|
||||
|
||||
if (in_byte & BIT0) {
|
||||
out_byte |= BIT7;
|
||||
if (in_byte & BIT(0)) {
|
||||
out_byte |= BIT(7);
|
||||
}
|
||||
if (in_byte & BIT1) {
|
||||
out_byte |= BIT6;
|
||||
if (in_byte & BIT(1)) {
|
||||
out_byte |= BIT(6);
|
||||
}
|
||||
if (in_byte & BIT2) {
|
||||
out_byte |= BIT5;
|
||||
if (in_byte & BIT(2)) {
|
||||
out_byte |= BIT(5);
|
||||
}
|
||||
if (in_byte & BIT3) {
|
||||
out_byte |= BIT4;
|
||||
if (in_byte & BIT(3)) {
|
||||
out_byte |= BIT(4);
|
||||
}
|
||||
if (in_byte & BIT4) {
|
||||
out_byte |= BIT3;
|
||||
if (in_byte & BIT(4)) {
|
||||
out_byte |= BIT(3);
|
||||
}
|
||||
if (in_byte & BIT5) {
|
||||
out_byte |= BIT2;
|
||||
if (in_byte & BIT(5)) {
|
||||
out_byte |= BIT(2);
|
||||
}
|
||||
if (in_byte & BIT6) {
|
||||
out_byte |= BIT1;
|
||||
if (in_byte & BIT(6)) {
|
||||
out_byte |= BIT(1);
|
||||
}
|
||||
if (in_byte & BIT7) {
|
||||
out_byte |= BIT0;
|
||||
if (in_byte & BIT(7)) {
|
||||
out_byte |= BIT(0);
|
||||
}
|
||||
|
||||
return out_byte;
|
||||
@@ -2522,7 +2522,7 @@ static void testBACDCodeTags(Test *pTest)
|
||||
test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value);
|
||||
ct_test(pTest, len == test_len);
|
||||
/* stop at the the last value */
|
||||
if (value & BIT31) {
|
||||
if (value & BIT(31L)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ extern "C" {
|
||||
|
||||
/* from clause 20.2.1.1 Class */
|
||||
/* true if the tag is context specific */
|
||||
#define IS_CONTEXT_SPECIFIC(x) ((x & BIT3) == BIT3)
|
||||
#define IS_CONTEXT_SPECIFIC(x) ((x & BIT(3)) == BIT(3))
|
||||
|
||||
/* from clause 20.2.1.3.2 Constructed Data */
|
||||
/* true if the tag is an opening tag */
|
||||
|
||||
+21
-36
@@ -27,54 +27,39 @@
|
||||
/********************************************************************
|
||||
* Bit Masks
|
||||
*********************************************************************/
|
||||
#define BIT(x) (1<<(x))
|
||||
#define BIT0 (0x01)
|
||||
#define BIT1 (0x02)
|
||||
#define BIT2 (0x04)
|
||||
#define BIT3 (0x08)
|
||||
#define BIT4 (0x10)
|
||||
#define BIT5 (0x20)
|
||||
#define BIT6 (0x40)
|
||||
#define BIT7 (0x80)
|
||||
#define BIT8 (0x0100)
|
||||
#define BIT9 (0x0200)
|
||||
#define BIT10 (0x0400)
|
||||
#define BIT11 (0x0800)
|
||||
#define BIT12 (0x1000)
|
||||
#define BIT13 (0x2000)
|
||||
#define BIT14 (0x4000)
|
||||
#define BIT15 (0x8000)
|
||||
#define BIT16 (0x010000UL)
|
||||
#define BIT17 (0x020000UL)
|
||||
#define BIT18 (0x040000UL)
|
||||
#define BIT19 (0x080000UL)
|
||||
#define BIT20 (0x100000UL)
|
||||
#define BIT21 (0x200000UL)
|
||||
#define BIT22 (0x400000UL)
|
||||
#define BIT23 (0x800000UL)
|
||||
#define BIT24 (0x01000000UL)
|
||||
#define BIT25 (0x02000000UL)
|
||||
#define BIT26 (0x04000000UL)
|
||||
#define BIT27 (0x08000000UL)
|
||||
#define BIT28 (0x10000000UL)
|
||||
#define BIT29 (0x20000000UL)
|
||||
#define BIT30 (0x40000000UL)
|
||||
#define BIT31 (0x80000000UL)
|
||||
#ifndef BIT
|
||||
#define BIT(x) (1<<(x))
|
||||
#endif
|
||||
#ifndef _BV
|
||||
#define _BV(x) (1<<(x))
|
||||
#endif
|
||||
|
||||
/* a=register, b=bit number to act upon 0-n */
|
||||
#ifndef BIT_SET
|
||||
#define BIT_SET(a,b) ((a) |= (1<<(b)))
|
||||
#endif
|
||||
#ifndef BIT_CLEAR
|
||||
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
|
||||
#endif
|
||||
#ifndef BIT_FLIP
|
||||
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))
|
||||
#endif
|
||||
#ifndef BIT_CHECK
|
||||
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
|
||||
#endif
|
||||
|
||||
/* x=target variable, y=mask */
|
||||
#ifndef BITMASK_SET
|
||||
#define BITMASK_SET(x,y) ((x) |= (y))
|
||||
#endif
|
||||
#ifndef BITMASK_CLEAR
|
||||
#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
|
||||
#endif
|
||||
#ifndef BITMASK_FLIP
|
||||
#define BITMASK_FLIP(x,y) ((x) ^= (y))
|
||||
#endif
|
||||
#ifndef BITMASK_CHECK
|
||||
#define BITMASK_CHECK(x,y) (((x) & (y)) == (y))
|
||||
|
||||
#ifndef _BV
|
||||
#define _BV(x) (1<<(x))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+8
-8
@@ -144,7 +144,7 @@ int npdu_encode_pdu(uint8_t *npdu,
|
||||
/* 0 indicates that the NSDU contains a BACnet APDU. */
|
||||
/* Message Type field is absent. */
|
||||
if (npdu_data->network_layer_message) {
|
||||
npdu[1] |= BIT7;
|
||||
npdu[1] |= BIT(7);
|
||||
}
|
||||
/*Bit 6: Reserved. Shall be zero. */
|
||||
/*Bit 5: Destination specifier where: */
|
||||
@@ -153,7 +153,7 @@ int npdu_encode_pdu(uint8_t *npdu,
|
||||
/* 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;
|
||||
npdu[1] |= BIT(5);
|
||||
}
|
||||
/* Bit 4: Reserved. Shall be zero. */
|
||||
/* Bit 3: Source specifier where: */
|
||||
@@ -162,7 +162,7 @@ int npdu_encode_pdu(uint8_t *npdu,
|
||||
/* SLEN = 0 Invalid */
|
||||
/* SLEN > 0 specifies length of SADR field */
|
||||
if (src && src->net && src->len) {
|
||||
npdu[1] |= BIT3;
|
||||
npdu[1] |= BIT(3);
|
||||
}
|
||||
/* Bit 2: The value of this bit corresponds to the */
|
||||
/* data_expecting_reply parameter in the N-UNITDATA primitives. */
|
||||
@@ -173,7 +173,7 @@ int npdu_encode_pdu(uint8_t *npdu,
|
||||
/* 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;
|
||||
npdu[1] |= BIT(2);
|
||||
}
|
||||
/* Bits 1,0: Network priority where: */
|
||||
/* B'11' = Life Safety message */
|
||||
@@ -330,7 +330,7 @@ int npdu_decode(uint8_t *npdu,
|
||||
/* 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;
|
||||
npdu_data->network_layer_message = (npdu[1] & BIT(7)) ? true : false;
|
||||
/*Bit 6: Reserved. Shall be zero. */
|
||||
/* Bit 4: Reserved. Shall be zero. */
|
||||
/* Bit 2: The value of this bit corresponds to data expecting reply */
|
||||
@@ -341,7 +341,7 @@ int npdu_decode(uint8_t *npdu,
|
||||
/* 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;
|
||||
npdu_data->data_expecting_reply = (npdu[1] & BIT(2)) ? true : false;
|
||||
/* Bits 1,0: Network priority where: */
|
||||
/* B'11' = Life Safety message */
|
||||
/* B'10' = Critical Equipment message */
|
||||
@@ -355,7 +355,7 @@ int npdu_decode(uint8_t *npdu,
|
||||
/* 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) {
|
||||
if (npdu[1] & BIT(5)) {
|
||||
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 */
|
||||
@@ -389,7 +389,7 @@ int npdu_decode(uint8_t *npdu,
|
||||
/* Bit 3: Source specifier where: */
|
||||
/* 0 = SNET, SLEN, and SADR absent */
|
||||
/* 1 = SNET, SLEN, and SADR present */
|
||||
if (npdu[1] & BIT3) {
|
||||
if (npdu[1] & BIT(3)) {
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user