2020-11-05 19:25:17 -04:00
|
|
|
#include "LogReader.h"
|
2013-12-29 07:56:54 -04:00
|
|
|
|
2020-11-05 19:25:17 -04:00
|
|
|
#include "MsgHandler.h"
|
2020-11-07 05:42:21 -04:00
|
|
|
#include "Replay.h"
|
2020-03-09 00:28:23 -03:00
|
|
|
|
2013-12-29 07:56:54 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2020-11-07 17:21:12 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2013-12-29 07:56:54 -04:00
|
|
|
|
2018-04-22 07:19:11 -03:00
|
|
|
#define DEBUG 1
|
2015-07-01 08:11:46 -03:00
|
|
|
#if DEBUG
|
|
|
|
# define debug(fmt, args...) printf(fmt "\n", ##args)
|
|
|
|
#else
|
|
|
|
# define debug(fmt, args...)
|
|
|
|
#endif
|
|
|
|
|
2015-04-22 20:24:45 -03:00
|
|
|
#define streq(x, y) (!strcmp(x, y))
|
|
|
|
|
2020-11-07 17:21:12 -04:00
|
|
|
extern struct user_parameter *user_parameters;
|
|
|
|
|
2020-11-05 19:25:17 -04:00
|
|
|
LogReader::LogReader(struct LogStructure *log_structure, NavEKF2 &_ekf2, NavEKF3 &_ekf3) :
|
2019-01-18 00:23:42 -04:00
|
|
|
AP_LoggerFileReader(),
|
2018-04-22 07:19:11 -03:00
|
|
|
_log_structure(log_structure),
|
2020-11-05 19:25:17 -04:00
|
|
|
ekf2(_ekf2),
|
|
|
|
ekf3(_ekf3)
|
2015-07-02 20:32:05 -03:00
|
|
|
{
|
2015-04-22 20:24:45 -03:00
|
|
|
}
|
2020-11-05 19:25:17 -04:00
|
|
|
|
2015-05-19 07:22:36 -03:00
|
|
|
/*
|
|
|
|
see if a type is in a list of types
|
|
|
|
*/
|
|
|
|
bool LogReader::in_list(const char *type, const char *list[])
|
|
|
|
{
|
2015-07-07 02:13:51 -03:00
|
|
|
if (list == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 07:22:36 -03:00
|
|
|
for (uint8_t i=0; list[i] != NULL; i++) {
|
|
|
|
if (strcmp(type, list[i]) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-08 22:06:04 -04:00
|
|
|
bool LogReader::handle_log_format_msg(const struct log_Format &f)
|
2015-07-04 02:14:14 -03:00
|
|
|
{
|
2020-11-05 19:25:17 -04:00
|
|
|
// emit the output as we receive it:
|
|
|
|
AP::logger().WriteBlock((void*)&f, sizeof(f));
|
|
|
|
|
2015-04-27 00:25:16 -03:00
|
|
|
char name[5];
|
|
|
|
memset(name, '\0', 5);
|
|
|
|
memcpy(name, f.name, 4);
|
2018-04-22 07:19:11 -03:00
|
|
|
|
|
|
|
if (msgparser[f.type] != NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-08 22:06:04 -04:00
|
|
|
// map from format name to a parser subclass:
|
2015-04-27 00:25:16 -03:00
|
|
|
if (streq(name, "PARM")) {
|
2020-11-08 22:06:04 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_PARM(formats[f.type]);
|
|
|
|
} else if (streq(name, "RFRH")) {
|
2020-11-05 19:25:17 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_RFRH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RFRF")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RFRF(formats[f.type], ekf2, ekf3);
|
|
|
|
} else if (streq(name, "RFRN")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RFRN(formats[f.type]);
|
|
|
|
} else if (streq(name, "REV2")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_REV2(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "RSO2")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_RSO2(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "RWA2")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_RWA2(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "REV3")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_REV3(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "RSO3")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_RSO3(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "RWA3")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_RWA3(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "REY3")) {
|
2020-11-15 23:34:44 -04:00
|
|
|
msgparser[f.type] = new LR_MsgHandler_REY3(formats[f.type], ekf2, ekf3);
|
2020-11-05 19:25:17 -04:00
|
|
|
} else if (streq(name, "RISH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RISH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RISI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RISI(formats[f.type]);
|
|
|
|
} else if (streq(name, "RASH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RASH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RASI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RASI(formats[f.type]);
|
|
|
|
} else if (streq(name, "RBRH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RBRH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RBRI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RBRI(formats[f.type]);
|
|
|
|
} else if (streq(name, "RRNH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RRNH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RRNI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RRNI(formats[f.type]);
|
|
|
|
} else if (streq(name, "RGPH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RGPH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RGPI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RGPI(formats[f.type]);
|
|
|
|
} else if (streq(name, "RGPJ")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RGPJ(formats[f.type]);
|
|
|
|
} else if (streq(name, "RMGH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RMGH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RMGI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RMGI(formats[f.type]);
|
|
|
|
} else if (streq(name, "RBCH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RBCH(formats[f.type]);
|
|
|
|
} else if (streq(name, "RBCI")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RBCI(formats[f.type]);
|
2020-11-06 18:29:30 -04:00
|
|
|
} else if (streq(name, "RVOH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RVOH(formats[f.type]);
|
|
|
|
} else if (streq(name, "ROFH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_ROFH(formats[f.type], ekf2, ekf3);
|
2020-11-06 19:57:07 -04:00
|
|
|
} else if (streq(name, "REPH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_REPH(formats[f.type], ekf2, ekf3);
|
2023-05-13 20:55:43 -03:00
|
|
|
} else if (streq(name, "RSLL")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RSLL(formats[f.type], ekf2, ekf3);
|
2020-11-06 19:57:07 -04:00
|
|
|
} else if (streq(name, "REVH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_REVH(formats[f.type], ekf2, ekf3);
|
2020-11-06 20:33:40 -04:00
|
|
|
} else if (streq(name, "RWOH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RWOH(formats[f.type], ekf2, ekf3);
|
2020-11-07 01:57:11 -04:00
|
|
|
} else if (streq(name, "RBOH")) {
|
|
|
|
msgparser[f.type] = new LR_MsgHandler_RBOH(formats[f.type], ekf2, ekf3);
|
2015-04-27 00:25:16 -03:00
|
|
|
} else {
|
2020-11-05 19:25:17 -04:00
|
|
|
// debug(" No parser for (%s)\n", name);
|
|
|
|
}
|
2015-04-22 20:24:45 -03:00
|
|
|
|
2020-11-05 19:25:17 -04:00
|
|
|
return true;
|
2015-06-12 09:52:52 -03:00
|
|
|
}
|
2013-12-29 07:56:54 -04:00
|
|
|
|
2020-11-05 19:25:17 -04:00
|
|
|
bool LogReader::handle_msg(const struct log_Format &f, uint8_t *msg) {
|
|
|
|
// emit the output as we receive it:
|
|
|
|
AP::logger().WriteBlock(msg, f.length);
|
2015-01-21 01:26:38 -04:00
|
|
|
|
2015-06-12 09:52:52 -03:00
|
|
|
LR_MsgHandler *p = msgparser[f.type];
|
2015-04-27 00:25:16 -03:00
|
|
|
if (p == NULL) {
|
2020-11-05 19:25:17 -04:00
|
|
|
return true;
|
2015-01-21 01:26:38 -04:00
|
|
|
}
|
|
|
|
|
2020-11-05 19:25:17 -04:00
|
|
|
p->process_message(msg);
|
2013-12-29 07:56:54 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-22 20:24:45 -03:00
|
|
|
|
2020-11-07 05:42:21 -04:00
|
|
|
/*
|
|
|
|
see if a user parameter is set
|
|
|
|
*/
|
|
|
|
bool LogReader::check_user_param(const char *name)
|
2015-04-27 00:25:16 -03:00
|
|
|
{
|
2020-11-07 05:42:21 -04:00
|
|
|
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;
|
|
|
|
}
|
2015-10-26 03:37:16 -03:00
|
|
|
enum ap_var_type var_type;
|
|
|
|
AP_Param *vp = AP_Param::find(name, &var_type);
|
|
|
|
if (vp == NULL) {
|
2020-11-05 19:25:17 -04:00
|
|
|
// a lot of parameters will not be found - e.g. FORMAT_VERSION
|
|
|
|
// and all of the vehicle-specific parameters, ....
|
2015-10-26 03:37:16 -03:00
|
|
|
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 {
|
2020-11-05 19:25:17 -04:00
|
|
|
AP_HAL::panic("What manner of evil is var_type=%u", var_type);
|
2015-04-27 00:25:16 -03:00
|
|
|
}
|
2015-10-26 03:37:16 -03:00
|
|
|
if (fabsf(old_value - value) > 1.0e-12) {
|
2020-11-08 22:06:04 -04:00
|
|
|
::printf("Changed %s to %.8f from %.8f\n", name, value, old_value);
|
2015-10-26 03:37:16 -03:00
|
|
|
}
|
|
|
|
return true;
|
2015-04-27 00:25:16 -03:00
|
|
|
}
|
2020-11-08 22:06:04 -04:00
|
|
|
|