2011-11-12 23:29:07 -04:00
|
|
|
/* ************************************************************ */
|
|
|
|
/* Test for DataFlash Log library */
|
|
|
|
/* ************************************************************ */
|
2016-02-17 21:25:53 -04:00
|
|
|
#pragma once
|
2011-11-12 23:29:07 -04:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_GPS/AP_GPS.h>
|
|
|
|
#include <AP_InertialSensor/AP_InertialSensor.h>
|
2015-09-04 12:50:23 -03:00
|
|
|
#include <AP_RSSI/AP_RSSI.h>
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
|
|
|
#include <AP_Vehicle/AP_Vehicle.h>
|
|
|
|
#include <AP_Mission/AP_Mission.h>
|
2015-08-15 19:53:26 -03:00
|
|
|
#include <AP_Airspeed/AP_Airspeed.h>
|
|
|
|
#include <AP_BattMonitor/AP_BattMonitor.h>
|
|
|
|
#include <AP_RPM/AP_RPM.h>
|
2015-09-14 03:44:45 -03:00
|
|
|
#include <AP_RangeFinder/AP_RangeFinder.h>
|
2015-11-05 19:50:54 -04:00
|
|
|
#include <DataFlash/LogStructure.h>
|
2016-03-24 22:11:11 -03:00
|
|
|
#include <AP_Motors/AP_Motors.h>
|
2016-07-03 23:14:26 -03:00
|
|
|
#include <AP_Rally/AP_Rally.h>
|
2011-11-12 23:29:07 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-11-20 23:48:44 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
2014-11-13 06:38:33 -04:00
|
|
|
#include <uORB/topics/esc_status.h>
|
2014-11-20 23:48:44 -04:00
|
|
|
#endif
|
2014-11-13 06:38:33 -04:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
#include "DFMessageWriter.h"
|
2014-11-13 06:38:33 -04:00
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
class DataFlash_Backend;
|
2015-11-09 18:14:22 -04:00
|
|
|
|
|
|
|
enum DataFlash_Backend_Type {
|
|
|
|
DATAFLASH_BACKEND_NONE = 0,
|
|
|
|
DATAFLASH_BACKEND_FILE = 1,
|
2015-11-10 02:34:31 -04:00
|
|
|
DATAFLASH_BACKEND_MAVLINK = 2,
|
|
|
|
DATAFLASH_BACKEND_BOTH = 3,
|
2015-11-09 18:14:22 -04:00
|
|
|
};
|
2014-08-01 02:57:15 -03:00
|
|
|
|
2016-03-24 22:11:11 -03:00
|
|
|
// fwd declarations to avoid include errors
|
|
|
|
class AC_AttitudeControl;
|
|
|
|
class AC_PosControl;
|
|
|
|
|
2011-11-12 23:29:07 -04:00
|
|
|
class DataFlash_Class
|
|
|
|
{
|
2015-11-09 18:14:22 -04:00
|
|
|
friend class DataFlash_Backend; // for _num_types
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2013-02-22 20:17:34 -04:00
|
|
|
public:
|
2015-05-24 18:55:06 -03:00
|
|
|
FUNCTOR_TYPEDEF(print_mode_fn, void, AP_HAL::BetterStream*, uint8_t);
|
2015-08-06 09:18:28 -03:00
|
|
|
FUNCTOR_TYPEDEF(vehicle_startup_message_Log_Writer, void);
|
2015-10-26 08:25:44 -03:00
|
|
|
DataFlash_Class(const char *firmware_string) :
|
2015-11-09 18:14:22 -04:00
|
|
|
_firmware_string(firmware_string)
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2016-05-03 03:33:15 -03:00
|
|
|
if (_instance != nullptr) {
|
|
|
|
AP_HAL::panic("DataFlash must be singleton");
|
|
|
|
}
|
|
|
|
_instance = this;
|
2015-11-09 18:14:22 -04:00
|
|
|
}
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2016-05-03 03:33:15 -03:00
|
|
|
// get singleton instance
|
|
|
|
static DataFlash_Class *instance(void) {
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
void set_mission(const AP_Mission *mission);
|
2015-05-12 03:59:55 -03:00
|
|
|
|
2013-02-22 20:17:34 -04:00
|
|
|
// initialisation
|
2015-06-25 10:53:20 -03:00
|
|
|
void Init(const struct LogStructure *structure, uint8_t num_types);
|
|
|
|
bool CardInserted(void);
|
2013-02-22 20:17:34 -04:00
|
|
|
|
|
|
|
// erase handling
|
2015-06-25 10:53:20 -03:00
|
|
|
bool NeedErase(void);
|
|
|
|
void EraseAll();
|
2013-02-22 20:17:34 -04:00
|
|
|
|
2015-08-08 03:13:38 -03:00
|
|
|
// possibly expensive calls to start log system:
|
|
|
|
bool NeedPrep();
|
|
|
|
void Prep();
|
|
|
|
|
2016-05-25 07:46:00 -03:00
|
|
|
// get a pointer to structures
|
|
|
|
const struct LogStructure *get_structures(uint8_t &num_types) {
|
|
|
|
num_types = _num_types;
|
|
|
|
return _structures;
|
|
|
|
}
|
|
|
|
|
2013-02-22 20:17:34 -04:00
|
|
|
/* Write a block of data at current offset */
|
2015-11-09 18:14:22 -04:00
|
|
|
void WriteBlock(const void *pBuffer, uint16_t size);
|
2015-08-06 09:18:28 -03:00
|
|
|
/* Write an *important* block of data at current offset */
|
2015-11-09 18:14:22 -04:00
|
|
|
void WriteCriticalBlock(const void *pBuffer, uint16_t size);
|
2013-02-22 20:17:34 -04:00
|
|
|
|
|
|
|
// high level interface
|
2015-10-20 07:32:31 -03:00
|
|
|
uint16_t find_last_log() const;
|
2015-06-25 10:53:20 -03:00
|
|
|
void get_log_boundaries(uint16_t log_num, uint16_t & start_page, uint16_t & end_page);
|
|
|
|
void get_log_info(uint16_t log_num, uint32_t &size, uint32_t &time_utc);
|
|
|
|
int16_t get_log_data(uint16_t log_num, uint16_t page, uint32_t offset, uint16_t len, uint8_t *data);
|
|
|
|
uint16_t get_num_logs(void);
|
|
|
|
void LogReadProcess(uint16_t log_num,
|
2013-04-19 04:49:16 -03:00
|
|
|
uint16_t start_page, uint16_t end_page,
|
2015-05-12 03:59:55 -03:00
|
|
|
print_mode_fn printMode,
|
2015-06-25 10:53:20 -03:00
|
|
|
AP_HAL::BetterStream *port);
|
|
|
|
void DumpPageInfo(AP_HAL::BetterStream *port);
|
|
|
|
void ShowDeviceInfo(AP_HAL::BetterStream *port);
|
|
|
|
void ListAvailableLogs(AP_HAL::BetterStream *port);
|
2013-02-22 20:17:34 -04:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
void setVehicle_Startup_Log_Writer(vehicle_startup_message_Log_Writer writer);
|
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
void StartNewLog(void);
|
2015-06-25 10:53:20 -03:00
|
|
|
void EnableWrites(bool enable);
|
2016-01-01 06:03:22 -04:00
|
|
|
|
2016-04-22 10:33:40 -03:00
|
|
|
void StopLogging();
|
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
void Log_Write_Parameter(const char *name, float value);
|
2016-05-05 00:37:16 -03:00
|
|
|
void Log_Write_GPS(const AP_GPS &gps, uint8_t instance, uint64_t time_us=0);
|
2015-09-10 07:27:47 -03:00
|
|
|
void Log_Write_RFND(const RangeFinder &rangefinder);
|
2013-11-03 23:36:14 -04:00
|
|
|
void Log_Write_IMU(const AP_InertialSensor &ins);
|
2016-05-08 23:26:30 -03:00
|
|
|
void Log_Write_IMUDT(const AP_InertialSensor &ins, uint64_t time_us, uint8_t imu_mask);
|
2015-06-11 10:26:45 -03:00
|
|
|
void Log_Write_Vibration(const AP_InertialSensor &ins);
|
2013-11-25 17:44:00 -04:00
|
|
|
void Log_Write_RCIN(void);
|
2013-11-27 07:14:17 -04:00
|
|
|
void Log_Write_RCOUT(void);
|
2015-09-04 12:50:23 -03:00
|
|
|
void Log_Write_RSSI(AP_RSSI &rssi);
|
2016-05-05 00:37:16 -03:00
|
|
|
void Log_Write_Baro(AP_Baro &baro, uint64_t time_us=0);
|
2014-02-13 07:07:32 -04:00
|
|
|
void Log_Write_Power(void);
|
2014-01-03 01:01:08 -04:00
|
|
|
void Log_Write_AHRS2(AP_AHRS &ahrs);
|
2015-05-14 22:59:40 -03:00
|
|
|
void Log_Write_POS(AP_AHRS &ahrs);
|
2014-01-03 20:51:22 -04:00
|
|
|
#if AP_AHRS_NAVEKF_AVAILABLE
|
2014-12-23 16:39:23 -04:00
|
|
|
void Log_Write_EKF(AP_AHRS_NavEKF &ahrs, bool optFlowEnabled);
|
2015-09-22 23:09:48 -03:00
|
|
|
void Log_Write_EKF2(AP_AHRS_NavEKF &ahrs, bool optFlowEnabled);
|
2014-01-03 20:51:22 -04:00
|
|
|
#endif
|
2015-08-06 09:18:28 -03:00
|
|
|
bool Log_Write_MavCmd(uint16_t cmd_total, const mavlink_mission_item_t& mav_cmd);
|
2014-03-11 14:05:02 -03:00
|
|
|
void Log_Write_Radio(const mavlink_radio_t &packet);
|
2015-11-09 18:14:22 -04:00
|
|
|
void Log_Write_Message(const char *message);
|
2016-01-28 18:51:52 -04:00
|
|
|
void Log_Write_CameraInfo(enum LogMessages msg, const AP_AHRS &ahrs, const AP_GPS &gps, const Location ¤t_loc);
|
2014-06-10 23:55:04 -03:00
|
|
|
void Log_Write_Camera(const AP_AHRS &ahrs, const AP_GPS &gps, const Location ¤t_loc);
|
2016-01-06 20:29:52 -04:00
|
|
|
void Log_Write_Trigger(const AP_AHRS &ahrs, const AP_GPS &gps, const Location ¤t_loc);
|
2014-11-13 06:38:33 -04:00
|
|
|
void Log_Write_ESC(void);
|
2015-01-19 18:10:33 -04:00
|
|
|
void Log_Write_Airspeed(AP_Airspeed &airspeed);
|
2015-01-20 15:44:39 -04:00
|
|
|
void Log_Write_Attitude(AP_AHRS &ahrs, const Vector3f &targets);
|
2016-06-02 17:58:26 -03:00
|
|
|
void Log_Write_Current(const AP_BattMonitor &battery);
|
2016-05-05 00:37:16 -03:00
|
|
|
void Log_Write_Compass(const Compass &compass, uint64_t time_us=0);
|
2016-01-25 19:45:27 -04:00
|
|
|
void Log_Write_Mode(uint8_t mode, uint8_t reason = 0);
|
2013-04-19 04:49:16 -03:00
|
|
|
|
2015-06-30 01:33:50 -03:00
|
|
|
void Log_Write_EntireMission(const AP_Mission &mission);
|
2015-11-09 18:14:22 -04:00
|
|
|
void Log_Write_Mission_Cmd(const AP_Mission &mission,
|
2015-06-30 01:33:50 -03:00
|
|
|
const AP_Mission::Mission_Command &cmd);
|
2015-07-03 08:49:45 -03:00
|
|
|
void Log_Write_Origin(uint8_t origin_type, const Location &loc);
|
2015-08-07 07:34:14 -03:00
|
|
|
void Log_Write_RPM(const AP_RPM &rpm_sensor);
|
2016-03-24 22:11:11 -03:00
|
|
|
void Log_Write_Rate(const AP_AHRS &ahrs,
|
|
|
|
const AP_Motors &motors,
|
|
|
|
const AC_AttitudeControl &attitude_control,
|
|
|
|
const AC_PosControl &pos_control);
|
2016-07-03 23:14:26 -03:00
|
|
|
void Log_Write_Rally(const AP_Rally &rally);
|
2015-06-30 01:33:50 -03:00
|
|
|
|
2016-04-20 02:07:48 -03:00
|
|
|
void Log_Write(const char *name, const char *labels, const char *fmt, ...);
|
|
|
|
|
2015-05-21 22:42:08 -03:00
|
|
|
// This structure provides information on the internal member data of a PID for logging purposes
|
|
|
|
struct PID_Info {
|
2015-05-22 19:56:05 -03:00
|
|
|
float desired;
|
2015-05-21 22:42:08 -03:00
|
|
|
float P;
|
|
|
|
float I;
|
|
|
|
float D;
|
|
|
|
float FF;
|
2015-05-22 20:57:49 -03:00
|
|
|
float AFF;
|
2015-05-21 22:42:08 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
void Log_Write_PID(uint8_t msg_type, const PID_Info &info);
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
bool logging_started(void);
|
2013-04-19 04:49:16 -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:
|
|
|
|
void flush(void);
|
|
|
|
#endif
|
|
|
|
|
2015-11-10 02:34:31 -04:00
|
|
|
// for DataFlash_MAVLink:
|
|
|
|
void remote_log_block_status_msg(mavlink_channel_t chan,
|
|
|
|
mavlink_message_t* msg);
|
|
|
|
// end for DataFlash_MAVLink:
|
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
void periodic_tasks(); // may want to split this into GCS/non-GCS duties
|
|
|
|
|
2016-04-21 03:11:21 -03:00
|
|
|
// number of blocks that have been dropped
|
|
|
|
uint32_t num_dropped(void) const;
|
2016-05-08 23:00:55 -03:00
|
|
|
|
|
|
|
// accesss to public parameters
|
|
|
|
bool log_while_disarmed(void) const { return _params.log_disarmed != 0; }
|
|
|
|
uint8_t log_replay(void) const { return _params.log_replay; }
|
2016-04-21 03:11:21 -03:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
vehicle_startup_message_Log_Writer _vehicle_messages;
|
|
|
|
|
2015-11-09 18:14:22 -04:00
|
|
|
// parameter support
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
struct {
|
|
|
|
AP_Int8 backend_types;
|
2015-12-03 07:01:53 -04:00
|
|
|
AP_Int8 file_bufsize; // in kilobytes
|
2016-05-08 23:00:55 -03:00
|
|
|
AP_Int8 log_disarmed;
|
|
|
|
AP_Int8 log_replay;
|
2015-11-09 18:14:22 -04:00
|
|
|
} _params;
|
|
|
|
|
|
|
|
const struct LogStructure *structure(uint16_t num) const;
|
|
|
|
|
2016-07-07 04:12:27 -03:00
|
|
|
// methods for mavlink SYS_STATUS message (send_extended_status1)
|
|
|
|
// these methods cover only the first logging backend used -
|
|
|
|
// typically DataFlash_File.
|
|
|
|
bool logging_present() const;
|
|
|
|
bool logging_enabled() const;
|
|
|
|
bool logging_failed() const;
|
|
|
|
|
2013-04-19 04:49:16 -03:00
|
|
|
protected:
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2013-12-16 20:12:42 -04:00
|
|
|
const struct LogStructure *_structures;
|
|
|
|
uint8_t _num_types;
|
2013-04-19 21:25:10 -03:00
|
|
|
|
2015-08-06 09:18:28 -03:00
|
|
|
/* Write a block with specified importance */
|
|
|
|
/* might be useful if you have a boolean indicating a message is
|
|
|
|
* important... */
|
2015-11-09 18:14:22 -04:00
|
|
|
void WritePrioritisedBlock(const void *pBuffer, uint16_t size,
|
2015-08-06 09:18:28 -03:00
|
|
|
bool is_critical);
|
|
|
|
|
2015-06-25 10:53:20 -03:00
|
|
|
private:
|
2015-11-09 18:14:22 -04:00
|
|
|
#define DATAFLASH_MAX_BACKENDS 2
|
|
|
|
uint8_t _next_backend;
|
|
|
|
DataFlash_Backend *backends[DATAFLASH_MAX_BACKENDS];
|
|
|
|
const char *_firmware_string;
|
2016-04-20 02:07:48 -03:00
|
|
|
|
|
|
|
void internal_error() const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* support for dynamic Log_Write; user-supplies name, format,
|
|
|
|
* labels and values in a single function call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// this structure looks much like struct LogStructure in
|
|
|
|
// LogStructure.h, however we need to remember a pointer value for
|
|
|
|
// efficiency of finding message types
|
2016-05-04 06:06:23 -03:00
|
|
|
struct log_write_fmt {
|
|
|
|
struct log_write_fmt *next;
|
2016-04-20 02:07:48 -03:00
|
|
|
uint8_t msg_type;
|
|
|
|
uint8_t msg_len;
|
2016-05-04 06:06:23 -03:00
|
|
|
uint8_t sent_mask; // bitmask of backends sent to
|
2016-04-20 02:07:48 -03:00
|
|
|
const char *name;
|
|
|
|
const char *fmt;
|
|
|
|
const char *labels;
|
2016-05-04 06:06:23 -03:00
|
|
|
} *log_write_fmts;
|
2016-04-20 02:07:48 -03:00
|
|
|
|
2016-05-04 06:06:23 -03:00
|
|
|
// return (possibly allocating) a log_write_fmt for a name
|
|
|
|
struct log_write_fmt *msg_fmt_for_name(const char *name, const char *labels, const char *fmt);
|
|
|
|
|
2016-04-20 02:07:48 -03:00
|
|
|
// returns true if msg_type is associated with a message
|
|
|
|
bool msg_type_in_use(uint8_t msg_type) const;
|
|
|
|
|
|
|
|
// return a msg_type which is not currently in use (or -1 if none available)
|
|
|
|
int16_t find_free_msg_type() const;
|
|
|
|
|
|
|
|
// fill LogStructure with information about msg_type
|
|
|
|
bool fill_log_write_logstructure(struct LogStructure &logstruct, const uint8_t msg_type) const;
|
|
|
|
|
|
|
|
// calculate the length of a message using fields specified in
|
|
|
|
// fmt; includes the message header
|
|
|
|
int16_t Log_Write_calc_msg_len(const char *fmt) const;
|
2016-05-03 03:33:15 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
static DataFlash_Class *_instance;
|
2011-11-12 23:29:07 -04:00
|
|
|
};
|