Updated CRC method
This commit is contained in:
committed by
Pawel Spychalski (DzikuVx)
parent
36dc76db0d
commit
9f48e0fd6f
@@ -13,7 +13,7 @@ Development, ready for testing
|
|||||||
| 1 | Channel ID | channel used for comunication between TX and RX |
|
| 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 |
|
| 2 | Frame type & Length | bits 7-5 defines frame, bits 4-0 payload length |
|
||||||
| 3 - 34 | Payload | 32 bytes max |
|
| 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
|
## Frame types
|
||||||
|
|
||||||
|
|||||||
23
qsp.cpp
23
qsp.cpp
@@ -49,9 +49,22 @@ uint8_t get10bitLowShift(uint8_t channel) {
|
|||||||
return 8 - get10bitHighShift(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)
|
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) {
|
void encodeRxHealthPayload(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceState, RadioState_t *radioState) {
|
||||||
@@ -161,8 +174,8 @@ void qspDecodeIncomingFrame(
|
|||||||
{
|
{
|
||||||
qsp->frameDecodingStartedAt = millis();
|
qsp->frameDecodingStartedAt = millis();
|
||||||
qsp->protocolState = QSP_STATE_CHANNEL_RECEIVED;
|
qsp->protocolState = QSP_STATE_CHANNEL_RECEIVED;
|
||||||
qsp->crc = 0 ^ incomingByte;
|
qsp->crc = 0;
|
||||||
|
qspComputeCrc(qsp, incomingByte);
|
||||||
qspClearPayload(qsp);
|
qspClearPayload(qsp);
|
||||||
|
|
||||||
receivedPayload = 0;
|
receivedPayload = 0;
|
||||||
@@ -175,7 +188,7 @@ void qspDecodeIncomingFrame(
|
|||||||
else if (qsp->protocolState == QSP_STATE_CHANNEL_RECEIVED)
|
else if (qsp->protocolState == QSP_STATE_CHANNEL_RECEIVED)
|
||||||
{
|
{
|
||||||
//Frame ID and payload length
|
//Frame ID and payload length
|
||||||
qsp->crc ^= incomingByte;
|
qspComputeCrc(qsp, incomingByte);
|
||||||
|
|
||||||
frameId = (incomingByte >> 4) & 0x0f;
|
frameId = (incomingByte >> 4) & 0x0f;
|
||||||
payloadLength = incomingByte & 0x0f;
|
payloadLength = incomingByte & 0x0f;
|
||||||
@@ -189,7 +202,7 @@ void qspDecodeIncomingFrame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Now it's time for payload
|
//Now it's time for payload
|
||||||
qsp->crc ^= incomingByte;
|
qspComputeCrc(qsp, incomingByte);
|
||||||
qsp->payload[receivedPayload] = incomingByte;
|
qsp->payload[receivedPayload] = incomingByte;
|
||||||
|
|
||||||
receivedPayload++;
|
receivedPayload++;
|
||||||
|
|||||||
Reference in New Issue
Block a user