Rev 88 | Rev 101 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 88 | Rev 92 | ||
---|---|---|---|
Line 62... | Line 62... | ||
62 | #include "kml.h" |
62 | #include "kml.h" |
63 | #include "gpx.h" |
63 | #include "gpx.h" |
64 | #include "ssc.h" |
64 | #include "ssc.h" |
65 | #include "settings.h" |
65 | #include "settings.h" |
Line -... | Line 66... | ||
- | 66 | ||
- | 67 | ||
- | 68 | #define LOG_FLUSH_INTERVAL 20000 // 20s |
|
66 | 69 | ||
67 | typedef enum |
70 | typedef enum |
68 | { |
71 | { |
69 | LOGFILE_IDLE, |
72 | LOGFILE_IDLE, |
70 | LOGFILE_START, |
73 | LOGFILE_START, |
Line 81... | Line 84... | ||
81 | { |
84 | { |
82 | u32 KML_Interval; // the kml-log interval (0 = off) |
85 | u32 KML_Interval; // the kml-log interval (0 = off) |
83 | u32 GPX_Interval; // the gpx-log interval (0 = off) |
86 | u32 GPX_Interval; // the gpx-log interval (0 = off) |
84 | } LogCfg_t; |
87 | } LogCfg_t; |
Line 85... | Line 88... | ||
85 | 88 | ||
Line 86... | Line 89... | ||
86 | LogCfg_t LogCfg = {500 , 1000}; |
89 | LogCfg_t LogCfg = {500 , 0}; |
87 | 90 | ||
88 | 91 | ||
Line 142... | Line 145... | ||
142 | // logs the current gps position to a kml file |
145 | // logs the current gps position to a kml file |
143 | logfilestate_t Logging_KML(u32 LogDelay) |
146 | logfilestate_t Logging_KML(u32 LogDelay) |
144 | { |
147 | { |
145 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
148 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
146 | static s8* logfilename = NULL; // the pointer to the logfilename |
149 | static s8* logfilename = NULL; // the pointer to the logfilename |
147 | static u32 logtimer = 0; // the log update timer |
150 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
148 | static KML_Document_t logfile; // the logfilehandle |
151 | static KML_Document_t logfile; // the logfilehandle |
Line 149... | Line 152... | ||
149 | 152 | ||
150 | // initialize if LogDelay os zero |
153 | // initialize if LogDelay os zero |
151 | if(!LogDelay) |
154 | if(!LogDelay) |
Line 190... | Line 193... | ||
190 | if(logfilename != NULL) |
193 | if(logfilename != NULL) |
191 | { |
194 | { |
192 | // try to create the log file |
195 | // try to create the log file |
193 | if(KML_DocumentOpen(logfilename, &logfile)) |
196 | if(KML_DocumentOpen(logfilename, &logfile)) |
194 | { |
197 | { |
- | 198 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
|
195 | logfilestate = LOGFILE_OPENED; // goto next step |
199 | logfilestate = LOGFILE_OPENED; // goto next step |
196 | SerialPutString("\r\nOpening kml-file:"); |
200 | SerialPutString("\r\nOpening kml-file:"); |
197 | SerialPutString(logfilename); |
201 | SerialPutString(logfilename); |
198 | SerialPutString("\r\n"); |
202 | SerialPutString("\r\n"); |
199 | } |
203 | } |
Line 221... | Line 225... | ||
221 | { // error logging data |
225 | { // error logging data |
222 | SerialPutString("\r\nError logging to kml-file\r\n"); |
226 | SerialPutString("\r\nError logging to kml-file\r\n"); |
223 | KML_DocumentClose(&logfile); |
227 | KML_DocumentClose(&logfile); |
224 | logfilestate = LOGFILE_ERROR; |
228 | logfilestate = LOGFILE_ERROR; |
225 | } |
229 | } |
- | 230 | else // sucessfully logged |
|
- | 231 | { |
|
- | 232 | if(CheckDelay(flushtimer)) |
|
- | 233 | { |
|
226 | //else DebugOut.Analog[26]++; // count SD-Logs |
234 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
- | 235 | fflush_(logfile.file); |
|
- | 236 | } |
|
- | 237 | } |
|
- | 238 | ||
227 | } |
239 | } |
228 | break; |
240 | break; |
Line 229... | Line 241... | ||
229 | 241 | ||
230 | case LOGFILE_ERROR: |
242 | case LOGFILE_ERROR: |
Line 231... | Line 243... | ||
231 | break; |
243 | break; |
232 | 244 | ||
233 | default: |
245 | default: |
234 | logfilestate = LOGFILE_IDLE; |
246 | logfilestate = LOGFILE_IDLE; |
235 | break; |
247 | break; |
236 | } |
248 | } |
237 | } // EOF model is flying |
249 | } // EOF motors are not running |
238 | else // model is not flying |
250 | else // model is not flying |
239 | { // close log file if opened |
251 | { // close log file if opened |
240 | if(logfilestate == LOGFILE_OPENED) |
252 | if(logfilestate == LOGFILE_OPENED) |
Line 244... | Line 256... | ||
244 | SerialPutString("\r\nClosing kml-file\r\n"); |
256 | SerialPutString("\r\nClosing kml-file\r\n"); |
245 | logfilestate = LOGFILE_CLOSED; |
257 | logfilestate = LOGFILE_CLOSED; |
246 | } |
258 | } |
247 | else // could not be closed |
259 | else // could not be closed |
248 | { |
260 | { |
- | 261 | SerialPutString("\r\nError closing kml-file\r\n"); |
|
249 | logfilestate = LOGFILE_ERROR; |
262 | logfilestate = LOGFILE_ERROR; |
250 | } |
263 | } |
251 | } |
264 | } |
252 | } //EOF model is not flying |
265 | } //EOF motors are not running |
253 | } // EOF Check LogTimer |
266 | } // EOF Check LogTimer |
Line 254... | Line 267... | ||
254 | 267 | ||
255 | return logfilestate; |
268 | return logfilestate; |
Line 259... | Line 272... | ||
259 | // logs gps and state info to a gpx file |
272 | // logs gps and state info to a gpx file |
260 | logfilestate_t Logging_GPX(u32 LogDelay) |
273 | logfilestate_t Logging_GPX(u32 LogDelay) |
261 | { |
274 | { |
262 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
275 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
263 | static s8* logfilename = NULL; // the pointer to the logfilename |
276 | static s8* logfilename = NULL; // the pointer to the logfilename |
264 | static u32 logtimer = 0; // the log update timer |
277 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
265 | static GPX_Document_t logfile; // the logfilehandle |
278 | static GPX_Document_t logfile; // the logfilehandle |
Line 266... | Line 279... | ||
266 | 279 | ||
267 | // initialize if LogDelay os zero |
280 | // initialize if LogDelay os zero |
268 | if(!LogDelay) |
281 | if(!LogDelay) |
Line 307... | Line 320... | ||
307 | if(logfilename != NULL) |
320 | if(logfilename != NULL) |
308 | { |
321 | { |
309 | // try to create the log file |
322 | // try to create the log file |
310 | if(GPX_DocumentOpen(logfilename, &logfile)) |
323 | if(GPX_DocumentOpen(logfilename, &logfile)) |
311 | { |
324 | { |
- | 325 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
|
312 | logfilestate = LOGFILE_OPENED; // goto next step |
326 | logfilestate = LOGFILE_OPENED; // goto next step |
313 | SerialPutString("\r\nOpening gpx-file:"); |
327 | SerialPutString("\r\nOpening gpx-file:"); |
314 | SerialPutString(logfilename); |
328 | SerialPutString(logfilename); |
315 | SerialPutString("\r\n"); |
329 | SerialPutString("\r\n"); |
316 | } |
330 | } |
Line 338... | Line 352... | ||
338 | { // error logging data |
352 | { // error logging data |
339 | SerialPutString("\r\nError logging to gpx-file\r\n"); |
353 | SerialPutString("\r\nError logging to gpx-file\r\n"); |
340 | GPX_DocumentClose(&logfile); |
354 | GPX_DocumentClose(&logfile); |
341 | logfilestate = LOGFILE_ERROR; |
355 | logfilestate = LOGFILE_ERROR; |
342 | } |
356 | } |
- | 357 | else // successful log |
|
- | 358 | { |
|
- | 359 | if(CheckDelay(flushtimer)) |
|
- | 360 | { |
|
- | 361 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
|
- | 362 | fflush_(logfile.file); |
|
- | 363 | } |
|
- | 364 | } |
|
343 | } |
365 | } |
344 | break; |
366 | break; |
Line 345... | Line 367... | ||
345 | 367 | ||
346 | case LOGFILE_ERROR: |
368 | case LOGFILE_ERROR: |
Line 360... | Line 382... | ||
360 | SerialPutString("\r\nClosing gpx-file\r\n"); |
382 | SerialPutString("\r\nClosing gpx-file\r\n"); |
361 | logfilestate = LOGFILE_CLOSED; |
383 | logfilestate = LOGFILE_CLOSED; |
362 | } |
384 | } |
363 | else // could not be closed |
385 | else // could not be closed |
364 | { |
386 | { |
- | 387 | SerialPutString("\r\nError closing gpx-file\r\n"); |
|
365 | logfilestate = LOGFILE_ERROR; |
388 | logfilestate = LOGFILE_ERROR; |
366 | } |
389 | } |
367 | } |
390 | } |
368 | } //EOF model is not flying |
391 | } //EOF model is not flying |
369 | } // EOF Check LogTimer |
392 | } // EOF Check LogTimer |
Line 375... | Line 398... | ||
375 | // initialize logging |
398 | // initialize logging |
376 | void Logging_Init(void) |
399 | void Logging_Init(void) |
377 | { |
400 | { |
378 | LogCfg.KML_Interval = 500; //default |
401 | LogCfg.KML_Interval = 500; //default |
379 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
402 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
380 | Logging_KML(0); |
403 | Logging_KML(0); // initialize |
381 | LogCfg.GPX_Interval = 0; //default |
404 | LogCfg.GPX_Interval = 0; //default |
382 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
405 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
383 | Logging_GPX(0); |
406 | Logging_GPX(0); // initialize |
384 | } |
407 | } |
Line 385... | Line 408... | ||
385 | 408 | ||
386 | //---------------------------------------------------------------------------------------------------- |
409 | //---------------------------------------------------------------------------------------------------- |
387 | // gobal logging handler |
410 | // gobal logging handler |
388 | void Logging_Update(void) |
411 | void Logging_Update(void) |
389 | { |
412 | { |
390 | static u32 logtimer = 0; |
413 | static u32 logtimer = 0; |
Line 391... | Line 414... | ||
391 | static logfilestate_t logstate = LOGFILE_IDLE; |
414 | static logfilestate_t logstate = LOGFILE_IDLE; |
392 | 415 | ||
393 | - | ||
394 | if(SD_SWITCH && CheckDelay(logtimer)) // a card is in slot |
- | |
395 | { |
- | |
396 | logtimer = SetDelay(10); // faster makes no sense |
- | |
397 | // call the logger handlers if no error has occured |
- | |
398 | if(logstate != LOGFILE_ERROR) logstate = Logging_KML(LogCfg.KML_Interval); |
- | |
399 | if(logstate != LOGFILE_ERROR) logstate = Logging_GPX(LogCfg.GPX_Interval); |
416 | |
400 | 417 | if(SD_SWITCH) // a card is in slot |
|
401 | // a logging error has occured |
418 | { |
- | 419 | if(CheckDelay(logtimer)) |
|
- | 420 | { |
|
- | 421 | logtimer = SetDelay(10); // faster makes no sense |
|
- | 422 | // call the logger handlers if no error has occured |
|
402 | if(logstate == LOGFILE_ERROR) |
423 | if(logstate != LOGFILE_ERROR) logstate = Logging_KML(LogCfg.KML_Interval); |
403 | { |
424 | if(logstate != LOGFILE_ERROR) logstate = Logging_GPX(LogCfg.GPX_Interval); |
- | 425 | ||
- | 426 | // a logging error has occured |
|
- | 427 | if(logstate == LOGFILE_ERROR) |
|
404 | Logging_Init(); // initialize the logs |
428 | { |
405 | // try to initialize the Fat 16 filesystem |
429 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
406 | if(0 == Fat16_Init()) |
430 | { |
407 | { // Fat 16 successfully initialized |
431 | Logging_Init(); // initialize the logs |
408 | logstate = LOGFILE_IDLE; |
432 | logstate = LOGFILE_IDLE; |
409 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
433 | logtimer = SetDelay(10); // try next log in 10 mili sec |
410 | } |
434 | } |
411 | else |
435 | else |
412 | { // retry in 5 seconds |
436 | { // retry in 5 seconds |
413 | logtimer = SetDelay(5000); // try again in 5 sec |
437 | logtimer = SetDelay(5000); // try again in 5 sec |
- | 438 | } |
|
414 | } |
439 | } //EOF logfile error |