Skip to content

Commit

Permalink
[FEC] Fix missing parentheses in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Sep 22, 2024
1 parent 8068bcc commit f045ed1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/protocols/AX25/AX25.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/FEC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f045ed1

Please sign in to comment.