ublox社製GPSモジュール NEO-7Mから、SPI経由でGPSデータをUBXプロトコルで読み出すライブラリです SPI経由ではGPSの出力設定が出来ないので、予めUART接続でPCから出力データを変更する必要があります。ここら辺の詳細については https://ameblo.jp/tsukuba-step/entry-12282936077.html を参考にして下さい。 出力設定は、 NAV-POSLLH,NAV-TIMEUTC,NAV-VELNED のみを出力して下さい
ublox_Nav.cpp@0:956653b6d3ad, 2018-02-13 (annotated)
- Committer:
- kim1212
- Date:
- Tue Feb 13 04:21:32 2018 +0000
- Revision:
- 0:956653b6d3ad
U-Blox?UBX????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kim1212 | 0:956653b6d3ad | 1 | #include "ublox_Nav.h" |
kim1212 | 0:956653b6d3ad | 2 | |
kim1212 | 0:956653b6d3ad | 3 | |
kim1212 | 0:956653b6d3ad | 4 | GPS::GPS(PinName mosi,PinName miso,PinName sck,PinName _cs):_gps(mosi,miso,sck),cs(_cs){ |
kim1212 | 0:956653b6d3ad | 5 | cs=1; |
kim1212 | 0:956653b6d3ad | 6 | _gps.frequency(5500000); |
kim1212 | 0:956653b6d3ad | 7 | } |
kim1212 | 0:956653b6d3ad | 8 | |
kim1212 | 0:956653b6d3ad | 9 | bool GPS::updateData(){ |
kim1212 | 0:956653b6d3ad | 10 | bool flag=false; |
kim1212 | 0:956653b6d3ad | 11 | |
kim1212 | 0:956653b6d3ad | 12 | cs=0; |
kim1212 | 0:956653b6d3ad | 13 | |
kim1212 | 0:956653b6d3ad | 14 | //読み込みバッファ |
kim1212 | 0:956653b6d3ad | 15 | static unsigned char val[2]; |
kim1212 | 0:956653b6d3ad | 16 | |
kim1212 | 0:956653b6d3ad | 17 | val[0]=val[1]; |
kim1212 | 0:956653b6d3ad | 18 | val[1]=_gps.write(0xFF); |
kim1212 | 0:956653b6d3ad | 19 | |
kim1212 | 0:956653b6d3ad | 20 | if(val[0]==0xb5&&val[1]==0x62){ |
kim1212 | 0:956653b6d3ad | 21 | |
kim1212 | 0:956653b6d3ad | 22 | flag=true; //flagをtrueに |
kim1212 | 0:956653b6d3ad | 23 | |
kim1212 | 0:956653b6d3ad | 24 | buf0[0]=val[0]; |
kim1212 | 0:956653b6d3ad | 25 | |
kim1212 | 0:956653b6d3ad | 26 | for(int i=1;i<50;i++){ |
kim1212 | 0:956653b6d3ad | 27 | |
kim1212 | 0:956653b6d3ad | 28 | //読み込みバッファ更新 |
kim1212 | 0:956653b6d3ad | 29 | val[0]=val[1]; |
kim1212 | 0:956653b6d3ad | 30 | val[1]=_gps.write(0xFF); |
kim1212 | 0:956653b6d3ad | 31 | |
kim1212 | 0:956653b6d3ad | 32 | if(val[0]==0xb5&&val[1]==0x62){ |
kim1212 | 0:956653b6d3ad | 33 | i=0; |
kim1212 | 0:956653b6d3ad | 34 | for(int j=0;j<50;j++) buf2[j]=buf1[j]; |
kim1212 | 0:956653b6d3ad | 35 | for(int j=0;j<50;j++) buf1[j]=buf0[j]; |
kim1212 | 0:956653b6d3ad | 36 | |
kim1212 | 0:956653b6d3ad | 37 | } |
kim1212 | 0:956653b6d3ad | 38 | |
kim1212 | 0:956653b6d3ad | 39 | buf0[i]=val[0]; |
kim1212 | 0:956653b6d3ad | 40 | |
kim1212 | 0:956653b6d3ad | 41 | } |
kim1212 | 0:956653b6d3ad | 42 | |
kim1212 | 0:956653b6d3ad | 43 | |
kim1212 | 0:956653b6d3ad | 44 | //GPSモジュールから来たデータを読み取り構造体に代入 |
kim1212 | 0:956653b6d3ad | 45 | for(int i=6;i<TIMEUTC_LEN+6;i++){ |
kim1212 | 0:956653b6d3ad | 46 | timeData.Raw[i-6]=buf0[i]; |
kim1212 | 0:956653b6d3ad | 47 | } |
kim1212 | 0:956653b6d3ad | 48 | |
kim1212 | 0:956653b6d3ad | 49 | |
kim1212 | 0:956653b6d3ad | 50 | for(int i=6;i<VELNED_LEN+6;i++){ |
kim1212 | 0:956653b6d3ad | 51 | velData.Raw[i-6]=buf1[i]; |
kim1212 | 0:956653b6d3ad | 52 | } |
kim1212 | 0:956653b6d3ad | 53 | |
kim1212 | 0:956653b6d3ad | 54 | |
kim1212 | 0:956653b6d3ad | 55 | for(int i=6;i<POSLLH_LEN+6;i++){ |
kim1212 | 0:956653b6d3ad | 56 | posData.Raw[i-6]=buf2[i]; |
kim1212 | 0:956653b6d3ad | 57 | } |
kim1212 | 0:956653b6d3ad | 58 | |
kim1212 | 0:956653b6d3ad | 59 | } |
kim1212 | 0:956653b6d3ad | 60 | |
kim1212 | 0:956653b6d3ad | 61 | cs=1; |
kim1212 | 0:956653b6d3ad | 62 | |
kim1212 | 0:956653b6d3ad | 63 | return flag; |
kim1212 | 0:956653b6d3ad | 64 | |
kim1212 | 0:956653b6d3ad | 65 | } |
kim1212 | 0:956653b6d3ad | 66 | |
kim1212 | 0:956653b6d3ad | 67 | void GPS::chkData(obsvdData *obs){ |
kim1212 | 0:956653b6d3ad | 68 | |
kim1212 | 0:956653b6d3ad | 69 | obs->Lon=posData.Data.lon; |
kim1212 | 0:956653b6d3ad | 70 | obs->Lat=posData.Data.lat; |
kim1212 | 0:956653b6d3ad | 71 | obs->GHeight=posData.Data.height; |
kim1212 | 0:956653b6d3ad | 72 | |
kim1212 | 0:956653b6d3ad | 73 | obs->VelN=velData.Data.velN; |
kim1212 | 0:956653b6d3ad | 74 | obs->VelE=velData.Data.velE; |
kim1212 | 0:956653b6d3ad | 75 | obs->VelD=velData.Data.velD; |
kim1212 | 0:956653b6d3ad | 76 | |
kim1212 | 0:956653b6d3ad | 77 | } |
kim1212 | 0:956653b6d3ad | 78 | |
kim1212 | 0:956653b6d3ad | 79 | void GPS::chkTime(timData* t){ |
kim1212 | 0:956653b6d3ad | 80 | t->Year=(int)timeData.Data.year; |
kim1212 | 0:956653b6d3ad | 81 | t->Month=(int)timeData.Data.month; |
kim1212 | 0:956653b6d3ad | 82 | t->Day=(int)timeData.Data.day; |
kim1212 | 0:956653b6d3ad | 83 | t->Hour=(int)timeData.Data.hour+9; //日本標準時に変換 |
kim1212 | 0:956653b6d3ad | 84 | t->Min=(int)timeData.Data.min; |
kim1212 | 0:956653b6d3ad | 85 | t->Sec=(int)timeData.Data.sec; |
kim1212 | 0:956653b6d3ad | 86 | } |