2011-03-19 07:20:11 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-12-23 18:26:24 -04:00
|
|
|
#if LOGGING_ENABLED == ENABLED
|
2011-07-17 07:31:07 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Code to Write and Read packets from DataFlash log memory
|
|
|
|
// Code to interact with the user to dump or erase logs
|
|
|
|
|
|
|
|
// These are function definitions so the Menu can be constructed before the functions
|
|
|
|
// are defined below. Order matters to the compiler.
|
2011-07-17 07:30:21 -03:00
|
|
|
static bool print_log_menu(void);
|
2012-08-21 23:19:50 -03:00
|
|
|
static int8_t dump_log(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t erase_logs(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t select_logs(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// Creates a constant array of structs representing menu options
|
|
|
|
// and stores them in Flash memory, not RAM.
|
|
|
|
// User enters the string in the console to call the functions on the right.
|
|
|
|
// See class Menu in AP_Coommon for implementation details
|
|
|
|
const struct Menu::command log_menu_commands[] PROGMEM = {
|
2012-08-21 23:19:50 -03:00
|
|
|
{"dump", dump_log},
|
|
|
|
{"erase", erase_logs},
|
|
|
|
{"enable", select_logs},
|
|
|
|
{"disable", select_logs}
|
2010-12-19 12:40:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU2(log_menu, "Log", log_menu_commands, print_log_menu);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
print_log_menu(void)
|
|
|
|
{
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("logs enabled: "));
|
2012-08-21 23:19:50 -03:00
|
|
|
|
|
|
|
if (0 == g.log_bitmask) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("none"));
|
2012-08-21 23:19:50 -03:00
|
|
|
}else{
|
2012-11-21 02:08:03 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_ATTITUDE_FAST) cliSerial->printf_P(PSTR(" ATTITUDE_FAST"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_ATTITUDE_MED) cliSerial->printf_P(PSTR(" ATTITUDE_MED"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_GPS) cliSerial->printf_P(PSTR(" GPS"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_PM) cliSerial->printf_P(PSTR(" PM"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_CTUN) cliSerial->printf_P(PSTR(" CTUN"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_NTUN) cliSerial->printf_P(PSTR(" NTUN"));
|
2013-01-12 11:17:44 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_IMU) cliSerial->printf_P(PSTR(" IMU"));
|
2012-11-21 02:08:03 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_CMD) cliSerial->printf_P(PSTR(" CMD"));
|
2013-01-26 04:20:41 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_CURRENT) cliSerial->printf_P(PSTR(" CURRENT"));
|
2012-11-21 02:08:03 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_MOTORS) cliSerial->printf_P(PSTR(" MOTORS"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_OPTFLOW) cliSerial->printf_P(PSTR(" OPTFLOW"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_PID) cliSerial->printf_P(PSTR(" PID"));
|
2013-02-09 02:24:02 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_COMPASS) cliSerial->printf_P(PSTR(" COMPASS"));
|
2012-11-21 02:08:03 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_INAV) cliSerial->printf_P(PSTR(" INAV"));
|
2012-12-06 11:57:08 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_CAMERA) cliSerial->printf_P(PSTR(" CAMERA"));
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->println();
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2013-04-17 08:34:42 -03:00
|
|
|
DataFlash.ListAvailableLogs(cliSerial);
|
|
|
|
|
2012-08-21 23:19:50 -03:00
|
|
|
return(true);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
dump_log(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
int16_t dump_log;
|
2013-02-22 19:15:01 -04:00
|
|
|
uint16_t dump_log_start;
|
|
|
|
uint16_t dump_log_end;
|
|
|
|
uint16_t last_log_num;
|
2012-08-21 23:19:50 -03:00
|
|
|
|
|
|
|
// check that the requested log number can be read
|
|
|
|
dump_log = argv[1].i;
|
|
|
|
last_log_num = DataFlash.find_last_log();
|
|
|
|
|
|
|
|
if (dump_log == -2) {
|
2013-02-22 19:15:01 -04:00
|
|
|
DataFlash.DumpPageInfo(cliSerial);
|
2012-08-21 23:19:50 -03:00
|
|
|
return(-1);
|
|
|
|
} else if (dump_log <= 0) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("dumping all\n"));
|
2013-02-28 16:16:48 -04:00
|
|
|
Log_Read(0, 1, 0);
|
2012-08-21 23:19:50 -03:00
|
|
|
return(-1);
|
2013-07-07 22:24:01 -03:00
|
|
|
} else if ((argc != 2) || ((uint16_t)dump_log <= (last_log_num - DataFlash.get_num_logs())) || (static_cast<uint16_t>(dump_log) > last_log_num)) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("bad log number\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DataFlash.get_log_boundaries(dump_log, dump_log_start, dump_log_end);
|
2013-04-17 08:34:42 -03:00
|
|
|
Log_Read((uint16_t)dump_log, dump_log_start, dump_log_end);
|
2012-08-21 23:19:50 -03:00
|
|
|
return (0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-12-28 00:53:05 -04:00
|
|
|
static void do_erase_logs(void)
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2012-08-28 19:31:02 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW, PSTR("Erasing logs\n"));
|
2012-12-12 21:25:09 -04:00
|
|
|
DataFlash.EraseAll();
|
2012-08-28 19:31:02 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW, PSTR("Log erase complete\n"));
|
2011-12-17 19:19:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
erase_logs(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-12-28 00:53:05 -04:00
|
|
|
in_mavlink_delay = true;
|
|
|
|
do_erase_logs();
|
|
|
|
in_mavlink_delay = false;
|
2011-11-25 10:13:32 -04:00
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
select_logs(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
uint16_t bits;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("missing log type\n"));
|
2012-08-21 23:19:50 -03:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bits = 0;
|
|
|
|
|
|
|
|
// Macro to make the following code a bit easier on the eye.
|
|
|
|
// Pass it the capitalised name of the log option, as defined
|
|
|
|
// in defines.h but without the LOG_ prefix. It will check for
|
|
|
|
// that name as the argument to the command, and set the bit in
|
|
|
|
// bits accordingly.
|
|
|
|
//
|
|
|
|
if (!strcasecmp_P(argv[1].str, PSTR("all"))) {
|
|
|
|
bits = ~0;
|
|
|
|
} else {
|
|
|
|
#define TARG(_s) if (!strcasecmp_P(argv[1].str, PSTR(# _s))) bits |= MASK_LOG_ ## _s
|
|
|
|
TARG(ATTITUDE_FAST);
|
|
|
|
TARG(ATTITUDE_MED);
|
|
|
|
TARG(GPS);
|
|
|
|
TARG(PM);
|
|
|
|
TARG(CTUN);
|
|
|
|
TARG(NTUN);
|
|
|
|
TARG(MODE);
|
2013-01-12 11:17:44 -04:00
|
|
|
TARG(IMU);
|
2012-08-21 23:19:50 -03:00
|
|
|
TARG(CMD);
|
2013-01-26 04:20:41 -04:00
|
|
|
TARG(CURRENT);
|
2012-08-21 23:19:50 -03:00
|
|
|
TARG(MOTORS);
|
|
|
|
TARG(OPTFLOW);
|
|
|
|
TARG(PID);
|
2013-02-09 02:24:02 -04:00
|
|
|
TARG(COMPASS);
|
2012-11-07 06:03:30 -04:00
|
|
|
TARG(INAV);
|
2012-12-06 11:57:08 -04:00
|
|
|
TARG(CAMERA);
|
2012-08-21 23:19:50 -03:00
|
|
|
#undef TARG
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp_P(argv[0].str, PSTR("enable"))) {
|
|
|
|
g.log_bitmask.set_and_save(g.log_bitmask | bits);
|
|
|
|
}else{
|
|
|
|
g.log_bitmask.set_and_save(g.log_bitmask & ~bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static int8_t
|
2010-12-19 12:40:33 -04:00
|
|
|
process_logs(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
log_menu.run();
|
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Current {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
int16_t throttle_in;
|
|
|
|
uint32_t throttle_integrator;
|
|
|
|
int16_t battery_voltage;
|
|
|
|
int16_t current_amps;
|
2013-04-19 21:28:59 -03:00
|
|
|
uint16_t board_voltage;
|
|
|
|
float current_total;
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
2011-07-10 21:47:08 -03:00
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an Current data packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Current()
|
2011-01-16 23:44:12 -04:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Current pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CURRENT_MSG),
|
|
|
|
throttle_in : g.rc_3.control_in,
|
|
|
|
throttle_integrator : throttle_integrator,
|
2013-01-10 14:42:24 -04:00
|
|
|
battery_voltage : (int16_t) (battery_voltage1 * 100.0f),
|
|
|
|
current_amps : (int16_t) (current_amps1 * 100.0f),
|
2013-04-19 21:28:59 -03:00
|
|
|
board_voltage : board_voltage(),
|
|
|
|
current_total : current_total1
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-01-16 23:44:12 -04:00
|
|
|
}
|
2011-01-29 22:36:03 -04:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Motors {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
#if FRAME_CONFIG == OCTA_FRAME || FRAME_CONFIG == OCTA_QUAD_FRAME
|
|
|
|
int16_t motor_out[8];
|
|
|
|
#elif FRAME_CONFIG == HEXA_FRAME || FRAME_CONFIG == Y6_FRAME
|
|
|
|
int16_t motor_out[6];
|
|
|
|
#elif FRAME_CONFIG == HELI_FRAME
|
|
|
|
int16_t motor_out[4];
|
|
|
|
int16_t ext_gyro_gain;
|
|
|
|
#else // quads & TRI_FRAME
|
|
|
|
int16_t motor_out[4];
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an Motors packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Motors()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Motors pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MOTORS_MSG),
|
|
|
|
#if FRAME_CONFIG == OCTA_FRAME || FRAME_CONFIG == OCTA_QUAD_FRAME
|
|
|
|
motor_out : {motors.motor_out[AP_MOTORS_MOT_1],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_2],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_3],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_4],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_5],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_6],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_7],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_8]}
|
|
|
|
#elif FRAME_CONFIG == HEXA_FRAME || FRAME_CONFIG == Y6_FRAME
|
|
|
|
motor_out : {motors.motor_out[AP_MOTORS_MOT_1],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_2],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_3],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_4],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_5],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_6]}
|
|
|
|
#elif FRAME_CONFIG == HELI_FRAME
|
|
|
|
motor_out : {motors.motor_out[AP_MOTORS_MOT_1],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_2],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_3],
|
2013-01-13 02:57:47 -04:00
|
|
|
motors.motor_out[AP_MOTORS_MOT_4]},
|
|
|
|
ext_gyro_gain : motors.ext_gyro_gain
|
2013-01-12 11:17:44 -04:00
|
|
|
#elif FRAME_CONFIG == TRI_FRAME
|
|
|
|
motor_out : {motors.motor_out[AP_MOTORS_MOT_1],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_2],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_4],
|
|
|
|
motors.motor_out[g.rc_4.radio_out]}
|
|
|
|
#else // QUAD frame
|
|
|
|
motor_out : {motors.motor_out[AP_MOTORS_MOT_1],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_2],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_3],
|
|
|
|
motors.motor_out[AP_MOTORS_MOT_4]}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Optflow {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
int16_t dx;
|
|
|
|
int16_t dy;
|
|
|
|
uint8_t surface_quality;
|
|
|
|
int16_t x_cm;
|
|
|
|
int16_t y_cm;
|
|
|
|
float latitude;
|
|
|
|
float longitude;
|
|
|
|
int32_t roll;
|
|
|
|
int32_t pitch;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an optical flow packet
|
2011-07-21 20:14:53 -03:00
|
|
|
static void Log_Write_Optflow()
|
|
|
|
{
|
2012-11-18 12:16:07 -04:00
|
|
|
#if OPTFLOW == ENABLED
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Optflow pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_OPTFLOW_MSG),
|
|
|
|
dx : optflow.dx,
|
|
|
|
dy : optflow.dx,
|
|
|
|
surface_quality : optflow.surface_quality,
|
2013-01-13 02:53:39 -04:00
|
|
|
x_cm : (int16_t) optflow.x_cm,
|
|
|
|
y_cm : (int16_t) optflow.y_cm,
|
2013-01-12 11:17:44 -04:00
|
|
|
latitude : optflow.vlat,
|
|
|
|
longitude : optflow.vlon,
|
|
|
|
roll : of_roll,
|
|
|
|
pitch : of_pitch
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-11-18 12:16:07 -04:00
|
|
|
#endif // OPTFLOW == ENABLED
|
2011-07-21 20:14:53 -03:00
|
|
|
}
|
2011-12-23 18:26:24 -04:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Nav_Tuning {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2013-01-26 04:05:38 -04:00
|
|
|
uint32_t wp_distance;
|
2013-02-18 01:58:24 -04:00
|
|
|
int16_t wp_bearing;
|
2013-05-19 10:53:35 -03:00
|
|
|
float pos_error_x;
|
|
|
|
float pos_error_y;
|
|
|
|
float desired_velocity_x;
|
|
|
|
float desired_velocity_y;
|
|
|
|
float velocity_x;
|
|
|
|
float velocity_y;
|
|
|
|
float desired_accel_x;
|
|
|
|
float desired_accel_y;
|
|
|
|
int32_t desired_roll;
|
|
|
|
int32_t desired_pitch;
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
2011-07-21 20:14:53 -03:00
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an Nav Tuning packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Nav_Tuning()
|
2011-05-23 02:53:00 -03:00
|
|
|
{
|
2013-05-19 10:53:35 -03:00
|
|
|
Vector3f velocity = inertial_nav.get_velocity();
|
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Nav_Tuning pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_NAV_TUNING_MSG),
|
2013-05-19 10:53:35 -03:00
|
|
|
wp_distance : wp_distance,
|
|
|
|
wp_bearing : (int16_t) (wp_bearing/100),
|
|
|
|
pos_error_x : wp_nav.dist_error.x,
|
|
|
|
pos_error_y : wp_nav.dist_error.y,
|
|
|
|
desired_velocity_x : wp_nav.desired_vel.x,
|
|
|
|
desired_velocity_y : wp_nav.desired_vel.y,
|
|
|
|
velocity_x : velocity.x,
|
|
|
|
velocity_y : velocity.y,
|
|
|
|
desired_accel_x : wp_nav.desired_accel.x,
|
|
|
|
desired_accel_y : wp_nav.desired_accel.y,
|
|
|
|
desired_roll : wp_nav.get_desired_roll(),
|
|
|
|
desired_pitch : wp_nav.get_desired_pitch()
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-05-23 02:53:00 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Control_Tuning {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
int16_t throttle_in;
|
|
|
|
int16_t sonar_alt;
|
2013-03-22 09:59:17 -03:00
|
|
|
int32_t baro_alt;
|
|
|
|
float next_wp_alt;
|
2013-01-12 11:17:44 -04:00
|
|
|
int16_t nav_throttle;
|
|
|
|
int16_t angle_boost;
|
|
|
|
int16_t climb_rate;
|
|
|
|
int16_t throttle_out;
|
|
|
|
int16_t desired_climb_rate;
|
|
|
|
};
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a control tuning packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Control_Tuning()
|
2011-04-21 02:15:45 -03:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Control_Tuning pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CONTROL_TUNING_MSG),
|
|
|
|
throttle_in : g.rc_3.control_in,
|
|
|
|
sonar_alt : sonar_alt,
|
2013-03-22 09:59:17 -03:00
|
|
|
baro_alt : baro_alt,
|
2013-05-08 04:41:16 -03:00
|
|
|
next_wp_alt : get_target_alt_for_reporting() / 100.0f,
|
2013-01-12 11:17:44 -04:00
|
|
|
nav_throttle : nav_throttle,
|
|
|
|
angle_boost : angle_boost,
|
|
|
|
climb_rate : climb_rate,
|
|
|
|
throttle_out : g.rc_3.servo_out,
|
|
|
|
desired_climb_rate : desired_climb_rate
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-04-21 02:15:45 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Compass {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2013-02-09 02:24:02 -04:00
|
|
|
int16_t mag_x;
|
|
|
|
int16_t mag_y;
|
|
|
|
int16_t mag_z;
|
|
|
|
int16_t offset_x;
|
|
|
|
int16_t offset_y;
|
|
|
|
int16_t offset_z;
|
2013-03-01 04:57:40 -04:00
|
|
|
int16_t motor_offset_x;
|
|
|
|
int16_t motor_offset_y;
|
|
|
|
int16_t motor_offset_z;
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a Compass packet
|
2013-02-09 02:24:02 -04:00
|
|
|
static void Log_Write_Compass()
|
2012-09-11 00:26:48 -03:00
|
|
|
{
|
2013-02-09 02:24:02 -04:00
|
|
|
Vector3f mag_offsets = compass.get_offsets();
|
2013-03-01 04:57:40 -04:00
|
|
|
Vector3f mag_motor_offsets = compass.get_motor_offsets();
|
2013-02-09 02:24:02 -04:00
|
|
|
struct log_Compass pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_COMPASS_MSG),
|
2013-03-01 04:57:40 -04:00
|
|
|
mag_x : compass.mag_x,
|
|
|
|
mag_y : compass.mag_y,
|
|
|
|
mag_z : compass.mag_z,
|
|
|
|
offset_x : (int16_t)mag_offsets.x,
|
|
|
|
offset_y : (int16_t)mag_offsets.y,
|
|
|
|
offset_z : (int16_t)mag_offsets.z,
|
|
|
|
motor_offset_x : (int16_t)mag_motor_offsets.x,
|
|
|
|
motor_offset_y : (int16_t)mag_motor_offsets.y,
|
|
|
|
motor_offset_z : (int16_t)mag_motor_offsets.z
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-09-11 00:26:48 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Performance {
|
2013-01-12 03:15:23 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t renorm_count;
|
|
|
|
uint8_t renorm_blowup;
|
|
|
|
uint8_t gps_fix_count;
|
|
|
|
uint16_t num_long_running;
|
|
|
|
uint16_t num_loops;
|
|
|
|
uint32_t max_time;
|
2013-04-29 09:30:22 -03:00
|
|
|
int16_t pm_test;
|
2013-04-26 10:39:22 -03:00
|
|
|
uint8_t i2c_lockup_count;
|
2013-01-12 03:15:23 -04:00
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a performance monitoring packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Performance()
|
2011-05-09 01:16:58 -03:00
|
|
|
{
|
2013-01-12 03:15:23 -04:00
|
|
|
struct log_Performance pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PERFORMANCE_MSG),
|
|
|
|
renorm_count : ahrs.renorm_range_count,
|
|
|
|
renorm_blowup : ahrs.renorm_blowup_count,
|
|
|
|
gps_fix_count : gps_fix_count,
|
|
|
|
num_long_running : perf_info_get_num_long_running(),
|
|
|
|
num_loops : perf_info_get_num_loops(),
|
2013-04-26 10:39:22 -03:00
|
|
|
max_time : perf_info_get_max_time(),
|
2013-04-29 09:30:22 -03:00
|
|
|
pm_test : pmTest1,
|
2013-04-26 10:39:22 -03:00
|
|
|
i2c_lockup_count : hal.i2c->lockup_count()
|
2013-01-12 03:15:23 -04:00
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-05-09 01:16:58 -03:00
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Cmd {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t command_total;
|
|
|
|
uint8_t command_number;
|
|
|
|
uint8_t waypoint_id;
|
|
|
|
uint8_t waypoint_options;
|
|
|
|
uint8_t waypoint_param1;
|
|
|
|
int32_t waypoint_altitude;
|
|
|
|
int32_t waypoint_latitude;
|
|
|
|
int32_t waypoint_longitude;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a command processing packet
|
2013-03-26 08:58:54 -03:00
|
|
|
static void Log_Write_Cmd(uint8_t num, const struct Location *wp)
|
2011-05-12 18:37:38 -03:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Cmd pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CMD_MSG),
|
|
|
|
command_total : g.command_total,
|
|
|
|
command_number : num,
|
|
|
|
waypoint_id : wp->id,
|
|
|
|
waypoint_options : wp->options,
|
|
|
|
waypoint_param1 : wp->p1,
|
|
|
|
waypoint_altitude : wp->alt,
|
|
|
|
waypoint_latitude : wp->lat,
|
|
|
|
waypoint_longitude : wp->lng
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-05-12 18:37:38 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Attitude {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
int16_t roll_in;
|
|
|
|
int16_t roll;
|
|
|
|
int16_t pitch_in;
|
|
|
|
int16_t pitch;
|
|
|
|
int16_t yaw_in;
|
|
|
|
uint16_t yaw;
|
|
|
|
uint16_t nav_yaw;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an attitude packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Attitude()
|
2011-05-09 01:16:58 -03:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Attitude pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_ATTITUDE_MSG),
|
|
|
|
roll_in : (int16_t)control_roll,
|
|
|
|
roll : (int16_t)ahrs.roll_sensor,
|
|
|
|
pitch_in : (int16_t)control_pitch,
|
|
|
|
pitch : (int16_t)ahrs.pitch_sensor,
|
|
|
|
yaw_in : (int16_t)g.rc_4.control_in,
|
|
|
|
yaw : (uint16_t)ahrs.yaw_sensor,
|
|
|
|
nav_yaw : (uint16_t)nav_yaw
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-05-09 01:16:58 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_INAV {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
int16_t baro_alt;
|
|
|
|
int16_t inav_alt;
|
|
|
|
int16_t inav_climb_rate;
|
|
|
|
float accel_corr_x;
|
|
|
|
float accel_corr_y;
|
|
|
|
float accel_corr_z;
|
|
|
|
int32_t gps_lat_from_home;
|
|
|
|
int32_t gps_lon_from_home;
|
|
|
|
float inav_lat_from_home;
|
|
|
|
float inav_lon_from_home;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an INAV packet
|
2012-12-28 03:21:13 -04:00
|
|
|
static void Log_Write_INAV()
|
2012-11-07 06:03:30 -04:00
|
|
|
{
|
2013-01-05 22:59:09 -04:00
|
|
|
Vector3f accel_corr = inertial_nav.accel_correction_ef;
|
2012-12-09 11:43:11 -04:00
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_INAV pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_INAV_MSG),
|
|
|
|
baro_alt : (int16_t)baro_alt, // 1 barometer altitude
|
|
|
|
inav_alt : (int16_t)inertial_nav.get_altitude(), // 2 accel + baro filtered altitude
|
2013-02-01 23:00:09 -04:00
|
|
|
inav_climb_rate : (int16_t)inertial_nav.get_velocity_z(), // 3 accel + baro based climb rate
|
|
|
|
accel_corr_x : accel_corr.x, // 4 accel correction x-axis
|
|
|
|
accel_corr_y : accel_corr.y, // 5 accel correction y-axis
|
|
|
|
accel_corr_z : accel_corr.z, // 6 accel correction z-axis
|
2013-04-15 09:54:29 -03:00
|
|
|
gps_lat_from_home : g_gps->latitude-home.lat, // 7 lat from home
|
|
|
|
gps_lon_from_home : g_gps->longitude-home.lng, // 8 lon from home
|
|
|
|
inav_lat_from_home : inertial_nav.get_latitude_diff(), // 9 accel based lat from home
|
2013-04-17 10:39:30 -03:00
|
|
|
inav_lon_from_home : inertial_nav.get_longitude_diff() // 10 accel based lon from home
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-11-07 06:03:30 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Mode {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t mode;
|
|
|
|
int16_t throttle_cruise;
|
|
|
|
};
|
2012-11-07 06:03:30 -04:00
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a mode packet
|
2012-12-12 19:46:20 -04:00
|
|
|
static void Log_Write_Mode(uint8_t mode)
|
2011-05-16 02:28:20 -03:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Mode pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MODE_MSG),
|
|
|
|
mode : mode,
|
|
|
|
throttle_cruise : g.throttle_cruise,
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-05-16 02:28:20 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Startup {
|
2013-01-26 04:05:38 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write Startup packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Startup()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2013-01-26 04:05:38 -04:00
|
|
|
struct log_Startup pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_STARTUP_MSG)
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Event {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
};
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
// Wrote an event packet
|
|
|
|
static void Log_Write_Event(uint8_t id)
|
2011-11-19 20:57:10 -04:00
|
|
|
{
|
2013-01-09 08:06:40 -04:00
|
|
|
if (g.log_bitmask != 0) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Event pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_EVENT_MSG),
|
|
|
|
id : id
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_Int16t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
int16_t data_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write an int16_t data packet
|
|
|
|
static void Log_Write_Data(uint8_t id, int16_t value)
|
2011-11-19 20:57:10 -04:00
|
|
|
{
|
2013-01-09 08:06:40 -04:00
|
|
|
if (g.log_bitmask != 0) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_Int16t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_INT16_MSG),
|
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_UInt16t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
uint16_t data_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write an uint16_t data packet
|
|
|
|
static void Log_Write_Data(uint8_t id, uint16_t value)
|
2012-11-10 02:04:23 -04:00
|
|
|
{
|
2013-01-09 08:06:40 -04:00
|
|
|
if (g.log_bitmask != 0) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_UInt16t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_UINT16_MSG),
|
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_Int32t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
int32_t data_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write an int32_t data packet
|
|
|
|
static void Log_Write_Data(uint8_t id, int32_t value)
|
2012-11-10 02:04:23 -04:00
|
|
|
{
|
2013-01-09 08:06:40 -04:00
|
|
|
if (g.log_bitmask != 0) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_Int32t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_INT32_MSG),
|
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2011-11-19 20:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_UInt32t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
uint32_t data_value;
|
|
|
|
};
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
// Write a uint32_t data packet
|
|
|
|
static void Log_Write_Data(uint8_t id, uint32_t value)
|
|
|
|
{
|
|
|
|
if (g.log_bitmask != 0) {
|
|
|
|
struct log_Data_UInt32t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_UINT32_MSG),
|
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_Float {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
float data_value;
|
|
|
|
};
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
// Write a float data packet
|
|
|
|
static void Log_Write_Data(uint8_t id, float value)
|
|
|
|
{
|
|
|
|
if (g.log_bitmask != 0) {
|
|
|
|
struct log_Data_Float pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_FLOAT_MSG),
|
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
2011-11-19 20:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_PID {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t id;
|
|
|
|
int32_t error;
|
|
|
|
int32_t p;
|
|
|
|
int32_t i;
|
|
|
|
int32_t d;
|
|
|
|
int32_t output;
|
|
|
|
float gain;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an PID packet
|
2013-01-13 02:53:39 -04:00
|
|
|
static void Log_Write_PID(uint8_t pid_id, int32_t error, int32_t p, int32_t i, int32_t d, int32_t output, float gain)
|
2012-03-25 03:55:49 -03:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_PID pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PID_MSG),
|
|
|
|
id : pid_id,
|
|
|
|
error : error,
|
|
|
|
p : p,
|
|
|
|
i : i,
|
|
|
|
d : d,
|
|
|
|
output : output,
|
|
|
|
gain : gain
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-03-25 03:55:49 -03:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_DMP {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
int16_t dcm_roll;
|
|
|
|
int16_t dmp_roll;
|
|
|
|
int16_t dcm_pitch;
|
|
|
|
int16_t dmp_pitch;
|
|
|
|
uint16_t dcm_yaw;
|
|
|
|
uint16_t dmp_yaw;
|
|
|
|
};
|
|
|
|
|
2013-04-05 10:25:58 -03:00
|
|
|
#if SECONDARY_DMP_ENABLED == ENABLED
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a DMP attitude packet
|
2012-09-29 12:25:40 -03:00
|
|
|
static void Log_Write_DMP()
|
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_DMP pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DMP_MSG),
|
|
|
|
dcm_roll : (int16_t)ahrs.roll_sensor,
|
|
|
|
dmp_roll : (int16_t)ahrs2.roll_sensor,
|
|
|
|
dcm_pitch : (int16_t)ahrs.pitch_sensor,
|
|
|
|
dmp_pitch : (int16_t)ahrs2.pitch_sensor,
|
|
|
|
dcm_yaw : (uint16_t)ahrs.yaw_sensor,
|
|
|
|
dmp_yaw : (uint16_t)ahrs2.yaw_sensor
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-09-29 12:25:40 -03:00
|
|
|
}
|
2013-04-05 10:25:58 -03:00
|
|
|
#endif
|
2012-09-29 12:25:40 -03:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Camera {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint32_t gps_time;
|
|
|
|
int32_t latitude;
|
|
|
|
int32_t longitude;
|
|
|
|
int32_t altitude;
|
|
|
|
int16_t roll;
|
|
|
|
int16_t pitch;
|
|
|
|
uint16_t yaw;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a Camera packet
|
2012-12-06 11:57:08 -04:00
|
|
|
static void Log_Write_Camera()
|
|
|
|
{
|
|
|
|
#if CAMERA == ENABLED
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Camera pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CAMERA_MSG),
|
|
|
|
gps_time : g_gps->time,
|
|
|
|
latitude : current_loc.lat,
|
|
|
|
longitude : current_loc.lng,
|
|
|
|
altitude : current_loc.alt,
|
|
|
|
roll : (int16_t)ahrs.roll_sensor,
|
|
|
|
pitch : (int16_t)ahrs.pitch_sensor,
|
|
|
|
yaw : (uint16_t)ahrs.yaw_sensor
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-12-06 11:57:08 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Error {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint8_t sub_system;
|
|
|
|
uint8_t error_code;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an error packet
|
2012-12-29 23:08:25 -04:00
|
|
|
static void Log_Write_Error(uint8_t sub_system, uint8_t error_code)
|
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Error pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_ERROR_MSG),
|
|
|
|
sub_system : sub_system,
|
|
|
|
error_code : error_code,
|
|
|
|
};
|
|
|
|
DataFlash.WriteBlock(&pkt, sizeof(pkt));
|
2012-12-29 23:08:25 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
static const struct LogStructure log_structure[] PROGMEM = {
|
|
|
|
LOG_COMMON_STRUCTURES,
|
|
|
|
{ LOG_CURRENT_MSG, sizeof(log_Current),
|
2013-04-19 21:28:59 -03:00
|
|
|
"CURR", "hIhhhf", "Thr,ThrInt,Volt,Curr,Vcc,CurrTot" },
|
2013-04-19 20:51:09 -03:00
|
|
|
|
|
|
|
#if FRAME_CONFIG == OCTA_FRAME || FRAME_CONFIG == OCTA_QUAD_FRAME
|
|
|
|
{ LOG_MOTORS_MSG, sizeof(log_Motors),
|
|
|
|
"MOT", "hhhhhhhh", "Mot1,Mot2,Mot3,Mot4,Mot5,Mot6,Mot7,Mot8" },
|
|
|
|
#elif FRAME_CONFIG == HEXA_FRAME || FRAME_CONFIG == Y6_FRAME
|
|
|
|
{ LOG_MOTORS_MSG, sizeof(log_Motors),
|
|
|
|
"MOT", "hhhhhh", "Mot1,Mot2,Mot3,Mot4,Mot5,Mot6" },
|
|
|
|
#elif FRAME_CONFIG == HELI_FRAME
|
|
|
|
{ LOG_MOTORS_MSG, sizeof(log_Motors),
|
|
|
|
"MOT", "hhhhh", "Mot1,Mot2,Mot3,Mot4,GGain" },
|
|
|
|
#else
|
|
|
|
{ LOG_MOTORS_MSG, sizeof(log_Motors),
|
|
|
|
"MOT", "hhhh", "Mot1,Mot2,Mot3,Mot4" },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{ LOG_OPTFLOW_MSG, sizeof(log_Optflow),
|
|
|
|
"OF", "hhBccffee", "Dx,Dy,SQual,X,Y,Lat,Lng,Roll,Pitch" },
|
|
|
|
{ LOG_NAV_TUNING_MSG, sizeof(log_Nav_Tuning),
|
2013-05-19 10:53:35 -03:00
|
|
|
"NTUN", "Ecffffffffee", "WPDst,WPBrg,PErX,PErY,DVelX,DVelY,VelX,VelY,DAcX,DAcY,DRol,DPit" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_CONTROL_TUNING_MSG, sizeof(log_Control_Tuning),
|
|
|
|
"CTUN", "hcefhhhhh", "ThrIn,SonAlt,BarAlt,WPAlt,NavThr,AngBst,CRate,ThrOut,DCRate" },
|
|
|
|
{ LOG_COMPASS_MSG, sizeof(log_Compass),
|
|
|
|
"MAG", "hhhhhhhhh", "MagX,MagY,MagZ,OfsX,OfsY,OfsZ,MOfsX,MOfsY,MOfsZ" },
|
|
|
|
{ LOG_PERFORMANCE_MSG, sizeof(log_Performance),
|
2013-04-29 09:30:22 -03:00
|
|
|
"PM", "BBBHHIhB", "RenCnt,RenBlw,FixCnt,NLon,NLoop,MaxT,PMT,I2CErr" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_CMD_MSG, sizeof(log_Cmd),
|
|
|
|
"CMD", "BBBBBeLL", "CTot,CNum,CId,COpt,Prm1,Alt,Lat,Lng" },
|
|
|
|
{ LOG_ATTITUDE_MSG, sizeof(log_Attitude),
|
|
|
|
"ATT", "cccccCC", "RollIn,Roll,PitchIn,Pitch,YawIn,Yaw,NavYaw" },
|
|
|
|
{ LOG_INAV_MSG, sizeof(log_INAV),
|
|
|
|
"INAV", "cccfffiiff", "BAlt,IAlt,IClb,ACorrX,ACorrY,ACorrZ,GLat,GLng,ILat,ILng" },
|
2013-04-20 02:18:22 -03:00
|
|
|
{ LOG_MODE_MSG, sizeof(log_Mode),
|
|
|
|
"MODE", "Mh", "Mode,ThrCrs" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_STARTUP_MSG, sizeof(log_Startup),
|
|
|
|
"STRT", "", "" },
|
|
|
|
{ LOG_EVENT_MSG, sizeof(log_Event),
|
|
|
|
"EV", "B", "Id" },
|
|
|
|
{ LOG_DATA_INT16_MSG, sizeof(log_Data_Int16t),
|
|
|
|
"D16", "Bh", "Id,Value" },
|
|
|
|
{ LOG_DATA_UINT16_MSG, sizeof(log_Data_UInt16t),
|
|
|
|
"DU16", "BH", "Id,Value" },
|
|
|
|
{ LOG_DATA_INT32_MSG, sizeof(log_Data_Int32t),
|
|
|
|
"D32", "Bi", "Id,Value" },
|
|
|
|
{ LOG_DATA_UINT32_MSG, sizeof(log_Data_UInt32t),
|
|
|
|
"DU32", "BI", "Id,Value" },
|
|
|
|
{ LOG_DATA_FLOAT_MSG, sizeof(log_Data_Float),
|
|
|
|
"DFLT", "Bf", "Id,Value" },
|
|
|
|
{ LOG_PID_MSG, sizeof(log_PID),
|
|
|
|
"PID", "Biiiiif", "Id,Error,P,I,D,Out,Gain" },
|
|
|
|
{ LOG_DMP_MSG, sizeof(log_DMP),
|
|
|
|
"DMP", "ccccCC", "DCMRoll,DMPRoll,DCMPtch,DMPPtch,DCMYaw,DMPYaw" },
|
|
|
|
{ LOG_CAMERA_MSG, sizeof(log_Camera),
|
|
|
|
"CAM", "ILLeccC", "GPSTime,Lat,Lng,Alt,Roll,Pitch,Yaw" },
|
|
|
|
{ LOG_ERROR_MSG, sizeof(log_Error),
|
|
|
|
"ERR", "BB", "Subsys,ECode" },
|
|
|
|
};
|
2013-04-15 09:54:29 -03:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
// Read the DataFlash log memory
|
2013-04-17 08:34:42 -03:00
|
|
|
static void Log_Read(uint16_t log_num, uint16_t start_page, uint16_t end_page)
|
2011-11-25 10:13:32 -04:00
|
|
|
{
|
2012-08-21 23:19:50 -03:00
|
|
|
#ifdef AIRFRAME_NAME
|
2013-01-14 23:02:54 -04:00
|
|
|
cliSerial->printf_P(PSTR((AIRFRAME_NAME)));
|
2012-08-21 23:19:50 -03:00
|
|
|
#endif
|
|
|
|
|
2012-11-21 02:08:03 -04:00
|
|
|
cliSerial->printf_P(PSTR("\n" THISFIRMWARE
|
2013-01-14 23:02:54 -04:00
|
|
|
"\nFree RAM: %u\n"),
|
|
|
|
(unsigned) memcheck_available_memory());
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2013-02-22 19:15:01 -04:00
|
|
|
cliSerial->println_P(PSTR(HAL_BOARD_NAME));
|
2012-08-21 23:19:50 -03:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
DataFlash.LogReadProcess(log_num, start_page, end_page,
|
|
|
|
sizeof(log_structure)/sizeof(log_structure[0]),
|
2013-04-20 02:18:22 -03:00
|
|
|
log_structure,
|
|
|
|
print_flight_mode,
|
|
|
|
cliSerial);
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
// start a new log
|
|
|
|
static void start_logging()
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2013-05-03 02:49:01 -03:00
|
|
|
if (g.log_bitmask != 0 && !ap.logging_started) {
|
|
|
|
ap.logging_started = true;
|
|
|
|
DataFlash.StartNewLog(sizeof(log_structure)/sizeof(log_structure[0]), log_structure);
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-12-23 18:26:24 -04:00
|
|
|
#else // LOGGING_ENABLED
|
2011-12-20 01:04:51 -04:00
|
|
|
|
2013-01-26 04:05:38 -04:00
|
|
|
static void Log_Write_Startup() {}
|
2013-03-26 08:58:54 -03:00
|
|
|
static void Log_Write_Cmd(uint8_t num, const struct Location *wp) {}
|
2013-01-26 04:05:38 -04:00
|
|
|
static void Log_Write_Mode(uint8_t mode) {}
|
|
|
|
static void Log_Write_IMU() {}
|
|
|
|
static void Log_Write_GPS() {}
|
|
|
|
static void Log_Write_Current() {}
|
2013-02-09 02:24:02 -04:00
|
|
|
static void Log_Write_Compass() {}
|
2013-01-26 04:05:38 -04:00
|
|
|
static void Log_Write_Attitude() {}
|
|
|
|
static void Log_Write_INAV() {}
|
|
|
|
static void Log_Write_Data(uint8_t id, int16_t value){}
|
|
|
|
static void Log_Write_Data(uint8_t id, uint16_t value){}
|
|
|
|
static void Log_Write_Data(uint8_t id, int32_t value){}
|
|
|
|
static void Log_Write_Data(uint8_t id, uint32_t value){}
|
|
|
|
static void Log_Write_Data(uint8_t id, float value){}
|
|
|
|
static void Log_Write_Event(uint8_t id){}
|
|
|
|
static void Log_Write_Optflow() {}
|
|
|
|
static void Log_Write_Nav_Tuning() {}
|
|
|
|
static void Log_Write_Control_Tuning() {}
|
|
|
|
static void Log_Write_Motors() {}
|
|
|
|
static void Log_Write_Performance() {}
|
|
|
|
static void Log_Write_PID(uint8_t pid_id, int32_t error, int32_t p, int32_t i, int32_t d, int32_t output, float gain) {}
|
2013-04-05 10:25:58 -03:00
|
|
|
#if SECONDARY_DMP_ENABLED == ENABLED
|
2013-01-26 04:05:38 -04:00
|
|
|
static void Log_Write_DMP() {}
|
2013-04-05 10:25:58 -03:00
|
|
|
#endif
|
2013-01-26 04:05:38 -04:00
|
|
|
static void Log_Write_Camera() {}
|
|
|
|
static void Log_Write_Error(uint8_t sub_system, uint8_t error_code) {}
|
2012-08-21 23:19:50 -03:00
|
|
|
static int8_t process_logs(uint8_t argc, const Menu::arg *argv) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-20 01:04:51 -04:00
|
|
|
|
2011-12-23 18:26:24 -04:00
|
|
|
#endif // LOGGING_DISABLED
|