Skip to content

Commit

Permalink
Emit a metadata message as the first message on a raw connection.
Browse files Browse the repository at this point in the history
Add --raw-legacy-port option to restore the old behaviour.

The initial message uses the new metadata format and identifies the
source dump978 version & that it has the FEC fixes.

Software based on older versions of dump978 and dump978-fa's parsers
(e.g. uat2esnt) will harmlessly ignore the initial message.

The --raw-legacy-port option configures a raw listening port which
does _not_ emit the metadata message, in case there is other 3rd party
software which is confused by the new message format.
  • Loading branch information
mutability committed Feb 17, 2021
1 parent a850dae commit 640a4b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
25 changes: 23 additions & 2 deletions dump978_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static int realmain(int argc, char **argv) {
("sdr-device-settings", po::value<std::string>(), "set SDR device key-value settings")
("stratuxv3", po::value<std::string>(), "read messages from Stratux v3 UAT dongle on given serial port")
("raw-port", po::value<std::vector<listen_option>>(), "listen for connections on [host:]port and provide raw messages")
("raw-legacy-port", po::value<std::vector<listen_option>>(), "listen for connections on [host:]port and provide raw messages, with no initial metadata header")
("json-port", po::value<std::vector<listen_option>>(), "listen for connections on [host:]port and provide decoded json");
// clang-format on

Expand Down Expand Up @@ -184,9 +185,29 @@ static int realmain(int argc, char **argv) {
return ok;
};

auto raw_ok = create_output_port("raw-port", &RawOutput::Create);
// Emit initial metadata-only message advertising our version etc
SharedMessageVector header;
if (!opts.count("raw-disable-header")) {
header = std::make_shared<MessageVector>();

// clang-format off
RawMessage::MetadataMap metadata = {
{"program", "dump978-fa"},
{"version", VERSION},
{"fecfix", "1"} // we have a fixed version of the FEC library
};
// clang-format on
header->push_back(RawMessage(std::move(metadata)));
}

auto raw_factory = std::bind(&RawOutput::Create, std::placeholders::_1, std::placeholders::_2, header);
auto raw_ok = create_output_port("raw-port", raw_factory);

auto raw_legacy_factory = std::bind(&RawOutput::Create, std::placeholders::_1, std::placeholders::_2, SharedMessageVector());
auto raw_legacy_ok = create_output_port("raw-legacy-port", raw_legacy_factory);

auto json_ok = create_output_port("json-port", &JsonOutput::Create);
if (!raw_ok || !json_ok) {
if (!raw_ok || !raw_legacy_ok || !json_ok) {
return 1;
}

Expand Down
6 changes: 6 additions & 0 deletions socket_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ void SocketOutput::Close() {

//////////////

void RawOutput::Start() {
SocketOutput::Start();
if (header_)
Write(header_);
}

void RawOutput::InternalWrite(SharedMessageVector messages) {
for (const auto &message : *messages) {
Buf() << message << '\n';
Expand Down
8 changes: 6 additions & 2 deletions socket_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ namespace flightaware::uat {
class RawOutput : public SocketOutput {
public:
// factory method, this class must always be constructed via make_shared
static Pointer Create(boost::asio::io_service &service, boost::asio::ip::tcp::socket &&socket) { return Pointer(new RawOutput(service, std::move(socket))); }
static Pointer Create(boost::asio::io_service &service, boost::asio::ip::tcp::socket &&socket, SharedMessageVector header) { return Pointer(new RawOutput(service, std::move(socket), header)); }

void Start() override;

protected:
void InternalWrite(SharedMessageVector messages) override;

private:
RawOutput(boost::asio::io_service &service_, boost::asio::ip::tcp::socket &&socket_) : SocketOutput(service_, std::move(socket_)) {}
RawOutput(boost::asio::io_service &service_, boost::asio::ip::tcp::socket &&socket_, SharedMessageVector header) : SocketOutput(service_, std::move(socket_)) { header_ = header; }

SharedMessageVector header_;
};

class JsonOutput : public SocketOutput {
Expand Down

0 comments on commit 640a4b0

Please sign in to comment.