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-20 01:04:51 -04:00
|
|
|
#if LOGGING_ENABLED == ENABLED && CONFIG_LOGGING == LOGGING_VERBOSE
|
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
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
#define HEAD_BYTE1 0xA3 // Decimal 163
|
|
|
|
#define HEAD_BYTE2 0x95 // Decimal 149
|
|
|
|
#define END_BYTE 0xBA // Decimal 186
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
2010-12-19 12:40:33 -04: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);
|
|
|
|
|
|
|
|
// This is the help function
|
|
|
|
// PSTR is an AVR macro to read strings from flash memory
|
|
|
|
// printf_P is a version of print_f that reads from flash memory
|
2011-11-19 14:56:15 -04:00
|
|
|
//static int8_t help_log(uint8_t argc, const Menu::arg *argv)
|
|
|
|
/*{
|
2010-12-19 12:40:33 -04:00
|
|
|
Serial.printf_P(PSTR("\n"
|
|
|
|
"Commands:\n"
|
2011-03-26 03:35:52 -03:00
|
|
|
" dump <n>"
|
|
|
|
" erase (all logs)\n"
|
|
|
|
" enable <name> | all\n"
|
|
|
|
" disable <name> | all\n"
|
2010-12-19 12:40:33 -04:00
|
|
|
"\n"));
|
2011-07-17 07:30:21 -03:00
|
|
|
return 0;
|
2011-11-19 14:56:15 -04:00
|
|
|
}*/
|
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 = {
|
|
|
|
{"dump", dump_log},
|
|
|
|
{"erase", erase_logs},
|
|
|
|
{"enable", select_logs},
|
2011-11-19 14:56:15 -04:00
|
|
|
{"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);
|
|
|
|
|
2011-06-16 14:12:10 -03:00
|
|
|
static void get_log_boundaries(byte log_num, int & start_page, int & end_page);
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static bool
|
|
|
|
print_log_menu(void)
|
|
|
|
{
|
|
|
|
int log_start;
|
|
|
|
int log_end;
|
2011-11-27 23:17:04 -04:00
|
|
|
int temp;
|
2011-12-13 23:06:46 -04:00
|
|
|
int last_log_num = find_last_log();
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
uint16_t num_logs = get_num_logs();
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
Serial.printf_P(PSTR("logs enabled: "));
|
2011-05-23 02:53:00 -03:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
if (0 == g.log_bitmask) {
|
2010-12-19 12:40:33 -04:00
|
|
|
Serial.printf_P(PSTR("none"));
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-05-23 02:53:00 -03:00
|
|
|
if (g.log_bitmask & MASK_LOG_ATTITUDE_FAST) Serial.printf_P(PSTR(" ATTITUDE_FAST"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_ATTITUDE_MED) Serial.printf_P(PSTR(" ATTITUDE_MED"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_GPS) Serial.printf_P(PSTR(" GPS"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_PM) Serial.printf_P(PSTR(" PM"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_CTUN) Serial.printf_P(PSTR(" CTUN"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_NTUN) Serial.printf_P(PSTR(" NTUN"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_RAW) Serial.printf_P(PSTR(" RAW"));
|
|
|
|
if (g.log_bitmask & MASK_LOG_CMD) Serial.printf_P(PSTR(" CMD"));
|
2011-07-30 17:42:54 -03:00
|
|
|
if (g.log_bitmask & MASK_LOG_CUR) Serial.printf_P(PSTR(" CURRENT"));
|
2011-06-16 14:03:26 -03:00
|
|
|
if (g.log_bitmask & MASK_LOG_MOTORS) Serial.printf_P(PSTR(" MOTORS"));
|
2011-07-21 20:14:53 -03:00
|
|
|
if (g.log_bitmask & MASK_LOG_OPTFLOW) Serial.printf_P(PSTR(" OPTFLOW"));
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-05-23 02:53:00 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
Serial.println();
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
if (num_logs == 0) {
|
|
|
|
Serial.printf_P(PSTR("\nNo logs\n\n"));
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-11-25 10:13:32 -04:00
|
|
|
Serial.printf_P(PSTR("\n%d logs\n"), num_logs);
|
2011-05-21 23:49:57 -03:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
for(int i=num_logs;i>=1;i--) {
|
2011-11-26 00:04:50 -04:00
|
|
|
int last_log_start = log_start, last_log_end = log_end;
|
2011-12-13 23:06:46 -04:00
|
|
|
temp = last_log_num-i+1;
|
2011-11-25 10:13:32 -04:00
|
|
|
get_log_boundaries(temp, log_start, log_end);
|
|
|
|
Serial.printf_P(PSTR("Log %d, start %d, end %d\n"), temp, log_start, log_end);
|
2011-11-26 00:04:50 -04:00
|
|
|
if (last_log_start == log_start && last_log_end == log_end) {
|
|
|
|
// we are printing bogus logs
|
|
|
|
break;
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
dump_log(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-11-25 10:13:32 -04:00
|
|
|
int dump_log;
|
2010-12-19 12:40:33 -04:00
|
|
|
int dump_log_start;
|
|
|
|
int dump_log_end;
|
2011-11-25 10:13:32 -04:00
|
|
|
byte last_log_num;
|
2011-05-25 22:50:32 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// check that the requested log number can be read
|
|
|
|
dump_log = argv[1].i;
|
2011-12-13 23:06:46 -04:00
|
|
|
last_log_num = find_last_log();
|
2011-12-10 14:17:04 -04:00
|
|
|
|
2011-12-07 11:13:30 -04:00
|
|
|
if (dump_log == -2) {
|
|
|
|
for(int count=1; count<=DF_LAST_PAGE; count++) {
|
|
|
|
DataFlash.StartRead(count);
|
|
|
|
Serial.printf_P(PSTR("DF page, log file #, log page: %d,\t"), count);
|
|
|
|
Serial.printf_P(PSTR("%d,\t"), DataFlash.GetFileNumber());
|
|
|
|
Serial.printf_P(PSTR("%d\n"), DataFlash.GetFilePage());
|
|
|
|
}
|
|
|
|
return(-1);
|
|
|
|
} else if (dump_log <= 0) {
|
2011-11-25 10:13:32 -04:00
|
|
|
Serial.printf_P(PSTR("dumping all\n"));
|
|
|
|
Log_Read(1, DF_LAST_PAGE);
|
|
|
|
return(-1);
|
|
|
|
} else if ((argc != 2) || (dump_log <= (last_log_num - get_num_logs())) || (dump_log > last_log_num)) {
|
|
|
|
Serial.printf_P(PSTR("bad log number\n"));
|
2011-05-27 01:59:01 -03:00
|
|
|
return(-1);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-06-16 14:12:10 -03:00
|
|
|
get_log_boundaries(dump_log, dump_log_start, dump_log_end);
|
2011-05-23 02:53:00 -03:00
|
|
|
/*Serial.printf_P(PSTR("Dumping Log number %d, start %d, end %d\n"),
|
2011-03-09 02:37:09 -04:00
|
|
|
dump_log,
|
|
|
|
dump_log_start,
|
|
|
|
dump_log_end);
|
2011-05-23 02:53:00 -03:00
|
|
|
*/
|
2010-12-19 12:40:33 -04:00
|
|
|
Log_Read(dump_log_start, dump_log_end);
|
2011-05-23 02:53:00 -03:00
|
|
|
//Serial.printf_P(PSTR("Done\n"));
|
2011-05-25 22:50:32 -03:00
|
|
|
return (0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-12-17 19:19:41 -04:00
|
|
|
static void
|
|
|
|
do_erase_logs(void (*delay_cb)(unsigned long))
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("\nErasing log...\n"));
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.SetFileNumber(0xFFFF);
|
|
|
|
for(int j = 1; j <= DF_LAST_PAGE; j++) {
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.PageErase(j);
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartWrite(j); // We need this step to clean FileNumbers
|
2011-11-28 22:42:27 -04:00
|
|
|
if(j%128 == 0) Serial.printf_P(PSTR("+"));
|
2011-12-17 19:19:41 -04:00
|
|
|
delay_cb(1);
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
2011-09-04 21:15:36 -03:00
|
|
|
|
|
|
|
Serial.printf_P(PSTR("\nLog erased.\n"));
|
2011-03-09 02:37:09 -04:00
|
|
|
DataFlash.FinishWrite();
|
2011-12-17 19:19:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
erase_logs(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
do_erase_logs(delay);
|
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)
|
|
|
|
{
|
|
|
|
uint16_t bits;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
Serial.printf_P(PSTR("missing log type\n"));
|
|
|
|
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"))) {
|
2011-07-17 07:30:21 -03:00
|
|
|
bits = ~0;
|
2011-03-09 02:37:09 -04:00
|
|
|
} else {
|
|
|
|
#define TARG(_s) if (!strcasecmp_P(argv[1].str, PSTR(#_s))) bits |= MASK_LOG_ ## _s
|
2010-12-19 12:40:33 -04:00
|
|
|
TARG(ATTITUDE_FAST);
|
|
|
|
TARG(ATTITUDE_MED);
|
|
|
|
TARG(GPS);
|
|
|
|
TARG(PM);
|
|
|
|
TARG(CTUN);
|
|
|
|
TARG(NTUN);
|
|
|
|
TARG(MODE);
|
|
|
|
TARG(RAW);
|
|
|
|
TARG(CMD);
|
2011-07-30 17:42:54 -03:00
|
|
|
TARG(CUR);
|
2011-06-16 14:03:26 -03:00
|
|
|
TARG(MOTORS);
|
2011-07-21 20:14:53 -03:00
|
|
|
TARG(OPTFLOW);
|
2011-03-09 02:37:09 -04:00
|
|
|
#undef TARG
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp_P(argv[0].str, PSTR("enable"))) {
|
2011-02-19 03:44:44 -04:00
|
|
|
g.log_bitmask.set_and_save(g.log_bitmask | bits);
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-02-19 03:44:44 -04:00
|
|
|
g.log_bitmask.set_and_save(g.log_bitmask & ~bits);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-05-31 02:29:06 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
log_menu.run();
|
2011-06-16 14:03:26 -03:00
|
|
|
return 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
|
|
|
|
// This function determines the number of whole or partial log files in the DataFlash
|
|
|
|
// Wholly overwritten files are (of course) lost.
|
2011-07-17 07:32:00 -03:00
|
|
|
static byte get_num_logs(void)
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-11-25 10:13:32 -04:00
|
|
|
uint16_t lastpage;
|
|
|
|
uint16_t last;
|
|
|
|
uint16_t first;
|
2011-05-15 14:42:32 -03:00
|
|
|
|
2011-12-13 23:06:46 -04:00
|
|
|
if(find_last_page() == 1) return 0;
|
2011-05-21 23:49:57 -03:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartRead(1);
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
if(DataFlash.GetFileNumber() == 0XFFFF) return 0;
|
|
|
|
|
2011-12-13 23:06:46 -04:00
|
|
|
lastpage = find_last_page();
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartRead(lastpage);
|
|
|
|
last = DataFlash.GetFileNumber();
|
|
|
|
DataFlash.StartRead(lastpage + 2);
|
|
|
|
first = DataFlash.GetFileNumber();
|
|
|
|
if(first > last) {
|
|
|
|
DataFlash.StartRead(1);
|
|
|
|
first = DataFlash.GetFileNumber();
|
|
|
|
}
|
|
|
|
if(last == first)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return (last - first + 1);
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
// This function starts a new log file in the DataFlash
|
2011-07-17 07:32:00 -03:00
|
|
|
static void start_new_log()
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-12-13 23:06:46 -04:00
|
|
|
uint16_t last_page = find_last_page();
|
2011-12-17 02:02:41 -04:00
|
|
|
|
2011-12-13 23:06:46 -04:00
|
|
|
DataFlash.StartRead(last_page);
|
|
|
|
//Serial.print("last page: "); Serial.println(last_page);
|
|
|
|
//Serial.print("file #: "); Serial.println(DataFlash.GetFileNumber());
|
|
|
|
//Serial.print("file page: "); Serial.println(DataFlash.GetFilePage());
|
2011-12-17 02:02:41 -04:00
|
|
|
|
2011-12-13 23:06:46 -04:00
|
|
|
if(find_last_log() == 0 || DataFlash.GetFileNumber() == 0xFFFF) {
|
|
|
|
DataFlash.SetFileNumber(1);
|
|
|
|
DataFlash.StartWrite(1);
|
|
|
|
//Serial.println("start log from 0");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-17 02:02:41 -04:00
|
|
|
|
2011-12-13 23:06:46 -04:00
|
|
|
// Check for log of length 1 page and suppress
|
|
|
|
if(DataFlash.GetFilePage() <= 1) {
|
|
|
|
DataFlash.SetFileNumber(DataFlash.GetFileNumber()); // Last log too short, reuse its number
|
|
|
|
DataFlash.StartWrite(last_page); // and overwrite it
|
|
|
|
//Serial.println("start log from short");
|
|
|
|
} else {
|
|
|
|
if(last_page == 0xFFFF) last_page=0;
|
|
|
|
DataFlash.SetFileNumber(DataFlash.GetFileNumber()+1);
|
|
|
|
DataFlash.StartWrite(last_page + 1);
|
|
|
|
//Serial.println("start log normal");
|
|
|
|
}
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
// This function finds the first and last pages of a log file
|
|
|
|
// The first page may be greater than the last page if the DataFlash has been filled and partially overwritten.
|
|
|
|
static void get_log_boundaries(byte log_num, int & start_page, int & end_page)
|
|
|
|
{
|
|
|
|
int num = get_num_logs();
|
|
|
|
int look;
|
|
|
|
if(num == 1)
|
|
|
|
{
|
|
|
|
DataFlash.StartRead(DF_LAST_PAGE);
|
|
|
|
if(DataFlash.GetFileNumber() == 0xFFFF)
|
|
|
|
{
|
|
|
|
start_page = 1;
|
2011-12-13 23:06:46 -04:00
|
|
|
end_page = find_last_page_of_log((uint16_t)log_num);
|
2011-11-25 10:13:32 -04:00
|
|
|
} else {
|
2011-12-13 23:06:46 -04:00
|
|
|
end_page = find_last_page_of_log((uint16_t)log_num);
|
2011-11-25 10:13:32 -04:00
|
|
|
start_page = end_page + 1;
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
} else {
|
|
|
|
if(log_num==1) {
|
|
|
|
DataFlash.StartRead(DF_LAST_PAGE);
|
|
|
|
if(DataFlash.GetFileNumber() == 0xFFFF) {
|
|
|
|
start_page = 1;
|
|
|
|
} else {
|
2011-12-13 23:06:46 -04:00
|
|
|
start_page = find_last_page() + 1;
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
|
|
|
} else {
|
2011-12-13 23:06:46 -04:00
|
|
|
if(log_num == find_last_log() - num + 1) {
|
|
|
|
start_page = find_last_page() + 1;
|
2011-11-25 10:13:32 -04:00
|
|
|
} else {
|
|
|
|
look = log_num-1;
|
|
|
|
do {
|
2011-12-13 23:06:46 -04:00
|
|
|
start_page = find_last_page_of_log(look) + 1;
|
2011-11-25 10:13:32 -04:00
|
|
|
look--;
|
2011-12-13 23:06:46 -04:00
|
|
|
} while (start_page <= 0 && look >=1);
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
|
|
|
}
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
2011-11-25 10:13:32 -04:00
|
|
|
if(start_page == DF_LAST_PAGE+1 || start_page == 0) start_page=1;
|
2011-12-13 23:06:46 -04:00
|
|
|
end_page = find_last_page_of_log((uint16_t)log_num);
|
2011-11-25 10:13:32 -04:00
|
|
|
if(end_page <= 0) end_page = start_page;
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
static bool check_wrapped(void)
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartRead(DF_LAST_PAGE);
|
|
|
|
if(DataFlash.GetFileNumber() == 0xFFFF)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-12-13 23:06:46 -04:00
|
|
|
// This funciton finds the last log number
|
|
|
|
static int find_last_log(void)
|
|
|
|
{
|
|
|
|
int last_page = find_last_page();
|
|
|
|
DataFlash.StartRead(last_page);
|
|
|
|
return DataFlash.GetFileNumber();
|
|
|
|
}
|
2011-12-17 02:02:41 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
// This function finds the last page of the last file
|
2011-12-13 23:06:46 -04:00
|
|
|
static int find_last_page(void)
|
2011-11-25 10:13:32 -04:00
|
|
|
{
|
|
|
|
uint16_t look;
|
|
|
|
uint16_t bottom = 1;
|
|
|
|
uint16_t top = DF_LAST_PAGE;
|
|
|
|
uint32_t look_hash;
|
|
|
|
uint32_t bottom_hash;
|
|
|
|
uint32_t top_hash;
|
|
|
|
|
|
|
|
DataFlash.StartRead(bottom);
|
|
|
|
bottom_hash = (long)DataFlash.GetFileNumber()<<16 | DataFlash.GetFilePage();
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
while(top-bottom > 1)
|
|
|
|
{
|
|
|
|
look = (top+bottom)/2;
|
|
|
|
DataFlash.StartRead(look);
|
|
|
|
look_hash = (long)DataFlash.GetFileNumber()<<16 | DataFlash.GetFilePage();
|
|
|
|
if (look_hash >= 0xFFFF0000) look_hash = 0;
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
if(look_hash < bottom_hash) {
|
|
|
|
// move down
|
|
|
|
top = look;
|
|
|
|
} else {
|
|
|
|
// move up
|
|
|
|
bottom = look;
|
|
|
|
bottom_hash = look_hash;
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartRead(top);
|
|
|
|
top_hash = (long)DataFlash.GetFileNumber()<<16 | DataFlash.GetFilePage();
|
|
|
|
if (top_hash >= 0xFFFF0000) top_hash = 0;
|
|
|
|
if (top_hash > bottom_hash)
|
|
|
|
{
|
|
|
|
return top;
|
|
|
|
} else {
|
|
|
|
return bottom;
|
|
|
|
}
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
// This function finds the last page of a particular log file
|
2011-12-13 23:06:46 -04:00
|
|
|
static int find_last_page_of_log(uint16_t log_number)
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
uint16_t look;
|
|
|
|
uint16_t bottom;
|
|
|
|
uint16_t top;
|
|
|
|
uint32_t look_hash;
|
|
|
|
uint32_t check_hash;
|
|
|
|
|
|
|
|
if(check_wrapped())
|
|
|
|
{
|
|
|
|
DataFlash.StartRead(1);
|
|
|
|
bottom = DataFlash.GetFileNumber();
|
|
|
|
if (bottom > log_number)
|
|
|
|
{
|
2011-12-13 23:06:46 -04:00
|
|
|
bottom = find_last_page();
|
2011-11-25 10:13:32 -04:00
|
|
|
top = DF_LAST_PAGE;
|
|
|
|
} else {
|
|
|
|
bottom = 1;
|
2011-12-13 23:06:46 -04:00
|
|
|
top = find_last_page();
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bottom = 1;
|
2011-12-13 23:06:46 -04:00
|
|
|
top = find_last_page();
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
2011-05-21 23:49:57 -03:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
check_hash = (long)log_number<<16 | 0xFFFF;
|
|
|
|
while(top-bottom > 1)
|
|
|
|
{
|
|
|
|
look = (top+bottom)/2;
|
|
|
|
DataFlash.StartRead(look);
|
|
|
|
look_hash = (long)DataFlash.GetFileNumber()<<16 | DataFlash.GetFilePage();
|
|
|
|
if (look_hash >= 0xFFFF0000) look_hash = 0;
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
if(look_hash > check_hash) {
|
|
|
|
// move down
|
|
|
|
top = look;
|
|
|
|
} else {
|
|
|
|
// move up
|
|
|
|
bottom = look;
|
|
|
|
}
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartRead(top);
|
|
|
|
if (DataFlash.GetFileNumber() == log_number) return top;
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
DataFlash.StartRead(bottom);
|
|
|
|
if (DataFlash.GetFileNumber() == log_number) return bottom;
|
2011-11-27 23:17:04 -04:00
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
return -1;
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Write an GPS packet. Total length : 30 bytes
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_GPS()
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_GPS_MSG);
|
2011-04-21 02:15:45 -03:00
|
|
|
|
|
|
|
DataFlash.WriteLong(g_gps->time); // 1
|
2011-09-14 17:58:18 -03:00
|
|
|
DataFlash.WriteByte(g_gps->num_sats); // 2
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2011-09-14 17:58:18 -03:00
|
|
|
DataFlash.WriteLong(current_loc.lat); // 3
|
|
|
|
DataFlash.WriteLong(current_loc.lng); // 4
|
|
|
|
DataFlash.WriteLong(current_loc.alt); // 5
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteLong(g_gps->altitude); // 6
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2011-09-14 17:58:18 -03:00
|
|
|
DataFlash.WriteInt(g_gps->ground_speed); // 7
|
2011-12-10 14:17:04 -04:00
|
|
|
DataFlash.WriteLong(g_gps->ground_course); // 8
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
2011-04-21 02:15:45 -03:00
|
|
|
// Read a GPS packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_GPS()
|
2011-05-12 18:37:38 -03:00
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int32_t temp1 = DataFlash.ReadLong(); // 1 time
|
|
|
|
int8_t temp2 = DataFlash.ReadByte(); // 2 sats
|
|
|
|
float temp3 = DataFlash.ReadLong() / t7; // 3 lat
|
|
|
|
float temp4 = DataFlash.ReadLong() / t7; // 4 lon
|
|
|
|
float temp5 = DataFlash.ReadLong() / 100.0; // 5 gps alt
|
|
|
|
float temp6 = DataFlash.ReadLong() / 100.0; // 6 sensor alt
|
|
|
|
int16_t temp7 = DataFlash.ReadInt(); // 7 ground speed
|
2011-12-10 14:17:04 -04:00
|
|
|
int32_t temp8 = DataFlash.ReadLong();// 8 ground course
|
2011-11-08 02:23:48 -04:00
|
|
|
|
|
|
|
// 1 2 3 4 5 6 7 8
|
2011-12-10 14:17:04 -04:00
|
|
|
Serial.printf_P(PSTR("GPS, %ld, %d, %4.7f, %4.7f, %4.4f, %4.4f, %d, %ld\n"),
|
2011-11-08 02:23:48 -04:00
|
|
|
temp1, // 1 time
|
|
|
|
temp2, // 2 sats
|
|
|
|
temp3, // 3 lat
|
|
|
|
temp4, // 4 lon
|
|
|
|
temp5, // 5 gps alt
|
|
|
|
temp6, // 6 sensor alt
|
|
|
|
temp7, // 7 ground speed
|
|
|
|
temp8); // 8 ground course
|
2011-04-21 02:15:45 -03:00
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Write an raw accel/gyro data packet. Total length : 28 bytes
|
2011-02-24 01:56:59 -04:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Raw()
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2011-02-19 03:44:44 -04:00
|
|
|
Vector3f gyro = imu.get_gyro();
|
|
|
|
Vector3f accel = imu.get_accel();
|
2011-07-10 21:47:08 -03:00
|
|
|
//Vector3f accel_filt = imu.get_accel_filtered();
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
gyro *= t7; // Scale up for storage as long integers
|
|
|
|
accel *= t7;
|
2011-07-10 21:47:08 -03:00
|
|
|
//accel_filt *= t7;
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_RAW_MSG);
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-11-07 18:24:32 -04:00
|
|
|
DataFlash.WriteLong(gyro.x);
|
|
|
|
DataFlash.WriteLong(gyro.y);
|
|
|
|
DataFlash.WriteLong(gyro.z);
|
2011-07-10 21:47:08 -03:00
|
|
|
|
|
|
|
|
2011-11-07 18:24:32 -04:00
|
|
|
//DataFlash.WriteLong(accels_rot.x * t7);
|
|
|
|
//DataFlash.WriteLong(accels_rot.y * t7);
|
|
|
|
//DataFlash.WriteLong(accels_rot.z * t7);
|
2011-07-10 21:47:08 -03:00
|
|
|
|
2011-11-07 18:24:32 -04:00
|
|
|
DataFlash.WriteLong(accel.x);
|
|
|
|
DataFlash.WriteLong(accel.y);
|
|
|
|
DataFlash.WriteLong(accel.z);
|
2011-02-24 01:56:59 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
2011-02-24 01:56:59 -04:00
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-07-10 21:47:08 -03:00
|
|
|
// Read a raw accel/gyro packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Raw()
|
2011-07-10 21:47:08 -03:00
|
|
|
{
|
|
|
|
float logvar;
|
|
|
|
Serial.printf_P(PSTR("RAW,"));
|
|
|
|
for (int y = 0; y < 6; y++) {
|
|
|
|
logvar = (float)DataFlash.ReadLong() / t7;
|
|
|
|
Serial.print(logvar);
|
|
|
|
Serial.print(comma);
|
|
|
|
}
|
|
|
|
Serial.println(" ");
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Current()
|
2011-01-16 23:44:12 -04:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_CURRENT_MSG);
|
2011-04-30 13:01:57 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
DataFlash.WriteInt(g.rc_3.control_in); // 1
|
|
|
|
DataFlash.WriteLong(throttle_integrator); // 2
|
|
|
|
DataFlash.WriteInt(battery_voltage * 100.0); // 3
|
|
|
|
DataFlash.WriteInt(current_amps * 100.0); // 4
|
|
|
|
DataFlash.WriteInt(current_total); // 5
|
2011-04-30 13:01:57 -03:00
|
|
|
|
2011-01-16 23:44:12 -04:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
2011-01-29 22:36:03 -04:00
|
|
|
|
2011-01-16 23:44:12 -04:00
|
|
|
// Read a Current packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Current()
|
2011-01-16 23:44:12 -04:00
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt(); // 1
|
|
|
|
int32_t temp2 = DataFlash.ReadLong(); // 2
|
|
|
|
float temp3 = DataFlash.ReadInt() / 100.f; // 3
|
|
|
|
float temp4 = DataFlash.ReadInt() / 100.f; // 4
|
|
|
|
int16_t temp5 = DataFlash.ReadInt(); // 5
|
2011-04-30 13:01:57 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
// 1 2 3 4 5
|
|
|
|
Serial.printf_P(PSTR("CURR, %d, %ld, %4.4f, %4.4f, %d\n"),
|
|
|
|
temp1,
|
|
|
|
temp2,
|
|
|
|
temp3,
|
|
|
|
temp4,
|
|
|
|
temp5);
|
2011-01-16 23:44:12 -04:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Motors()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_MOTORS_MSG);
|
|
|
|
|
2011-10-28 02:36:25 -03:00
|
|
|
#if FRAME_CONFIG == TRI_FRAME
|
|
|
|
DataFlash.WriteInt(motor_out[CH_1]);//1
|
|
|
|
DataFlash.WriteInt(motor_out[CH_2]);//2
|
|
|
|
DataFlash.WriteInt(motor_out[CH_4]);//3
|
|
|
|
DataFlash.WriteInt(g.rc_4.radio_out);//4
|
|
|
|
|
|
|
|
#elif FRAME_CONFIG == HEXA_FRAME
|
|
|
|
DataFlash.WriteInt(motor_out[CH_1]);//1
|
|
|
|
DataFlash.WriteInt(motor_out[CH_2]);//2
|
|
|
|
DataFlash.WriteInt(motor_out[CH_3]);//3
|
|
|
|
DataFlash.WriteInt(motor_out[CH_4]);//4
|
|
|
|
DataFlash.WriteInt(motor_out[CH_7]);//5
|
|
|
|
DataFlash.WriteInt(motor_out[CH_8]);//6
|
|
|
|
|
|
|
|
#elif FRAME_CONFIG == Y6_FRAME
|
|
|
|
//left
|
|
|
|
DataFlash.WriteInt(motor_out[CH_2]);//1
|
|
|
|
DataFlash.WriteInt(motor_out[CH_3]);//2
|
|
|
|
//right
|
|
|
|
DataFlash.WriteInt(motor_out[CH_7]);//3
|
|
|
|
DataFlash.WriteInt(motor_out[CH_1]);//4
|
|
|
|
//back
|
|
|
|
DataFlash.WriteInt(motor_out[CH_8]);//5
|
|
|
|
DataFlash.WriteInt(motor_out[CH_4]);//6
|
|
|
|
|
|
|
|
#elif FRAME_CONFIG == OCTA_FRAME || FRAME_CONFIG == OCTA_QUAD_FRAME
|
|
|
|
DataFlash.WriteInt(motor_out[CH_1]);//1
|
|
|
|
DataFlash.WriteInt(motor_out[CH_2]);//2
|
|
|
|
DataFlash.WriteInt(motor_out[CH_3]);//3
|
|
|
|
DataFlash.WriteInt(motor_out[CH_4]);//4
|
|
|
|
DataFlash.WriteInt(motor_out[CH_7]);//5
|
|
|
|
DataFlash.WriteInt(motor_out[CH_8]); //6
|
|
|
|
DataFlash.WriteInt(motor_out[CH_10]);//7
|
|
|
|
DataFlash.WriteInt(motor_out[CH_11]);//8
|
|
|
|
|
|
|
|
#elif FRAME_CONFIG == HELI_FRAME
|
|
|
|
DataFlash.WriteInt(heli_servo_out[0]);//1
|
|
|
|
DataFlash.WriteInt(heli_servo_out[1]);//2
|
|
|
|
DataFlash.WriteInt(heli_servo_out[2]);//3
|
|
|
|
DataFlash.WriteInt(heli_servo_out[3]);//4
|
|
|
|
DataFlash.WriteInt(g.heli_ext_gyro_gain);//5
|
|
|
|
|
|
|
|
#else // quads
|
|
|
|
DataFlash.WriteInt(motor_out[CH_1]);//1
|
|
|
|
DataFlash.WriteInt(motor_out[CH_2]);//2
|
|
|
|
DataFlash.WriteInt(motor_out[CH_3]);//3
|
|
|
|
DataFlash.WriteInt(motor_out[CH_4]);//4
|
|
|
|
#endif
|
2011-06-16 14:03:26 -03:00
|
|
|
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read a Current packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Motors()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2011-10-28 02:36:25 -03:00
|
|
|
#if FRAME_CONFIG == HEXA_FRAME || FRAME_CONFIG == Y6_FRAME
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt(); // 1
|
|
|
|
int16_t temp2 = DataFlash.ReadInt(); // 2
|
|
|
|
int16_t temp3 = DataFlash.ReadInt(); // 3
|
|
|
|
int16_t temp4 = DataFlash.ReadInt(); // 4
|
|
|
|
int16_t temp5 = DataFlash.ReadInt(); // 5
|
|
|
|
int16_t temp6 = DataFlash.ReadInt(); // 6
|
2011-10-28 02:36:25 -03:00
|
|
|
// 1 2 3 4 5 6
|
2011-11-08 02:23:48 -04:00
|
|
|
Serial.printf_P(PSTR("MOT, %d, %d, %d, %d, %d, %d\n"),
|
|
|
|
temp1, //1
|
|
|
|
temp2, //2
|
|
|
|
temp3, //3
|
|
|
|
temp4, //4
|
|
|
|
temp5, //5
|
|
|
|
temp6); //6
|
2011-10-28 02:36:25 -03:00
|
|
|
|
|
|
|
#elif FRAME_CONFIG == OCTA_FRAME || FRAME_CONFIG == OCTA_QUAD_FRAME
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt(); // 1
|
|
|
|
int16_t temp2 = DataFlash.ReadInt(); // 2
|
|
|
|
int16_t temp3 = DataFlash.ReadInt(); // 3
|
|
|
|
int16_t temp4 = DataFlash.ReadInt(); // 4
|
|
|
|
int16_t temp5 = DataFlash.ReadInt(); // 5
|
|
|
|
int16_t temp6 = DataFlash.ReadInt(); // 6
|
|
|
|
int16_t temp7 = DataFlash.ReadInt(); // 7
|
|
|
|
int16_t temp8 = DataFlash.ReadInt(); // 8
|
2011-10-28 02:36:25 -03:00
|
|
|
// 1 2 3 4 5 6 7 8
|
2011-11-08 02:23:48 -04:00
|
|
|
Serial.printf_P(PSTR("MOT, %d, %d, %d, %d, %d, %d, %d, %d\n"),
|
|
|
|
temp1, //1
|
|
|
|
temp2, //2
|
|
|
|
temp3, //3
|
|
|
|
temp4, //4
|
|
|
|
temp5, //5
|
|
|
|
temp6, //6
|
|
|
|
temp7, //7
|
|
|
|
temp8); //8
|
2011-10-28 02:36:25 -03:00
|
|
|
|
|
|
|
#elif FRAME_CONFIG == HELI_FRAME
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt(); // 1
|
|
|
|
int16_t temp2 = DataFlash.ReadInt(); // 2
|
|
|
|
int16_t temp3 = DataFlash.ReadInt(); // 3
|
|
|
|
int16_t temp4 = DataFlash.ReadInt(); // 4
|
|
|
|
int16_t temp5 = DataFlash.ReadInt(); // 5
|
2011-10-28 02:36:25 -03:00
|
|
|
// 1 2 3 4 5
|
2011-11-08 02:23:48 -04:00
|
|
|
Serial.printf_P(PSTR("MOT, %d, %d, %d, %d, %d\n"),
|
|
|
|
temp1, //1
|
|
|
|
temp2, //2
|
|
|
|
temp3, //3
|
|
|
|
temp4, //4
|
|
|
|
temp5); //5
|
2011-10-28 02:36:25 -03:00
|
|
|
|
|
|
|
#else // quads, TRIs
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt(); // 1
|
|
|
|
int16_t temp2 = DataFlash.ReadInt(); // 2
|
|
|
|
int16_t temp3 = DataFlash.ReadInt(); // 3
|
|
|
|
int16_t temp4 = DataFlash.ReadInt(); // 4
|
|
|
|
|
2011-10-28 02:36:25 -03:00
|
|
|
// 1 2 3 4
|
2011-11-08 02:23:48 -04:00
|
|
|
Serial.printf_P(PSTR("MOT, %d, %d, %d, %d\n"),
|
|
|
|
temp1, //1
|
|
|
|
temp2, //2
|
|
|
|
temp3, //3
|
|
|
|
temp4); //4;
|
2011-10-28 02:36:25 -03:00
|
|
|
#endif
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
#ifdef OPTFLOW_ENABLED
|
|
|
|
// Write an optical flow packet. Total length : 18 bytes
|
|
|
|
static void Log_Write_Optflow()
|
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_OPTFLOW_MSG);
|
|
|
|
DataFlash.WriteInt((int)optflow.dx);
|
|
|
|
DataFlash.WriteInt((int)optflow.dy);
|
|
|
|
DataFlash.WriteInt((int)optflow.surface_quality);
|
2011-09-17 10:09:18 -03:00
|
|
|
DataFlash.WriteLong(optflow.vlat);//optflow_offset.lat + optflow.lat);
|
|
|
|
DataFlash.WriteLong(optflow.vlon);//optflow_offset.lng + optflow.lng);
|
2011-07-21 20:14:53 -03:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-14 17:58:18 -03:00
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
static void Log_Read_Optflow()
|
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt(); // 1
|
|
|
|
int16_t temp2 = DataFlash.ReadInt(); // 2
|
|
|
|
int16_t temp3 = DataFlash.ReadInt(); // 3
|
|
|
|
float temp4 = DataFlash.ReadLong(); // 4
|
|
|
|
float temp5 = DataFlash.ReadLong(); // 5
|
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
Serial.printf_P(PSTR("OF, %d, %d, %d, %4.7f, %4.7f\n"),
|
2011-11-08 02:23:48 -04:00
|
|
|
temp1,
|
|
|
|
temp2,
|
|
|
|
temp3,
|
|
|
|
temp4,
|
|
|
|
temp5);
|
2011-07-21 20:14:53 -03:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Nav_Tuning()
|
2011-05-23 02:53:00 -03:00
|
|
|
{
|
2011-09-06 22:22:29 -03:00
|
|
|
//Matrix3f tempmat = dcm.get_dcm_matrix();
|
2011-05-23 02:53:00 -03:00
|
|
|
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_NAV_TUNING_MSG);
|
|
|
|
|
2011-11-07 18:24:32 -04:00
|
|
|
DataFlash.WriteInt(wp_distance); // 1
|
2011-11-08 02:23:48 -04:00
|
|
|
DataFlash.WriteInt(target_bearing/100); // 2
|
|
|
|
DataFlash.WriteInt(long_error); // 3
|
2011-11-07 18:24:32 -04:00
|
|
|
DataFlash.WriteInt(lat_error); // 4
|
|
|
|
DataFlash.WriteInt(nav_lon); // 5
|
|
|
|
DataFlash.WriteInt(nav_lat); // 6
|
|
|
|
DataFlash.WriteInt(g.pi_nav_lon.get_integrator()); // 7
|
|
|
|
DataFlash.WriteInt(g.pi_nav_lat.get_integrator()); // 8
|
2011-12-10 14:17:04 -04:00
|
|
|
//crosstrack_error
|
|
|
|
//DataFlash.WriteInt(crosstrack_error); // 9
|
2011-11-07 18:24:32 -04:00
|
|
|
DataFlash.WriteInt(g.pi_loiter_lon.get_integrator()); // 9
|
|
|
|
DataFlash.WriteInt(g.pi_loiter_lat.get_integrator()); // 10
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2011-05-23 02:53:00 -03:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
2011-05-30 01:24:07 -03:00
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Nav_Tuning()
|
2011-05-23 02:53:00 -03:00
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp;
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("NTUN, "));
|
|
|
|
|
|
|
|
for(int8_t i = 1; i < 10; i++ ){
|
|
|
|
temp = DataFlash.ReadInt();
|
|
|
|
Serial.printf("%d, ", temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = DataFlash.ReadInt();
|
|
|
|
Serial.printf("%d\n", temp);
|
2011-05-23 02:53:00 -03:00
|
|
|
}
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2011-04-21 02:15:45 -03:00
|
|
|
// Write a control tuning packet. Total length : 22 bytes
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Control_Tuning()
|
2011-04-21 02:15:45 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_CONTROL_TUNING_MSG);
|
|
|
|
|
2011-11-28 14:26:36 -04:00
|
|
|
DataFlash.WriteInt(g.rc_1.control_in); // 0
|
|
|
|
DataFlash.WriteInt(g.rc_2.control_in); // 1
|
|
|
|
DataFlash.WriteInt(g.rc_3.control_in); // 2
|
|
|
|
DataFlash.WriteInt(g.rc_4.control_in); // 3
|
|
|
|
DataFlash.WriteInt(sonar_alt); // 4
|
|
|
|
DataFlash.WriteInt(baro_alt); // 5
|
|
|
|
DataFlash.WriteInt(next_WP.alt); // 6
|
|
|
|
DataFlash.WriteInt(nav_throttle); // 7
|
|
|
|
DataFlash.WriteInt(angle_boost); // 8
|
|
|
|
DataFlash.WriteInt(manual_boost); // 9
|
|
|
|
DataFlash.WriteInt(climb_rate); // 10
|
|
|
|
DataFlash.WriteInt(g.rc_3.servo_out); // 11
|
|
|
|
DataFlash.WriteInt(g.pi_alt_hold.get_integrator()); // 12
|
|
|
|
DataFlash.WriteInt(g.pi_throttle.get_integrator()); // 13
|
2011-04-21 02:15:45 -03:00
|
|
|
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Read an control tuning packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Control_Tuning()
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp;
|
2011-05-09 01:16:58 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
Serial.printf_P(PSTR("CTUN, "));
|
2011-04-16 17:39:56 -03:00
|
|
|
|
2011-11-28 14:26:36 -04:00
|
|
|
for(int8_t i = 0; i < 13; i++ ){
|
2011-11-08 02:23:48 -04:00
|
|
|
temp = DataFlash.ReadInt();
|
|
|
|
Serial.printf("%d, ", temp);
|
|
|
|
}
|
2011-11-28 14:26:36 -04:00
|
|
|
// read 13
|
2011-11-08 02:23:48 -04:00
|
|
|
temp = DataFlash.ReadInt();
|
|
|
|
Serial.printf("%d\n", temp);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-05-09 01:16:58 -03:00
|
|
|
// Write a performance monitoring packet. Total length : 19 bytes
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Performance()
|
2011-05-09 01:16:58 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_PERFORMANCE_MSG);
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
//DataFlash.WriteByte( delta_ms_fast_loop);
|
|
|
|
//DataFlash.WriteByte( loop_step);
|
|
|
|
|
|
|
|
|
2011-10-28 02:36:25 -03:00
|
|
|
|
2011-11-17 14:37:01 -04:00
|
|
|
DataFlash.WriteLong( millis()- perf_mon_timer); //1
|
|
|
|
DataFlash.WriteByte( dcm.gyro_sat_count); //2
|
|
|
|
DataFlash.WriteByte( imu.adc_constraints); //3
|
|
|
|
DataFlash.WriteByte( dcm.renorm_sqrt_count); //4
|
|
|
|
DataFlash.WriteByte( dcm.renorm_blowup_count); //5
|
|
|
|
DataFlash.WriteByte( gps_fix_count); //6
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2011-05-09 01:16:58 -03:00
|
|
|
|
2011-10-28 02:36:25 -03:00
|
|
|
//DataFlash.WriteInt ( (int)(dcm.get_health() * 1000)); //7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// control_mode
|
2011-11-17 14:37:01 -04:00
|
|
|
/*
|
2011-10-28 02:36:25 -03:00
|
|
|
DataFlash.WriteByte(control_mode); //1
|
|
|
|
DataFlash.WriteByte(yaw_mode); //2
|
|
|
|
DataFlash.WriteByte(roll_pitch_mode); //3
|
|
|
|
DataFlash.WriteByte(throttle_mode); //4
|
|
|
|
DataFlash.WriteInt(g.throttle_cruise.get()); //5
|
|
|
|
DataFlash.WriteLong(throttle_integrator); //6
|
2011-05-09 01:16:58 -03:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
2011-11-17 14:37:01 -04:00
|
|
|
*/
|
|
|
|
|
2011-05-09 01:16:58 -03:00
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// Read a performance packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Performance()
|
2011-11-08 02:23:48 -04:00
|
|
|
{
|
2011-11-17 14:37:01 -04:00
|
|
|
int32_t temp1 = DataFlash.ReadLong();
|
|
|
|
int8_t temp2 = DataFlash.ReadByte();
|
|
|
|
int8_t temp3 = DataFlash.ReadByte();
|
|
|
|
int8_t temp4 = DataFlash.ReadByte();
|
|
|
|
int8_t temp5 = DataFlash.ReadByte();
|
|
|
|
int8_t temp6 = DataFlash.ReadByte();
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
//1 2 3 4 5 6
|
2011-11-17 14:37:01 -04:00
|
|
|
Serial.printf_P(PSTR("PM, %ld, %d, %d, %d, %d, %d\n"),
|
2011-11-08 02:23:48 -04:00
|
|
|
temp1,
|
|
|
|
temp2,
|
|
|
|
temp3,
|
|
|
|
temp4,
|
2011-11-10 03:28:50 -04:00
|
|
|
temp5,
|
|
|
|
temp6);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-05-12 18:37:38 -03:00
|
|
|
// Write a command processing packet.
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Cmd(byte num, struct Location *wp)
|
2011-05-12 18:37:38 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_CMD_MSG);
|
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
DataFlash.WriteByte(g.command_total); // 1
|
|
|
|
DataFlash.WriteByte(num); // 2
|
|
|
|
DataFlash.WriteByte(wp->id); // 3
|
|
|
|
DataFlash.WriteByte(wp->options); // 4
|
|
|
|
DataFlash.WriteByte(wp->p1); // 5
|
|
|
|
DataFlash.WriteLong(wp->alt); // 6
|
|
|
|
DataFlash.WriteLong(wp->lat); // 7
|
|
|
|
DataFlash.WriteLong(wp->lng); // 8
|
2011-05-12 18:37:38 -03:00
|
|
|
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
2011-05-21 23:49:57 -03:00
|
|
|
//CMD, 3, 0, 16, 8, 1, 800, 340440192, -1180692736
|
2011-05-12 18:37:38 -03:00
|
|
|
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Read a command processing packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Cmd()
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int8_t temp1 = DataFlash.ReadByte();
|
|
|
|
int8_t temp2 = DataFlash.ReadByte();
|
|
|
|
int8_t temp3 = DataFlash.ReadByte();
|
|
|
|
int8_t temp4 = DataFlash.ReadByte();
|
|
|
|
int8_t temp5 = DataFlash.ReadByte();
|
2011-11-08 17:46:05 -04:00
|
|
|
long temp6 = DataFlash.ReadLong();
|
|
|
|
long temp7 = DataFlash.ReadLong();
|
|
|
|
long temp8 = DataFlash.ReadLong();
|
2011-05-12 18:37:38 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
// 1 2 3 4 5 6 7 8
|
|
|
|
Serial.printf_P(PSTR( "CMD, %d, %d, %d, %d, %d, %ld, %ld, %ld\n"),
|
2011-11-08 17:46:05 -04:00
|
|
|
temp1,
|
|
|
|
temp2,
|
|
|
|
temp3,
|
|
|
|
temp4,
|
|
|
|
temp5,
|
|
|
|
temp6,
|
|
|
|
temp7,
|
|
|
|
temp8);
|
2011-10-13 01:21:46 -03:00
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-05-09 01:16:58 -03:00
|
|
|
// Write an attitude packet. Total length : 10 bytes
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Attitude()
|
2011-05-09 01:16:58 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_ATTITUDE_MSG);
|
2011-09-14 17:58:18 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
DataFlash.WriteInt((int)dcm.roll_sensor); // 1
|
|
|
|
DataFlash.WriteInt((int)dcm.pitch_sensor); // 2
|
|
|
|
DataFlash.WriteInt((uint16_t)dcm.yaw_sensor); // 3
|
2011-09-14 17:58:18 -03:00
|
|
|
|
2011-11-08 02:23:48 -04:00
|
|
|
DataFlash.WriteInt((int)g.rc_1.servo_out); // 4
|
|
|
|
DataFlash.WriteInt((int)g.rc_2.servo_out); // 5
|
|
|
|
DataFlash.WriteInt((int)g.rc_4.servo_out); // 6
|
2011-09-14 17:58:18 -03:00
|
|
|
|
2011-05-09 01:16:58 -03:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Read an attitude packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Attitude()
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-11-08 02:23:48 -04:00
|
|
|
int16_t temp1 = DataFlash.ReadInt();
|
|
|
|
int16_t temp2 = DataFlash.ReadInt();
|
|
|
|
uint16_t temp3 = DataFlash.ReadInt();
|
2011-11-17 14:26:46 -04:00
|
|
|
int16_t temp4 = DataFlash.ReadInt();
|
|
|
|
int16_t temp5 = DataFlash.ReadInt();
|
|
|
|
int16_t temp6 = DataFlash.ReadInt();
|
2011-11-08 02:23:48 -04:00
|
|
|
|
|
|
|
// 1 2 3 4 5 6
|
2011-09-16 20:54:45 -03:00
|
|
|
Serial.printf_P(PSTR("ATT, %d, %d, %u, %d, %d, %d\n"),
|
2011-11-08 02:23:48 -04:00
|
|
|
temp1,
|
|
|
|
temp2,
|
|
|
|
temp3,
|
|
|
|
temp4,
|
|
|
|
temp5,
|
|
|
|
temp6);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-05-16 02:28:20 -03:00
|
|
|
// Write a mode packet. Total length : 5 bytes
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Mode(byte mode)
|
2011-05-16 02:28:20 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_MODE_MSG);
|
|
|
|
DataFlash.WriteByte(mode);
|
2011-06-16 14:03:26 -03:00
|
|
|
DataFlash.WriteInt(g.throttle_cruise);
|
2011-05-16 02:28:20 -03:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Read a mode packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Mode()
|
2011-02-24 01:56:59 -04:00
|
|
|
{
|
2011-04-15 10:24:05 -03:00
|
|
|
Serial.printf_P(PSTR("MOD:"));
|
2011-05-23 02:53:00 -03:00
|
|
|
Serial.print(flight_mode_strings[DataFlash.ReadByte()]);
|
|
|
|
Serial.printf_P(PSTR(", %d\n"),DataFlash.ReadInt());
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Write_Startup()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_STARTUP_MSG);
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read a mode packet
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read_Startup()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("START UP\n"));
|
|
|
|
}
|
|
|
|
|
2011-11-19 20:57:10 -04:00
|
|
|
static void Log_Write_Data(int8_t _type, float _data)
|
|
|
|
{
|
|
|
|
Log_Write_Data(_type, (int32_t)(_data * 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log_Write_Data(int8_t _type, int32_t _data)
|
|
|
|
{
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_DATA_MSG);
|
|
|
|
DataFlash.WriteByte(_type);
|
|
|
|
DataFlash.WriteLong(_data);
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read a mode packet
|
|
|
|
static void Log_Read_Data()
|
|
|
|
{
|
|
|
|
int8_t temp1 = DataFlash.ReadByte();
|
|
|
|
int32_t temp2 = DataFlash.ReadLong();
|
|
|
|
Serial.printf_P(PSTR("DATA: %d, %ld\n"), temp1, temp2);
|
|
|
|
}
|
|
|
|
|
2011-11-25 10:13:32 -04:00
|
|
|
// Read the DataFlash log memory
|
|
|
|
static void Log_Read(int start_page, int end_page)
|
|
|
|
{
|
|
|
|
int packet_count = 0;
|
|
|
|
|
|
|
|
#ifdef AIRFRAME_NAME
|
|
|
|
Serial.printf_P(PSTR((AIRFRAME_NAME)
|
|
|
|
#endif
|
|
|
|
Serial.printf_P(PSTR("\n" THISFIRMWARE
|
|
|
|
"\nFree RAM: %u\n"),
|
|
|
|
memcheck_available_memory());
|
|
|
|
|
|
|
|
if(start_page > end_page)
|
|
|
|
{
|
|
|
|
packet_count = Log_Read_Process(start_page, DF_LAST_PAGE);
|
|
|
|
packet_count += Log_Read_Process(1, end_page);
|
|
|
|
} else {
|
|
|
|
packet_count = Log_Read_Process(start_page, end_page);
|
|
|
|
}
|
|
|
|
|
2011-12-17 02:02:41 -04:00
|
|
|
//Serial.printf_P(PSTR("Number of packets read: %d\n"), packet_count);
|
2011-11-25 10:13:32 -04:00
|
|
|
}
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Read the DataFlash log memory : Packet Parser
|
2011-11-25 10:13:32 -04:00
|
|
|
static int Log_Read_Process(int start_page, int end_page)
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
|
|
|
byte data;
|
2011-04-17 02:17:42 -03:00
|
|
|
byte log_step = 0;
|
|
|
|
int page = start_page;
|
2011-11-25 10:13:32 -04:00
|
|
|
int packet_count = 0;
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
DataFlash.StartRead(start_page);
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-03-09 02:37:09 -04:00
|
|
|
while (page < end_page && page != -1){
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
data = DataFlash.ReadByte();
|
2011-04-17 02:17:42 -03:00
|
|
|
|
|
|
|
// This is a state machine to read the packets
|
|
|
|
switch(log_step){
|
2011-02-19 03:44:44 -04:00
|
|
|
case 0:
|
2011-03-09 02:37:09 -04:00
|
|
|
if(data == HEAD_BYTE1) // Head byte 1
|
2010-12-19 12:40:33 -04:00
|
|
|
log_step++;
|
2011-01-29 01:55:23 -04:00
|
|
|
break;
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
case 1:
|
2011-03-09 02:37:09 -04:00
|
|
|
if(data == HEAD_BYTE2) // Head byte 2
|
2010-12-19 12:40:33 -04:00
|
|
|
log_step++;
|
2011-09-16 20:54:45 -03:00
|
|
|
else{
|
2010-12-19 12:40:33 -04:00
|
|
|
log_step = 0;
|
2011-09-16 20:54:45 -03:00
|
|
|
Serial.println(".");
|
|
|
|
}
|
2011-01-29 01:55:23 -04:00
|
|
|
break;
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
case 2:
|
2011-06-16 14:03:26 -03:00
|
|
|
log_step = 0;
|
|
|
|
switch(data){
|
|
|
|
case LOG_ATTITUDE_MSG:
|
|
|
|
Log_Read_Attitude();
|
|
|
|
break;
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_MODE_MSG:
|
|
|
|
Log_Read_Mode();
|
|
|
|
break;
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_CONTROL_TUNING_MSG:
|
|
|
|
Log_Read_Control_Tuning();
|
|
|
|
break;
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_NAV_TUNING_MSG:
|
|
|
|
Log_Read_Nav_Tuning();
|
|
|
|
break;
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_PERFORMANCE_MSG:
|
|
|
|
Log_Read_Performance();
|
|
|
|
break;
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_RAW_MSG:
|
|
|
|
Log_Read_Raw();
|
|
|
|
break;
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_CMD_MSG:
|
|
|
|
Log_Read_Cmd();
|
|
|
|
break;
|
2011-02-24 01:56:59 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_CURRENT_MSG:
|
|
|
|
Log_Read_Current();
|
|
|
|
break;
|
2011-02-24 01:56:59 -04:00
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_STARTUP_MSG:
|
|
|
|
Log_Read_Startup();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOG_MOTORS_MSG:
|
|
|
|
Log_Read_Motors();
|
|
|
|
break;
|
|
|
|
|
2011-07-21 20:14:53 -03:00
|
|
|
case LOG_OPTFLOW_MSG:
|
|
|
|
Log_Read_Optflow();
|
|
|
|
break;
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
case LOG_GPS_MSG:
|
2011-05-15 14:42:32 -03:00
|
|
|
Log_Read_GPS();
|
2011-06-16 14:03:26 -03:00
|
|
|
break;
|
2011-11-19 20:57:10 -04:00
|
|
|
|
|
|
|
case LOG_DATA_MSG:
|
|
|
|
Log_Read_Data();
|
|
|
|
break;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
break;
|
2011-11-25 10:13:32 -04:00
|
|
|
case 3:
|
|
|
|
if(data == END_BYTE){
|
|
|
|
packet_count++;
|
|
|
|
}else{
|
|
|
|
Serial.printf_P(PSTR("Error Reading END_BYTE: %d\n"),data);
|
|
|
|
}
|
|
|
|
log_step = 0; // Restart sequence: new packet...
|
|
|
|
break;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-04-17 02:17:42 -03:00
|
|
|
page = DataFlash.GetPage();
|
|
|
|
}
|
2011-11-25 10:13:32 -04:00
|
|
|
return packet_count;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:31:07 -03:00
|
|
|
#endif // LOGGING_ENABLED
|
2011-12-20 01:04:51 -04:00
|
|
|
|
|
|
|
#if LOGGING_ENABLED == DISABLED
|
|
|
|
|
|
|
|
static void Log_Write_Startup() {}
|
|
|
|
static void Log_Read_Startup() {}
|
|
|
|
static void Log_Read(int start_page, int end_page) {}
|
|
|
|
static void Log_Write_Cmd(byte num, struct Location *wp) {}
|
|
|
|
static void Log_Write_Mode(byte mode) {}
|
|
|
|
static void start_new_log() {}
|
|
|
|
static void Log_Write_Raw() {}
|
|
|
|
static void Log_Write_GPS() {}
|
|
|
|
static void Log_Write_Current() {}
|
|
|
|
static void Log_Write_Attitude() {}
|
|
|
|
static void Log_Write_Data(int8_t _type, float _data){}
|
|
|
|
static void Log_Write_Data(int8_t _type, int32_t _data){}
|
|
|
|
#ifdef OPTFLOW_ENABLED
|
|
|
|
static void Log_Write_Optflow() {}
|
|
|
|
#endif
|
|
|
|
static void Log_Write_Nav_Tuning() {}
|
|
|
|
static void Log_Write_Control_Tuning() {}
|
|
|
|
static void Log_Write_Motors() {}
|
|
|
|
static void Log_Write_Performance() {}
|
|
|
|
static int8_t process_logs(uint8_t argc, const Menu::arg *argv) { return 0; }
|
|
|
|
static void do_erase_logs(void (*delay_cb)(unsigned long)) {}
|
|
|
|
|
|
|
|
#endif
|