#include "LogReader.h" #include "MsgHandler.h" #include "Replay.h" #include #include #include #include #include #include #define DEBUG 1 #if DEBUG # define debug(fmt, args...) printf(fmt "\n", ##args) #else # define debug(fmt, args...) #endif #define streq(x, y) (!strcmp(x, y)) extern struct user_parameter *user_parameters; LogReader::LogReader(struct LogStructure *log_structure, NavEKF2 &_ekf2, NavEKF3 &_ekf3) : AP_LoggerFileReader(), _log_structure(log_structure), ekf2(_ekf2), ekf3(_ekf3) { } // these names we emit from the code as normal, but are emitted using // Log_Write. Thus they are not present in LOG_COMMON_STRUCTURES. A // format will be written for this by the code itself the first time // the message is emitted to the log. However, we must not write the // messages from the old log to the new log, so we need to keep a map // of IDs to prune out... static const char *log_write_names[] = { nullptr }; static const char *generated_names[] = { NULL }; /* see if a type is in a list of types */ bool LogReader::in_list(const char *type, const char *list[]) { if (list == NULL) { return false; } for (uint8_t i=0; list[i] != NULL; i++) { if (strcmp(type, list[i]) == 0) { return true; } } return false; } /* map from an incoming format type to an outgoing format type */ uint8_t LogReader::map_fmt_type(const char *name, uint8_t intype) { if (intype == 128) { // everybody's favourite FMT message... return 128; } if (mapped_msgid[intype] != 0) { // already mapped return mapped_msgid[intype]; } for (uint8_t n=next_msgid; n<255; n++) { // ::fprintf(stderr, "next_msgid=%u\n", n); bool already_mapped = false; for (uint16_t i=0; iprocess_message(msg); return true; } /* see if a user parameter is set */ bool LogReader::check_user_param(const char *name) { for (struct user_parameter *u=user_parameters; u; u=u->next) { if (strcmp(name, u->name) == 0) { return true; } } return false; } bool LogReader::set_parameter(const char *name, float value, bool force) { if (!force && check_user_param(name)) { // ignore user set parameters return false; } enum ap_var_type var_type; AP_Param *vp = AP_Param::find(name, &var_type); if (vp == NULL) { // a lot of parameters will not be found - e.g. FORMAT_VERSION // and all of the vehicle-specific parameters, .... // ::fprintf(stderr, "Parameter (%s) not found\n", name); return false; } float old_value = 0; if (var_type == AP_PARAM_FLOAT) { old_value = ((AP_Float *)vp)->cast_to_float(); ((AP_Float *)vp)->set(value); } else if (var_type == AP_PARAM_INT32) { old_value = ((AP_Int32 *)vp)->cast_to_float(); ((AP_Int32 *)vp)->set(value); } else if (var_type == AP_PARAM_INT16) { old_value = ((AP_Int16 *)vp)->cast_to_float(); ((AP_Int16 *)vp)->set(value); } else if (var_type == AP_PARAM_INT8) { old_value = ((AP_Int8 *)vp)->cast_to_float(); ((AP_Int8 *)vp)->set(value); } else { AP_HAL::panic("What manner of evil is var_type=%u", var_type); } if (fabsf(old_value - value) > 1.0e-12) { ::fprintf(stderr, "Changed %s to %.8f from %.8f\n", name, value, old_value); } return true; }