#include #include #include #include #include #include #include #include #include #include #include "LogReader.h" #include #include #include #include #include "MsgHandler.h" #include "Replay.h" #define DEBUG 0 #if DEBUG # define debug(fmt, args...) printf(fmt "\n", ##args) #else # define debug(fmt, args...) #endif #define streq(x, y) (!strcmp(x, y)) extern const AP_HAL::HAL& hal; const struct LogStructure log_structure[] = { LOG_COMMON_STRUCTURES, { LOG_CHEK_MSG, sizeof(log_Chek), "CHEK", "QccCLLffff", "TimeUS,Roll,Pitch,Yaw,Lat,Lng,Alt,VN,VE,VD" } }; LogReader::LogReader(AP_AHRS &_ahrs, AP_InertialSensor &_ins, AP_Baro &_baro, Compass &_compass, AP_GPS &_gps, AP_Airspeed &_airspeed, DataFlash_Class &_dataflash, const char **&_nottypes): DataFlashFileReader(), vehicle(VehicleType::VEHICLE_UNKNOWN), ahrs(_ahrs), ins(_ins), baro(_baro), compass(_compass), gps(_gps), airspeed(_airspeed), dataflash(_dataflash), accel_mask(7), gyro_mask(7), last_timestamp_usec(0), installed_vehicle_specific_parsers(false), nottypes(_nottypes) { } struct log_Format deferred_formats[LOGREADER_MAX_FORMATS]; // some log entries (e.g. "NTUN") are used by the different vehicle // types with wildy varying payloads. We thus can't use the same // parser for just any e.g. NTUN message. We defer the registration // of a parser for these messages until we know what model we're // dealing with. void LogReader::maybe_install_vehicle_specific_parsers() { if (! installed_vehicle_specific_parsers && vehicle != VehicleType::VEHICLE_UNKNOWN) { switch(vehicle) { case VehicleType::VEHICLE_COPTER: for (uint8_t i = 0; istop_clock(last_timestamp_usec); } LR_MsgHandler *p = msgparser[f.type]; if (p == NULL) { return true; } p->process_message(msg); maybe_install_vehicle_specific_parsers(); return true; } bool LogReader::wait_type(const char *wtype) { while (true) { char type[5]; if (!update(type)) { return false; } if (streq(type,wtype)) { break; } } return true; } bool LogReader::set_parameter(const char *name, float value) { if (parameter_handler == NULL) { ::printf("No parameter format message found"); return false; } return parameter_handler->set_parameter(name, value); } /* called when the last FMT message has been processed */ void LogReader::end_format_msgs(void) { // write out any formats we will be producing for (uint8_t i=0; generated_names[i]; i++) { for (uint8_t n=0; nmsg_type; pkt.length = s->msg_len; strncpy(pkt.name, s->name, sizeof(pkt.name)); strncpy(pkt.format, s->format, sizeof(pkt.format)); strncpy(pkt.labels, s->labels, sizeof(pkt.labels)); dataflash.WriteCriticalBlock(&pkt, sizeof(pkt)); } } } }