/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-01-07     user       the first version
 */

#include "nmea_decode_test.h"

void nmea_decode_test(void)
{
        double deg_lat;
        double deg_lon;

    nmeaINFO info;
    nmeaPARSER parser;
    uint8_t new_parse=0;

    nmeaTIME beiJingTime;


    nmea_property()->trace_func = &trace;
    nmea_property()->error_func = &error;
//    nmea_property()->info_func = &gps_info;


    nmea_zero_INFO(&info);
    nmea_parser_init(&parser);

    while(1)
    {
      if(GPS_HalfTransferEnd)
      {

        nmea_parse(&parser, (const char*)&gps_rbuff[0], HALF_GPS_RBUFF_SIZE, &info);

        GPS_HalfTransferEnd = 0;
        new_parse = 1;
      }
      else if(GPS_TransferEnd)
      {

        nmea_parse(&parser, (const char*)&gps_rbuff[HALF_GPS_RBUFF_SIZE], HALF_GPS_RBUFF_SIZE, &info);

        GPS_TransferEnd = 0;
        new_parse =1;
      }

      if(new_parse )
      {

        GMTconvert(&info.utc,&beiJingTime,8,1);


                printf("\r\n%d-%02d-%02d,%d:%d:%d\r\n", beiJingTime.year+1900, beiJingTime.mon,beiJingTime.day,beiJingTime.hour,beiJingTime.min,beiJingTime.sec);


                deg_lat = nmea_ndeg2degree(info.lat);
                deg_lon = nmea_ndeg2degree(info.lon);

                printf("\r\n%f,%f\r\n",deg_lat,deg_lon);
        printf("\r\n%f Ã× ", info.elv);
        printf("\r\n%f km/h ", info.speed);
        printf("\r\n%f ¶È", info.direction);

                printf("\r\n%d,%d",info.satinfo.inuse,info.satinfo.inview);

//                printf("\r\n%d,%d",info.satinfo.inuse,info.satinfo.inview);
                printf("\r\n%f,%f,%f",info.PDOP,info.HDOP,info.VDOP);

        new_parse = 0;
      }

    }

    // nmea_parser_destroy(&parser);

    //  return 0;
}
