SSLM1 / Mbed 2 deprecated 1_Transiver_GPS

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* GMS6-CR6の流すデータからフォーマットGPGGAのみを取得して,PCに出力 (ネットにあったコード)*/
00002 
00003 #include "mbed.h"
00004 #include "math.h"
00005 
00006 #define TIME_GAP 6.0
00007 
00008 Serial gps (p9, p10);       //GPSのピンを設定
00009 Serial pc (USBTX, USBRX);
00010 Serial twe (p13, p14);
00011 
00012 /* 時間測定 */
00013 Timer  timer_open;
00014 Timer  timer_log;
00015 Ticker tic_open;
00016 Ticker tic_log;
00017 
00018 /* プロタイプ宣言 */
00019 float _DMS2DEG(float raw_data);
00020 int   _input(char cha);
00021 
00022 /* グローバル変数の設定 */
00023 float Time;
00024 char  gps_data[256];
00025 int   cnt_gps;
00026 int   Cnt_GPS = 0;
00027 
00028 int main()
00029 {
00030     float world_time, lon_east, lat_north;
00031     int rlock, sat_num;
00032     char lat, lon;
00033     
00034     pc.baud(115200);
00035     twe.baud(115200);
00036     
00037     while(1)
00038     {
00039         if(gps.readable())
00040         {
00041             gps_data[cnt_gps] = gps.getc();
00042             
00043             if(gps_data[cnt_gps] == '$' || cnt_gps == 256)
00044             {
00045                 cnt_gps = 0;
00046                 memset(gps_data, '\0', 256); //この関数なんや
00047             }
00048             else if(gps_data[cnt_gps] == '\r')
00049             {   
00050                 if(sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d", &world_time, &lat_north, &lat, &lon_east, &lon, &rlock, &sat_num) >= 1)
00051                 {
00052                     twe.printf("%s \r\n", gps_data);
00053                 }
00054             }
00055              else
00056              {
00057                  cnt_gps++;
00058              }
00059         }
00060         if(timer_log.read() >= 30.0*60.0) timer_log.reset();
00061     }
00062 }
00063 
00064 float _DMS2DEG(float raw_data)
00065 {
00066     int d = (int)(raw_data/100);
00067     float m = (raw_data - (float)d * 100);
00068     return (float) d + m /60;
00069 }