Skytraq S1315F-RAW-EVK Logger

Dependencies:   TextLCD mbed

Committer:
tosihisa
Date:
Sun Dec 19 09:11:48 2010 +0000
Revision:
2:7eb11afe02bd
Parent:
1:d1bb695fe3bc
Add \"SYSTEM RESTART\" at boot time.

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 2:7eb11afe02bd 158 unsigned char Skytraq_System_Restart[] = {0x01,0x01};
tosihisa 1:d1bb695fe3bc 159 unsigned char Skytraq_QUERY_SOFTWARE_VERSION[] = {0x02,0x01};
tosihisa 0:e0ec137da369 160 unsigned char Skytraq_set_rate[] = {
tosihisa 0:e0ec137da369 161 0x12, /* ID */
tosihisa 0:e0ec137da369 162 0x00, /* 00: 1Hz / 01: 2Hz / 02: 4Hz / 03: 5Hz / 04: 10Hz / 05: 20Hz / Others: 20Hz */
tosihisa 0:e0ec137da369 163 0x01, /* Meas_time Enabling */
tosihisa 0:e0ec137da369 164 0x01, /* Raw_meas Enabling */
tosihisa 0:e0ec137da369 165 0x00, /* SV_CH_Staus Enabling */
tosihisa 0:e0ec137da369 166 0x00, /* RCV_State Enabling */
tosihisa 0:e0ec137da369 167 0x00, /* Subframe Enabling */
tosihisa 0:e0ec137da369 168 0x00 /* Attributes */
tosihisa 0:e0ec137da369 169 };
tosihisa 0:e0ec137da369 170
tosihisa 0:e0ec137da369 171 void Skytraq_bin_send(unsigned short LEN,unsigned char *body)
tosihisa 0:e0ec137da369 172 {
tosihisa 0:e0ec137da369 173 unsigned short i;
tosihisa 0:e0ec137da369 174 unsigned char sum;
tosihisa 0:e0ec137da369 175 gps.putc(0xA0);
tosihisa 0:e0ec137da369 176 gps.putc(0xA1);
tosihisa 0:e0ec137da369 177 gps.putc((LEN >> 8) & 0x00ff);
tosihisa 0:e0ec137da369 178 gps.putc(LEN & 0x00ff);
tosihisa 0:e0ec137da369 179 sum = 0;
tosihisa 0:e0ec137da369 180 for(i = 0;i < LEN;i++){
tosihisa 0:e0ec137da369 181 gps.putc((char)(*(body+i)));
tosihisa 0:e0ec137da369 182 sum = sum ^ *(body+i);
tosihisa 0:e0ec137da369 183 }
tosihisa 0:e0ec137da369 184 gps.putc(sum);
tosihisa 0:e0ec137da369 185 gps.putc(0x0D);
tosihisa 0:e0ec137da369 186 gps.putc(0x0A);
tosihisa 0:e0ec137da369 187 }
tosihisa 0:e0ec137da369 188
tosihisa 0:e0ec137da369 189 void Skytraq_bin_parse(unsigned char c,Skytraq_bin_info_t *info)
tosihisa 0:e0ec137da369 190 {
tosihisa 0:e0ec137da369 191 if(info->cjobst == 0){
tosihisa 1:d1bb695fe3bc 192 info->cjobst = (c == 0xA0) ? 1 : 0;
tosihisa 0:e0ec137da369 193 } else if(info->cjobst == 1){
tosihisa 1:d1bb695fe3bc 194 info->cjobst = (c == 0xA1) ? 2 : 0;
tosihisa 0:e0ec137da369 195 } else if(info->cjobst == 2){
tosihisa 0:e0ec137da369 196 info->len = c;
tosihisa 0:e0ec137da369 197 info->cjobst = 3;
tosihisa 0:e0ec137da369 198 } else if(info->cjobst == 3){
tosihisa 0:e0ec137da369 199 info->len = (info->len << 8) | c;
tosihisa 0:e0ec137da369 200 info->cjobst = 4;
tosihisa 0:e0ec137da369 201 info->sum = 0;
tosihisa 0:e0ec137da369 202 info->recv = 0;
tosihisa 0:e0ec137da369 203 if(info->len >= sizeof(info->body)){
tosihisa 0:e0ec137da369 204 info->cjobst = 0;
tosihisa 0:e0ec137da369 205 }
tosihisa 0:e0ec137da369 206 } else if(info->cjobst == 4){
tosihisa 0:e0ec137da369 207 if(info->recv == 0){
tosihisa 0:e0ec137da369 208 info->ID = c;
tosihisa 0:e0ec137da369 209 } else {
tosihisa 0:e0ec137da369 210 info->body[info->recv - 1] = c;
tosihisa 0:e0ec137da369 211 }
tosihisa 0:e0ec137da369 212 info->sum = info->sum ^ c;
tosihisa 0:e0ec137da369 213 info->recv++;
tosihisa 0:e0ec137da369 214 if(info->recv >= info->len){
tosihisa 0:e0ec137da369 215 info->cjobst = 5;
tosihisa 0:e0ec137da369 216 }
tosihisa 0:e0ec137da369 217 } else if(info->cjobst == 5){
tosihisa 0:e0ec137da369 218 //debug.printf("sum[%02x][%02x]\n",info->sum,c);
tosihisa 0:e0ec137da369 219 if(info->sum == c){
tosihisa 0:e0ec137da369 220 info->cjobst = 6;
tosihisa 0:e0ec137da369 221 } else {
tosihisa 0:e0ec137da369 222 info->cjobst = 0;
tosihisa 0:e0ec137da369 223 debug.printf("\nSUMERROR[%02x][%02x]\n",info->sum,c);
tosihisa 0:e0ec137da369 224 }
tosihisa 1:d1bb695fe3bc 225 } else if(info->cjobst == 6){
tosihisa 1:d1bb695fe3bc 226 info->cjobst = (c == 0x0D) ? 7 : 0;
tosihisa 1:d1bb695fe3bc 227 } else if(info->cjobst == 7){
tosihisa 1:d1bb695fe3bc 228 info->cjobst = (c == 0x0A) ? 8 : 0;
tosihisa 1:d1bb695fe3bc 229 }
tosihisa 1:d1bb695fe3bc 230 }
tosihisa 1:d1bb695fe3bc 231
tosihisa 1:d1bb695fe3bc 232 char *logDir = "/" FSNAME "/GPSLOG";
tosihisa 1:d1bb695fe3bc 233 unsigned short logNextCount = 0;
tosihisa 1:d1bb695fe3bc 234 int UseLogMemory = 0;
tosihisa 1:d1bb695fe3bc 235
tosihisa 1:d1bb695fe3bc 236 char *logFile_getName(int addDir) {
tosihisa 1:d1bb695fe3bc 237 static char fname[32];
tosihisa 1:d1bb695fe3bc 238 if (addDir) {
tosihisa 1:d1bb695fe3bc 239 snprintf(fname,sizeof(fname)-1,"%s/RAW%05d.STQ",logDir,logNextCount);
tosihisa 1:d1bb695fe3bc 240 } else {
tosihisa 1:d1bb695fe3bc 241 snprintf(fname,sizeof(fname)-1,"RAW%05d.STQ",logNextCount);
tosihisa 1:d1bb695fe3bc 242 }
tosihisa 1:d1bb695fe3bc 243 return fname;
tosihisa 1:d1bb695fe3bc 244 }
tosihisa 1:d1bb695fe3bc 245
tosihisa 1:d1bb695fe3bc 246 void logFile_Init() {
tosihisa 1:d1bb695fe3bc 247 DIR *d;
tosihisa 1:d1bb695fe3bc 248 struct dirent *p;
tosihisa 1:d1bb695fe3bc 249 unsigned short countCandidate;
tosihisa 1:d1bb695fe3bc 250 char *endptr;
tosihisa 1:d1bb695fe3bc 251 int sts;
tosihisa 1:d1bb695fe3bc 252
tosihisa 1:d1bb695fe3bc 253 UseLogMemory = 0;
tosihisa 1:d1bb695fe3bc 254
tosihisa 1:d1bb695fe3bc 255 sts = mkdir(logDir,0777);
tosihisa 1:d1bb695fe3bc 256 debug.printf("mkdir(\"%s\") - %d\n",logDir,sts);
tosihisa 1:d1bb695fe3bc 257 d = opendir(logDir);
tosihisa 1:d1bb695fe3bc 258 if ( d != NULL ) {
tosihisa 1:d1bb695fe3bc 259 while ( (p = readdir(d)) != NULL ) {
tosihisa 1:d1bb695fe3bc 260 debug.printf("FILE - %s\x0d\x0a", p->d_name);
tosihisa 1:d1bb695fe3bc 261 if (strlen(p->d_name) == (sizeof("RAWxxxxx.stq")-1)) {
tosihisa 1:d1bb695fe3bc 262 if ( ((p->d_name[0] == 'R') || (p->d_name[0] == 'r'))
tosihisa 1:d1bb695fe3bc 263 && ((p->d_name[1] == 'A') || (p->d_name[1] == 'a'))
tosihisa 1:d1bb695fe3bc 264 && ((p->d_name[2] == 'W') || (p->d_name[2] == 'w'))) {
tosihisa 1:d1bb695fe3bc 265 }
tosihisa 1:d1bb695fe3bc 266 countCandidate = (unsigned short)strtoul(&(p->d_name[3]),&endptr,10);
tosihisa 1:d1bb695fe3bc 267 if (strcasecmp(endptr,".STQ") == 0) {
tosihisa 1:d1bb695fe3bc 268 if (countCandidate > logNextCount) {
tosihisa 1:d1bb695fe3bc 269 logNextCount = countCandidate;
tosihisa 1:d1bb695fe3bc 270 }
tosihisa 1:d1bb695fe3bc 271 }
tosihisa 1:d1bb695fe3bc 272 }
tosihisa 1:d1bb695fe3bc 273 }
tosihisa 1:d1bb695fe3bc 274 closedir(d);
tosihisa 1:d1bb695fe3bc 275 logNextCount++;
tosihisa 1:d1bb695fe3bc 276 UseLogMemory = 1;
tosihisa 0:e0ec137da369 277 }
tosihisa 0:e0ec137da369 278 }
tosihisa 0:e0ec137da369 279
tosihisa 0:e0ec137da369 280 unsigned char wbuf[512];
tosihisa 0:e0ec137da369 281 int wcnt = 0;
tosihisa 0:e0ec137da369 282
tosihisa 0:e0ec137da369 283 int main() {
tosihisa 0:e0ec137da369 284 Skytraq_bin_info_t bin_info;
tosihisa 0:e0ec137da369 285 int i;
tosihisa 0:e0ec137da369 286 unsigned long recv_bytes = 0;
tosihisa 0:e0ec137da369 287 FILE *fp = NULL;
tosihisa 0:e0ec137da369 288 unsigned char c;
tosihisa 0:e0ec137da369 289
tosihisa 0:e0ec137da369 290 bin_info.cjobst = 0;
tosihisa 0:e0ec137da369 291
tosihisa 0:e0ec137da369 292 debug.format(8,Serial::None,1);
tosihisa 0:e0ec137da369 293 debug.baud(115200);
tosihisa 0:e0ec137da369 294 debug.printf("GPS Logger \"__S1315F__1\" Start (BUILD:[" __DATE__ "/" __TIME__ "])\x0d\x0a");
tosihisa 0:e0ec137da369 295
tosihisa 0:e0ec137da369 296 PPS.rise(pps_rise);
tosihisa 0:e0ec137da369 297
tosihisa 0:e0ec137da369 298 lcd.cls();
tosihisa 0:e0ec137da369 299 lcd.locate(0,0);
tosihisa 0:e0ec137da369 300 lcd.printf("S1315F Logger");
tosihisa 0:e0ec137da369 301
tosihisa 0:e0ec137da369 302 lcd.locate(0,1);
tosihisa 0:e0ec137da369 303 lcd.printf("Please wait");
tosihisa 0:e0ec137da369 304 wait(1.0);
tosihisa 0:e0ec137da369 305
tosihisa 1:d1bb695fe3bc 306 logFile_Init();
tosihisa 1:d1bb695fe3bc 307
tosihisa 0:e0ec137da369 308 gps.format(8,Serial::None,1);
tosihisa 0:e0ec137da369 309 gps.baud(115200);
tosihisa 0:e0ec137da369 310 gps.recvStart();
tosihisa 0:e0ec137da369 311
tosihisa 0:e0ec137da369 312 Skytraq_set_rate[1] = 0x05;
tosihisa 0:e0ec137da369 313 #ifdef OUTPUT_RATE_1HZ
tosihisa 0:e0ec137da369 314 Skytraq_set_rate[1] = 0x00;
tosihisa 0:e0ec137da369 315 #endif
tosihisa 2:7eb11afe02bd 316 lcd.locate(0,1);
tosihisa 2:7eb11afe02bd 317 lcd.printf("S1315F Restart");
tosihisa 2:7eb11afe02bd 318 Skytraq_bin_send(sizeof(Skytraq_System_Restart),Skytraq_System_Restart);
tosihisa 2:7eb11afe02bd 319
tosihisa 2:7eb11afe02bd 320 wait(1.0);
tosihisa 2:7eb11afe02bd 321
tosihisa 2:7eb11afe02bd 322 lcd.locate(0,1);
tosihisa 2:7eb11afe02bd 323 lcd.printf("S1315F Configure");
tosihisa 2:7eb11afe02bd 324
tosihisa 0:e0ec137da369 325 Skytraq_bin_send(sizeof(Skytraq_set_rate),Skytraq_set_rate);
tosihisa 1:d1bb695fe3bc 326 //Skytraq_bin_send(sizeof(Skytraq_QUERY_SOFTWARE_VERSION),Skytraq_QUERY_SOFTWARE_VERSION);
tosihisa 1:d1bb695fe3bc 327
tosihisa 1:d1bb695fe3bc 328 timer.attach_us(timer_handler,1000*50);
tosihisa 0:e0ec137da369 329
tosihisa 2:7eb11afe02bd 330 lcd.cls();
tosihisa 2:7eb11afe02bd 331
tosihisa 0:e0ec137da369 332 while(1) {
tosihisa 1:d1bb695fe3bc 333 if(do_disp){
tosihisa 1:d1bb695fe3bc 334 do_disp = 0;
tosihisa 1:d1bb695fe3bc 335 lcd.locate(0,0);
tosihisa 1:d1bb695fe3bc 336 if(UseLogMemory){
tosihisa 1:d1bb695fe3bc 337 lcd.printf("LOG:%s",logFile_getName(0));
tosihisa 1:d1bb695fe3bc 338 } else {
tosihisa 1:d1bb695fe3bc 339 lcd.printf("NO SD Card");
tosihisa 1:d1bb695fe3bc 340 }
tosihisa 1:d1bb695fe3bc 341 lcd.locate(0,1);
tosihisa 1:d1bb695fe3bc 342 lcd.printf("R:%-10lu",recv_bytes);
tosihisa 1:d1bb695fe3bc 343 }
tosihisa 1:d1bb695fe3bc 344 if((logSW_state[0] == 0) && (logSW_state[1] == 0)){
tosihisa 1:d1bb695fe3bc 345 if((fp != NULL) && (bin_info.cjobst == 0)){
tosihisa 1:d1bb695fe3bc 346 if(wcnt > 0){
tosihisa 1:d1bb695fe3bc 347 fwrite(wbuf,sizeof(wbuf[0]),wcnt,fp);
tosihisa 1:d1bb695fe3bc 348 wcnt = 0;
tosihisa 0:e0ec137da369 349 }
tosihisa 1:d1bb695fe3bc 350 fclose(fp);
tosihisa 1:d1bb695fe3bc 351 fp = NULL;
tosihisa 1:d1bb695fe3bc 352 logNextCount++;
tosihisa 1:d1bb695fe3bc 353 recv_bytes=0;
tosihisa 1:d1bb695fe3bc 354 LOGLED=0;
tosihisa 1:d1bb695fe3bc 355 }
tosihisa 1:d1bb695fe3bc 356 } else if((logSW_state[0] != 0) && (logSW_state[1] != 0)){
tosihisa 1:d1bb695fe3bc 357 if((fp == NULL) && (bin_info.cjobst == 0)){
tosihisa 1:d1bb695fe3bc 358 if((fp = fopen(logFile_getName(1),"w+b")) != NULL){
tosihisa 1:d1bb695fe3bc 359 recv_bytes=0;
tosihisa 1:d1bb695fe3bc 360 LOGLED=0.80;
tosihisa 1:d1bb695fe3bc 361 }
tosihisa 1:d1bb695fe3bc 362 }
tosihisa 0:e0ec137da369 363 }
tosihisa 0:e0ec137da369 364
tosihisa 0:e0ec137da369 365 if (gps.readable()) {
tosihisa 0:e0ec137da369 366 c = (unsigned char)(gps.getc());
tosihisa 0:e0ec137da369 367 Skytraq_bin_parse(c,&bin_info);
tosihisa 0:e0ec137da369 368 recv_bytes++;
tosihisa 0:e0ec137da369 369 if(fp != NULL){
tosihisa 0:e0ec137da369 370 wbuf[wcnt] = c;
tosihisa 0:e0ec137da369 371 wcnt++;
tosihisa 0:e0ec137da369 372 if(wcnt >= sizeof(wbuf)){
tosihisa 1:d1bb695fe3bc 373 fwrite(wbuf,sizeof(wbuf[0]),wcnt,fp);
tosihisa 0:e0ec137da369 374 wcnt = 0;
tosihisa 0:e0ec137da369 375 }
tosihisa 0:e0ec137da369 376 }
tosihisa 1:d1bb695fe3bc 377 if(bin_info.cjobst == 8){
tosihisa 0:e0ec137da369 378 for(i = 0;Skytraq_ID_List[i].ID != 0xFF;i++){
tosihisa 0:e0ec137da369 379 if(bin_info.ID == Skytraq_ID_List[i].ID){
tosihisa 0:e0ec137da369 380 break;
tosihisa 0:e0ec137da369 381 }
tosihisa 0:e0ec137da369 382 }
tosihisa 0:e0ec137da369 383 debug.printf("ID=%02x len=%5d [%s]\n",bin_info.ID,bin_info.len,Skytraq_ID_List[i].name);
tosihisa 1:d1bb695fe3bc 384 if(Skytraq_ID_List[i].func != NULL){
tosihisa 1:d1bb695fe3bc 385 (*Skytraq_ID_List[i].func)(&bin_info);
tosihisa 1:d1bb695fe3bc 386 }
tosihisa 0:e0ec137da369 387 bin_info.cjobst = 0;
tosihisa 0:e0ec137da369 388 }
tosihisa 0:e0ec137da369 389 //debug.printf("[%02x]",gps.getc());
tosihisa 0:e0ec137da369 390 }
tosihisa 0:e0ec137da369 391 }
tosihisa 0:e0ec137da369 392 }