Skip to content

Commit 29e8a7d

Browse files
committed
realtime shows shipname instead of mmsi
1 parent b32fe55 commit 29e8a7d

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Source/Application/WebViewer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ void SSEStreamer::Receive(const JSON::JSON *data, int len, TAG &tag)
6868
}
6969
nmea_array += "]";
7070

71+
std::string shipname_str;
72+
std::string shipname_escaped(tag.shipname);
73+
JSON::StringBuilder::stringify(shipname_escaped, shipname_str);
74+
7175
std::string json = "{\"mmsi\":" + std::to_string(m->mmsi()) +
7276
",\"timestamp\":" + std::to_string(now) +
7377
",\"channel\":\"" + m->getChannel() +
7478
"\",\"type\":" + std::to_string(m->type()) +
79+
",\"shipname\":" + shipname_str +
7580
",\"nmea\":" + nmea_array + "}";
7681
server->sendSSE(1, "nmea", json);
7782
}

Source/HTML/script.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6949,7 +6949,16 @@ class RealtimeViewer {
69496949

69506950
const mmsi = data.mmsi;
69516951
const mmsiSpan = document.createElement('span');
6952-
mmsiSpan.textContent = data.mmsi;
6952+
6953+
// Show shipname if available and not empty, otherwise show MMSI
6954+
const hasShipname = data.shipname && data.shipname.trim() !== '';
6955+
if (hasShipname) {
6956+
mmsiSpan.textContent = data.shipname;
6957+
mmsiSpan.title = 'MMSI: ' + data.mmsi;
6958+
} else {
6959+
mmsiSpan.textContent = data.mmsi;
6960+
}
6961+
69536962
mmsiSpan.style.border = '1px solid #d0d0d0';
69546963
mmsiSpan.style.padding = '2px 6px';
69556964
mmsiSpan.style.borderRadius = '3px';

Source/Library/Common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ struct TAG
205205
float level = 0;
206206
float ppm = 0;
207207
uint64_t group = GROUP_OUT_UNDEFINED;
208+
char shipname[21] = {0};
208209

209210
// some data flowing from DB downstream
210211
int version = VERSION_NUMBER;
@@ -247,6 +248,7 @@ struct TAG
247248
shipclass = CLASS_UNKNOWN;
248249
ipv4 = 0;
249250
error = MESSAGE_ERROR_NONE;
251+
shipname[0] = 0;
250252
}
251253
};
252254

Source/Tracking/DB.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ void DB::Receive(const JSON::JSON *data, int len, TAG &tag)
10431043

10441044
tag.shipclass = ship.shipclass;
10451045
tag.speed = ship.speed;
1046+
std::strcpy(tag.shipname, ship.shipname, sizeof(tag.shipname));
10461047

10471048
if (position_updated && isValidCoord(lat_old, lon_old))
10481049
{

0 commit comments

Comments
 (0)