コウスケ スズキ / Mbed 2 deprecated 20220803GPS

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "math.h"
00004 
00005 #define TIME_GAP      6.0
00006 
00007 Serial        gps(PA_9,PA_10);
00008 
00009 Timer timer_open;
00010 Timer timer_log;
00011 Ticker tic_open;
00012 Ticker tic_log;
00013 
00014 float    _DMS2DEG(float raw_data);
00015 int      _imput(char cha);
00016 
00017 float Time;
00018 char gps_data[256];
00019 int cnt_gps;
00020 int Cnt_GPS=0;
00021 
00022 int main(){
00023     while(1){
00024         if(gps.readable()){
00025             gps_data[cnt_gps]=gps.getc();
00026             if(gps_data[cnt_gps]=='$' || cnt_gps==256){
00027                 cnt_gps=0;
00028                 memset(gps_data,'\0',256);
00029          }else if (gps_data[cnt_gps]=='\r'){
00030             float world_time, lon_east, lat_north;
00031             int rlock, sat_num;
00032             char lat,lon;
00033             if(sscanf(gps_data,
00034             "GPGGA,%f,%f,%c,%f,%c,%d,%d"
00035             ,&world_time,&lat_north,&lat,
00036             &lon_east,&lon,
00037             &rlock,&sat_num)>=1){
00038                 if(rlock==1){
00039                     lat_north=_DMS2DEG(lat_north);
00040                     lon_east=_DMS2DEG(lon_east);
00041                     printf("Lat:%f,Lon:%f\r\ntime:%f,sat_num:%d\r\n",
00042                     lat_north,lon_east,world_time,sat_num);
00043                     }else{
00044                         printf("%s\r\n",gps_data);
00045                     }
00046             }
00047         }else{
00048               cnt_gps++;
00049         }
00050     }
00051     if(timer_log.read()>=30.0*60.0)timer_log.reset();
00052     }
00053     }
00054     float _DMS2DEG(float raw_data){
00055             int d=(int)(raw_data/100);
00056             float m=(raw_data-(float)d*100);
00057             return (float)d+m/60;
00058 }
00059             
00060             
00061             
00062             
00063             
00064             
00065             
00066