2016-02-17 21:25:53 -04:00
|
|
|
#pragma once
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
#include "DataFlash.h"
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
class DFMessageWriter_DFLogStart;
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
class DataFlash_Backend
|
|
|
|
{
|
2015-11-09 18:14:22 -04:00
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
public:
|
2015-11-09 18:14:22 -04:00
|
|
|
FUNCTOR_TYPEDEF(vehicle_startup_message_Log_Writer, void);
|
|
|
|
|
|
|
|
DataFlash_Backend(DataFlash_Class &front,
|
|
|
|
class DFMessageWriter_DFLogStart *writer);
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
vehicle_startup_message_Log_Writer vehicle_message_writer();
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
void internal_error();
|
|
|
|
|
2017-06-14 22:19:54 -03:00
|
|
|
virtual bool CardInserted(void) const = 0;
|
2015-06-25 10:53:20 -03:00
|
|
|
|
|
|
|
// erase handling
|
|
|
|
virtual void EraseAll() = 0;
|
|
|
|
|
2015-08-08 03:13:38 -03:00
|
|
|
virtual bool NeedPrep() = 0;
|
|
|
|
virtual void Prep() = 0;
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
/* Write a block of data at current offset */
|
2015-08-06 09:18:28 -03:00
|
|
|
bool WriteBlock(const void *pBuffer, uint16_t size) {
|
|
|
|
return WritePrioritisedBlock(pBuffer, size, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WriteCriticalBlock(const void *pBuffer, uint16_t size) {
|
|
|
|
return WritePrioritisedBlock(pBuffer, size, true);
|
|
|
|
}
|
|
|
|
|
2017-06-30 08:09:20 -03:00
|
|
|
bool WritePrioritisedBlock(const void *pBuffer, uint16_t size, bool is_critical);
|
2015-06-25 10:53:20 -03:00
|
|
|
|
|
|
|
// high level interface
|
2015-10-20 07:32:31 -03:00
|
|
|
virtual uint16_t find_last_log() = 0;
|
2015-06-25 10:53:20 -03:00
|
|
|
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;
|
2015-10-20 07:32:31 -03:00
|
|
|
virtual uint16_t get_num_logs() = 0;
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2017-07-06 22:34:31 -03:00
|
|
|
virtual bool logging_started(void) const = 0;
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2017-06-14 22:21:17 -03:00
|
|
|
virtual void Init() { }
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
void set_mission(const AP_Mission *mission);
|
|
|
|
|
2016-07-30 15:13:12 -03:00
|
|
|
virtual uint32_t bufferspace_available() = 0;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2017-07-06 22:28:42 -03:00
|
|
|
virtual void PrepForArming() { }
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
virtual uint16_t start_new_log(void) = 0;
|
|
|
|
|
2016-04-22 10:33:40 -03:00
|
|
|
/* stop logging - close output files etc etc.
|
|
|
|
*
|
|
|
|
* note that this doesn't stop logging from starting up again
|
|
|
|
* immediately - e.g. DataFlash_MAVLink might get another start
|
|
|
|
* packet from a client.
|
|
|
|
*/
|
|
|
|
virtual void stop_logging(void) = 0;
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
void Log_Fill_Format(const struct LogStructure *structure, struct log_Format &pkt);
|
2015-12-07 20:51:46 -04:00
|
|
|
void Log_Fill_Format_Units(const struct LogStructure *s, struct log_Format_Units &pkt);
|
2015-06-25 10:53:20 -03:00
|
|
|
|
2015-06-18 22:57:01 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL || CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
|
|
|
// currently only DataFlash_File support this:
|
|
|
|
virtual void flush(void) { }
|
|
|
|
#endif
|
|
|
|
|
2015-11-10 02:34:31 -04:00
|
|
|
// for Dataflash_MAVlink
|
|
|
|
virtual void remote_log_block_status_msg(mavlink_channel_t chan,
|
|
|
|
mavlink_message_t* msg) { }
|
|
|
|
// end for Dataflash_MAVlink
|
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
virtual void periodic_tasks();
|
|
|
|
|
|
|
|
uint8_t num_types() const;
|
|
|
|
const struct LogStructure *structure(uint8_t structure) const;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2015-12-07 20:51:46 -04:00
|
|
|
uint8_t num_units() const;
|
|
|
|
const struct UnitStructure *unit(uint8_t unit) const;
|
|
|
|
|
|
|
|
uint8_t num_multipliers() const;
|
|
|
|
const struct MultiplierStructure *multiplier(uint8_t multiplier) const;
|
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
void Log_Write_EntireMission(const AP_Mission &mission);
|
|
|
|
bool Log_Write_Format(const struct LogStructure *structure);
|
|
|
|
bool Log_Write_MavCmd(uint16_t cmd_total, const mavlink_mission_item_t& mav_cmd);
|
|
|
|
bool Log_Write_Message(const char *message);
|
2018-06-12 00:34:00 -03:00
|
|
|
bool Log_Write_MessageF(const char *fmt, ...);
|
2015-11-09 18:14:22 -04:00
|
|
|
bool Log_Write_Mission_Cmd(const AP_Mission &mission,
|
|
|
|
const AP_Mission::Mission_Command &cmd);
|
2016-01-25 19:45:27 -04:00
|
|
|
bool Log_Write_Mode(uint8_t mode, uint8_t reason = 0);
|
2015-11-09 18:14:22 -04:00
|
|
|
bool Log_Write_Parameter(const char *name, float value);
|
|
|
|
bool Log_Write_Parameter(const AP_Param *ap,
|
|
|
|
const AP_Param::ParamToken &token,
|
|
|
|
enum ap_var_type type);
|
|
|
|
|
2016-04-21 03:11:21 -03:00
|
|
|
uint32_t num_dropped(void) const {
|
|
|
|
return _dropped;
|
|
|
|
}
|
2016-04-20 02:07:48 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Log_Write support
|
|
|
|
*/
|
|
|
|
// write a FMT message out (if it hasn't been done already).
|
|
|
|
// Returns true if the FMT message has ever been written.
|
|
|
|
bool Log_Write_Emit_FMT(uint8_t msg_type);
|
|
|
|
|
|
|
|
// write a log message out to the log of msg_type type, with
|
|
|
|
// values contained in arg_list:
|
|
|
|
bool Log_Write(uint8_t msg_type, va_list arg_list, bool is_critical=false);
|
|
|
|
|
2016-07-07 04:12:27 -03:00
|
|
|
// these methods are used when reporting system status over mavlink
|
|
|
|
virtual bool logging_enabled() const = 0;
|
|
|
|
virtual bool logging_failed() const = 0;
|
|
|
|
|
2016-07-28 02:58:20 -03:00
|
|
|
virtual void vehicle_was_disarmed() { };
|
|
|
|
|
2015-12-07 20:51:46 -04:00
|
|
|
bool Log_Write_Unit(const struct UnitStructure *s);
|
|
|
|
bool Log_Write_Multiplier(const struct MultiplierStructure *s);
|
|
|
|
bool Log_Write_Format_Units(const struct LogStructure *structure);
|
|
|
|
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
protected:
|
2015-11-09 18:14:22 -04:00
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
DataFlash_Class &_front;
|
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
virtual void periodic_10Hz(const uint32_t now);
|
|
|
|
virtual void periodic_1Hz(const uint32_t now);
|
|
|
|
virtual void periodic_fullrate(const uint32_t now);
|
|
|
|
|
2017-10-26 02:29:09 -03:00
|
|
|
bool ShouldLog(bool is_critical);
|
2017-07-04 13:53:20 -03:00
|
|
|
virtual bool WritesOK() const = 0;
|
2017-06-30 08:09:20 -03:00
|
|
|
virtual bool StartNewLogOK() const;
|
2017-06-08 22:36:18 -03:00
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
/*
|
|
|
|
read a block
|
|
|
|
*/
|
2015-08-06 09:18:28 -03:00
|
|
|
virtual bool WriteBlockCheckStartupMessages();
|
|
|
|
virtual void WriteMoreStartupMessages();
|
|
|
|
virtual void push_log_blocks();
|
2015-11-09 18:14:22 -04:00
|
|
|
|
|
|
|
DFMessageWriter_DFLogStart *_startup_messagewriter;
|
|
|
|
bool _writing_startup_messages;
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2017-08-25 09:03:40 -03:00
|
|
|
uint8_t _internal_errors;
|
2015-08-06 09:18:28 -03:00
|
|
|
uint32_t _dropped;
|
2015-11-09 18:14:22 -04:00
|
|
|
|
2016-04-15 06:53:54 -03:00
|
|
|
// must be called when a new log is being started:
|
|
|
|
virtual void start_new_log_reset_variables();
|
|
|
|
|
2017-06-30 08:09:20 -03:00
|
|
|
virtual bool _WritePrioritisedBlock(const void *pBuffer, uint16_t size, bool is_critical) = 0;
|
|
|
|
|
2017-06-30 01:42:31 -03:00
|
|
|
bool _initialised;
|
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
private:
|
2015-11-09 18:14:22 -04:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
uint32_t _last_periodic_1Hz;
|
|
|
|
uint32_t _last_periodic_10Hz;
|
2017-10-26 02:29:09 -03:00
|
|
|
bool have_logged_armed;
|
2015-06-25 10:53:20 -03:00
|
|
|
};
|