sample for GPS (used by nucleo_STM-F303K8)
Dependencies: mbed
Fork of Nucleo_GPS by
main.cpp@0:8889ed33c550, 2016-08-08 (annotated)
- Committer:
- Koob
- Date:
- Mon Aug 08 02:05:09 2016 +0000
- Revision:
- 0:8889ed33c550
- Child:
- 1:91f4ae33e6ac
nucleo_GPS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Koob | 0:8889ed33c550 | 1 | #include "mbed.h" |
Koob | 0:8889ed33c550 | 2 | |
Koob | 0:8889ed33c550 | 3 | Serial gps(D1, D0); // tx, rx |
Koob | 0:8889ed33c550 | 4 | Serial pc(USBTX, USBRX); // tx, rx |
Koob | 0:8889ed33c550 | 5 | |
Koob | 0:8889ed33c550 | 6 | int main() { |
Koob | 0:8889ed33c550 | 7 | |
Koob | 0:8889ed33c550 | 8 | unsigned char c; |
Koob | 0:8889ed33c550 | 9 | int i,rlock; |
Koob | 0:8889ed33c550 | 10 | char gps_data[256],gps2_data[256]; |
Koob | 0:8889ed33c550 | 11 | char ns,ew; |
Koob | 0:8889ed33c550 | 12 | float time,hokui,tokei; |
Koob | 0:8889ed33c550 | 13 | float g_hokui,g_tokei; |
Koob | 0:8889ed33c550 | 14 | float d_hokui,m_hokui,d_tokei,m_tokei; |
Koob | 0:8889ed33c550 | 15 | |
Koob | 0:8889ed33c550 | 16 | gps.baud(9600); |
Koob | 0:8889ed33c550 | 17 | pc.printf("*** GPS GT-720F ***"); |
Koob | 0:8889ed33c550 | 18 | |
Koob | 0:8889ed33c550 | 19 | while (1) { |
Koob | 0:8889ed33c550 | 20 | i=0; |
Koob | 0:8889ed33c550 | 21 | while(gps.getc()!='$'){ |
Koob | 0:8889ed33c550 | 22 | } |
Koob | 0:8889ed33c550 | 23 | |
Koob | 0:8889ed33c550 | 24 | while((gps_data[i]=gps.getc()) != '\r'){ |
Koob | 0:8889ed33c550 | 25 | i++; |
Koob | 0:8889ed33c550 | 26 | if(i==256){ |
Koob | 0:8889ed33c550 | 27 | pc.printf("*** Div Error! ***\n"); |
Koob | 0:8889ed33c550 | 28 | i=255; |
Koob | 0:8889ed33c550 | 29 | break; |
Koob | 0:8889ed33c550 | 30 | } |
Koob | 0:8889ed33c550 | 31 | } |
Koob | 0:8889ed33c550 | 32 | gps_data[i]='\0'; |
Koob | 0:8889ed33c550 | 33 | |
Koob | 0:8889ed33c550 | 34 | if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d",&time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){ |
Koob | 0:8889ed33c550 | 35 | if(rlock==1){ |
Koob | 0:8889ed33c550 | 36 | pc.printf("Status:Lock(%d)\n\r",rlock); |
Koob | 0:8889ed33c550 | 37 | //logitude |
Koob | 0:8889ed33c550 | 38 | d_tokei= int(tokei/100); |
Koob | 0:8889ed33c550 | 39 | m_tokei= (tokei-d_tokei*100)/60; |
Koob | 0:8889ed33c550 | 40 | g_tokei= d_tokei+m_tokei; |
Koob | 0:8889ed33c550 | 41 | pc.printf("Log:%4.5f,",g_tokei); |
Koob | 0:8889ed33c550 | 42 | //Latitude |
Koob | 0:8889ed33c550 | 43 | d_hokui=int(hokui/100); |
Koob | 0:8889ed33c550 | 44 | m_hokui=(hokui-d_hokui*100)/60; |
Koob | 0:8889ed33c550 | 45 | g_hokui=d_hokui+m_hokui; |
Koob | 0:8889ed33c550 | 46 | pc.printf("Lat:%4.5f\n\r",g_hokui); |
Koob | 0:8889ed33c550 | 47 | |
Koob | 0:8889ed33c550 | 48 | } |
Koob | 0:8889ed33c550 | 49 | else{ |
Koob | 0:8889ed33c550 | 50 | pc.printf("\n\rStatus:unLock(%d)\n\r",rlock); |
Koob | 0:8889ed33c550 | 51 | for(i=0;i<40;i++){ |
Koob | 0:8889ed33c550 | 52 | pc.printf("%c",gps_data[i]); |
Koob | 0:8889ed33c550 | 53 | } |
Koob | 0:8889ed33c550 | 54 | } |
Koob | 0:8889ed33c550 | 55 | }//if |
Koob | 0:8889ed33c550 | 56 | }//while |
Koob | 0:8889ed33c550 | 57 | }//main |