diff --git a/firmware/application/apps/ais_app.cpp b/firmware/application/apps/ais_app.cpp index 74f4183b1..5f3fa9a12 100644 --- a/firmware/application/apps/ais_app.cpp +++ b/firmware/application/apps/ais_app.cpp @@ -64,9 +64,9 @@ static std::string mmsi( static std::string mid( const ais::MMSI& mmsi) { - std::database db; + database db; std::string mid_code = ""; - std::database::MidDBRecord mid_record = {}; + database::MidDBRecord mid_record = {}; int return_code = 0; // Try getting the country name from mids.db using MID code for given MMSI diff --git a/firmware/application/apps/ui_adsb_rx.cpp b/firmware/application/apps/ui_adsb_rx.cpp index a91b8ab0c..c8888e58b 100644 --- a/firmware/application/apps/ui_adsb_rx.cpp +++ b/firmware/application/apps/ui_adsb_rx.cpp @@ -127,8 +127,8 @@ ADSBRxAircraftDetailsView::ADSBRxAircraftDetailsView( text_icao_address.set(entry.icao_str); // Try getting the aircraft information from icao24.db - std::database db{}; - std::database::AircraftDBRecord aircraft_record; + database db{}; + database::AircraftDBRecord aircraft_record; auto return_code = db.retrieve_aircraft_record(&aircraft_record, entry.icao_str); switch (return_code) { case DATABASE_RECORD_FOUND: @@ -233,24 +233,6 @@ ADSBRxDetailsView::ADSBRxDetailsView( &button_aircraft_details, &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); button_aircraft_details.on_select = [this, &nav](Button&) { @@ -330,6 +312,31 @@ void ADSBRxDetailsView::on_orientation(const OrientationDataMessage* msg) { } 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; if (age < 60) text_last_seen.set(to_string_dec_uint(age) + " seconds ago"); diff --git a/firmware/application/apps/ui_adsb_rx.hpp b/firmware/application/apps/ui_adsb_rx.hpp index 3285f01f6..4407d055a 100644 --- a/firmware/application/apps/ui_adsb_rx.hpp +++ b/firmware/application/apps/ui_adsb_rx.hpp @@ -280,6 +280,7 @@ class ADSBRxDetailsView : public View { // NB: Keeping a copy so that it doesn't end up dangling // if removed from the recent entries list. AircraftRecentEntry entry_{AircraftRecentEntry::invalid_key}; + bool airline_checked{false}; Labels labels{ {{0 * 8, 1 * 16}, "ICAO:", Color::light_grey()}, diff --git a/firmware/application/database.cpp b/firmware/application/database.cpp index 55f784e5f..5c192e90c 100644 --- a/firmware/application/database.cpp +++ b/firmware/application/database.cpp @@ -25,14 +25,12 @@ #include "file.hpp" #include -namespace std { - int database::retrieve_mid_record(MidDBRecord* record, std::string search_term) { file_path = "AIS/mids.db"; index_item_length = 4; 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); } @@ -42,7 +40,7 @@ int database::retrieve_airline_record(AirlinesDBRecord* record, std::string sear index_item_length = 4; 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); } @@ -52,7 +50,7 @@ int database::retrieve_aircraft_record(AircraftDBRecord* record, std::string sea index_item_length = 7; 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); } @@ -91,5 +89,3 @@ int database::retrieve_record(std::string file_path, int index_item_length, int } else return (DATABASE_NOT_FOUND); } - -} /* namespace std */ diff --git a/firmware/application/database.hpp b/firmware/application/database.hpp index a7d3f29d9..336c7aa90 100644 --- a/firmware/application/database.hpp +++ b/firmware/application/database.hpp @@ -30,7 +30,6 @@ #include "file.hpp" -namespace std { class database { public: #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); private: - string file_path = ""; // path inclusing filename - int index_item_length = 0; // length of index item - int record_length = 0; // length of record + std::string file_path = ""; // path inclusing filename + int index_item_length = 0; // length of index item + int record_length = 0; // length of record File db_file{}; 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); }; -} // namespace std #endif /*__DATABASE_H__*/