Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/Replay/LogReader.cpp
Views: 1798
#include "LogReader.h"12#include "MsgHandler.h"3#include "Replay.h"45#include <stdio.h>6#include <unistd.h>7#include <sys/types.h>8#include <sys/stat.h>9#include <sys/types.h>10#include <signal.h>111213#define DEBUG 114#if DEBUG15# define debug(fmt, args...) printf(fmt "\n", ##args)16#else17# define debug(fmt, args...)18#endif1920#define streq(x, y) (!strcmp(x, y))2122extern struct user_parameter *user_parameters;2324LogReader::LogReader(struct LogStructure *log_structure, NavEKF2 &_ekf2, NavEKF3 &_ekf3) :25AP_LoggerFileReader(),26ekf2(_ekf2),27ekf3(_ekf3),28_log_structure(log_structure)29{30}3132/*33see if a type is in a list of types34*/35bool LogReader::in_list(const char *type, const char *list[])36{37if (list == NULL) {38return false;39}40for (uint8_t i=0; list[i] != NULL; i++) {41if (strcmp(type, list[i]) == 0) {42return true;43}44}45return false;46}4748bool LogReader::handle_log_format_msg(const struct log_Format &f)49{50// emit the output as we receive it:51AP::logger().WriteBlock((void*)&f, sizeof(f));5253char name[5];54memset(name, '\0', 5);55memcpy(name, f.name, 4);5657if (msgparser[f.type] != NULL) {58return true;59}6061// map from format name to a parser subclass:62if (streq(name, "PARM")) {63msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_PARM(formats[f.type]);64} else if (streq(name, "RFRH")) {65msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RFRH(formats[f.type]);66} else if (streq(name, "RFRF")) {67msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RFRF(formats[f.type], ekf2, ekf3);68} else if (streq(name, "RFRN")) {69msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RFRN(formats[f.type]);70} else if (streq(name, "REV2")) {71msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REV2(formats[f.type], ekf2, ekf3);72} else if (streq(name, "RSO2")) {73msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RSO2(formats[f.type], ekf2, ekf3);74} else if (streq(name, "RWA2")) {75msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RWA2(formats[f.type], ekf2, ekf3);76} else if (streq(name, "REV3")) {77msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REV3(formats[f.type], ekf2, ekf3);78} else if (streq(name, "RSO3")) {79msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RSO3(formats[f.type], ekf2, ekf3);80} else if (streq(name, "RWA3")) {81msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RWA3(formats[f.type], ekf2, ekf3);82} else if (streq(name, "REY3")) {83msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REY3(formats[f.type], ekf2, ekf3);84} else if (streq(name, "RISH")) {85msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RISH(formats[f.type]);86} else if (streq(name, "RISI")) {87msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RISI(formats[f.type]);88} else if (streq(name, "RASH")) {89msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RASH(formats[f.type]);90} else if (streq(name, "RASI")) {91msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RASI(formats[f.type]);92} else if (streq(name, "RBRH")) {93msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBRH(formats[f.type]);94} else if (streq(name, "RBRI")) {95msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBRI(formats[f.type]);96} else if (streq(name, "RRNH")) {97msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RRNH(formats[f.type]);98} else if (streq(name, "RRNI")) {99msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RRNI(formats[f.type]);100} else if (streq(name, "RGPH")) {101msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RGPH(formats[f.type]);102} else if (streq(name, "RGPI")) {103msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RGPI(formats[f.type]);104} else if (streq(name, "RGPJ")) {105msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RGPJ(formats[f.type]);106} else if (streq(name, "RMGH")) {107msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RMGH(formats[f.type]);108} else if (streq(name, "RMGI")) {109msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RMGI(formats[f.type]);110} else if (streq(name, "RBCH")) {111msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBCH(formats[f.type]);112} else if (streq(name, "RBCI")) {113msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBCI(formats[f.type]);114} else if (streq(name, "RVOH")) {115msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RVOH(formats[f.type]);116} else if (streq(name, "ROFH")) {117msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_ROFH(formats[f.type], ekf2, ekf3);118} else if (streq(name, "REPH")) {119msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REPH(formats[f.type], ekf2, ekf3);120} else if (streq(name, "RSLL")) {121msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RSLL(formats[f.type], ekf2, ekf3);122} else if (streq(name, "REVH")) {123msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REVH(formats[f.type], ekf2, ekf3);124} else if (streq(name, "RWOH")) {125msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RWOH(formats[f.type], ekf2, ekf3);126} else if (streq(name, "RBOH")) {127msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBOH(formats[f.type], ekf2, ekf3);128} else {129// debug(" No parser for (%s)\n", name);130}131132return true;133}134135bool LogReader::handle_msg(const struct log_Format &f, uint8_t *msg) {136// emit the output as we receive it:137AP::logger().WriteBlock(msg, f.length);138139LR_MsgHandler *p = msgparser[f.type];140if (p == NULL) {141return true;142}143144p->process_message(msg);145146return true;147}148149/*150see if a user parameter is set151*/152bool LogReader::check_user_param(const char *name)153{154for (struct user_parameter *u=user_parameters; u; u=u->next) {155if (strcmp(name, u->name) == 0) {156return true;157}158}159return false;160}161162bool LogReader::set_parameter(const char *name, float value, bool force)163{164if (!force && check_user_param(name)) {165// ignore user set parameters166return false;167}168enum ap_var_type var_type;169AP_Param *vp = AP_Param::find(name, &var_type);170if (vp == NULL) {171// a lot of parameters will not be found - e.g. FORMAT_VERSION172// and all of the vehicle-specific parameters, ....173return false;174}175float old_value = 0;176if (var_type == AP_PARAM_FLOAT) {177old_value = ((AP_Float *)vp)->cast_to_float();178((AP_Float *)vp)->set(value);179} else if (var_type == AP_PARAM_INT32) {180old_value = ((AP_Int32 *)vp)->cast_to_float();181((AP_Int32 *)vp)->set(value);182} else if (var_type == AP_PARAM_INT16) {183old_value = ((AP_Int16 *)vp)->cast_to_float();184((AP_Int16 *)vp)->set(value);185} else if (var_type == AP_PARAM_INT8) {186old_value = ((AP_Int8 *)vp)->cast_to_float();187((AP_Int8 *)vp)->set(value);188} else {189AP_HAL::panic("What manner of evil is var_type=%u", var_type);190}191if (fabsf(old_value - value) > 1.0e-12) {192::printf("Changed %s to %.8f from %.8f\n", name, value, old_value);193}194return true;195}196197198199