add another crc to make sure we don't get corrupt data
This commit is contained in:
15
main/radio.c
15
main/radio.c
@@ -27,6 +27,10 @@ void send_ack(uint32_t packetIndex, uint32_t crc)
|
||||
uplinkHeader.packetIndex = uplinkPacketIndex++;
|
||||
uplinkHeader.packetType = UplinkPacketType_ACK;
|
||||
|
||||
uint32_t crcCheck = esp_rom_crc32_le(0, (uint8_t *)&ack, sizeof(ack));
|
||||
|
||||
uplinkHeader.CRCCheck = crcCheck;
|
||||
|
||||
uint8_t txBuf[256] = {0};
|
||||
int offset = 0;
|
||||
|
||||
@@ -146,6 +150,8 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
||||
ESP_LOGI(TAG, " Servos:");
|
||||
ESP_LOGI(TAG, " Servo A: Current = %d, Target = %d", packet->currentServoA, packet->targetServoA);
|
||||
ESP_LOGI(TAG, " Servo B: Current = %d, Target = %d", packet->currentServoB, packet->targetServoB);
|
||||
ESP_LOGI(TAG, " TelemetryIndex: %d", packet->telemetryIndex);
|
||||
|
||||
}
|
||||
|
||||
void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
||||
@@ -171,6 +177,13 @@ void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
||||
uint8_t *payload = buf + sizeof(DownBoundPacket);
|
||||
uint32_t payloadSize = rxLen - sizeof(DownBoundPacket);
|
||||
|
||||
uint32_t crcCheck = esp_rom_crc32_le(0, payload, payloadSize);
|
||||
|
||||
if (crcCheck != down.CRCCheck) {
|
||||
ESP_LOGE(TAG, "Received BAD CRC for packet %d, crc is %ld, should be %ld", down.packetIndex, crcCheck, down.CRCCheck);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (down.packetType)
|
||||
{
|
||||
case DownlinkPacketType_Telemetry:
|
||||
@@ -227,7 +240,7 @@ void lora_comms_task(void *pvParameters)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t spreadingFactor = 6;
|
||||
uint8_t spreadingFactor = 7;
|
||||
uint8_t bandwidth = SX126X_LORA_BW_250_0;
|
||||
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
||||
uint16_t preambleLength = 8;
|
||||
|
Reference in New Issue
Block a user