15 changed files with 235 additions and 62 deletions
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
#include <DataFlash.h> |
||||
|
||||
// start functions pass straight through to backend:
|
||||
void DataFlash_Class::WriteBlock(const void *pBuffer, uint16_t size) { |
||||
backend->WriteBlock(pBuffer, size); |
||||
} |
||||
uint16_t DataFlash_Class::start_new_log() { |
||||
return backend->start_new_log(); |
||||
} |
||||
|
||||
// change me to "DoTimeConsumingPreparations"?
|
||||
void DataFlash_Class::EraseAll() { |
||||
backend->EraseAll(); |
||||
} |
||||
// change me to "LoggingAvailable"?
|
||||
bool DataFlash_Class::CardInserted(void) { |
||||
return backend->CardInserted(); |
||||
} |
||||
// remove me in favour of calling "DoTimeConsumingPreparations" all the time?
|
||||
bool DataFlash_Class::NeedErase(void) { |
||||
return backend->NeedErase(); |
||||
} |
||||
|
||||
uint16_t DataFlash_Class::find_last_log(void) { |
||||
return backend->find_last_log(); |
||||
} |
||||
void DataFlash_Class::get_log_boundaries(uint16_t log_num, uint16_t & start_page, uint16_t & end_page) { |
||||
backend->get_log_boundaries(log_num, start_page, end_page); |
||||
} |
||||
void DataFlash_Class::get_log_info(uint16_t log_num, uint32_t &size, uint32_t &time_utc) { |
||||
backend->get_log_info(log_num, size, time_utc); |
||||
} |
||||
int16_t DataFlash_Class::get_log_data(uint16_t log_num, uint16_t page, uint32_t offset, uint16_t len, uint8_t *data) { |
||||
return backend->get_log_data(log_num, page, offset, len, data); |
||||
} |
||||
uint16_t DataFlash_Class::get_num_logs(void) { |
||||
return backend->get_num_logs(); |
||||
} |
||||
void DataFlash_Class::Log_Fill_Format(const struct LogStructure *s, struct log_Format &pkt) { |
||||
backend->Log_Fill_Format(s, pkt); |
||||
} |
||||
|
||||
#ifndef DATAFLASH_NO_CLI |
||||
void DataFlash_Class::LogReadProcess(uint16_t log_num, |
||||
uint16_t start_page, uint16_t end_page, |
||||
print_mode_fn printMode, |
||||
AP_HAL::BetterStream *port) { |
||||
backend->LogReadProcess(log_num, start_page, end_page, printMode, port); |
||||
} |
||||
void DataFlash_Class::DumpPageInfo(AP_HAL::BetterStream *port) { |
||||
backend->DumpPageInfo(port); |
||||
} |
||||
void DataFlash_Class::ShowDeviceInfo(AP_HAL::BetterStream *port) { |
||||
backend->ShowDeviceInfo(port); |
||||
} |
||||
void DataFlash_Class::ListAvailableLogs(AP_HAL::BetterStream *port) { |
||||
backend->ListAvailableLogs(port); |
||||
} |
||||
#endif // DATAFLASH_NO_CLI
|
||||
|
||||
bool DataFlash_Class::logging_started(void) { |
||||
return backend->log_write_started; |
||||
} |
||||
|
||||
void DataFlash_Class::EnableWrites(bool enable) { |
||||
backend->EnableWrites(enable); |
||||
} |
||||
|
||||
|
||||
// end functions pass straight through to backend
|
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
#ifndef DATAFLASH_BACKEND_H |
||||
#define DATAFLASH_BACKEND_H |
||||
|
||||
#if HAL_CPU_CLASS < HAL_CPU_CLASS_75 |
||||
#define DATAFLASH_NO_CLI |
||||
#endif |
||||
|
||||
#include <AP_HAL.h> |
||||
#include <AP_Common.h> |
||||
#include <AP_Param.h> |
||||
#include <AP_GPS.h> |
||||
#include <AP_InertialSensor.h> |
||||
#include <AP_Baro.h> |
||||
#include <AP_AHRS.h> |
||||
#include <AP_Vehicle.h> |
||||
#include "../AP_Airspeed/AP_Airspeed.h" |
||||
#include "../AP_BattMonitor/AP_BattMonitor.h" |
||||
#include <stdint.h> |
||||
|
||||
class DataFlash_Backend |
||||
{ |
||||
public: |
||||
FUNCTOR_TYPEDEF(print_mode_fn, void, AP_HAL::BetterStream*, uint8_t); |
||||
|
||||
DataFlash_Backend(DataFlash_Class &front) : |
||||
_front(front) |
||||
{ } |
||||
|
||||
virtual bool CardInserted(void) = 0; |
||||
|
||||
// erase handling
|
||||
virtual bool NeedErase(void) = 0; |
||||
virtual void EraseAll() = 0; |
||||
|
||||
/* Write a block of data at current offset */ |
||||
virtual void WriteBlock(const void *pBuffer, uint16_t size) = 0; |
||||
|
||||
// high level interface
|
||||
virtual uint16_t find_last_log(void) = 0; |
||||
virtual void get_log_boundaries(uint16_t log_num, uint16_t & start_page, uint16_t & end_page) = 0; |
||||
virtual void get_log_info(uint16_t log_num, uint32_t &size, uint32_t &time_utc) = 0; |
||||
virtual int16_t get_log_data(uint16_t log_num, uint16_t page, uint32_t offset, uint16_t len, uint8_t *data) = 0; |
||||
virtual uint16_t get_num_logs(void) = 0; |
||||
#ifndef DATAFLASH_NO_CLI |
||||
virtual void LogReadProcess(uint16_t log_num, |
||||
uint16_t start_page, uint16_t end_page, |
||||
print_mode_fn printMode, |
||||
AP_HAL::BetterStream *port) = 0; |
||||
virtual void DumpPageInfo(AP_HAL::BetterStream *port) = 0; |
||||
virtual void ShowDeviceInfo(AP_HAL::BetterStream *port) = 0; |
||||
virtual void ListAvailableLogs(AP_HAL::BetterStream *port) = 0; |
||||
#endif // DATAFLASH_NO_CLI
|
||||
|
||||
void EnableWrites(bool enable) { _writes_enabled = enable; } |
||||
bool logging_started(void) const { return log_write_started; } |
||||
|
||||
// initialisation this really shouldn't take structure and
|
||||
// num_types, however the CLI LogReadProcess function requires it.
|
||||
// That function needs to be split.
|
||||
virtual void Init(const struct LogStructure *structure, uint8_t num_types) { |
||||
_writes_enabled = true; |
||||
_num_types = num_types; |
||||
_structures = structure; |
||||
} |
||||
|
||||
virtual uint16_t start_new_log(void) = 0; |
||||
bool log_write_started; |
||||
|
||||
void Log_Fill_Format(const struct LogStructure *structure, struct log_Format &pkt); |
||||
|
||||
protected: |
||||
DataFlash_Class &_front; |
||||
|
||||
/*
|
||||
read and print a log entry using the format strings from the given structure |
||||
*/ |
||||
void _print_log_entry(uint8_t msg_type, |
||||
print_mode_fn print_mode, |
||||
AP_HAL::BetterStream *port); |
||||
|
||||
const struct LogStructure *_structures; |
||||
uint8_t _num_types = 0; |
||||
bool _writes_enabled = false; |
||||
|
||||
/*
|
||||
read a block |
||||
*/ |
||||
virtual bool ReadBlock(void *pkt, uint16_t size) = 0; |
||||
|
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue