diff --git a/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs b/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs index 5025bfdf..432feb26 100644 --- a/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs +++ b/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs @@ -65,12 +65,19 @@ namespace bsmd.AIS2Service _repeatIndicator = GetUInt(bits, 6, 7); _mmsi = GetInt(bits, 8, 37); year = GetUInt(bits, 38, 51); - month = GetUInt(bits, 52, 55); - day = GetUInt(bits, 56, 60); - hour = GetUInt(bits, 61, 65); - minute = GetUInt(bits, 66, 71); - second = GetUInt(bits, 72, 77); - _utcTimestamp = new DateTime((int) year, (int) month, (int) day, (int) hour, (int) minute, (int) second, DateTimeKind.Utc); + if (year != 0) // year = 0 -> N/A + { + if (year > DateTime.UtcNow.Year || year < DateTime.UtcNow.Year) // liar + { + return Status.PARSE_ERROR; + } + month = GetUInt(bits, 52, 55); + day = GetUInt(bits, 56, 60); + hour = GetUInt(bits, 61, 65); + minute = GetUInt(bits, 66, 71); + second = GetUInt(bits, 72, 77); + _utcTimestamp = new DateTime((int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second, DateTimeKind.Utc); + } _accuracy = GetInt(bits, 78, 78) == 1; _longitude = GetInt(bits, 79, 106); _latitude = GetInt(bits, 107, 133); diff --git a/AIS/bsmd.AIS2Service/Program.cs b/AIS/bsmd.AIS2Service/Program.cs index 581fea4a..a6b67bd8 100644 --- a/AIS/bsmd.AIS2Service/Program.cs +++ b/AIS/bsmd.AIS2Service/Program.cs @@ -17,7 +17,7 @@ namespace bsmd.AIS2Service { AISManager.Start(); // TODO wait some - Thread.Sleep(180000); + Thread.Sleep(720000); // Test finish.. AISManager.Stop(); } diff --git a/AIS/bsmd.AIS2Service/index.html b/AIS/bsmd.AIS2Service/index.html index 75abb240..839cef00 100644 --- a/AIS/bsmd.AIS2Service/index.html +++ b/AIS/bsmd.AIS2Service/index.html @@ -4,7 +4,7 @@ - JSON Test + AIS List @@ -17,6 +17,7 @@ Latitude Longitude IMO + Class B diff --git a/AIS/bsmd.AIS2Service/update.js b/AIS/bsmd.AIS2Service/update.js index dadb0d79..a221b707 100644 --- a/AIS/bsmd.AIS2Service/update.js +++ b/AIS/bsmd.AIS2Service/update.js @@ -10,26 +10,34 @@ console.log('error: ' + err); }); function updateData(data) { - - const table = document.getElementById("aisTable"); - let numItems = 1; - - numItems++; - const row = document.createElement('tr'); - row.innerHTML = ` - - - - -`; - // You could also do the same for the cells and inputs - table.appendChild(row); - - + var table = document.getElementById('aisTable'); for (var i = 0; i < data.length; i++) { - var div = document.createElement("div"); - div.innerHTML = 'Name: ' + data[i].Name; - mainContainer.appendChild(div); + let row_id = "row_" + data[i].MMSI; + row = document.getElementById(row_id); + + if(row == null) { // not found, create new row + row = document.createElement('tr'); + row.innerHTML = `` + data[i].MMSI + + `` + + `` + + `` + + `` + + `` + + `` + data[i].IsClassB + ``; + table.appendChild(row); + } + + // update existing row + var td = document.getElementById("name_" + data[i].MMSI); + td.innerHTML = data[i].Name; + td = document.getElementById("timestamp_" + data[i].MMSI); + td.innerHTML = data[i].LastUpdate; + td = document.getElementById("lat_" + data[i].MMSI); + td.innerHTML = data[i].Latitude; + td = document.getElementById("lon_" + data[i].MMSI); + td.innerHTML = data[i].Longitude; + td = document.getElementById("imo_" + data[i].MMSI); + td.innerHTML = data[i].IMO; } } }