add another crc to make sure we don't get corrupt data
This commit is contained in:
@@ -44,7 +44,7 @@ void setup_lora(void)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -54,13 +54,14 @@ void setup_lora(void)
|
||||
LoRaConfig(spreadingFactor, bandwidth, codingRate, preambleLength, 0, crcOn, invertIrq);
|
||||
}
|
||||
|
||||
static void prepare_downbound_packet(DownBoundPacket *packet, uint8_t type, uint64_t missionTimer)
|
||||
static void prepare_downbound_packet(DownBoundPacket *packet, uint8_t type, uint64_t missionTimer, uint32_t crc)
|
||||
{
|
||||
memset(packet, 0, sizeof(DownBoundPacket));
|
||||
packet->missionTimer = missionTimer;
|
||||
packet->packetIndex = packetIndexTX++;
|
||||
ESP_LOGI(TAG_RADIO, "Sending downbound packet with index %ld", packetIndexTX - 1);
|
||||
packet->packetType = type;
|
||||
packet->CRCCheck = crc;
|
||||
strcpy(packet->syncPhrase, "PlechDole");
|
||||
}
|
||||
|
||||
@@ -106,7 +107,8 @@ void prepare_and_send_telemetry(uint64_t missionTimer)
|
||||
uint8_t bufOut[256] = {0};
|
||||
|
||||
DownBoundPacket downboundPacket;
|
||||
prepare_downbound_packet(&downboundPacket, DownlinkPacketType_Telemetry, missionTimer);
|
||||
uint32_t crc = esp_rom_crc32_le(0,(uint8_t *) &telemetryPacket, sizeof(telemetryPacket));
|
||||
prepare_downbound_packet(&downboundPacket, DownlinkPacketType_Telemetry, missionTimer, crc);
|
||||
|
||||
uint16_t offset = 0;
|
||||
memcpy(bufOut + offset, &downboundPacket, sizeof(downboundPacket));
|
||||
@@ -122,14 +124,17 @@ static void build_and_send_ack(uint32_t ackIndex, uint32_t crc32Checksum, uint64
|
||||
{
|
||||
uint8_t bufOut[256] = {0};
|
||||
|
||||
DownBoundPacket downboundPacket;
|
||||
prepare_downbound_packet(&downboundPacket, DownlinkPacketType_ACK, missionTimer);
|
||||
|
||||
|
||||
ACKPacket ackPacket = {
|
||||
.packetIndex = ackIndex,
|
||||
.crc32Checksum = crc32Checksum,
|
||||
};
|
||||
|
||||
uint32_t crc = esp_rom_crc32_le(0, (uint8_t *) &ackPacket, sizeof(ackPacket));
|
||||
|
||||
DownBoundPacket downboundPacket;
|
||||
prepare_downbound_packet(&downboundPacket, DownlinkPacketType_ACK, missionTimer, crc);
|
||||
|
||||
uint16_t offset = 0;
|
||||
memcpy(bufOut + offset, &downboundPacket, sizeof(downboundPacket));
|
||||
offset += sizeof(downboundPacket);
|
||||
@@ -169,8 +174,17 @@ void process_uplink_packet(uint8_t *data, uint8_t len, uint64_t missionTimer)
|
||||
|
||||
ESP_LOGI(TAG, "Got uplink packet of type %d, index %d", uplinkPacket.packetType, uplinkPacket.packetIndex);
|
||||
|
||||
uint8_t *payload = data + sizeof(UplinkPacket);
|
||||
|
||||
uint8_t payloadRXLen = len - sizeof(UplinkPacket);
|
||||
|
||||
uint32_t crc = esp_rom_crc32_le(0, payload, payloadRXLen);
|
||||
|
||||
if (crc != uplinkPacket.CRCCheck) {
|
||||
ESP_LOGE(TAG, "Received BAD CRC for packet %d, crc is %ld, should be %ld", uplinkPacket.packetIndex, crc, uplinkPacket.CRCCheck);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uplinkPacket.packetType == UplinkPacketType_ACK)
|
||||
{
|
||||
ESP_LOGI(TAG, "Received ACK for packet %d", uplinkPacket.packetIndex);
|
||||
|
Reference in New Issue
Block a user