![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
GPS test
Diff: main.cpp
- Revision:
- 0:f7f81e36e9d7
- Child:
- 1:020b393621e5
diff -r 000000000000 -r f7f81e36e9d7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 05 09:18:42 2021 +0000 @@ -0,0 +1,73 @@ +#include "mbed.h" +#include "AsyncSerial.hpp" +#include <string.h> +//"include <strlib.h> + +Serial pc(USBTX, USBRX); +Serial gps(PC_12, PD_2); + +void GPS_Read(); + +const int uart_max = 1000; +int uart_start = 0; +int uart_index = 0; +char uart_buffer[uart_max]; + +void gps_receive() +{ + while (gps.readable()) + { + char c; + c = gps.getc(); + uart_buffer[uart_index] = c; + if (c == '$') + { + uart_start = uart_index; + } + if (c == '\n') + { + GPS_Read(); + } + uart_index = (uart_index + 1) % uart_max; + } +} + + +void GPS_Read() +{ + char line[256]; + for (int i = 0 ;i < 256; i++) + { + line[i] = 0; + } + bool flag = false; + int counts = 0; + for (int i = 0; i < 256; i++) + { + line[i] = uart_buffer[(uart_start + i) % uart_max]; + counts++; + if (line[i] == '\n') + { + flag = true; + break; + } + } + if (flag) + { + pc.printf("Counts:%d\r\n", counts); + pc.printf("%s\r\n", line); + } +} + +int main() +{ + pc.baud(115200); + gps.baud(57600); + gps.attach(gps_receive, Serial::RxIrq); + while (1) + { +// GPS_Read(); +// pc.printf("A\n"); + + } +} \ No newline at end of file