Skip to content

Commit

Permalink
moved leftshift function to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
Witty-Wizard committed Jun 30, 2024
1 parent d43bc71 commit 000936e
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/SerialIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ SerialIO::~SerialIO() {
#else
#warning "Unsupported hardware platform."
#endif
}

void SerialIO::leftShift(uint8_t arr[], size_t size) {
memmove(arr, arr + 1, (size - 1));
arr[size - 1] = 0xFF;
}
1 change: 1 addition & 0 deletions src/SerialIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SerialIO {
// not (false).
int _rxPin; // The RX pin number.
int _txPin; // The TX pin number.
void leftShift(uint8_t arr[], size_t size);
};
#include "crsf/crsf.h"
#include "fport/fport.h"
Expand Down
30 changes: 7 additions & 23 deletions src/crsf/crsf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,16 @@ void crsf::begin() {

void crsf::processIncoming() {
while (_rxPort->available()) {
_buffer = _rxPort->read();
if (_headerDetected) {
_rxData[_rxIndex] = _buffer;
_rxIndex++;
if (_rxIndex > _rxData[1] + 2)

{
_rxIndex = 0;
_headerDetected = false;
}
} else {
if (_buffer == CRSF_ADDRESS_FLIGHT_CONTROLLER ||
_buffer == CRSF_ADDRESS_CRSF_TRANSMITTER) {
_headerDetected = true;
_rxData[0] = _buffer;
_rxIndex = 1;
}
_rxData[CRSF_MAX_PACKET_SIZE - 1] = _rxPort->read();
if ((_rxData[0] == CRSF_ADDRESS_CRSF_TRANSMITTER ||
_rxData[0] == CRSF_ADDRESS_CRSF_TRANSMITTER) &&
(crc8(&_rxData[2], _rxData[1]) == 0)) {
memcpy(&channelData, &_rxData[3], sizeof(channelData));
}

if (_rxIndex == sizeof(_rxData) / sizeof(_rxData[0])) {
_rxIndex = 0;
_headerDetected = false;
else{
leftShift(_rxData,sizeof(_rxData));
}
}
if (crc8(&_rxData[2], _rxData[1]) == 0)
memcpy(&channelData, &_rxData[3], sizeof(channelData));
}

void crsf::getChannel(void *channelData) {
Expand Down
7 changes: 1 addition & 6 deletions src/fport/fport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ void fport::processIncoming() {
}
}

void fport::getChannel(void *channelData) {}

void fport::leftShift(uint8_t arr[], size_t size) {
memmove(arr, arr + 1, (size - 1));
arr[size - 1] = 0xFF;
}
void fport::getChannel(void *channelData) {}
1 change: 0 additions & 1 deletion src/fport/fport.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ explicit fport(Stream *rxPort, int rxPin = -1, int txPin = -1,
void begin() override;
void processIncoming() override;
void getChannel(void *channelData) override;
void leftShift(uint8_t arr[],size_t size);
};
#endif
7 changes: 1 addition & 6 deletions src/ibus/ibus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,4 @@ bool ibus::checkSum() {

// Check if the sum matches the expected CRC
return (sum == 0xFFFF); // Assuming IBUS CRC is 0xFFFF when correct
}

void ibus::leftShift(uint8_t arr[], size_t size) {
memmove(arr, arr + 1, (size - 1));
arr[size - 1] = 0xFF;
}
}
1 change: 0 additions & 1 deletion src/ibus/ibus.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ibus : public SerialIO {
* channel data will be stored.
*/
void getChannel(void *channelData) override;
void leftShift(uint8_t arr[], size_t size);
};

#endif // IBUS_H
5 changes: 0 additions & 5 deletions src/sbus/sbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@ void sbus::processIncoming() {

void sbus::getChannel(void *channelData) {
*static_cast<decltype(_channelData) *>(channelData) = _channelData;
}

void sbus::leftShift(uint8_t arr[], size_t size) {
memmove(arr, arr + 1, (size - 1));
arr[size - 1] = 0xFF;
}
2 changes: 0 additions & 2 deletions src/sbus/sbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class sbus : public SerialIO {
* channel data will be stored.
*/
void getChannel(void *channelData) override;

void leftShift(uint8_t arr[], size_t size);
};

#endif // SBUS_H

0 comments on commit 000936e

Please sign in to comment.