Added country to AIS app, so you know from which country a vessel is.

It's using the MID database, which is also part of the PR.
mids.db should be placed in /AIS folder on SD card.
This commit is contained in:
Arjan Onwezen
2022-03-26 07:05:13 -04:00
parent 68d40ebce8
commit be0427889f
9 changed files with 403 additions and 2 deletions

View File

@@ -22,6 +22,7 @@
#include "ais_app.hpp"
#include "string_format.hpp"
#include "database.hpp"
#include "baseband_api.hpp"
@@ -62,6 +63,25 @@ static std::string mmsi(
return to_string_dec_uint(mmsi, 9, '0'); // MMSI is always is always 9 characters pre-padded with zeros
}
static std::string mid(
const ais::MMSI& mmsi
) {
std::database db;
std::string mid_code = "";
std::database::MidDBRecord mid_record = {};
int return_code = 0;
// Try getting the country name from mids.db using MID code for given MMSI
mid_code = to_string_dec_uint(mmsi, 9, ' ').substr(0, 3);
return_code = db.retrieve_mid_record(&mid_record, mid_code);
switch(return_code) {
case DATABASE_RECORD_FOUND: return mid_record.country;
case DATABASE_NOT_FOUND: return "No mids.db file";
default: return "";
}
}
static std::string navigational_status(const unsigned int value) {
switch(value) {
case 0: return "under way w/engine";
@@ -271,6 +291,7 @@ void AISRecentEntryDetailView::paint(Painter& painter) {
auto field_rect = Rect { rect.left(), rect.top() + 16, rect.width(), 16 };
field_rect = draw_field(painter, field_rect, s, "MMSI", ais::format::mmsi(entry_.mmsi));
field_rect = draw_field(painter, field_rect, s, "Ctry", ais::format::mid(entry_.mmsi));
field_rect = draw_field(painter, field_rect, s, "Name", entry_.name);
field_rect = draw_field(painter, field_rect, s, "Call", entry_.call_sign);
field_rect = draw_field(painter, field_rect, s, "Dest", entry_.destination);

View File

@@ -131,11 +131,11 @@ private:
AISRecentEntry entry_ { };
Button button_done {
{ 125, 216, 96, 24 },
{ 125, 224, 96, 24 },
"Done"
};
Button button_see_map {
{ 19, 216, 96, 24 },
{ 19, 224, 96, 24 },
"See on map"
};
GeoMapView* geomap_view { nullptr };
@@ -169,6 +169,7 @@ private:
static constexpr uint32_t initial_target_frequency = 162025000;
static constexpr uint32_t sampling_rate = 2457600;
static constexpr uint32_t baseband_bandwidth = 1750000;
NavigationView& nav_;
AISRecentEntries recent { };