Extract common bit reflection methods
This commit is contained in:
parent
494aa33a16
commit
5c0b4dbb10
4 changed files with 27 additions and 19 deletions
|
@ -398,6 +398,21 @@ uint32_t Module::micros() {
|
|||
return(::micros());
|
||||
}
|
||||
|
||||
uint8_t Module::flipBits(uint8_t b) {
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
|
||||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
uint16_t Module::flipBits16(uint16_t i) {
|
||||
i = (i & 0xFF00) >> 8 | (i & 0x00FF) << 8;
|
||||
i = (i & 0xF0F0) >> 4 | (i & 0x0F0F) << 4;
|
||||
i = (i & 0xCCCC) >> 2 | (i & 0x3333) << 2;
|
||||
i = (i & 0xAAAA) >> 1 | (i & 0x5555) << 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
|
||||
_useRfSwitch = true;
|
||||
_rxEn = rxEn;
|
||||
|
|
10
src/Module.h
10
src/Module.h
|
@ -468,6 +468,16 @@ class Module {
|
|||
*/
|
||||
static uint32_t micros();
|
||||
|
||||
/*!
|
||||
\brief Function to reflect bits within a byte.
|
||||
*/
|
||||
static uint8_t flipBits(uint8_t b);
|
||||
|
||||
/*!
|
||||
\brief Function to reflect bits within an integer.
|
||||
*/
|
||||
static uint16_t flipBits16(uint16_t i);
|
||||
|
||||
#ifndef RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
|
|
@ -283,7 +283,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
|||
|
||||
// flip bit order
|
||||
for(size_t i = 0; i < frameBuffLen; i++) {
|
||||
frameBuff[i] = flipBits(frameBuff[i]);
|
||||
frameBuff[i] = Module::flipBits(frameBuff[i]);
|
||||
}
|
||||
|
||||
// calculate FCS
|
||||
|
@ -441,22 +441,7 @@ uint16_t AX25Client::getFrameCheckSequence(uint8_t* buff, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
return(flipBits16(~shiftReg));
|
||||
}
|
||||
|
||||
uint8_t AX25Client::flipBits(uint8_t b) {
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
|
||||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
uint16_t AX25Client::flipBits16(uint16_t i) {
|
||||
i = (i & 0xFF00) >> 8 | (i & 0x00FF) << 8;
|
||||
i = (i & 0xF0F0) >> 4 | (i & 0x0F0F) << 4;
|
||||
i = (i & 0xCCCC) >> 2 | (i & 0x3333) << 2;
|
||||
i = (i & 0xAAAA) >> 1 | (i & 0x5555) << 1;
|
||||
return i;
|
||||
return(Module::flipBits16(~shiftReg));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -344,8 +344,6 @@ class AX25Client {
|
|||
uint16_t _preambleLen = 0;
|
||||
|
||||
static uint16_t getFrameCheckSequence(uint8_t* buff, size_t len);
|
||||
static uint8_t flipBits(uint8_t b);
|
||||
static uint16_t flipBits16(uint16_t i);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue