sample for GPS (used by nucleo_STM-F303K8)

Dependencies:   mbed

Fork of Nucleo_GPS by Kosuke Furumoto

main.cpp

Committer:
mikawataru
Date:
2017-01-28
Revision:
3:03e5370e74a3
Parent:
2:59b33f158822
Child:
4:ccc66c37d3f1

File content as of revision 3:03e5370e74a3:

/*
説明
Nucleo-F303K8とGPSモジュールを使ったサンプルプログラム.

使用GPS
http://akizukidenshi.com/catalog/g/gK-09991/

参考
http://www.hiramine.com/physicalcomputing/general/gps_nmeaformat.html


以下ピン配置
Nucleo  GPSモジュール
GND-----GND-----------0V
5V------VIN
D0------TX
D1------RX
*/
#include "mbed.h"

DigitalOut myled(LED1);
Serial gps(D1, D0);       // tx, rx
Serial pc(USBTX, USBRX);    // tx, rx
int i,rlock,mode;
char gps_data[256],gps2_data[256];
char ns,ew;
float w_time,hokui,tokei;
float g_hokui,g_tokei;
float d_hokui,m_hokui,d_tokei,m_tokei;
unsigned char c;

void getGPS() {
  c = gps.getc();
  if( c=='$' || i == 256){
    mode = 0;
    i = 0;
  }
  if(mode==0){
    if((gps_data[i]=c) != '\r'){
      i++;
    }else{
      gps_data[i]='\0';
      
      if( sscanf(gps_data, "$GPGGA,%f,%f,%c,%f,%c,%d",&w_time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){
        if(rlock==1){
          pc.printf("Status:Lock(%d)\n\r",rlock);
          //logitude
          d_tokei= int(tokei/100);
          m_tokei= (tokei-d_tokei*100)/60;
          g_tokei= d_tokei+m_tokei;
          //Latitude
          d_hokui=int(hokui/100);
          m_hokui=(hokui-d_hokui*100)/60;
          g_hokui=d_hokui+m_hokui;
          pc.printf("Lon:%.6f, Lat:%.6f\n\r",g_tokei, g_hokui);
        }
        else{
          pc.printf("\n\rStatus:unLock(%d)\n\r",rlock);
          pc.printf("%s",gps_data);
        }
        sprintf(gps_data, "");
      }//if
    }
  }
}

int main(){
  pc.printf("*** GPS GT-720F ***");
  gps.baud(9600);
  pc.baud(115200);
  gps.attach(getGPS,Serial::RxIrq);
  while(1) {}
}