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-07-17 07:31:07 -03:00
|
|
|
#if LOGGING_ENABLED == ENABLED
|
|
|
|
|
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
|
|
|
|
static int8_t help_log(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
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;
|
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},
|
|
|
|
{"disable", select_logs},
|
|
|
|
{"help", help_log}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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-02-19 03:44:44 -04:00
|
|
|
byte last_log_num = 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();
|
|
|
|
|
|
|
|
if (last_log_num == 0) {
|
2011-07-02 19:44:59 -03:00
|
|
|
Serial.printf_P(PSTR("\nNo logs\nType 'dump 0'.\n\n"));
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-03-26 03:35:52 -03:00
|
|
|
Serial.printf_P(PSTR("\n%d logs\n"), last_log_num);
|
2011-05-21 23:49:57 -03:00
|
|
|
|
2011-04-17 02:17:42 -03:00
|
|
|
for(int i = 1; i < last_log_num + 1; i++) {
|
2011-06-16 14:12:10 -03:00
|
|
|
get_log_boundaries(i, log_start, log_end);
|
2011-05-21 23:49:57 -03:00
|
|
|
//Serial.printf_P(PSTR("last_num %d "), last_log_num);
|
|
|
|
Serial.printf_P(PSTR("Log # %d, start %d, end %d\n"), i, log_start, log_end);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
dump_log(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
byte dump_log;
|
|
|
|
int dump_log_start;
|
|
|
|
int dump_log_end;
|
2011-05-25 22:50:32 -03:00
|
|
|
|
2011-09-05 02:09:07 -03:00
|
|
|
//byte last_log_num = get_num_logs();
|
2011-05-25 22:50:32 -03:00
|
|
|
//Serial.printf_P(PSTR("\n%d logs\n"), last_log_num);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// check that the requested log number can be read
|
|
|
|
dump_log = argv[1].i;
|
2011-05-21 23:49:57 -03:00
|
|
|
|
2011-09-04 21:15:36 -03:00
|
|
|
if (/*(argc != 2) || */ (dump_log < 1)) {
|
2011-05-21 23:49:57 -03:00
|
|
|
Serial.printf_P(PSTR("bad log # %d\n"), dump_log);
|
2011-09-04 21:15:36 -03:00
|
|
|
Log_Read(0, 4095);
|
2011-07-02 19:44:59 -03:00
|
|
|
erase_logs(NULL, NULL);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
erase_logs(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-05-14 23:02:09 -03:00
|
|
|
//for(int i = 10 ; i > 0; i--) {
|
|
|
|
// Serial.printf_P(PSTR("ATTENTION - Erasing log in %d seconds.\n"), i);
|
|
|
|
// delay(1000);
|
|
|
|
//}
|
|
|
|
|
2011-05-15 14:42:32 -03:00
|
|
|
// lay down a bunch of "log end" messages.
|
2010-12-19 12:40:33 -04:00
|
|
|
Serial.printf_P(PSTR("\nErasing log...\n"));
|
2011-02-19 03:44:44 -04:00
|
|
|
for(int j = 1; j < 4096; j++)
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.PageErase(j);
|
2011-07-30 17:42:54 -03:00
|
|
|
|
2011-09-04 21:15:36 -03:00
|
|
|
clear_header();
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("\nLog erased.\n"));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_header()
|
|
|
|
{
|
2011-02-19 03:44:44 -04:00
|
|
|
DataFlash.StartWrite(1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_INDEX_MSG);
|
|
|
|
DataFlash.WriteByte(0);
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
2011-03-09 02:37:09 -04:00
|
|
|
DataFlash.FinishWrite();
|
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-05-21 23:49:57 -03:00
|
|
|
// finds out how many logs are available
|
2011-07-17 07:32:00 -03:00
|
|
|
static byte get_num_logs(void)
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
|
|
|
int page = 1;
|
|
|
|
byte data;
|
2011-05-25 22:50:32 -03:00
|
|
|
byte log_step = 0;
|
2011-02-19 03:44:44 -04:00
|
|
|
|
|
|
|
DataFlash.StartRead(1);
|
2011-05-15 14:42:32 -03:00
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
while (page == 1) {
|
|
|
|
data = DataFlash.ReadByte();
|
2011-05-15 14:42:32 -03:00
|
|
|
|
|
|
|
switch(log_step){ //This is a state machine to read the packets
|
2011-02-19 03:44:44 -04:00
|
|
|
case 0:
|
|
|
|
if(data==HEAD_BYTE1) // Head byte 1
|
|
|
|
log_step++;
|
|
|
|
break;
|
2011-05-15 14:42:32 -03:00
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
case 1:
|
|
|
|
if(data==HEAD_BYTE2) // Head byte 2
|
|
|
|
log_step++;
|
|
|
|
else
|
|
|
|
log_step = 0;
|
|
|
|
break;
|
2011-05-15 14:42:32 -03:00
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
case 2:
|
2011-05-21 23:49:57 -03:00
|
|
|
if(data == LOG_INDEX_MSG){
|
2011-02-19 03:44:44 -04:00
|
|
|
byte num_logs = DataFlash.ReadByte();
|
2011-05-21 23:49:57 -03:00
|
|
|
//Serial.printf("num_logs, %d\n", num_logs);
|
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
return num_logs;
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-05-21 23:49:57 -03:00
|
|
|
//Serial.printf("* %d\n", data);
|
|
|
|
log_step = 0; // Restart, we have a problem...
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
page = DataFlash.GetPage();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-15 14:42:32 -03:00
|
|
|
// send the number of the last log?
|
2011-07-17 07:32:00 -03:00
|
|
|
static void start_new_log()
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-05-21 23:49:57 -03:00
|
|
|
byte num_existing_logs = get_num_logs();
|
|
|
|
|
2011-07-30 17:42:54 -03:00
|
|
|
int start_pages[50] = {0,0,0};
|
|
|
|
int end_pages[50] = {0,0,0};
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-05-15 14:42:32 -03:00
|
|
|
if(num_existing_logs > 0){
|
|
|
|
for(int i = 0; i < num_existing_logs; i++) {
|
2011-06-16 14:12:10 -03:00
|
|
|
get_log_boundaries(i + 1, start_pages[i], end_pages[i]);
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
end_pages[num_existing_logs - 1] = find_last_log_page(start_pages[num_existing_logs - 1]);
|
|
|
|
}
|
|
|
|
|
2011-05-21 23:49:57 -03:00
|
|
|
if((end_pages[num_existing_logs - 1] < 4095) && (num_existing_logs < MAX_NUM_LOGS /*50*/)) {
|
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
if(num_existing_logs > 0)
|
|
|
|
start_pages[num_existing_logs] = end_pages[num_existing_logs - 1] + 1;
|
|
|
|
else
|
|
|
|
start_pages[0] = 2;
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
num_existing_logs++;
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
DataFlash.StartWrite(1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE1);
|
|
|
|
DataFlash.WriteByte(HEAD_BYTE2);
|
|
|
|
DataFlash.WriteByte(LOG_INDEX_MSG);
|
|
|
|
DataFlash.WriteByte(num_existing_logs);
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-05-15 14:42:32 -03:00
|
|
|
for(int i = 0; i < MAX_NUM_LOGS; i++) {
|
2011-02-19 03:44:44 -04:00
|
|
|
DataFlash.WriteInt(start_pages[i]);
|
|
|
|
DataFlash.WriteInt(end_pages[i]);
|
|
|
|
}
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-02-19 03:44:44 -04:00
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
DataFlash.FinishWrite();
|
2011-05-15 14:42:32 -03:00
|
|
|
DataFlash.StartWrite(start_pages[num_existing_logs - 1]);
|
2011-04-17 02:17:42 -03:00
|
|
|
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-07-30 17:42:54 -03:00
|
|
|
gcs.send_text_P(SEVERITY_LOW,PSTR("Logs full"));
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-21 23:49:57 -03:00
|
|
|
// All log data is stored in page 1?
|
2011-06-16 14:12:10 -03:00
|
|
|
static void get_log_boundaries(byte log_num, int & start_page, int & end_page)
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
2011-06-16 14:12:10 -03:00
|
|
|
int page = 1;
|
2011-02-19 03:44:44 -04:00
|
|
|
byte data;
|
2011-06-16 14:12:10 -03:00
|
|
|
byte log_step = 0;
|
2011-02-19 03:44:44 -04:00
|
|
|
|
2011-06-16 14:12:10 -03:00
|
|
|
DataFlash.StartRead(1);
|
2011-05-15 14:42:32 -03:00
|
|
|
while (page == 1) {
|
2011-02-19 03:44:44 -04:00
|
|
|
data = DataFlash.ReadByte();
|
2011-06-16 14:12:10 -03:00
|
|
|
switch(log_step) //This is a state machine to read the packets
|
|
|
|
{
|
2011-02-19 03:44:44 -04:00
|
|
|
case 0:
|
|
|
|
if(data==HEAD_BYTE1) // Head byte 1
|
|
|
|
log_step++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(data==HEAD_BYTE2) // Head byte 2
|
|
|
|
log_step++;
|
|
|
|
else
|
|
|
|
log_step = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
2011-06-16 14:12:10 -03:00
|
|
|
if(data==LOG_INDEX_MSG){
|
2011-02-19 03:44:44 -04:00
|
|
|
byte num_logs = DataFlash.ReadByte();
|
2011-06-16 14:12:10 -03:00
|
|
|
for(int i=0;i<log_num;i++) {
|
|
|
|
start_page = DataFlash.ReadInt();
|
|
|
|
end_page = DataFlash.ReadInt();
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
2011-06-16 14:12:10 -03:00
|
|
|
if(log_num==num_logs)
|
2011-02-19 03:44:44 -04:00
|
|
|
end_page = find_last_log_page(start_page);
|
|
|
|
|
|
|
|
return; // This is the normal exit point
|
2011-02-24 01:56:59 -04:00
|
|
|
}else{
|
2011-06-16 14:12:10 -03:00
|
|
|
log_step=0; // Restart, we have a problem...
|
2011-02-19 03:44:44 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
page = DataFlash.GetPage();
|
|
|
|
}
|
|
|
|
// Error condition if we reach here with page = 2 TO DO - report condition
|
|
|
|
}
|
|
|
|
|
2011-05-21 23:49:57 -03:00
|
|
|
//
|
2011-07-17 07:32:00 -03:00
|
|
|
static int find_last_log_page(int bottom_page)
|
2011-02-19 03:44:44 -04:00
|
|
|
{
|
|
|
|
int top_page = 4096;
|
|
|
|
int look_page;
|
|
|
|
long check;
|
|
|
|
|
|
|
|
while((top_page - bottom_page) > 1) {
|
|
|
|
look_page = (top_page + bottom_page) / 2;
|
|
|
|
DataFlash.StartRead(look_page);
|
|
|
|
check = DataFlash.ReadLong();
|
2011-05-21 23:49:57 -03:00
|
|
|
|
|
|
|
//Serial.printf("look page:%d, check:%d\n", look_page, check);
|
|
|
|
|
2011-06-16 14:12:10 -03:00
|
|
|
if(check == (long)0xFFFFFFFF)
|
2011-02-19 03:44:44 -04:00
|
|
|
top_page = look_page;
|
|
|
|
else
|
|
|
|
bottom_page = look_page;
|
|
|
|
}
|
|
|
|
return top_page;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
DataFlash.WriteByte(g_gps->fix); // 2
|
|
|
|
DataFlash.WriteByte(g_gps->num_sats); // 3
|
|
|
|
|
|
|
|
DataFlash.WriteLong(current_loc.lat); // 4
|
|
|
|
DataFlash.WriteLong(current_loc.lng); // 5
|
|
|
|
DataFlash.WriteLong(current_loc.alt); // 7
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteLong(g_gps->altitude); // 6
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2011-05-16 02:28:20 -03:00
|
|
|
DataFlash.WriteInt(g_gps->ground_speed); // 8
|
|
|
|
DataFlash.WriteInt((uint16_t)g_gps->ground_course); // 9
|
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
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("GPS, %ld, %d, %d, "
|
2011-05-30 01:24:07 -03:00
|
|
|
"%4.7f, %4.7f, %4.4f, %4.4f, "
|
|
|
|
"%d, %u\n"),
|
2011-05-12 18:37:38 -03:00
|
|
|
|
|
|
|
DataFlash.ReadLong(), // 1 time
|
|
|
|
(int)DataFlash.ReadByte(), // 2 fix
|
|
|
|
(int)DataFlash.ReadByte(), // 3 sats
|
|
|
|
|
|
|
|
(float)DataFlash.ReadLong() / t7, // 4 lat
|
|
|
|
(float)DataFlash.ReadLong() / t7, // 5 lon
|
|
|
|
(float)DataFlash.ReadLong() / 100.0, // 6 gps alt
|
|
|
|
(float)DataFlash.ReadLong() / 100.0, // 7 sensor alt
|
|
|
|
|
|
|
|
DataFlash.ReadInt(), // 8 ground speed
|
2011-05-22 03:23:10 -03:00
|
|
|
(uint16_t)DataFlash.ReadInt()); // 9 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
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.WriteLong((long)gyro.x);
|
|
|
|
DataFlash.WriteLong((long)gyro.y);
|
|
|
|
DataFlash.WriteLong((long)gyro.z);
|
2011-07-10 21:47:08 -03:00
|
|
|
|
|
|
|
|
|
|
|
//DataFlash.WriteLong((long)(accels_rot.x * t7));
|
|
|
|
//DataFlash.WriteLong((long)(accels_rot.y * t7));
|
|
|
|
//DataFlash.WriteLong((long)(accels_rot.z * t7));
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
DataFlash.WriteLong((long)accel.x);
|
|
|
|
DataFlash.WriteLong((long)accel.y);
|
|
|
|
DataFlash.WriteLong((long)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-02-17 03:09:13 -04:00
|
|
|
DataFlash.WriteInt(g.rc_3.control_in);
|
2011-04-30 13:01:57 -03:00
|
|
|
DataFlash.WriteLong(throttle_integrator);
|
|
|
|
|
2011-05-09 14:40:32 -03:00
|
|
|
DataFlash.WriteInt((int)(battery_voltage * 100.0));
|
2011-01-18 02:11:48 -04:00
|
|
|
DataFlash.WriteInt((int)(current_amps * 100.0));
|
2011-01-29 22:36:03 -04:00
|
|
|
DataFlash.WriteInt((int)current_total);
|
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-04-30 13:01:57 -03:00
|
|
|
Serial.printf_P(PSTR("CURR: %d, %ld, %4.4f, %4.4f, %d\n"),
|
2011-01-29 22:36:03 -04:00
|
|
|
DataFlash.ReadInt(),
|
2011-04-30 13:01:57 -03:00
|
|
|
DataFlash.ReadLong(),
|
|
|
|
|
2011-01-29 22:36:03 -04:00
|
|
|
((float)DataFlash.ReadInt() / 100.f),
|
|
|
|
((float)DataFlash.ReadInt() / 100.f),
|
|
|
|
DataFlash.ReadInt());
|
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);
|
|
|
|
|
|
|
|
DataFlash.WriteInt(motor_out[CH_1]);
|
|
|
|
DataFlash.WriteInt(motor_out[CH_2]);
|
|
|
|
DataFlash.WriteInt(motor_out[CH_3]);
|
|
|
|
DataFlash.WriteInt(motor_out[CH_4]);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("MOT: %d, %d, %d, %d\n"),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt());
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
DataFlash.WriteLong(optflow.lat);//optflow_offset.lat + optflow.lat);
|
|
|
|
DataFlash.WriteLong(optflow.lng);//optflow_offset.lng + optflow.lng);
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Read an attitude packet
|
|
|
|
static void Log_Read_Optflow()
|
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("OF, %d, %d, %d, %4.7f, %4.7f\n"),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
(float)DataFlash.ReadLong(),// / t7,
|
|
|
|
(float)DataFlash.ReadLong() // / t7
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteInt((int)wp_distance); // 1
|
|
|
|
DataFlash.WriteByte(wp_verify_byte); // 2
|
|
|
|
DataFlash.WriteInt((int)(target_bearing/100)); // 3
|
|
|
|
DataFlash.WriteInt((int)(nav_bearing/100)); // 4
|
|
|
|
DataFlash.WriteInt((int)long_error); // 5
|
|
|
|
DataFlash.WriteInt((int)lat_error); // 6
|
|
|
|
|
2011-05-23 02:53:00 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
/*
|
|
|
|
DataFlash.WriteInt((int)long_error); // 5
|
|
|
|
DataFlash.WriteInt((int)lat_error); // 6
|
2011-09-04 21:15:36 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteInt(x_rate_error); // 4
|
|
|
|
DataFlash.WriteInt(y_rate_error); // 4
|
2011-05-30 01:24:07 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteInt((int)nav_lon); // 7
|
|
|
|
DataFlash.WriteInt((int)nav_lat); // 8
|
2011-09-04 21:15:36 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteInt((int)g.pi_nav_lon.get_integrator()); // 7
|
|
|
|
DataFlash.WriteInt((int)g.pi_nav_lat.get_integrator()); // 8
|
|
|
|
DataFlash.WriteInt((int)g.pi_loiter_lon.get_integrator()); // 7
|
|
|
|
DataFlash.WriteInt((int)g.pi_loiter_lat.get_integrator()); // 8
|
|
|
|
|
|
|
|
*/
|
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-09-07 01:56:19 -03:00
|
|
|
Serial.printf_P(PSTR("NTUN, %d, %d, %d, %d, %d, %d\n"),
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.ReadInt(), // distance
|
|
|
|
DataFlash.ReadByte(), // wp_verify_byte
|
|
|
|
DataFlash.ReadInt(), // target_bearing
|
|
|
|
DataFlash.ReadInt(), // nav_bearing
|
|
|
|
|
|
|
|
DataFlash.ReadInt(), // long_error
|
|
|
|
DataFlash.ReadInt()); // lat_error
|
|
|
|
|
|
|
|
/*
|
2011-05-23 02:53:00 -03:00
|
|
|
// 1 2 3 4
|
2011-05-30 01:24:07 -03:00
|
|
|
Serial.printf_P(PSTR( "NTUN, %d, %d, %d, %d, "
|
2011-09-04 21:15:36 -03:00
|
|
|
"%d, %d, %d, %d, "
|
|
|
|
"%d, %d, %d, %d, "
|
|
|
|
"%d, %d\n"),
|
2011-05-30 01:24:07 -03:00
|
|
|
|
2011-05-23 02:53:00 -03:00
|
|
|
DataFlash.ReadInt(), //distance
|
|
|
|
DataFlash.ReadByte(), //bitmask
|
|
|
|
DataFlash.ReadInt(), //target bearing
|
2011-05-30 01:24:07 -03:00
|
|
|
DataFlash.ReadInt(),
|
|
|
|
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
2011-09-04 21:15:36 -03:00
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
|
2011-05-30 01:24:07 -03:00
|
|
|
DataFlash.ReadInt(),
|
2011-05-23 02:53:00 -03:00
|
|
|
DataFlash.ReadInt()); //nav bearing
|
2011-09-06 22:22:29 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
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
|
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
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);
|
|
|
|
|
|
|
|
// Control
|
2011-09-06 22:22:29 -03:00
|
|
|
//DataFlash.WriteInt((int)(g.rc_4.control_in/100));
|
|
|
|
//DataFlash.WriteInt((int)(g.rc_4.servo_out/100));
|
2011-04-22 18:15:17 -03:00
|
|
|
|
|
|
|
// yaw
|
|
|
|
DataFlash.WriteInt((int)(dcm.yaw_sensor/100));
|
2011-05-23 02:53:00 -03:00
|
|
|
DataFlash.WriteInt((int)(nav_yaw/100));
|
2011-05-28 03:52:56 -03:00
|
|
|
DataFlash.WriteInt((int)yaw_error/100);
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2011-05-23 02:53:00 -03:00
|
|
|
// Alt hold
|
2011-06-16 14:03:26 -03:00
|
|
|
DataFlash.WriteInt(g.rc_3.servo_out);
|
|
|
|
DataFlash.WriteInt(sonar_alt); //
|
|
|
|
DataFlash.WriteInt(baro_alt); //
|
2011-05-09 01:16:58 -03:00
|
|
|
|
2011-05-23 02:53:00 -03:00
|
|
|
DataFlash.WriteInt((int)next_WP.alt); //
|
2011-09-06 22:22:29 -03:00
|
|
|
//DataFlash.WriteInt((int)altitude_error); //
|
2011-09-04 21:15:36 -03:00
|
|
|
DataFlash.WriteInt((int)g.pi_throttle.get_integrator());
|
2011-04-21 02:15:45 -03:00
|
|
|
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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-09-04 21:15:36 -03:00
|
|
|
Serial.printf_P(PSTR( "CTUN, "
|
2011-09-06 22:22:29 -03:00
|
|
|
//"%d, %d, "
|
2011-09-05 14:06:08 -03:00
|
|
|
"%d, %d, %d, "
|
|
|
|
"%d, %d, %d, "
|
|
|
|
"%d, %d, %d\n"),
|
2011-05-09 01:16:58 -03:00
|
|
|
|
2011-04-16 17:39:56 -03:00
|
|
|
// Control
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
|
2011-04-22 18:15:17 -03:00
|
|
|
// yaw
|
|
|
|
DataFlash.ReadInt(),
|
2011-04-20 03:44:49 -03:00
|
|
|
DataFlash.ReadInt(),
|
2011-05-23 02:53:00 -03:00
|
|
|
DataFlash.ReadInt(),
|
2011-04-20 03:44:49 -03:00
|
|
|
|
2011-05-23 02:53:00 -03:00
|
|
|
// Alt Hold
|
|
|
|
DataFlash.ReadInt(),
|
2011-05-09 01:16:58 -03:00
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
2011-04-21 02:15:45 -03:00
|
|
|
|
2011-04-16 17:39:56 -03:00
|
|
|
DataFlash.ReadInt(),
|
2011-04-21 02:15:45 -03:00
|
|
|
DataFlash.ReadInt());
|
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-05-09 01:16:58 -03:00
|
|
|
DataFlash.WriteLong( millis()- perf_mon_timer);
|
2011-06-24 01:37:54 -03:00
|
|
|
DataFlash.WriteInt ( mainLoop_count);
|
|
|
|
DataFlash.WriteInt ( G_Dt_max);
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2011-05-09 01:16:58 -03:00
|
|
|
DataFlash.WriteByte( dcm.gyro_sat_count);
|
|
|
|
DataFlash.WriteByte( imu.adc_constraints);
|
|
|
|
DataFlash.WriteByte( dcm.renorm_sqrt_count);
|
|
|
|
DataFlash.WriteByte( dcm.renorm_blowup_count);
|
|
|
|
DataFlash.WriteByte( gps_fix_count);
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2011-06-24 01:37:54 -03:00
|
|
|
DataFlash.WriteInt ( (int)(dcm.get_health() * 1000));
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.WriteLong ( throttle_integrator);
|
|
|
|
|
2011-06-16 14:03:26 -03:00
|
|
|
//*/
|
2011-05-16 02:28:20 -03:00
|
|
|
//PM, 20005, 3742, 10,0,0,0,0,89,1000,
|
2011-05-09 01:16:58 -03:00
|
|
|
|
|
|
|
DataFlash.WriteByte(END_BYTE);
|
|
|
|
}
|
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-02-19 03:44:44 -04:00
|
|
|
{
|
2011-09-06 22:22:29 -03:00
|
|
|
Serial.printf_P(PSTR( "PM, %ld, %d, %d, "
|
|
|
|
"%d, %d, %d, %d, %d, "
|
|
|
|
"%d, %ld\n"),
|
2011-06-16 14:03:26 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
// Control
|
|
|
|
DataFlash.ReadLong(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
DataFlash.ReadByte(),
|
2011-09-07 13:43:06 -03:00
|
|
|
|
2011-09-06 22:22:29 -03:00
|
|
|
DataFlash.ReadByte(),
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadLong());
|
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);
|
|
|
|
|
|
|
|
DataFlash.WriteByte(g.waypoint_total);
|
|
|
|
|
|
|
|
DataFlash.WriteByte(num);
|
|
|
|
DataFlash.WriteByte(wp->id);
|
|
|
|
DataFlash.WriteByte(wp->options);
|
2011-05-21 23:49:57 -03:00
|
|
|
DataFlash.WriteByte(wp->p1);
|
2011-05-12 18:37:38 -03:00
|
|
|
DataFlash.WriteLong(wp->alt);
|
|
|
|
DataFlash.WriteLong(wp->lat);
|
|
|
|
DataFlash.WriteLong(wp->lng);
|
|
|
|
|
|
|
|
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-05-12 18:37:38 -03:00
|
|
|
Serial.printf_P(PSTR( "CMD, %d, %d, %d, %d, %d, %ld, %ld, %ld\n"),
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-05-12 18:37:38 -03:00
|
|
|
// WP total
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
|
|
|
|
// num, id, p1, options
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
DataFlash.ReadByte(),
|
|
|
|
|
|
|
|
// Alt, lat long
|
|
|
|
DataFlash.ReadLong(),
|
|
|
|
DataFlash.ReadLong(),
|
|
|
|
DataFlash.ReadLong());
|
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);
|
|
|
|
DataFlash.WriteInt((int)dcm.roll_sensor);
|
|
|
|
DataFlash.WriteInt((int)dcm.pitch_sensor);
|
|
|
|
DataFlash.WriteInt((uint16_t)dcm.yaw_sensor);
|
|
|
|
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-05-09 01:16:58 -03:00
|
|
|
Serial.printf_P(PSTR("ATT, %d, %d, %u\n"),
|
2011-03-09 02:37:09 -04:00
|
|
|
DataFlash.ReadInt(),
|
|
|
|
DataFlash.ReadInt(),
|
|
|
|
(uint16_t)DataFlash.ReadInt());
|
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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// Read the DataFlash log memory : Packet Parser
|
2011-07-17 07:32:00 -03:00
|
|
|
static void Log_Read(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;
|
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++;
|
|
|
|
else
|
|
|
|
log_step = 0;
|
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;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-17 02:17:42 -03:00
|
|
|
page = DataFlash.GetPage();
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:31:07 -03:00
|
|
|
#else // LOGGING_ENABLED
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
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() {}
|
2011-07-21 20:14:53 -03:00
|
|
|
#ifdef OPTFLOW_ENABLED
|
|
|
|
static void Log_Write_Optflow() {}
|
|
|
|
#endif
|
2011-07-17 07:32:00 -03:00
|
|
|
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; }
|
2011-07-17 07:31:07 -03:00
|
|
|
|
|
|
|
#endif // LOGGING_ENABLED
|