From 844e1b9ef9b5549fa0d8b802305b44a96af7483e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 20 Apr 2013 15:17:49 +1000 Subject: [PATCH] DataFlash: added support for printing flight mode as a string makes analysing logs easier. Pair-Programmed-With: Randy --- libraries/DataFlash/DataFlash.h | 3 +++ libraries/DataFlash/DataFlash_Block.h | 1 + libraries/DataFlash/DataFlash_File.cpp | 5 +++-- libraries/DataFlash/DataFlash_File.h | 1 + libraries/DataFlash/LogFile.cpp | 10 ++++++++-- .../examples/DataFlash_test/DataFlash_test.pde | 10 +++++++++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libraries/DataFlash/DataFlash.h b/libraries/DataFlash/DataFlash.h index 3a391781e0..70d71893d5 100644 --- a/libraries/DataFlash/DataFlash.h +++ b/libraries/DataFlash/DataFlash.h @@ -42,6 +42,7 @@ public: uint16_t start_page, uint16_t end_page, uint8_t num_types, const struct LogStructure *structure, + void (*printMode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port) = 0; virtual void DumpPageInfo(AP_HAL::BetterStream *port) = 0; virtual void ShowDeviceInfo(AP_HAL::BetterStream *port) = 0; @@ -76,6 +77,7 @@ protected: void _print_log_entry(uint8_t msg_type, uint8_t num_types, const struct LogStructure *structure, + void (*print_mode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port); void Log_Write_Parameter(const AP_Param *ap, const AP_Param::ParamToken &token, @@ -118,6 +120,7 @@ Format characters in the format string for binary log messages e : int32_t * 100 E : uint32_t * 100 L : int32_t latitude/longitude + M : uint8_t flight mode */ // structure used to define logging format diff --git a/libraries/DataFlash/DataFlash_Block.h b/libraries/DataFlash/DataFlash_Block.h index f2d3dcebfc..a6432d6bbf 100644 --- a/libraries/DataFlash/DataFlash_Block.h +++ b/libraries/DataFlash/DataFlash_Block.h @@ -39,6 +39,7 @@ public: uint16_t start_page, uint16_t end_page, uint8_t num_types, const struct LogStructure *structure, + void (*print_mode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port); void DumpPageInfo(AP_HAL::BetterStream *port); void ShowDeviceInfo(AP_HAL::BetterStream *port); diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index df5ac027c1..006bf2e87d 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -174,7 +174,7 @@ void DataFlash_File::WriteBlock(const void *pBuffer, uint16_t size) */ void DataFlash_File::ReadBlock(void *pkt, uint16_t size) { - if (_read_fd == -1 || !_initialised || size <= 3) { + if (_read_fd == -1 || !_initialised) { return; } @@ -295,6 +295,7 @@ void DataFlash_File::LogReadProcess(uint16_t log_num, uint16_t start_page, uint16_t end_page, uint8_t num_types, const struct LogStructure *structure, + void (*print_mode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port) { uint8_t log_step = 0; @@ -346,7 +347,7 @@ void DataFlash_File::LogReadProcess(uint16_t log_num, case 2: log_step = 0; - _print_log_entry(data, num_types, structure, port); + _print_log_entry(data, num_types, structure, print_mode, port); break; } if (_read_offset >= (end_page+1) * DATAFLASH_PAGE_SIZE) { diff --git a/libraries/DataFlash/DataFlash_File.h b/libraries/DataFlash/DataFlash_File.h index fbfeb223b8..64865749ec 100644 --- a/libraries/DataFlash/DataFlash_File.h +++ b/libraries/DataFlash/DataFlash_File.h @@ -36,6 +36,7 @@ public: uint16_t start_page, uint16_t end_page, uint8_t num_types, const struct LogStructure *structure, + void (*print_mode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port); void DumpPageInfo(AP_HAL::BetterStream *port); void ShowDeviceInfo(AP_HAL::BetterStream *port); diff --git a/libraries/DataFlash/LogFile.cpp b/libraries/DataFlash/LogFile.cpp index b9c070866d..34f4aac9ca 100644 --- a/libraries/DataFlash/LogFile.cpp +++ b/libraries/DataFlash/LogFile.cpp @@ -270,6 +270,7 @@ void DataFlash_Class::_print_format_headers(uint8_t num_types, void DataFlash_Class::_print_log_entry(uint8_t msg_type, uint8_t num_types, const struct LogStructure *structure, + void (*print_mode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port) { uint8_t i; @@ -385,6 +386,11 @@ void DataFlash_Class::_print_log_entry(uint8_t msg_type, ofs += sizeof(v)-1; break; } + case 'M': { + print_mode(port, pkt[ofs]); + ofs += 1; + break; + } default: ofs = msg_len; break; @@ -403,6 +409,7 @@ void DataFlash_Block::LogReadProcess(uint16_t log_num, uint16_t start_page, uint16_t end_page, uint8_t num_types, const struct LogStructure *structure, + void (*print_mode)(AP_HAL::BetterStream *port, uint8_t mode), AP_HAL::BetterStream *port) { uint8_t log_step = 0; @@ -438,7 +445,7 @@ void DataFlash_Block::LogReadProcess(uint16_t log_num, case 2: log_step = 0; - _print_log_entry(data, num_types, structure, port); + _print_log_entry(data, num_types, structure, print_mode, port); break; } uint16_t new_page = GetPage(); @@ -632,4 +639,3 @@ void DataFlash_Class::Log_Write_IMU(const AP_InertialSensor *ins) }; WriteBlock(&pkt, sizeof(pkt)); } - diff --git a/libraries/DataFlash/examples/DataFlash_test/DataFlash_test.pde b/libraries/DataFlash/examples/DataFlash_test/DataFlash_test.pde index 9edde09896..9de822b3ba 100644 --- a/libraries/DataFlash/examples/DataFlash_test/DataFlash_test.pde +++ b/libraries/DataFlash/examples/DataFlash_test/DataFlash_test.pde @@ -108,6 +108,12 @@ void setup() hal.scheduler->delay(100); } +static void +print_mode(AP_HAL::BetterStream *port, uint8_t mode) +{ + port->printf_P(PSTR("Mode(%u)"), (unsigned)mode); +} + void loop() { uint16_t start, end; @@ -117,7 +123,9 @@ void loop() DataFlash.get_log_boundaries(log_num, start, end); DataFlash.LogReadProcess(log_num, start, end, sizeof(log_structure)/sizeof(log_structure[0]), - log_structure, hal.console); + log_structure, + print_mode, + hal.console); hal.console->printf("\nTest complete. Test will repeat in 20 seconds\n"); hal.scheduler->delay(20000); }