2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Logger.cpp@30:ed791f1f7f7d, 2018-12-26 (annotated)
- Committer:
- shimniok
- Date:
- Wed Dec 26 19:34:17 2018 +0000
- Revision:
- 30:ed791f1f7f7d
- Parent:
- 29:cb2f55fbfe9c
- Child:
- 31:20a95043adb0
Implemented pushbutton, pushbutton toggles logging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 24:a7f92dfc5310 | 1 | #include "Logger.h" |
shimniok | 24:a7f92dfc5310 | 2 | |
shimniok | 24:a7f92dfc5310 | 3 | Logger::Logger(const char *file) { |
shimniok | 24:a7f92dfc5310 | 4 | _file = file; |
shimniok | 29:cb2f55fbfe9c | 5 | _fp = NULL; |
shimniok | 29:cb2f55fbfe9c | 6 | } |
shimniok | 29:cb2f55fbfe9c | 7 | |
shimniok | 29:cb2f55fbfe9c | 8 | |
shimniok | 29:cb2f55fbfe9c | 9 | void Logger::start() { |
shimniok | 29:cb2f55fbfe9c | 10 | if (_fp == NULL) _fp = fopen(_file, "a"); |
shimniok | 29:cb2f55fbfe9c | 11 | } |
shimniok | 29:cb2f55fbfe9c | 12 | |
shimniok | 29:cb2f55fbfe9c | 13 | |
shimniok | 29:cb2f55fbfe9c | 14 | void Logger::stop() { |
shimniok | 29:cb2f55fbfe9c | 15 | if (_fp && fclose(_fp) != EOF) { |
shimniok | 29:cb2f55fbfe9c | 16 | _fp = NULL; |
shimniok | 29:cb2f55fbfe9c | 17 | } |
shimniok | 29:cb2f55fbfe9c | 18 | } |
shimniok | 29:cb2f55fbfe9c | 19 | |
shimniok | 29:cb2f55fbfe9c | 20 | |
shimniok | 29:cb2f55fbfe9c | 21 | bool Logger::enabled() { |
shimniok | 29:cb2f55fbfe9c | 22 | return (_fp != NULL); |
shimniok | 24:a7f92dfc5310 | 23 | } |
shimniok | 24:a7f92dfc5310 | 24 | |
shimniok | 24:a7f92dfc5310 | 25 | |
shimniok | 30:ed791f1f7f7d | 26 | void Logger::log_gps(GpsData d) { |
shimniok | 29:cb2f55fbfe9c | 27 | if (enabled()) { |
shimniok | 29:cb2f55fbfe9c | 28 | fprintf(_fp, "G,%llu,%3.9f,%3.9f,%3.1f,%2.1f,%2.1f,%d\n", |
shimniok | 30:ed791f1f7f7d | 29 | d.timestamp, |
shimniok | 30:ed791f1f7f7d | 30 | d.latitude, |
shimniok | 30:ed791f1f7f7d | 31 | d.longitude, |
shimniok | 30:ed791f1f7f7d | 32 | d.course, |
shimniok | 30:ed791f1f7f7d | 33 | d.speed, |
shimniok | 30:ed791f1f7f7d | 34 | d.hdop, |
shimniok | 30:ed791f1f7f7d | 35 | d.svcount |
shimniok | 29:cb2f55fbfe9c | 36 | ); |
shimniok | 29:cb2f55fbfe9c | 37 | } |
shimniok | 24:a7f92dfc5310 | 38 | } |
shimniok | 24:a7f92dfc5310 | 39 | |
shimniok | 24:a7f92dfc5310 | 40 | |
shimniok | 30:ed791f1f7f7d | 41 | void Logger::log_sensors(SensorData d) { |
shimniok | 30:ed791f1f7f7d | 42 | if (enabled()) { |
shimniok | 30:ed791f1f7f7d | 43 | fprintf(_fp, "S,%llu,%u,%d,%d,%d\n", |
shimniok | 30:ed791f1f7f7d | 44 | d.timestamp, |
shimniok | 30:ed791f1f7f7d | 45 | d.encoder, |
shimniok | 30:ed791f1f7f7d | 46 | d.gyro[0], |
shimniok | 30:ed791f1f7f7d | 47 | d.gyro[1], |
shimniok | 30:ed791f1f7f7d | 48 | d.gyro[2] |
shimniok | 30:ed791f1f7f7d | 49 | ); |
shimniok | 30:ed791f1f7f7d | 50 | } |
shimniok | 30:ed791f1f7f7d | 51 | } |
shimniok | 30:ed791f1f7f7d | 52 | |
shimniok | 30:ed791f1f7f7d | 53 | |
shimniok | 24:a7f92dfc5310 | 54 | void Logger::log_estimation() { |
shimniok | 29:cb2f55fbfe9c | 55 | if (enabled()) { |
shimniok | 24:a7f92dfc5310 | 56 | } |
shimniok | 24:a7f92dfc5310 | 57 | } |