Adsb rx airline display fix (#1847)

* This doesn't do anything, just gives me some sanity :D

* Don’t abuse std

* Only look for airline info if the callsign is received

* Format…

* Let the airline update when callsign is received
This commit is contained in:
E.T 2024-02-05 19:06:29 +01:00 committed by GitHub
parent b8073bca0f
commit f2c008602d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 34 deletions

View File

@ -64,9 +64,9 @@ static std::string mmsi(
static std::string mid( static std::string mid(
const ais::MMSI& mmsi) { const ais::MMSI& mmsi) {
std::database db; database db;
std::string mid_code = ""; std::string mid_code = "";
std::database::MidDBRecord mid_record = {}; database::MidDBRecord mid_record = {};
int return_code = 0; int return_code = 0;
// Try getting the country name from mids.db using MID code for given MMSI // Try getting the country name from mids.db using MID code for given MMSI

View File

@ -127,8 +127,8 @@ ADSBRxAircraftDetailsView::ADSBRxAircraftDetailsView(
text_icao_address.set(entry.icao_str); text_icao_address.set(entry.icao_str);
// Try getting the aircraft information from icao24.db // Try getting the aircraft information from icao24.db
std::database db{}; database db{};
std::database::AircraftDBRecord aircraft_record; database::AircraftDBRecord aircraft_record;
auto return_code = db.retrieve_aircraft_record(&aircraft_record, entry.icao_str); auto return_code = db.retrieve_aircraft_record(&aircraft_record, entry.icao_str);
switch (return_code) { switch (return_code) {
case DATABASE_RECORD_FOUND: case DATABASE_RECORD_FOUND:
@ -233,24 +233,6 @@ ADSBRxDetailsView::ADSBRxDetailsView(
&button_aircraft_details, &button_aircraft_details,
&button_see_map}); &button_see_map});
// The following won't change for a given airborne aircraft.
// Try getting the airline's name from airlines.db.
// NB: Only works once callsign has been read and won't be updated.
std::database db;
std::database::AirlinesDBRecord airline_record;
std::string airline_code = entry_.callsign.substr(0, 3);
auto return_code = db.retrieve_airline_record(&airline_record, airline_code);
switch (return_code) {
case DATABASE_RECORD_FOUND:
text_airline.set(airline_record.airline);
text_country.set(airline_record.country);
break;
case DATABASE_NOT_FOUND:
text_airline.set("No airlines.db file");
break;
}
text_icao_address.set(entry_.icao_str); text_icao_address.set(entry_.icao_str);
button_aircraft_details.on_select = [this, &nav](Button&) { button_aircraft_details.on_select = [this, &nav](Button&) {
@ -330,6 +312,31 @@ void ADSBRxDetailsView::on_orientation(const OrientationDataMessage* msg) {
} }
void ADSBRxDetailsView::refresh_ui() { void ADSBRxDetailsView::refresh_ui() {
// The following won't change for a given airborne aircraft.
// Try getting the airline's name from airlines.db.
if (!airline_checked && !entry_.callsign.empty()) {
airline_checked = true;
database db;
database::AirlinesDBRecord airline_record;
std::string airline_code = entry_.callsign.substr(0, 3);
auto return_code = db.retrieve_airline_record(&airline_record, airline_code);
switch (return_code) {
case DATABASE_RECORD_FOUND:
text_airline.set(airline_record.airline);
text_country.set(airline_record.country);
break;
case DATABASE_RECORD_NOT_FOUND:
// text_airline.set("-"); // It's what it is constructed with
// text_country.set("-"); // It's what it is constructed with
break;
case DATABASE_NOT_FOUND:
text_airline.set("No airlines.db file");
break;
}
}
auto age = entry_.age; auto age = entry_.age;
if (age < 60) if (age < 60)
text_last_seen.set(to_string_dec_uint(age) + " seconds ago"); text_last_seen.set(to_string_dec_uint(age) + " seconds ago");

View File

@ -280,6 +280,7 @@ class ADSBRxDetailsView : public View {
// NB: Keeping a copy so that it doesn't end up dangling // NB: Keeping a copy so that it doesn't end up dangling
// if removed from the recent entries list. // if removed from the recent entries list.
AircraftRecentEntry entry_{AircraftRecentEntry::invalid_key}; AircraftRecentEntry entry_{AircraftRecentEntry::invalid_key};
bool airline_checked{false};
Labels labels{ Labels labels{
{{0 * 8, 1 * 16}, "ICAO:", Color::light_grey()}, {{0 * 8, 1 * 16}, "ICAO:", Color::light_grey()},

View File

@ -25,14 +25,12 @@
#include "file.hpp" #include "file.hpp"
#include <cstring> #include <cstring>
namespace std {
int database::retrieve_mid_record(MidDBRecord* record, std::string search_term) { int database::retrieve_mid_record(MidDBRecord* record, std::string search_term) {
file_path = "AIS/mids.db"; file_path = "AIS/mids.db";
index_item_length = 4; index_item_length = 4;
record_length = 32; record_length = 32;
result = std::database::retrieve_record(file_path, index_item_length, record_length, record, search_term); result = retrieve_record(file_path, index_item_length, record_length, record, search_term);
return (result); return (result);
} }
@ -42,7 +40,7 @@ int database::retrieve_airline_record(AirlinesDBRecord* record, std::string sear
index_item_length = 4; index_item_length = 4;
record_length = 64; record_length = 64;
result = std::database::retrieve_record(file_path, index_item_length, record_length, record, search_term); result = retrieve_record(file_path, index_item_length, record_length, record, search_term);
return (result); return (result);
} }
@ -52,7 +50,7 @@ int database::retrieve_aircraft_record(AircraftDBRecord* record, std::string sea
index_item_length = 7; index_item_length = 7;
record_length = 146; record_length = 146;
result = std::database::retrieve_record(file_path, index_item_length, record_length, record, search_term); result = retrieve_record(file_path, index_item_length, record_length, record, search_term);
return (result); return (result);
} }
@ -91,5 +89,3 @@ int database::retrieve_record(std::string file_path, int index_item_length, int
} else } else
return (DATABASE_NOT_FOUND); return (DATABASE_NOT_FOUND);
} }
} /* namespace std */

View File

@ -30,7 +30,6 @@
#include "file.hpp" #include "file.hpp"
namespace std {
class database { class database {
public: public:
#define DATABASE_RECORD_FOUND 0 // record found in database #define DATABASE_RECORD_FOUND 0 // record found in database
@ -62,9 +61,9 @@ class database {
int retrieve_aircraft_record(AircraftDBRecord* record, std::string search_term); int retrieve_aircraft_record(AircraftDBRecord* record, std::string search_term);
private: private:
string file_path = ""; // path inclusing filename std::string file_path = ""; // path inclusing filename
int index_item_length = 0; // length of index item int index_item_length = 0; // length of index item
int record_length = 0; // length of record int record_length = 0; // length of record
File db_file{}; File db_file{};
int number_of_records = 0; int number_of_records = 0;
@ -77,6 +76,5 @@ class database {
int retrieve_record(std::string file_path, int index_item_length, int record_length, void* record, std::string search_term); int retrieve_record(std::string file_path, int index_item_length, int record_length, void* record, std::string search_term);
}; };
} // namespace std
#endif /*__DATABASE_H__*/ #endif /*__DATABASE_H__*/