Skip to content

Commit

Permalink
faup978: use & report new metadata when available. Bump TSV version
Browse files Browse the repository at this point in the history
to 8U (no metadata or FEC fix not present) / 8UF (FEC fix present)
  • Loading branch information
mutability committed Feb 17, 2021
1 parent 640a4b0 commit cc34df4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
26 changes: 25 additions & 1 deletion faup978_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ void Reporter::Stop() {
purge_timer_.cancel();
}

void Reporter::HandleMessages(flightaware::uat::SharedMessageVector messages) {
// Process metadata messages, note fecfix and report versions
for (const auto &i : *messages) {
if (i.Type() != MessageType::METADATA)
continue;

auto &metadata = i.Metadata();
if (metadata.count("fecfix"))
fecfix_ = true;

if (metadata.count("program") || metadata.count("version")) {
const std::uint64_t now = now_millis();
std::cout << "_v" << '\t' << TSVVersion() << '\t' << "clock" << '\t' << (now / 1000);
if (metadata.count("program"))
std::cout << '\t' << "uat_program" << '\t' << metadata.at("program");
if (metadata.count("version"))
std::cout << '\t' << "uat_program_version" << '\t' << metadata.at("version");
std::cout << std::endl;
}
}

tracker_->HandleMessages(messages);
}

void Reporter::PurgeOld() {
tracker_->PurgeOld();

Expand Down Expand Up @@ -288,7 +312,7 @@ void Reporter::ReportOneAircraft(const Tracker::AddressKey &key, const AircraftS
}

// generate the line
std::cout << "_v" << '\t' << TSV_VERSION << '\t' << "clock" << '\t' << (now / 1000) << '\t';
std::cout << "_v" << '\t' << TSVVersion() << '\t' << "clock" << '\t' << (now / 1000) << '\t';

bool icao = (aircraft.address_qualifier == AddressQualifier::ADSB_ICAO || aircraft.address_qualifier == AddressQualifier::TISB_ICAO);
std::cout << (icao ? "hexid" : "otherid") << '\t' << std::hex << std::uppercase << std::setfill('0') << std::setw(6) << aircraft.address << std::dec << std::nouppercase << std::setfill(' ');
Expand Down
8 changes: 6 additions & 2 deletions faup978_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ namespace flightaware::faup978 {
public:
typedef std::shared_ptr<Reporter> Pointer;

static constexpr const char *TSV_VERSION = "6U";
static constexpr const char *TSV_VERSION_8U = "8U";
static constexpr const char *TSV_VERSION_8U_FIX = "8UF";

static Pointer Create(boost::asio::io_service &service, std::chrono::milliseconds interval = std::chrono::milliseconds(500), std::chrono::milliseconds timeout = std::chrono::seconds(300)) { return Pointer(new Reporter(service, interval, timeout)); }

void Start();
void Stop();

void HandleMessages(flightaware::uat::SharedMessageVector messages) { tracker_->HandleMessages(messages); }
void HandleMessages(flightaware::uat::SharedMessageVector messages);

private:
Reporter(boost::asio::io_service &service, std::chrono::milliseconds interval, std::chrono::milliseconds timeout) : service_(service), strand_(service), report_timer_(service), purge_timer_(service), interval_(interval), timeout_(timeout) { tracker_ = flightaware::uat::Tracker::Create(service, timeout); }
Expand All @@ -44,6 +45,8 @@ namespace flightaware::faup978 {
void PurgeOld();
void ReportOneAircraft(const flightaware::uat::Tracker::AddressKey &key, const flightaware::uat::AircraftState &aircraft, std::uint64_t now);

const char *TSVVersion() const { return fecfix_ ? TSV_VERSION_8U_FIX : TSV_VERSION_8U; }

boost::asio::io_service &service_;
boost::asio::io_service::strand strand_;
boost::asio::steady_timer report_timer_;
Expand All @@ -52,6 +55,7 @@ namespace flightaware::faup978 {
std::chrono::milliseconds timeout_;
flightaware::uat::Tracker::Pointer tracker_;
std::map<flightaware::uat::Tracker::AddressKey, ReportState> reported_;
bool fecfix_ = false;
};
} // namespace flightaware::faup978

Expand Down
10 changes: 7 additions & 3 deletions track.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,19 @@ void Tracker::HandleMessages(SharedMessageVector messages) {
const std::uint64_t FUTURE_FUZZ = 1000;

for (const auto &message : *messages) {
// Handle only downlink messages
if (message.Type() != MessageType::DOWNLINK_SHORT && message.Type() != MessageType::DOWNLINK_LONG) {
continue;
}

// validate message time vs system clock so we are only processing
// contemporaneous messages
if (message.ReceivedAt() == 0 || message.ReceivedAt() < (now - PAST_FUZZ) || message.ReceivedAt() > (now + FUTURE_FUZZ)) {
std::cerr << "DISCARD " << message.ReceivedAt() << std::endl;
continue;
}
if (message.Type() == MessageType::DOWNLINK_SHORT || message.Type() == MessageType::DOWNLINK_LONG) {
HandleMessage(AdsbMessage(message));
}

HandleMessage(AdsbMessage(message));
}
});
}
Expand Down

0 comments on commit cc34df4

Please sign in to comment.