GPS test

Dependencies:   mbed GYSFDMAXB

main.cpp

Committer:
cocorlow
Date:
2021-04-05
Revision:
0:f7f81e36e9d7
Child:
1:020b393621e5

File content as of revision 0:f7f81e36e9d7:

#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");
        
    }
}