From f045ed10b5409992233105fa935ec71de609e028 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 22 Sep 2024 17:22:36 +0100 Subject: [PATCH] [FEC] Fix missing parentheses in macro --- src/protocols/AX25/AX25.cpp | 20 ++++++++++---------- src/utils/FEC.h | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index c5913e947..82a64cebc 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -402,7 +402,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { uint16_t stuffedFrameBuffPos = stuffedFrameBuffLenBits + 7 - 2*(stuffedFrameBuffLenBits%8); if((frameBuff[i] >> shift) & 0x01) { // copy 1 and increment counter - SET_BIT_IN_ARRAY(stuffedFrameBuff, stuffedFrameBuffPos); + SET_BIT_IN_ARRAY_MSB(stuffedFrameBuff, stuffedFrameBuffPos); stuffedFrameBuffLenBits++; count++; @@ -412,14 +412,14 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { stuffedFrameBuffPos = stuffedFrameBuffLenBits + 7 - 2*(stuffedFrameBuffLenBits%8); // insert 0 and reset counter - CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, stuffedFrameBuffPos); + CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, stuffedFrameBuffPos); stuffedFrameBuffLenBits++; count = 0; } } else { // copy 0 and reset counter - CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, stuffedFrameBuffPos); + CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, stuffedFrameBuffPos); stuffedFrameBuffLenBits++; count = 0; } @@ -454,20 +454,20 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { for(size_t i = preambleLen + 1; i < stuffedFrameBuffLen*8; i++) { size_t currBitPos = i + 7 - 2*(i%8); size_t prevBitPos = (i - 1) + 7 - 2*((i - 1)%8); - if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos)) { + if(TEST_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos)) { // bit is 1, no change, copy previous bit - if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, prevBitPos)) { - SET_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos); + if(TEST_BIT_IN_ARRAY_MSB(stuffedFrameBuff, prevBitPos)) { + SET_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos); } else { - CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos); + CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos); } } else { // bit is 0, transition, copy inversion of the previous bit - if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, prevBitPos)) { - CLEAR_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos); + if(TEST_BIT_IN_ARRAY_MSB(stuffedFrameBuff, prevBitPos)) { + CLEAR_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos); } else { - SET_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos); + SET_BIT_IN_ARRAY_MSB(stuffedFrameBuff, currBitPos); } } } diff --git a/src/utils/FEC.h b/src/utils/FEC.h index a33ff61f8..cf201b114 100644 --- a/src/utils/FEC.h +++ b/src/utils/FEC.h @@ -72,10 +72,10 @@ class RadioLibBCH { extern RadioLibBCH RadioLibBCHInstance; // macros to access bits in byte array, from http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html -#define SET_BIT_IN_ARRAY(A, k) ( A[(k/8)] |= (1 << (k%8)) ) -#define CLEAR_BIT_IN_ARRAY(A, k) ( A[(k/8)] &= ~(1 << (k%8)) ) -#define TEST_BIT_IN_ARRAY(A, k) ( A[(k/8)] & (1 << (k%8)) ) -#define GET_BIT_IN_ARRAY(A, k) ( (A[(k/8)] & (1 << (k%8))) ? 1 : 0 ) +#define SET_BIT_IN_ARRAY_MSB(A, k) ( A[((k)/8)] |= (1 << ((k)%8)) ) +#define CLEAR_BIT_IN_ARRAY_MSB(A, k) ( A[((k)/8)] &= ~(1 << ((k)%8)) ) +#define TEST_BIT_IN_ARRAY_MSB(A, k) ( A[((k)/8)] & (1 << ((k)%8)) ) +#define GET_BIT_IN_ARRAY_MSB(A, k) ( (A[((k)/8)] & (1 << ((k)%8))) ? 1 : 0 ) #endif