add another crc to make sure we don't get corrupt data
This commit is contained in:
@@ -19,6 +19,7 @@ typedef struct __attribute__((packed))
|
|||||||
uint32_t packetIndex;
|
uint32_t packetIndex;
|
||||||
uint8_t packetType;
|
uint8_t packetType;
|
||||||
uint32_t missionTimer;
|
uint32_t missionTimer;
|
||||||
|
uint32_t CRCCheck;
|
||||||
} DownBoundPacket;
|
} DownBoundPacket;
|
||||||
|
|
||||||
typedef struct __attribute__((packed))
|
typedef struct __attribute__((packed))
|
||||||
@@ -90,6 +91,8 @@ typedef struct __attribute__((packed))
|
|||||||
int16_t currentServoB;
|
int16_t currentServoB;
|
||||||
int16_t targetServoB;
|
int16_t targetServoB;
|
||||||
|
|
||||||
|
uint8_t telemetryIndex;
|
||||||
|
|
||||||
} TelemetryPacket;
|
} TelemetryPacket;
|
||||||
|
|
||||||
typedef struct __attribute__((packed))
|
typedef struct __attribute__((packed))
|
||||||
@@ -97,6 +100,7 @@ typedef struct __attribute__((packed))
|
|||||||
char syncPhrase[10];
|
char syncPhrase[10];
|
||||||
uint32_t packetIndex;
|
uint32_t packetIndex;
|
||||||
uint8_t packetType;
|
uint8_t packetType;
|
||||||
|
uint32_t CRCCheck;
|
||||||
} UplinkPacket;
|
} UplinkPacket;
|
||||||
|
|
||||||
typedef struct __attribute__((packed))
|
typedef struct __attribute__((packed))
|
||||||
|
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.packetIndex = uplinkPacketIndex++;
|
||||||
uplinkHeader.packetType = UplinkPacketType_ACK;
|
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};
|
uint8_t txBuf[256] = {0};
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
@@ -146,6 +150,8 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
ESP_LOGI(TAG, " Servos:");
|
ESP_LOGI(TAG, " Servos:");
|
||||||
ESP_LOGI(TAG, " Servo A: Current = %d, Target = %d", packet->currentServoA, packet->targetServoA);
|
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, " 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)
|
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);
|
uint8_t *payload = buf + sizeof(DownBoundPacket);
|
||||||
uint32_t payloadSize = rxLen - 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)
|
switch (down.packetType)
|
||||||
{
|
{
|
||||||
case DownlinkPacketType_Telemetry:
|
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 bandwidth = SX126X_LORA_BW_250_0;
|
||||||
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
||||||
uint16_t preambleLength = 8;
|
uint16_t preambleLength = 8;
|
||||||
|
Reference in New Issue
Block a user