Skip to content

Commit

Permalink
AP_GSOF: refactor GSOF to expect packets by ID
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com>
  • Loading branch information
Ryanf55 committed Dec 4, 2024
1 parent 6efeef9 commit f990cf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
22 changes: 8 additions & 14 deletions libraries/AP_GSOF/AP_GSOF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ do { \
#endif

int
AP_GSOF::parse(const uint8_t temp, const uint8_t n_expected)
AP_GSOF::parse(const uint8_t temp, MsgTypes& message_types)
{
// https://receiverhelp.trimble.com/oem-gnss/index.html#API_DataCollectorFormatPacketStructure.html
switch (msg.state) {
Expand Down Expand Up @@ -67,11 +67,10 @@ AP_GSOF::parse(const uint8_t temp, const uint8_t n_expected)
msg.checksum = temp;
msg.state = Msg_Parser::State::ENDTX;
if (msg.checksum == msg.checksumcalc) {
const auto n_processed = process_message();
if (n_processed != n_expected ) {
if (!process_message(message_types)) {
return UNEXPECTED_NUM_GSOF_PACKETS;
}
return n_processed;
return PARSED_AS_EXPECTED;
}
break;
case Msg_Parser::State::ENDTX:
Expand All @@ -83,8 +82,8 @@ AP_GSOF::parse(const uint8_t temp, const uint8_t n_expected)
return NO_GSOF_DATA;
}

int
AP_GSOF::process_message(void)
bool
AP_GSOF::process_message(const MsgTypes& expected_msgs)
{
if (msg.packettype == 0x40) { // GSOF
// https://receiverhelp.trimble.com/oem-gnss/index.html#GSOFmessages_TIME.html?TocPath=Output%2520Messages%257CGSOF%2520Messages%257C_____25
Expand All @@ -98,11 +97,11 @@ AP_GSOF::process_message(void)
#endif

// This counts up the number of received packets.
int valid = 0;
MsgTypes parsed_msgs;

// want 1 2 8 9 12
for (uint32_t a = 3; a < msg.length; a++) {
const uint8_t output_type = msg.data[a];
parsed_msgs.set(output_type);
a++;
const uint8_t output_length = msg.data[a];
a++;
Expand All @@ -111,23 +110,18 @@ AP_GSOF::process_message(void)
switch (output_type) {
case POS_TIME:
parse_pos_time(a);
valid++;
break;
case POS:
parse_pos(a);
valid++;
break;
case VEL:
parse_vel(a);
valid++;
break;
case DOP:
parse_dop(a);
valid++;
break;
case POS_SIGMA:
parse_pos_sigma(a);
valid++;
break;
default:
break;
Expand All @@ -136,7 +130,7 @@ AP_GSOF::process_message(void)
a += output_length - 1u;
}

return valid;
return parsed_msgs == expected_msgs;
}

// No GSOF packets.
Expand Down
17 changes: 12 additions & 5 deletions libraries/AP_GSOF/AP_GSOF.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "AP_GSOF_config.h"
#include <AP_Common/Bitmask.h>

#if AP_GSOF_ENABLED

Expand All @@ -12,13 +13,17 @@ class AP_GSOF

static constexpr int NO_GSOF_DATA = 0;
static constexpr int UNEXPECTED_NUM_GSOF_PACKETS = -1;
static constexpr int PARSED_AS_EXPECTED = 1;

// A type alias for which packets have been parsed.
using MsgTypes = Bitmask<70>;

// Parse a single byte into the buffer.
// When enough data has arrived, it returns the number of GSOF packets parsed in the GENOUT packet.
// When enough data has arrived, it populates a bitmask of which GSOF packets were parsed in the GENOUT packet.
// If an unexpected number of GSOF packets were parsed, returns UNEXPECTED_NUM_GSOF_PACKETS.
// This means there is no fix.
// If it returns NO_GSOF_DATA, the parser just needs more data.
int parse(const uint8_t temp, const uint8_t n_expected) WARN_IF_UNUSED;
// Upon parsing the expected message contents, it returns PARSED_AS_EXPECTED.
int parse(const uint8_t temp, MsgTypes& message_types) WARN_IF_UNUSED;

// GSOF packet numbers.
enum msg_idx_t {
Expand Down Expand Up @@ -91,8 +96,10 @@ class AP_GSOF

private:

// Parses current data and returns the number of parsed GSOF messages.
int process_message() WARN_IF_UNUSED;
// Parses current data.
// Returns true if, and only if, the expected packets were parsed.
// Unexpected/unparsed data will make this return false.
bool process_message(const MsgTypes& expected_msgs) WARN_IF_UNUSED;

void parse_pos_time(uint32_t a);
void parse_pos(uint32_t a);
Expand Down

0 comments on commit f990cf9

Please sign in to comment.