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/LR_MsgHandler.cpp
Views: 1798
#include "LR_MsgHandler.h"1#include "LogReader.h"2#include "Replay.h"34#include <AP_DAL/AP_DAL.h>56#include <cinttypes>78extern const AP_HAL::HAL& hal;910#define MSG_CREATE(sname,msgbytes) log_ ##sname msg; memcpy((void*)&msg, (msgbytes)+3, sizeof(msg));1112LR_MsgHandler::LR_MsgHandler(struct log_Format &_f) :13MsgHandler(_f) {14}1516void LR_MsgHandler_RFRH::process_message(uint8_t *msgbytes)17{18MSG_CREATE(RFRH, msgbytes);19AP::dal().handle_message(msg);20}2122void LR_MsgHandler_RFRF::process_message(uint8_t *msgbytes)23{24MSG_CREATE(RFRF, msgbytes);25#define MAP_FLAG(flag1, flag2) if (msg.frame_types & uint8_t(flag1)) msg.frame_types |= uint8_t(flag2)26/*27when we force an EKF we map the trigger flags over28*/29if (replay_force_ekf2) {30MAP_FLAG(AP_DAL::FrameType::InitialiseFilterEKF3, AP_DAL::FrameType::InitialiseFilterEKF2);31MAP_FLAG(AP_DAL::FrameType::UpdateFilterEKF3, AP_DAL::FrameType::UpdateFilterEKF2);32MAP_FLAG(AP_DAL::FrameType::LogWriteEKF3, AP_DAL::FrameType::LogWriteEKF2);33}34if (replay_force_ekf3) {35MAP_FLAG(AP_DAL::FrameType::InitialiseFilterEKF2, AP_DAL::FrameType::InitialiseFilterEKF3);36MAP_FLAG(AP_DAL::FrameType::UpdateFilterEKF2, AP_DAL::FrameType::UpdateFilterEKF3);37MAP_FLAG(AP_DAL::FrameType::LogWriteEKF2, AP_DAL::FrameType::LogWriteEKF3);38}39#undef MAP_FLAG40AP::dal().handle_message(msg, ekf2, ekf3);41}4243void LR_MsgHandler_RFRN::process_message(uint8_t *msgbytes)44{45MSG_CREATE(RFRN, msgbytes);46AP::dal().handle_message(msg);47}4849void LR_MsgHandler_REV2::process_message(uint8_t *msgbytes)50{51MSG_CREATE(REV2, msgbytes);5253switch ((AP_DAL::Event)msg.event) {5455case AP_DAL::Event::resetGyroBias:56ekf2.resetGyroBias();57break;58case AP_DAL::Event::resetHeightDatum:59ekf2.resetHeightDatum();60break;61case AP_DAL::Event::setTerrainHgtStable:62ekf2.setTerrainHgtStable(true);63break;64case AP_DAL::Event::unsetTerrainHgtStable:65ekf2.setTerrainHgtStable(false);66break;67case AP_DAL::Event::requestYawReset:68ekf2.requestYawReset();69break;70case AP_DAL::Event::checkLaneSwitch:71ekf2.checkLaneSwitch();72break;73case AP_DAL::Event::setSourceSet0 ... AP_DAL::Event::setSourceSet2:74break;75}76if (replay_force_ekf3) {77LR_MsgHandler_REV3 h{f, ekf2, ekf3};78h.process_message(msgbytes);79}80}8182void LR_MsgHandler_RSO2::process_message(uint8_t *msgbytes)83{84MSG_CREATE(RSO2, msgbytes);85Location loc;86loc.lat = msg.lat;87loc.lng = msg.lng;88loc.alt = msg.alt;89ekf2.setOriginLLH(loc);9091if (replay_force_ekf3) {92LR_MsgHandler_RSO2 h{f, ekf2, ekf3};93h.process_message(msgbytes);94}95}9697void LR_MsgHandler_RWA2::process_message(uint8_t *msgbytes)98{99MSG_CREATE(RWA2, msgbytes);100ekf2.writeDefaultAirSpeed(msg.airspeed);101if (replay_force_ekf3) {102LR_MsgHandler_RWA2 h{f, ekf2, ekf3};103h.process_message(msgbytes);104}105}106107108void LR_MsgHandler_REV3::process_message(uint8_t *msgbytes)109{110MSG_CREATE(REV3, msgbytes);111112switch ((AP_DAL::Event)msg.event) {113114case AP_DAL::Event::resetGyroBias:115ekf3.resetGyroBias();116break;117case AP_DAL::Event::resetHeightDatum:118ekf3.resetHeightDatum();119break;120case AP_DAL::Event::setTerrainHgtStable:121ekf3.setTerrainHgtStable(true);122break;123case AP_DAL::Event::unsetTerrainHgtStable:124ekf3.setTerrainHgtStable(false);125break;126case AP_DAL::Event::requestYawReset:127ekf3.requestYawReset();128break;129case AP_DAL::Event::checkLaneSwitch:130ekf3.checkLaneSwitch();131break;132case AP_DAL::Event::setSourceSet0 ... AP_DAL::Event::setSourceSet2:133ekf3.setPosVelYawSourceSet(uint8_t(msg.event)-uint8_t(AP_DAL::Event::setSourceSet0));134break;135}136137if (replay_force_ekf2) {138LR_MsgHandler_REV2 h{f, ekf2, ekf3};139h.process_message(msgbytes);140}141}142143void LR_MsgHandler_RSO3::process_message(uint8_t *msgbytes)144{145MSG_CREATE(RSO3, msgbytes);146Location loc;147loc.lat = msg.lat;148loc.lng = msg.lng;149loc.alt = msg.alt;150ekf3.setOriginLLH(loc);151if (replay_force_ekf2) {152LR_MsgHandler_RSO2 h{f, ekf2, ekf3};153h.process_message(msgbytes);154}155}156157void LR_MsgHandler_RWA3::process_message(uint8_t *msgbytes)158{159MSG_CREATE(RWA3, msgbytes);160ekf3.writeDefaultAirSpeed(msg.airspeed, msg.uncertainty);161if (replay_force_ekf2) {162LR_MsgHandler_RWA2 h{f, ekf2, ekf3};163h.process_message(msgbytes);164}165}166167void LR_MsgHandler_REY3::process_message(uint8_t *msgbytes)168{169MSG_CREATE(REY3, msgbytes);170ekf3.writeEulerYawAngle(msg.yawangle, msg.yawangleerr, msg.timestamp_ms, msg.type);171}172173void LR_MsgHandler_RISH::process_message(uint8_t *msgbytes)174{175MSG_CREATE(RISH, msgbytes);176AP::dal().handle_message(msg);177}178void LR_MsgHandler_RISI::process_message(uint8_t *msgbytes)179{180MSG_CREATE(RISI, msgbytes);181AP::dal().handle_message(msg);182}183184void LR_MsgHandler_RASH::process_message(uint8_t *msgbytes)185{186MSG_CREATE(RASH, msgbytes);187AP::dal().handle_message(msg);188}189void LR_MsgHandler_RASI::process_message(uint8_t *msgbytes)190{191MSG_CREATE(RASI, msgbytes);192AP::dal().handle_message(msg);193}194195void LR_MsgHandler_RBRH::process_message(uint8_t *msgbytes)196{197MSG_CREATE(RBRH, msgbytes);198AP::dal().handle_message(msg);199}200201void LR_MsgHandler_RBRI::process_message(uint8_t *msgbytes)202{203MSG_CREATE(RBRI, msgbytes);204AP::dal().handle_message(msg);205}206207void LR_MsgHandler_RRNH::process_message(uint8_t *msgbytes)208{209MSG_CREATE(RRNH, msgbytes);210AP::dal().handle_message(msg);211}212213void LR_MsgHandler_RRNI::process_message(uint8_t *msgbytes)214{215MSG_CREATE(RRNI, msgbytes);216AP::dal().handle_message(msg);217}218219void LR_MsgHandler_RGPH::process_message(uint8_t *msgbytes)220{221MSG_CREATE(RGPH, msgbytes);222AP::dal().handle_message(msg);223}224225void LR_MsgHandler_RGPI::process_message(uint8_t *msgbytes)226{227MSG_CREATE(RGPI, msgbytes);228AP::dal().handle_message(msg);229}230231void LR_MsgHandler_RGPJ::process_message(uint8_t *msgbytes)232{233MSG_CREATE(RGPJ, msgbytes);234AP::dal().handle_message(msg);235}236237void LR_MsgHandler_RMGH::process_message(uint8_t *msgbytes)238{239MSG_CREATE(RMGH, msgbytes);240AP::dal().handle_message(msg);241}242243void LR_MsgHandler_RMGI::process_message(uint8_t *msgbytes)244{245MSG_CREATE(RMGI, msgbytes);246AP::dal().handle_message(msg);247}248249void LR_MsgHandler_RBCH::process_message(uint8_t *msgbytes)250{251MSG_CREATE(RBCH, msgbytes);252AP::dal().handle_message(msg);253}254255void LR_MsgHandler_RBCI::process_message(uint8_t *msgbytes)256{257MSG_CREATE(RBCI, msgbytes);258AP::dal().handle_message(msg);259}260261void LR_MsgHandler_RVOH::process_message(uint8_t *msgbytes)262{263MSG_CREATE(RVOH, msgbytes);264AP::dal().handle_message(msg);265}266267void LR_MsgHandler_ROFH::process_message(uint8_t *msgbytes)268{269MSG_CREATE(ROFH, msgbytes);270AP::dal().handle_message(msg, ekf2, ekf3);271}272273void LR_MsgHandler_RWOH::process_message(uint8_t *msgbytes)274{275MSG_CREATE(RWOH, msgbytes);276AP::dal().handle_message(msg, ekf2, ekf3);277}278279void LR_MsgHandler_RBOH::process_message(uint8_t *msgbytes)280{281MSG_CREATE(RBOH, msgbytes);282AP::dal().handle_message(msg, ekf2, ekf3);283}284285void LR_MsgHandler_REPH::process_message(uint8_t *msgbytes)286{287MSG_CREATE(REPH, msgbytes);288AP::dal().handle_message(msg, ekf2, ekf3);289}290291void LR_MsgHandler_RSLL::process_message(uint8_t *msgbytes)292{293MSG_CREATE(RSLL, msgbytes);294AP::dal().handle_message(msg, ekf2, ekf3);295}296297void LR_MsgHandler_REVH::process_message(uint8_t *msgbytes)298{299MSG_CREATE(REVH, msgbytes);300AP::dal().handle_message(msg, ekf2, ekf3);301}302303#include <AP_AHRS/AP_AHRS.h>304#include "VehicleType.h"305306bool LR_MsgHandler_PARM::set_parameter(const char *name, const float value)307{308const char *ignore_parms[] = {309"LOG_FILE_BUFSIZE",310"LOG_DISARMED"311};312for (uint8_t i=0; i < ARRAY_SIZE(ignore_parms); i++) {313if (strncmp(name, ignore_parms[i], AP_MAX_NAME_SIZE) == 0) {314::printf("Ignoring set of %s to %f\n", name, value);315return true;316}317}318319return LogReader::set_parameter(name, value);320}321322void LR_MsgHandler_PARM::process_message(uint8_t *msg)323{324const uint8_t parameter_name_len = AP_MAX_NAME_SIZE + 1; // null-term325char parameter_name[parameter_name_len];326327require_field(msg, "Name", parameter_name, parameter_name_len);328329float value = require_field_float(msg, "Value");330set_parameter(parameter_name, value);331}332333334