GPS (time, longitude, latitude)
Dependencies: mbed
Revision 1:c9f46190f418, committed 2015-04-25
- Comitter:
- wasaco
- Date:
- Sat Apr 25 03:29:54 2015 +0000
- Parent:
- 0:03a95da99c41
- Commit message:
- GPS yomuyo!
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 03a95da99c41 -r c9f46190f418 main.cpp --- a/main.cpp Sat Apr 25 02:59:08 2015 +0000 +++ b/main.cpp Sat Apr 25 03:29:54 2015 +0000 @@ -1,17 +1,17 @@ #include "mbed.h" -DigitalOut mled0(LED1); -DigitalOut mled1(LED2); - Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx Serial gps(PA_9, PA_10);// tx, rx int main() { - int i,rlock; + int i,rlock,stn; char gps_data[256]; char ns,ew; float time,hokui,tokei; + float g_hokui,g_tokei; + float d_hokui,m_hokui,d_tokei,m_tokei; + int h_time,m_time,s_time; gps.baud(4800); pc.printf("gps start! \r\n"); @@ -32,14 +32,42 @@ } gps_data[i]='\0'; - if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d",&time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){ + /* test data + ---- GPS 12:24:43 Lock(1),Stn(6) ---- + Hokui:35.031105 + Tokei:135.773605 + + ---- GPS 12:24:44 Lock(1),Stn(6) ---- + Hokui:35.031105 + Tokei:135.773605 + */ + + if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d",&time,&hokui,&ns,&tokei,&ew,&rlock,&stn) >= 1){ if(rlock==1){ - pc.printf("*** GPS received!! ***\r\n"); - pc.printf("Status:Lock(%d)\r\n",rlock); - // logitude - pc.printf("Tokei:%4.5f\r\n",tokei); - // Latitude - pc.printf("Hokui:%4.5f\r\n",hokui); + //latitude + d_hokui = int(hokui/100); + m_hokui = (hokui - d_hokui*100)/60; + g_hokui = d_hokui + m_hokui; + //longitude + d_tokei = int(tokei/100); + m_tokei = (tokei - d_tokei*100)/60; + g_tokei=d_tokei + m_tokei; +// g_hokui=int(hokui/100)+(hokui-int(hokui/100))/60; +// g_tokei=int(tokei/100)+(tokei-int(tokei/100))/60; + + //time set + h_time = int(time/10000); + m_time = int((time - h_time*10000)/100); + s_time = int(time - h_time*10000 - m_time*100); + h_time=h_time+9;//UTC =>JST + + pc.printf("---- GPS %2d:%2d:%2d ",h_time,m_time,s_time); + pc.printf("Lock(%d),Stn(%d) ----\r\n",rlock,stn); + // latitude + pc.printf("Hokui:%4.6f\r\n",g_hokui); + // longitude + pc.printf("Tokei:%4.6f\r\n\n",g_tokei); + } else{