Merge pull request #26 from DzikuVx/crc-update

Updated CRC method
This commit is contained in:
Paweł Spychalski
2017-11-15 19:09:49 +01:00
committed by GitHub
2 changed files with 19 additions and 6 deletions

View File

@@ -13,7 +13,7 @@ Development, ready for testing
| 1 | Channel ID | channel used for comunication between TX and RX |
| 2 | Frame type & Length | bits 7-5 defines frame, bits 4-0 payload length |
| 3 - 34 | Payload | 32 bytes max |
| payload length + 3 | CRC | XOR of all previous bytes |
| payload length + 3 | CRC | using crc8_dvb_s2 method |
## Frame types

23
qsp.cpp
View File

@@ -49,9 +49,22 @@ uint8_t get10bitLowShift(uint8_t channel) {
return 8 - get10bitHighShift(channel);
}
uint8_t crc8_dvb_s2(uint8_t crc, uint8_t a)
{
crc ^= a;
for (int ii = 0; ii < 8; ++ii) {
if (crc & 0x80) {
crc = (crc << 1) ^ 0xD5;
} else {
crc = crc << 1;
}
}
return crc;
}
void qspComputeCrc(QspConfiguration_t *qsp, uint8_t dataByte)
{
qsp->crc ^= dataByte;
qsp->crc = crc8_dvb_s2(qsp->crc, dataByte);
}
void encodeRxHealthPayload(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceState, RadioState_t *radioState) {
@@ -161,8 +174,8 @@ void qspDecodeIncomingFrame(
{
qsp->frameDecodingStartedAt = millis();
qsp->protocolState = QSP_STATE_CHANNEL_RECEIVED;
qsp->crc = 0 ^ incomingByte;
qsp->crc = 0;
qspComputeCrc(qsp, incomingByte);
qspClearPayload(qsp);
receivedPayload = 0;
@@ -175,7 +188,7 @@ void qspDecodeIncomingFrame(
else if (qsp->protocolState == QSP_STATE_CHANNEL_RECEIVED)
{
//Frame ID and payload length
qsp->crc ^= incomingByte;
qspComputeCrc(qsp, incomingByte);
frameId = (incomingByte >> 4) & 0x0f;
payloadLength = incomingByte & 0x0f;
@@ -189,7 +202,7 @@ void qspDecodeIncomingFrame(
}
//Now it's time for payload
qsp->crc ^= incomingByte;
qspComputeCrc(qsp, incomingByte);
qsp->payload[receivedPayload] = incomingByte;
receivedPayload++;