Skip to content

Commit

Permalink
Replay: add compatability code for old-format RRNH messages
Browse files Browse the repository at this point in the history
We've changed to passing in a float value in metres for maximum rangefinder distance to the EKFs.

The Replay messages must therefore change to passing in a float value.

Add compatability code to retain replayability of older logs.
  • Loading branch information
peterbarker committed Oct 10, 2024
1 parent 41222cd commit 89bf455
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Tools/Replay/LR_MsgHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,49 @@ void LR_MsgHandler_RBRI::process_message(uint8_t *msgbytes)
AP::dal().handle_message(msg);
}

// RRNH - Replay RaNgefinder Header constructor
LR_MsgHandler_RRNH::LR_MsgHandler_RRNH(struct log_Format &_f) :
LR_MsgHandler(_f)
{
// the checksum here is the checksum of the old "struct log_Format
// RRNH" before the type was changed from int16_t to float. It
// corresponds to log_RRNH_with_int16_max_distance, below.
if (strncmp(_f.format, "hhB", ARRAY_SIZE(_f.format)) == 0 &&
strncmp(_f.labels, "GCl,MaxD,NumSensors", ARRAY_SIZE(_f.labels)) == 0) {
distances_int16_to_float_transform_required = true;
}
}

void LR_MsgHandler_RRNH::process_message_int16_to_float_transformed(uint8_t *msgbytes)
{
// this structure was copied out of AP_DAL.cpp before being
// modified there. _end has been trimmed out

struct log_RRNH_with_int16_t_distance {
// this is rotation-pitch-270!
int16_t ground_clearance_cm;
int16_t max_distance_cm;
uint8_t num_sensors;
};

// note that if fields are added to RRNH message then this
// will be incorrect!
const log_RRNH_with_int16_t_distance &tmp = *((log_RRNH_with_int16_t_distance*)&msgbytes[3]);
const log_RRNH msg {
ground_clearance : tmp.ground_clearance_cm * 0.01,
max_distance : tmp.max_distance_cm * 0.01,
num_sensors : tmp.num_sensors,
};
AP::dal().handle_message(msg);
}

void LR_MsgHandler_RRNH::process_message(uint8_t *msgbytes)
{
if (distances_int16_to_float_transform_required) {
process_message_int16_to_float_transformed(msgbytes);
return;
}

MSG_CREATE(RRNH, msgbytes);
AP::dal().handle_message(msg);
}
Expand Down
8 changes: 7 additions & 1 deletion Tools/Replay/LR_MsgHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,17 @@ class LR_MsgHandler_RBRI : public LR_MsgHandler
void process_message(uint8_t *msg) override;
};

// RRNH - Replay RaNgefinder Header
class LR_MsgHandler_RRNH : public LR_MsgHandler
{
public:
using LR_MsgHandler::LR_MsgHandler;
LR_MsgHandler_RRNH(struct log_Format &_f);
void process_message(uint8_t *msg) override;
private:
// code to cope with transformation from older log format (16-bit
// distances) to new format (32-bit distances):
bool distances_int16_to_float_transform_required;
void process_message_int16_to_float_transformed(uint8_t *msgbytes);
};
class LR_MsgHandler_RRNI : public LR_MsgHandler
{
Expand Down

0 comments on commit 89bf455

Please sign in to comment.