diff --git a/main.c b/main.c index 90fa7b3..440ff78 100644 --- a/main.c +++ b/main.c @@ -70,6 +70,43 @@ void control_leds_based_on_speed(float speed_kmh) { } } + + +void nmea_sentence_process(const char *nmea_sentence) +{ + uint8_t i = 0; + uint8_t field_number = 0; + float speed_kmh = 0.0; + uint8_t field_index = 0; + + if (nmea_sentence[0] != '$') return; // Invalid sentence, exit + + if (strncmp(nmea_sentence + 1, "GPRMC", 5) == 0) + { + for (i = 6; nmea_sentence[i] != '\0'; i++) + { + if (nmea_sentence[i] == ',') + { + if (field_number == 7) // Speed in knots (field 7) + { speed_kmh = atof(nmea_sentence + i - field_index); + control_leds_based_on_speed(speed_kmh); + } + field_number++; + field_index = 0; + } + else if (nmea_sentence[i] == '*') + { + break; + } + else + { + field_index++; + } + } + } +} + + void UART1_Handler(void) { char data = UART1_DR_R & 0xFF;