Skytraq S1315F-RAW-EVK Logger

Dependencies:   TextLCD mbed

Committer:
tosihisa
Date:
Sat Dec 18 17:45:25 2010 +0000
Revision:
1:d1bb695fe3bc
Parent:
0:e0ec137da369
Child:
2:7eb11afe02bd
Debug finished.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tosihisa 0:e0ec137da369 1
tosihisa 0:e0ec137da369 2 /*
tosihisa 0:e0ec137da369 3 * S1315F-RAW-EVK Logger
tosihisa 0:e0ec137da369 4 * (c) @tosihisa http://twitter.com/tosihisa
tosihisa 0:e0ec137da369 5 */
tosihisa 0:e0ec137da369 6
tosihisa 0:e0ec137da369 7 #include "mbed.h"
tosihisa 0:e0ec137da369 8 #include "TextLCD.h"
tosihisa 0:e0ec137da369 9 #include "SDFileSystem.h"
tosihisa 0:e0ec137da369 10 #include "libT/mbed/tserialbuffer.h"
tosihisa 0:e0ec137da369 11
tosihisa 0:e0ec137da369 12 #define OUTPUT_RATE_1HZ
tosihisa 0:e0ec137da369 13
tosihisa 1:d1bb695fe3bc 14 #define FSNAME "sd"
tosihisa 1:d1bb695fe3bc 15
tosihisa 0:e0ec137da369 16 using namespace libT;
tosihisa 0:e0ec137da369 17
tosihisa 0:e0ec137da369 18 Serial debug(USBTX,USBRX);
tosihisa 0:e0ec137da369 19 InterruptIn PPS(p15);
tosihisa 0:e0ec137da369 20 PwmOut PPSLED(LED1);
tosihisa 0:e0ec137da369 21 PwmOut LOGLED(LED4);
tosihisa 0:e0ec137da369 22 tSerialBuffer gps(p13,p14);
tosihisa 0:e0ec137da369 23 DigitalIn LogSW(p22);
tosihisa 0:e0ec137da369 24 Ticker timer;
tosihisa 0:e0ec137da369 25
tosihisa 0:e0ec137da369 26 TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
tosihisa 1:d1bb695fe3bc 27 SDFileSystem sd(p5, p6, p7, p8, FSNAME);
tosihisa 0:e0ec137da369 28
tosihisa 0:e0ec137da369 29 int logSW_state[2] = { 0 , 0 };
tosihisa 0:e0ec137da369 30 int logSW_idx = 0;
tosihisa 0:e0ec137da369 31 unsigned long jif = 0;
tosihisa 1:d1bb695fe3bc 32 int do_disp = 0;
tosihisa 0:e0ec137da369 33 void timer_handler()
tosihisa 0:e0ec137da369 34 {
tosihisa 1:d1bb695fe3bc 35 logSW_state[logSW_idx] = (LogSW == 0) ? 1 : 0;
tosihisa 0:e0ec137da369 36 logSW_idx = (logSW_idx + 1) & 1;
tosihisa 0:e0ec137da369 37 jif++;
tosihisa 1:d1bb695fe3bc 38 do_disp++;
tosihisa 0:e0ec137da369 39 }
tosihisa 0:e0ec137da369 40
tosihisa 0:e0ec137da369 41 int pps_count = 0;
tosihisa 0:e0ec137da369 42 void pps_rise()
tosihisa 0:e0ec137da369 43 {
tosihisa 0:e0ec137da369 44 pps_count++;
tosihisa 0:e0ec137da369 45 if(pps_count & 1)
tosihisa 1:d1bb695fe3bc 46 PPSLED=0.80;
tosihisa 0:e0ec137da369 47 else
tosihisa 0:e0ec137da369 48 PPSLED=0.0;
tosihisa 0:e0ec137da369 49 }
tosihisa 0:e0ec137da369 50
tosihisa 0:e0ec137da369 51 typedef struct Skytraq_bin_info_s {
tosihisa 0:e0ec137da369 52 int cjobst;
tosihisa 0:e0ec137da369 53 unsigned short len;
tosihisa 0:e0ec137da369 54 unsigned short recv;
tosihisa 0:e0ec137da369 55 unsigned char sum;
tosihisa 0:e0ec137da369 56 unsigned char ID;
tosihisa 0:e0ec137da369 57 unsigned char body[2048];
tosihisa 0:e0ec137da369 58 void *work;
tosihisa 0:e0ec137da369 59
tosihisa 0:e0ec137da369 60 unsigned long KERNEL_ver;
tosihisa 0:e0ec137da369 61 unsigned long ODM_ver;
tosihisa 0:e0ec137da369 62 unsigned long Revision;
tosihisa 0:e0ec137da369 63 } Skytraq_bin_info_t;
tosihisa 0:e0ec137da369 64
tosihisa 0:e0ec137da369 65 typedef struct Skytraq_ID_s {
tosihisa 0:e0ec137da369 66 unsigned char ID;
tosihisa 0:e0ec137da369 67 int (*func)(Skytraq_bin_info_t *info);
tosihisa 0:e0ec137da369 68 char *name;
tosihisa 0:e0ec137da369 69 } Skytraq_ID_t;
tosihisa 0:e0ec137da369 70
tosihisa 0:e0ec137da369 71 int Skytraq_0x80(Skytraq_bin_info_t *info)
tosihisa 0:e0ec137da369 72 {
tosihisa 0:e0ec137da369 73 int idx = 1;
tosihisa 0:e0ec137da369 74
tosihisa 0:e0ec137da369 75 info->KERNEL_ver = 0;
tosihisa 0:e0ec137da369 76 info->KERNEL_ver = (info->KERNEL_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 77 info->KERNEL_ver = (info->KERNEL_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 78 info->KERNEL_ver = (info->KERNEL_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 79 info->KERNEL_ver = (info->KERNEL_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 80
tosihisa 0:e0ec137da369 81 info->ODM_ver = 0;
tosihisa 0:e0ec137da369 82 info->ODM_ver = (info->ODM_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 83 info->ODM_ver = (info->ODM_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 84 info->ODM_ver = (info->ODM_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 85 info->ODM_ver = (info->ODM_ver << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 86
tosihisa 0:e0ec137da369 87 info->Revision = 0;
tosihisa 0:e0ec137da369 88 info->Revision = (info->Revision << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 89 info->Revision = (info->Revision << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 90 info->Revision = (info->Revision << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 91 info->Revision = (info->Revision << 8) | info->body[idx]; idx++;
tosihisa 0:e0ec137da369 92
tosihisa 0:e0ec137da369 93 for(idx = 0;idx < 14;idx++){
tosihisa 0:e0ec137da369 94 debug.printf("%02x ",info->body[idx]);
tosihisa 0:e0ec137da369 95 }
tosihisa 0:e0ec137da369 96 debug.printf("\n");
tosihisa 0:e0ec137da369 97 debug.printf("KERNEL:0x%08x , ODM:0x%08x , Rev:0x%08x\n",info->KERNEL_ver,info->ODM_ver,info->Revision);
tosihisa 0:e0ec137da369 98
tosihisa 0:e0ec137da369 99 return 0;
tosihisa 0:e0ec137da369 100 }
tosihisa 0:e0ec137da369 101
tosihisa 1:d1bb695fe3bc 102 int Skytraq_0x83(Skytraq_bin_info_t *info)
tosihisa 1:d1bb695fe3bc 103 {
tosihisa 1:d1bb695fe3bc 104 debug.printf("\n");
tosihisa 1:d1bb695fe3bc 105 debug.printf("ACK ID:0x%02x\n",info->body[0]);
tosihisa 1:d1bb695fe3bc 106 return 0;
tosihisa 1:d1bb695fe3bc 107 }
tosihisa 1:d1bb695fe3bc 108
tosihisa 0:e0ec137da369 109 Skytraq_ID_t Skytraq_ID_List[] = {
tosihisa 0:e0ec137da369 110 { 0x01 ,NULL,"Input System Restart Force system to restart"},
tosihisa 0:e0ec137da369 111 { 0x02 ,NULL,"Input Query Software version Query revision information of software"},
tosihisa 0:e0ec137da369 112 { 0x03 ,NULL,"Input Query Software CRC Query the CRC of the software"},
tosihisa 0:e0ec137da369 113 { 0x04 ,NULL,"Input Set Factory Defaults Set system to factory default values"},
tosihisa 0:e0ec137da369 114 { 0x05 ,NULL,"Input Configure Serial Port Set up serial port COM, baud rate, data bits, stop bits and parity"},
tosihisa 0:e0ec137da369 115 { 0x06 ,NULL,"Input Reserved Reserved"},
tosihisa 0:e0ec137da369 116 { 0x07 ,NULL,"Input Reserved Reserved"},
tosihisa 0:e0ec137da369 117 { 0x08 ,NULL,"Input Configure NMEA Configure NMEA output message"},
tosihisa 0:e0ec137da369 118 { 0x09 ,NULL,"Input Configure Output Message Format Configure the output message format from GPS receiver" },
tosihisa 0:e0ec137da369 119 { 0x0C ,NULL,"Input Configure Power Mode Set system power mode" },
tosihisa 0:e0ec137da369 120 { 0x0E ,NULL,"Input Configure position update rate Configure the position update rate of GPS system" },
tosihisa 0:e0ec137da369 121 { 0x10 ,NULL,"Input Query position update rate Query the position update rate of GPS system" },
tosihisa 0:e0ec137da369 122 { 0x11 ,NULL,"Input Get Almanac Retrieve almanac data of the GPS receiver" },
tosihisa 0:e0ec137da369 123 { 0x12 ,NULL,"Input Configure binary measurement output rates Configure the output rates of the binary measurement outputs Input GPS Messages" },
tosihisa 0:e0ec137da369 124 { 0x29 ,NULL,"Input Configure Datum Configure Datum of the GPS receiver" },
tosihisa 0:e0ec137da369 125 { 0x2D ,NULL,"Input Query Datum Query datum used by the GPS receiver" },
tosihisa 0:e0ec137da369 126 { 0x30 ,NULL,"Input Get Ephemeris Retrieve ephemeris data of the GPS receiver Output System Messages" },
tosihisa 0:e0ec137da369 127 { 0x31 ,NULL,"Input Set ephemeris Set ephemeris data to the GPS receiver" },
tosihisa 0:e0ec137da369 128 { 0x37 ,NULL,"Input Configure WAAS Configure the enable or disable of WAAS" },
tosihisa 0:e0ec137da369 129 { 0x38 ,NULL,"Input Query WAAS status Query WAAS status of GPS receiver" },
tosihisa 0:e0ec137da369 130 { 0x39 ,NULL,"Input Configure position pinning Enable or disable position pinning of GPS receiver" },
tosihisa 0:e0ec137da369 131 { 0x3A ,NULL,"Input Query position pinning Query position pinning status of the GPS receiver" },
tosihisa 0:e0ec137da369 132 { 0x3B ,NULL,"Input Configure position pinning parameters Set position pinning parameters of GPS receiver" },
tosihisa 0:e0ec137da369 133 { 0x3C ,NULL,"Input Configuration navigation mode Configure the navigation mode of GPS system" },
tosihisa 0:e0ec137da369 134 { 0x3D ,NULL,"Input Query navigation mode Query the navigation mode of GPS receiver" },
tosihisa 0:e0ec137da369 135 { 0x3E ,NULL,"Input Configure 1PPS mode Set 1PPS mode to the GPS receiver" },
tosihisa 0:e0ec137da369 136 { 0x3F ,NULL,"Input Query 1PPS mode Query 1PPS mode of the GPS receiver" },
tosihisa 0:e0ec137da369 137 { 0x80 ,Skytraq_0x80,"Output Software version Software revision of the receiver" },
tosihisa 0:e0ec137da369 138 { 0x81 ,NULL,"Output Software CRC Software CRC of the receiver" },
tosihisa 0:e0ec137da369 139 { 0x82 ,NULL,"Output Reserved Reserved" },
tosihisa 1:d1bb695fe3bc 140 { 0x83 ,Skytraq_0x83,"Output ACK ACK to a successful input message" },
tosihisa 0:e0ec137da369 141 { 0x84 ,NULL,"Output NACK Response to an unsuccessful input message" },
tosihisa 0:e0ec137da369 142 { 0x86 ,NULL,"Output Position update rate Position update rate of GPS system" },
tosihisa 0:e0ec137da369 143 { 0x87 ,NULL,"Output GPS Almanac Data Outputting the GPS Almanac Data of GPS receiver"},
tosihisa 0:e0ec137da369 144 { 0xAE ,NULL,"Output GPS Datum Datum used by the GPS receiver"},
tosihisa 0:e0ec137da369 145 { 0xB1 ,NULL,"Output GPS Ephemeris Data Outputting the GPS Ephemeris Data of GPS receiver"},
tosihisa 0:e0ec137da369 146 { 0xB3 ,NULL,"Output GPS WAAS status WAAS status of the GPS receiver"},
tosihisa 0:e0ec137da369 147 { 0xB4 ,NULL,"Output GPS Position pinning status Position pinning status of the GPS receiver"},
tosihisa 0:e0ec137da369 148 { 0xB5 ,NULL,"Output GPS navigation mode Navigation mode of the GPS receiver"},
tosihisa 0:e0ec137da369 149 { 0xB6 ,NULL,"Output GPS 1PPS mode 1PPS mode of GPS receiver"},
tosihisa 0:e0ec137da369 150 { 0xDC ,NULL,"Output MEAS_TIME Measurement time information"},
tosihisa 0:e0ec137da369 151 { 0xDD ,NULL,"Output RAW_MEAS Raw channel measurements"},
tosihisa 0:e0ec137da369 152 { 0xDE ,NULL,"Output SV_CH_STATUS SV and Channel status information"},
tosihisa 0:e0ec137da369 153 { 0xDF ,NULL,"Output RCV_STATE GPS receiver navigation state"},
tosihisa 0:e0ec137da369 154 { 0xE0 ,NULL,"Output SUBFRAME Subframe buffer data"},
tosihisa 0:e0ec137da369 155 { 0xFF ,NULL,"****UNKNOWN****"}
tosihisa 0:e0ec137da369 156 };
tosihisa 0:e0ec137da369 157
tosihisa 1:d1bb695fe3bc 158 unsigned char Skytraq_QUERY_SOFTWARE_VERSION[] = {0x02,0x01};
tosihisa 0:e0ec137da369 159 unsigned char Skytraq_set_rate[] = {
tosihisa 0:e0ec137da369 160 0x12, /* ID */
tosihisa 0:e0ec137da369 161 0x00, /* 00: 1Hz / 01: 2Hz / 02: 4Hz / 03: 5Hz / 04: 10Hz / 05: 20Hz / Others: 20Hz */
tosihisa 0:e0ec137da369 162 0x01, /* Meas_time Enabling */
tosihisa 0:e0ec137da369 163 0x01, /* Raw_meas Enabling */
tosihisa 0:e0ec137da369 164 0x00, /* SV_CH_Staus Enabling */
tosihisa 0:e0ec137da369 165 0x00, /* RCV_State Enabling */
tosihisa 0:e0ec137da369 166 0x00, /* Subframe Enabling */
tosihisa 0:e0ec137da369 167 0x00 /* Attributes */
tosihisa 0:e0ec137da369 168 };
tosihisa 0:e0ec137da369 169
tosihisa 0:e0ec137da369 170 void Skytraq_bin_send(unsigned short LEN,unsigned char *body)
tosihisa 0:e0ec137da369 171 {
tosihisa 0:e0ec137da369 172 unsigned short i;
tosihisa 0:e0ec137da369 173 unsigned char sum;
tosihisa 0:e0ec137da369 174 gps.putc(0xA0);
tosihisa 0:e0ec137da369 175 gps.putc(0xA1);
tosihisa 0:e0ec137da369 176 gps.putc((LEN >> 8) & 0x00ff);
tosihisa 0:e0ec137da369 177 gps.putc(LEN & 0x00ff);
tosihisa 0:e0ec137da369 178 sum = 0;
tosihisa 0:e0ec137da369 179 for(i = 0;i < LEN;i++){
tosihisa 0:e0ec137da369 180 gps.putc((char)(*(body+i)));
tosihisa 0:e0ec137da369 181 sum = sum ^ *(body+i);
tosihisa 0:e0ec137da369 182 }
tosihisa 0:e0ec137da369 183 gps.putc(sum);
tosihisa 0:e0ec137da369 184 gps.putc(0x0D);
tosihisa 0:e0ec137da369 185 gps.putc(0x0A);
tosihisa 0:e0ec137da369 186 }
tosihisa 0:e0ec137da369 187
tosihisa 0:e0ec137da369 188 void Skytraq_bin_parse(unsigned char c,Skytraq_bin_info_t *info)
tosihisa 0:e0ec137da369 189 {
tosihisa 0:e0ec137da369 190 if(info->cjobst == 0){
tosihisa 1:d1bb695fe3bc 191 info->cjobst = (c == 0xA0) ? 1 : 0;
tosihisa 0:e0ec137da369 192 } else if(info->cjobst == 1){
tosihisa 1:d1bb695fe3bc 193 info->cjobst = (c == 0xA1) ? 2 : 0;
tosihisa 0:e0ec137da369 194 } else if(info->cjobst == 2){
tosihisa 0:e0ec137da369 195 info->len = c;
tosihisa 0:e0ec137da369 196 info->cjobst = 3;
tosihisa 0:e0ec137da369 197 } else if(info->cjobst == 3){
tosihisa 0:e0ec137da369 198 info->len = (info->len << 8) | c;
tosihisa 0:e0ec137da369 199 info->cjobst = 4;
tosihisa 0:e0ec137da369 200 info->sum = 0;
tosihisa 0:e0ec137da369 201 info->recv = 0;
tosihisa 0:e0ec137da369 202 if(info->len >= sizeof(info->body)){
tosihisa 0:e0ec137da369 203 info->cjobst = 0;
tosihisa 0:e0ec137da369 204 }
tosihisa 0:e0ec137da369 205 } else if(info->cjobst == 4){
tosihisa 0:e0ec137da369 206 if(info->recv == 0){
tosihisa 0:e0ec137da369 207 info->ID = c;
tosihisa 0:e0ec137da369 208 } else {
tosihisa 0:e0ec137da369 209 info->body[info->recv - 1] = c;
tosihisa 0:e0ec137da369 210 }
tosihisa 0:e0ec137da369 211 info->sum = info->sum ^ c;
tosihisa 0:e0ec137da369 212 info->recv++;
tosihisa 0:e0ec137da369 213 if(info->recv >= info->len){
tosihisa 0:e0ec137da369 214 info->cjobst = 5;
tosihisa 0:e0ec137da369 215 }
tosihisa 0:e0ec137da369 216 } else if(info->cjobst == 5){
tosihisa 0:e0ec137da369 217 //debug.printf("sum[%02x][%02x]\n",info->sum,c);
tosihisa 0:e0ec137da369 218 if(info->sum == c){
tosihisa 0:e0ec137da369 219 info->cjobst = 6;
tosihisa 0:e0ec137da369 220 } else {
tosihisa 0:e0ec137da369 221 info->cjobst = 0;
tosihisa 0:e0ec137da369 222 debug.printf("\nSUMERROR[%02x][%02x]\n",info->sum,c);
tosihisa 0:e0ec137da369 223 }
tosihisa 1:d1bb695fe3bc 224 } else if(info->cjobst == 6){
tosihisa 1:d1bb695fe3bc 225 info->cjobst = (c == 0x0D) ? 7 : 0;
tosihisa 1:d1bb695fe3bc 226 } else if(info->cjobst == 7){
tosihisa 1:d1bb695fe3bc 227 info->cjobst = (c == 0x0A) ? 8 : 0;
tosihisa 1:d1bb695fe3bc 228 }
tosihisa 1:d1bb695fe3bc 229 }
tosihisa 1:d1bb695fe3bc 230
tosihisa 1:d1bb695fe3bc 231 char *logDir = "/" FSNAME "/GPSLOG";
tosihisa 1:d1bb695fe3bc 232 unsigned short logNextCount = 0;
tosihisa 1:d1bb695fe3bc 233 int UseLogMemory = 0;
tosihisa 1:d1bb695fe3bc 234
tosihisa 1:d1bb695fe3bc 235 char *logFile_getName(int addDir) {
tosihisa 1:d1bb695fe3bc 236 static char fname[32];
tosihisa 1:d1bb695fe3bc 237 if (addDir) {
tosihisa 1:d1bb695fe3bc 238 snprintf(fname,sizeof(fname)-1,"%s/RAW%05d.STQ",logDir,logNextCount);
tosihisa 1:d1bb695fe3bc 239 } else {
tosihisa 1:d1bb695fe3bc 240 snprintf(fname,sizeof(fname)-1,"RAW%05d.STQ",logNextCount);
tosihisa 1:d1bb695fe3bc 241 }
tosihisa 1:d1bb695fe3bc 242 return fname;
tosihisa 1:d1bb695fe3bc 243 }
tosihisa 1:d1bb695fe3bc 244
tosihisa 1:d1bb695fe3bc 245 void logFile_Init() {
tosihisa 1:d1bb695fe3bc 246 DIR *d;
tosihisa 1:d1bb695fe3bc 247 struct dirent *p;
tosihisa 1:d1bb695fe3bc 248 unsigned short countCandidate;
tosihisa 1:d1bb695fe3bc 249 char *endptr;
tosihisa 1:d1bb695fe3bc 250 int sts;
tosihisa 1:d1bb695fe3bc 251
tosihisa 1:d1bb695fe3bc 252 UseLogMemory = 0;
tosihisa 1:d1bb695fe3bc 253
tosihisa 1:d1bb695fe3bc 254 sts = mkdir(logDir,0777);
tosihisa 1:d1bb695fe3bc 255 debug.printf("mkdir(\"%s\") - %d\n",logDir,sts);
tosihisa 1:d1bb695fe3bc 256 d = opendir(logDir);
tosihisa 1:d1bb695fe3bc 257 if ( d != NULL ) {
tosihisa 1:d1bb695fe3bc 258 while ( (p = readdir(d)) != NULL ) {
tosihisa 1:d1bb695fe3bc 259 debug.printf("FILE - %s\x0d\x0a", p->d_name);
tosihisa 1:d1bb695fe3bc 260 if (strlen(p->d_name) == (sizeof("RAWxxxxx.stq")-1)) {
tosihisa 1:d1bb695fe3bc 261 if ( ((p->d_name[0] == 'R') || (p->d_name[0] == 'r'))
tosihisa 1:d1bb695fe3bc 262 && ((p->d_name[1] == 'A') || (p->d_name[1] == 'a'))
tosihisa 1:d1bb695fe3bc 263 && ((p->d_name[2] == 'W') || (p->d_name[2] == 'w'))) {
tosihisa 1:d1bb695fe3bc 264 }
tosihisa 1:d1bb695fe3bc 265 countCandidate = (unsigned short)strtoul(&(p->d_name[3]),&endptr,10);
tosihisa 1:d1bb695fe3bc 266 if (strcasecmp(endptr,".STQ") == 0) {
tosihisa 1:d1bb695fe3bc 267 if (countCandidate > logNextCount) {
tosihisa 1:d1bb695fe3bc 268 logNextCount = countCandidate;
tosihisa 1:d1bb695fe3bc 269 }
tosihisa 1:d1bb695fe3bc 270 }
tosihisa 1:d1bb695fe3bc 271 }
tosihisa 1:d1bb695fe3bc 272 }
tosihisa 1:d1bb695fe3bc 273 closedir(d);
tosihisa 1:d1bb695fe3bc 274 logNextCount++;
tosihisa 1:d1bb695fe3bc 275 UseLogMemory = 1;
tosihisa 0:e0ec137da369 276 }
tosihisa 0:e0ec137da369 277 }
tosihisa 0:e0ec137da369 278
tosihisa 0:e0ec137da369 279 unsigned char wbuf[512];
tosihisa 0:e0ec137da369 280 int wcnt = 0;
tosihisa 0:e0ec137da369 281
tosihisa 0:e0ec137da369 282 int main() {
tosihisa 0:e0ec137da369 283 Skytraq_bin_info_t bin_info;
tosihisa 0:e0ec137da369 284 int i;
tosihisa 0:e0ec137da369 285 unsigned long recv_bytes = 0;
tosihisa 0:e0ec137da369 286 FILE *fp = NULL;
tosihisa 0:e0ec137da369 287 unsigned char c;
tosihisa 0:e0ec137da369 288
tosihisa 0:e0ec137da369 289 bin_info.cjobst = 0;
tosihisa 0:e0ec137da369 290
tosihisa 0:e0ec137da369 291 debug.format(8,Serial::None,1);
tosihisa 0:e0ec137da369 292 debug.baud(115200);
tosihisa 0:e0ec137da369 293 debug.printf("GPS Logger \"__S1315F__1\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\x0d\x0a");
tosihisa 0:e0ec137da369 294
tosihisa 0:e0ec137da369 295 PPS.rise(pps_rise);
tosihisa 0:e0ec137da369 296
tosihisa 0:e0ec137da369 297 lcd.cls();
tosihisa 0:e0ec137da369 298 lcd.locate(0,0);
tosihisa 0:e0ec137da369 299 lcd.printf("S1315F Logger");
tosihisa 0:e0ec137da369 300
tosihisa 0:e0ec137da369 301 lcd.locate(0,1);
tosihisa 0:e0ec137da369 302 lcd.printf("Please wait");
tosihisa 0:e0ec137da369 303 wait(1.0);
tosihisa 0:e0ec137da369 304
tosihisa 1:d1bb695fe3bc 305 logFile_Init();
tosihisa 1:d1bb695fe3bc 306
tosihisa 1:d1bb695fe3bc 307 lcd.cls();
tosihisa 1:d1bb695fe3bc 308
tosihisa 0:e0ec137da369 309 gps.format(8,Serial::None,1);
tosihisa 0:e0ec137da369 310 gps.baud(115200);
tosihisa 0:e0ec137da369 311 gps.recvStart();
tosihisa 0:e0ec137da369 312
tosihisa 0:e0ec137da369 313 Skytraq_set_rate[1] = 0x05;
tosihisa 0:e0ec137da369 314 #ifdef OUTPUT_RATE_1HZ
tosihisa 0:e0ec137da369 315 Skytraq_set_rate[1] = 0x00;
tosihisa 0:e0ec137da369 316 #endif
tosihisa 0:e0ec137da369 317 Skytraq_bin_send(sizeof(Skytraq_set_rate),Skytraq_set_rate);
tosihisa 0:e0ec137da369 318
tosihisa 1:d1bb695fe3bc 319 //Skytraq_bin_send(sizeof(Skytraq_QUERY_SOFTWARE_VERSION),Skytraq_QUERY_SOFTWARE_VERSION);
tosihisa 1:d1bb695fe3bc 320
tosihisa 1:d1bb695fe3bc 321 timer.attach_us(timer_handler,1000*50);
tosihisa 0:e0ec137da369 322
tosihisa 0:e0ec137da369 323 while(1) {
tosihisa 1:d1bb695fe3bc 324 if(do_disp){
tosihisa 1:d1bb695fe3bc 325 do_disp = 0;
tosihisa 1:d1bb695fe3bc 326 lcd.locate(0,0);
tosihisa 1:d1bb695fe3bc 327 if(UseLogMemory){
tosihisa 1:d1bb695fe3bc 328 lcd.printf("LOG:%s",logFile_getName(0));
tosihisa 1:d1bb695fe3bc 329 } else {
tosihisa 1:d1bb695fe3bc 330 lcd.printf("NO SD Card");
tosihisa 1:d1bb695fe3bc 331 }
tosihisa 1:d1bb695fe3bc 332 lcd.locate(0,1);
tosihisa 1:d1bb695fe3bc 333 lcd.printf("R:%-10lu",recv_bytes);
tosihisa 1:d1bb695fe3bc 334 }
tosihisa 1:d1bb695fe3bc 335 if((logSW_state[0] == 0) && (logSW_state[1] == 0)){
tosihisa 1:d1bb695fe3bc 336 if((fp != NULL) && (bin_info.cjobst == 0)){
tosihisa 1:d1bb695fe3bc 337 if(wcnt > 0){
tosihisa 1:d1bb695fe3bc 338 fwrite(wbuf,sizeof(wbuf[0]),wcnt,fp);
tosihisa 1:d1bb695fe3bc 339 wcnt = 0;
tosihisa 0:e0ec137da369 340 }
tosihisa 1:d1bb695fe3bc 341 fclose(fp);
tosihisa 1:d1bb695fe3bc 342 fp = NULL;
tosihisa 1:d1bb695fe3bc 343 logNextCount++;
tosihisa 1:d1bb695fe3bc 344 recv_bytes=0;
tosihisa 1:d1bb695fe3bc 345 LOGLED=0;
tosihisa 1:d1bb695fe3bc 346 }
tosihisa 1:d1bb695fe3bc 347 } else if((logSW_state[0] != 0) && (logSW_state[1] != 0)){
tosihisa 1:d1bb695fe3bc 348 if((fp == NULL) && (bin_info.cjobst == 0)){
tosihisa 1:d1bb695fe3bc 349 if((fp = fopen(logFile_getName(1),"w+b")) != NULL){
tosihisa 1:d1bb695fe3bc 350 recv_bytes=0;
tosihisa 1:d1bb695fe3bc 351 LOGLED=0.80;
tosihisa 1:d1bb695fe3bc 352 }
tosihisa 1:d1bb695fe3bc 353 }
tosihisa 0:e0ec137da369 354 }
tosihisa 0:e0ec137da369 355
tosihisa 0:e0ec137da369 356 if (gps.readable()) {
tosihisa 0:e0ec137da369 357 c = (unsigned char)(gps.getc());
tosihisa 0:e0ec137da369 358 Skytraq_bin_parse(c,&bin_info);
tosihisa 0:e0ec137da369 359 recv_bytes++;
tosihisa 0:e0ec137da369 360 if(fp != NULL){
tosihisa 0:e0ec137da369 361 wbuf[wcnt] = c;
tosihisa 0:e0ec137da369 362 wcnt++;
tosihisa 0:e0ec137da369 363 if(wcnt >= sizeof(wbuf)){
tosihisa 1:d1bb695fe3bc 364 fwrite(wbuf,sizeof(wbuf[0]),wcnt,fp);
tosihisa 0:e0ec137da369 365 wcnt = 0;
tosihisa 0:e0ec137da369 366 }
tosihisa 0:e0ec137da369 367 }
tosihisa 1:d1bb695fe3bc 368 if(bin_info.cjobst == 8){
tosihisa 0:e0ec137da369 369 for(i = 0;Skytraq_ID_List[i].ID != 0xFF;i++){
tosihisa 0:e0ec137da369 370 if(bin_info.ID == Skytraq_ID_List[i].ID){
tosihisa 0:e0ec137da369 371 break;
tosihisa 0:e0ec137da369 372 }
tosihisa 0:e0ec137da369 373 }
tosihisa 0:e0ec137da369 374 debug.printf("ID=%02x len=%5d [%s]\n",bin_info.ID,bin_info.len,Skytraq_ID_List[i].name);
tosihisa 1:d1bb695fe3bc 375 if(Skytraq_ID_List[i].func != NULL){
tosihisa 1:d1bb695fe3bc 376 (*Skytraq_ID_List[i].func)(&bin_info);
tosihisa 1:d1bb695fe3bc 377 }
tosihisa 0:e0ec137da369 378 bin_info.cjobst = 0;
tosihisa 0:e0ec137da369 379 }
tosihisa 0:e0ec137da369 380 //debug.printf("[%02x]",gps.getc());
tosihisa 0:e0ec137da369 381 }
tosihisa 0:e0ec137da369 382 }
tosihisa 0:e0ec137da369 383 }