2017年伊豆大島共同打ち上げ実験用電装モジュール搭載GPS測位プログラム

Dependents:   Hybrid_interruptGPS Hybrid_main_FirstEdtion rocket_logger_sinkan2018_v1 HYBRYD2018_IZU_ROCKET ... more

Committer:
Gaku0606
Date:
Mon Jan 02 18:48:44 2017 +0000
Revision:
2:7be89bab6db9
Parent:
1:57eeee14dd31
Child:
3:8e66ec281888
GPS_interrupt.lib ver1.2.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gaku0606 0:74d8e952a3bd 1 /*=============================================================================
Gaku0606 2:7be89bab6db9 2 * GPS_interrupt.lib ver 1.2.5
Gaku0606 0:74d8e952a3bd 3 *
Gaku0606 1:57eeee14dd31 4 * Each palameters are not stable because they can be changed unexpectedly.
Gaku0606 1:57eeee14dd31 5 * Therefor, you should use the funtions which have return value.
Gaku0606 1:57eeee14dd31 6 * Then, you must not substitute any value for those palameters.
Gaku0606 2:7be89bab6db9 7 * なんかコマンドの送信ミスがあるみたいで、確認して次に進めるようにすべきかも
Gaku0606 2:7be89bab6db9 8 * PCソフトで設定して、バックアップ電池付けるのが正確っぽい
Gaku0606 0:74d8e952a3bd 9 *=============================================================================*/
Gaku0606 0:74d8e952a3bd 10 #ifndef GPS_INTERRUPT_H_
Gaku0606 0:74d8e952a3bd 11 #define GPS_INTERRUPT_H_
Gaku0606 0:74d8e952a3bd 12
Gaku0606 2:7be89bab6db9 13 #include "mbed.h"//要る?
Gaku0606 0:74d8e952a3bd 14
Gaku0606 0:74d8e952a3bd 15 class GPS_interrupt{
Gaku0606 0:74d8e952a3bd 16
Gaku0606 0:74d8e952a3bd 17 public:
Gaku0606 2:7be89bab6db9 18 /**=====================================================================
Gaku0606 2:7be89bab6db9 19 * @brief GPS_interrupt's constructer
Gaku0606 2:7be89bab6db9 20 * @param *_gps : your Rawserial bus address
Gaku0606 2:7be89bab6db9 21 * @param _baudrate : baudrate you want to communication with GPS module
Gaku0606 2:7be89bab6db9 22 * @param _frequency : set updata rate
Gaku0606 2:7be89bab6db9 23 * @param start_baudrate : baudrate in starting link
Gaku0606 2:7be89bab6db9 24 *=======================================================================*/
Gaku0606 2:7be89bab6db9 25 GPS_interrupt(RawSerial *_gps, int _baudrate = 115200, int _frequency = 10, int start_baudrate = 9600);
Gaku0606 0:74d8e952a3bd 26 static GPS_interrupt* gps_irq;
Gaku0606 0:74d8e952a3bd 27 void initialize();//初期化関数
Gaku0606 0:74d8e952a3bd 28 void gps_auto_receive();
Gaku0606 2:7be89bab6db9 29 bool processGPRMC(char *line);
Gaku0606 2:7be89bab6db9 30 bool processGPGGA(char *line);
Gaku0606 2:7be89bab6db9 31 void debug(char *str);
Gaku0606 2:7be89bab6db9 32 unsigned char checkSum(char *str);
Gaku0606 2:7be89bab6db9 33 void rmc_initialize();
Gaku0606 2:7be89bab6db9 34 void gga_initialize();
Gaku0606 0:74d8e952a3bd 35
Gaku0606 2:7be89bab6db9 36 private://別にpublicにしても良かったけれど、unexpectedlyに変更されるので使えないようにしてやった
Gaku0606 2:7be89bab6db9 37 int baudrate;
Gaku0606 2:7be89bab6db9 38 int frequency;
Gaku0606 2:7be89bab6db9 39
Gaku0606 0:74d8e952a3bd 40 static double latitude;
Gaku0606 0:74d8e952a3bd 41 static double longitude;
Gaku0606 0:74d8e952a3bd 42 static int year;
Gaku0606 0:74d8e952a3bd 43 static int month;
Gaku0606 0:74d8e952a3bd 44 static int day;
Gaku0606 0:74d8e952a3bd 45 static int hour;
Gaku0606 0:74d8e952a3bd 46 static int minutes;
Gaku0606 0:74d8e952a3bd 47 static double seconds;
Gaku0606 0:74d8e952a3bd 48 static double knot;
Gaku0606 0:74d8e952a3bd 49 static double degree;
Gaku0606 0:74d8e952a3bd 50 static double height;
Gaku0606 0:74d8e952a3bd 51 static double geoid;
Gaku0606 0:74d8e952a3bd 52 static int number;
Gaku0606 0:74d8e952a3bd 53
Gaku0606 0:74d8e952a3bd 54 static char gps_buffer_A[128];
Gaku0606 0:74d8e952a3bd 55 static char gps_buffer_B[128];
Gaku0606 2:7be89bab6db9 56
Gaku0606 2:7be89bab6db9 57 public:
Gaku0606 0:74d8e952a3bd 58 static char *gps_read_buffer;
Gaku0606 0:74d8e952a3bd 59 static bool gps_readable;
Gaku0606 0:74d8e952a3bd 60 private:
Gaku0606 0:74d8e952a3bd 61 RawSerial *gps;
Gaku0606 0:74d8e952a3bd 62 public:
Gaku0606 0:74d8e952a3bd 63 inline double Longitude(){
Gaku0606 0:74d8e952a3bd 64 return longitude;
Gaku0606 0:74d8e952a3bd 65 }
Gaku0606 0:74d8e952a3bd 66 inline double Latitude(){
Gaku0606 0:74d8e952a3bd 67 return latitude;
Gaku0606 0:74d8e952a3bd 68 }
Gaku0606 0:74d8e952a3bd 69 inline int Year(){
Gaku0606 0:74d8e952a3bd 70 return year;
Gaku0606 0:74d8e952a3bd 71 }
Gaku0606 0:74d8e952a3bd 72 inline int Month(){
Gaku0606 0:74d8e952a3bd 73 return month;
Gaku0606 0:74d8e952a3bd 74 }
Gaku0606 0:74d8e952a3bd 75 inline int Day(){
Gaku0606 0:74d8e952a3bd 76 return day;
Gaku0606 0:74d8e952a3bd 77 }
Gaku0606 0:74d8e952a3bd 78 inline int Hour(){
Gaku0606 0:74d8e952a3bd 79 return hour;
Gaku0606 0:74d8e952a3bd 80 }
Gaku0606 0:74d8e952a3bd 81 inline int Minutes(){
Gaku0606 0:74d8e952a3bd 82 return minutes;
Gaku0606 0:74d8e952a3bd 83 }
Gaku0606 0:74d8e952a3bd 84 inline double Seconds(){
Gaku0606 0:74d8e952a3bd 85 return seconds;
Gaku0606 0:74d8e952a3bd 86 }
Gaku0606 0:74d8e952a3bd 87 inline void getPosition(double *lon, double *lat){
Gaku0606 0:74d8e952a3bd 88 *lon = longitude;
Gaku0606 0:74d8e952a3bd 89 *lat = latitude;
Gaku0606 0:74d8e952a3bd 90 }
Gaku0606 0:74d8e952a3bd 91 inline void getPosition(double *lonlat){
Gaku0606 0:74d8e952a3bd 92 lonlat[0] = longitude;
Gaku0606 0:74d8e952a3bd 93 lonlat[1] = latitude;
Gaku0606 0:74d8e952a3bd 94 }
Gaku0606 0:74d8e952a3bd 95 inline void getUTC(int *_year, int *_month, int *_day, int *_hour, int *_minutes, double *_seconds){
Gaku0606 0:74d8e952a3bd 96 *_year = year;
Gaku0606 0:74d8e952a3bd 97 *_month = month;
Gaku0606 0:74d8e952a3bd 98 *_day = day;
Gaku0606 0:74d8e952a3bd 99 *_hour = hour;
Gaku0606 0:74d8e952a3bd 100 *_minutes = minutes;
Gaku0606 0:74d8e952a3bd 101 *_seconds = seconds;
Gaku0606 0:74d8e952a3bd 102 }
Gaku0606 0:74d8e952a3bd 103 inline void getUTC(float *_utc){
Gaku0606 0:74d8e952a3bd 104 _utc[0] = (float)year;
Gaku0606 0:74d8e952a3bd 105 _utc[1] = (float)month;
Gaku0606 0:74d8e952a3bd 106 _utc[2] = (float)day;
Gaku0606 0:74d8e952a3bd 107 _utc[3] = (float)hour;
Gaku0606 0:74d8e952a3bd 108 _utc[4] = (float)minutes;
Gaku0606 0:74d8e952a3bd 109 _utc[5] = seconds;
Gaku0606 0:74d8e952a3bd 110 }
Gaku0606 0:74d8e952a3bd 111 inline void getUTC(int *_utc){
Gaku0606 0:74d8e952a3bd 112 _utc[0] = year;
Gaku0606 0:74d8e952a3bd 113 _utc[1] = month;
Gaku0606 0:74d8e952a3bd 114 _utc[2] = day;
Gaku0606 0:74d8e952a3bd 115 _utc[3] = hour;
Gaku0606 0:74d8e952a3bd 116 _utc[4] = minutes;
Gaku0606 0:74d8e952a3bd 117 _utc[5] = (int)seconds;
Gaku0606 0:74d8e952a3bd 118 }
Gaku0606 2:7be89bab6db9 119 inline void getSpeedVector(double *_knot, double *_degree){
Gaku0606 2:7be89bab6db9 120 *_knot = knot;
Gaku0606 2:7be89bab6db9 121 *_degree = degree;
Gaku0606 2:7be89bab6db9 122 }
Gaku0606 2:7be89bab6db9 123 inline int Number(){
Gaku0606 2:7be89bab6db9 124 return number;
Gaku0606 2:7be89bab6db9 125 }
Gaku0606 2:7be89bab6db9 126 inline double Height(){
Gaku0606 2:7be89bab6db9 127 return height;
Gaku0606 2:7be89bab6db9 128 }
Gaku0606 2:7be89bab6db9 129 inline double Knot(){
Gaku0606 2:7be89bab6db9 130 return knot;
Gaku0606 2:7be89bab6db9 131 }
Gaku0606 2:7be89bab6db9 132 inline double Degree(){
Gaku0606 2:7be89bab6db9 133 return degree;
Gaku0606 2:7be89bab6db9 134 }
Gaku0606 0:74d8e952a3bd 135 };
Gaku0606 1:57eeee14dd31 136 /////////////////
Gaku0606 1:57eeee14dd31 137 /////sample//////
Gaku0606 1:57eeee14dd31 138 /////////////////
Gaku0606 1:57eeee14dd31 139 /*
Gaku0606 1:57eeee14dd31 140 #include "mbed.h"
Gaku0606 1:57eeee14dd31 141 #include "GPS_interrupt.h"
Gaku0606 1:57eeee14dd31 142 Serial pc(USBTX, USBRX);
Gaku0606 1:57eeee14dd31 143 RawSerial mygps(p9, p10);
Gaku0606 0:74d8e952a3bd 144
Gaku0606 2:7be89bab6db9 145 GPS_interrupt gps(&mygps, 115200, 10, 115200);
Gaku0606 2:7be89bab6db9 146
Gaku0606 2:7be89bab6db9 147 void bootFunction(){//do not need
Gaku0606 2:7be89bab6db9 148 pc.printf("\r\n");
Gaku0606 2:7be89bab6db9 149 pc.printf("start LPC1768 boot phase\r\n");
Gaku0606 2:7be89bab6db9 150 wait(0.5);
Gaku0606 2:7be89bab6db9 151 for(int i = 0;i < 100;i++){
Gaku0606 2:7be89bab6db9 152 pc.printf("Loading... : %3d [%%]\r", i);
Gaku0606 2:7be89bab6db9 153 wait(0.025);
Gaku0606 2:7be89bab6db9 154 }
Gaku0606 2:7be89bab6db9 155 pc.printf("Loading... : %3d [%%]\r\n", 100);
Gaku0606 2:7be89bab6db9 156 pc.printf("\t-> finished!!\r\n");
Gaku0606 2:7be89bab6db9 157 pc.printf("System : %d Hz\r\n", SystemCoreClock );
Gaku0606 2:7be89bab6db9 158 wait(0.5);
Gaku0606 2:7be89bab6db9 159 pc.printf("start main program\r\n");
Gaku0606 2:7be89bab6db9 160 wait(0.1);
Gaku0606 2:7be89bab6db9 161 pc.printf("initialize");
Gaku0606 2:7be89bab6db9 162 wait(0.75);
Gaku0606 2:7be89bab6db9 163 pc.printf(" -> OK\r\n");
Gaku0606 2:7be89bab6db9 164 wait(0.1);
Gaku0606 2:7be89bab6db9 165 pc.printf("GPS Connecting");
Gaku0606 2:7be89bab6db9 166 wait(0.5);
Gaku0606 2:7be89bab6db9 167 pc.printf(".");
Gaku0606 2:7be89bab6db9 168 wait(0.5);
Gaku0606 2:7be89bab6db9 169 pc.printf(".");
Gaku0606 2:7be89bab6db9 170 wait(0.5);
Gaku0606 2:7be89bab6db9 171 pc.printf(".");
Gaku0606 2:7be89bab6db9 172 wait(0.5);
Gaku0606 2:7be89bab6db9 173 pc.printf(".");
Gaku0606 2:7be89bab6db9 174 wait(0.5);
Gaku0606 2:7be89bab6db9 175 pc.printf(".");
Gaku0606 2:7be89bab6db9 176 wait(0.5);
Gaku0606 2:7be89bab6db9 177 pc.printf(".");
Gaku0606 2:7be89bab6db9 178 wait(0.5);
Gaku0606 2:7be89bab6db9 179 while(1){
Gaku0606 2:7be89bab6db9 180 if(gps.gps_readable) break;
Gaku0606 2:7be89bab6db9 181 }
Gaku0606 2:7be89bab6db9 182 pc.printf(" -> OK\r\n");
Gaku0606 2:7be89bab6db9 183 pc.printf("start!!\r\n\r\n");
Gaku0606 2:7be89bab6db9 184 wait(0.5);
Gaku0606 2:7be89bab6db9 185 }
Gaku0606 1:57eeee14dd31 186
Gaku0606 1:57eeee14dd31 187 int main() {
Gaku0606 1:57eeee14dd31 188
Gaku0606 1:57eeee14dd31 189 pc.baud(115200);
Gaku0606 2:7be89bab6db9 190 //mygps.baud(9600);
Gaku0606 1:57eeee14dd31 191
Gaku0606 2:7be89bab6db9 192 bootFunction();
Gaku0606 1:57eeee14dd31 193
Gaku0606 1:57eeee14dd31 194 while(1){
Gaku0606 2:7be89bab6db9 195 double xy[2] = {0};
Gaku0606 2:7be89bab6db9 196 float utc[6] = {0};
Gaku0606 2:7be89bab6db9 197 gps.getPosition(xy);
Gaku0606 2:7be89bab6db9 198 gps.getUTC(utc);
Gaku0606 2:7be89bab6db9 199 pc.printf("\033[K");
Gaku0606 2:7be89bab6db9 200 pc.printf("%d/%d/%d %d:%d:%02.2f ",(int)utc[0],(int)utc[1], (int)utc[2], (int)utc[3], (int)utc[4] ,utc[5]);
Gaku0606 2:7be89bab6db9 201 pc.printf("(%3.7fe,%3.7fn) ",xy[0], xy[1]);
Gaku0606 2:7be89bab6db9 202 pc.printf("%d satellites, %.2f[m], %.3f[m/s], %3.2f[degree]\r", gps.Number(), gps.Height(), gps.Knot()*1852/3600, gps.Degree());
Gaku0606 2:7be89bab6db9 203 wait(0.1);
Gaku0606 1:57eeee14dd31 204 }
Gaku0606 1:57eeee14dd31 205 }
Gaku0606 2:7be89bab6db9 206
Gaku0606 1:57eeee14dd31 207 */
Gaku0606 0:74d8e952a3bd 208 #endif