Skip to content

Commit

Permalink
Add FEC flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachGarcia42 committed Apr 12, 2024
1 parent 5aa2428 commit d8816d5
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
*/

// Uncomment if you want debug information about signal strength and motor movements
// #define DEBUG
#define DEBUG

// Flag to enable forward error correction
// #define FEC

// #include <Stepper.h>
// #include <Servo.h>
Expand Down Expand Up @@ -126,11 +129,20 @@ int main() {
#ifdef DEBUG
printf("[SX1276] Waiting for incoming transmission ... ");
#endif

#ifdef FEC
uint8_t encoded[msglen + ECC_LENGTH];
int state = radio.receive(encoded, msglen + ECC_LENGTH);
#else
uint8_t received[msglen];
int state = radio.receive(received, msglen);
#endif

#ifdef FEC
if (state == RADIOLIB_ERR_NONE || state == RADIOLIB_ERR_CRC_MISMATCH || state == RADIOLIB_ERR_LORA_HEADER_DAMAGED) {
#else
if (state == RADIOLIB_ERR_NONE) {
#endif

#ifdef DEBUG
// packet was successfully received
printf("success!");
Expand All @@ -141,7 +153,7 @@ int main() {
}
printf("\n");
#endif

#ifdef FEC
if (!rs.Decode(encoded, repaired)) {
#ifdef DEBUG
printf("Decoding succeeded!\n");
Expand All @@ -150,6 +162,10 @@ int main() {
printf("Decoding failed!\n");
}
std::string result = repaired;
#else
std::string result = (char*)received;
#endif

#ifdef DEBUG
printf("Result: \"");
for (int i = 0; i < msglen; i++)
Expand All @@ -175,13 +191,25 @@ int main() {
printf(" Hz\n");
#endif

#ifdef FEC
// Send data to Ground Station
printf("%s", repaired);

// Extract values
memcpy(&rockElev, repaired + 9, 4); // Altitude field
memcpy(&rockLat, repaired + 13, 4); // Latitude field
memcpy(&rockLong, repaired + 17, 4); // Longitude field
#else
// Send data to Ground Station
printf("%s\n", received);
// for(uint i = 0; i < msglen; i++) {printf("%c", received[i]);}
// printf("\n");

// Extract values
memcpy(&rockElev, received + 9, 4); // Altitude field
memcpy(&rockLat, received + 13, 4); // Latitude field
memcpy(&rockLong, received + 17, 4); // Longitude field
#endif

} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Expand Down Expand Up @@ -239,7 +267,6 @@ int main() {
servo_move_to(12, 90 - asc);
// stepper_rotate_steps(&stepper, stepsToTake);
// stepper_release(&stepper);
sleep_ms(500);
}

return 0;
Expand Down

0 comments on commit d8816d5

Please sign in to comment.