added dict for base station reports

This commit is contained in:
Daniel Schick 2022-10-18 07:36:47 +02:00
parent e213afbab9
commit aceda066ce
7 changed files with 128 additions and 35 deletions

View File

@ -0,0 +1,66 @@
using System;
namespace bsmd.AIS2Service
{
/// <summary>
/// Simple container for BaseStation Reports (Type 4). This class just exists to decouple from
/// the actual AIS messages.
/// </summary>
internal class AIS_BaseStation
{
#region Fields
private readonly int _mmsi;
#endregion
#region Construction
public AIS_BaseStation(int mmsi)
{
_mmsi = mmsi;
}
#endregion
#region Properties
public int MMSI { get { return _mmsi; } }
public DateTime? LastTimeReference { get; private set; }
public bool? Accuracy { get; private set; }
public double? Latitude { get; private set; }
public double? Longitude { get; private set; }
public string EPFD { get; private set; }
public bool? RAIM { get; private set; }
public uint Radio { get; private set; }
#endregion
#region internal methods
internal void Update(AIS_BaseStationReport rep)
{
this.LastTimeReference = rep.UTCTimestamp;
this.Accuracy = rep.Accuracy;
this.Latitude = rep.Latitude;
this.Longitude = rep.Longitude;
if (Lookup.DeviceTypes.ContainsKey((int)rep.EPFD))
this.EPFD = Lookup.DeviceTypes[(int)rep.EPFD];
else
this.EPFD = "";
this.RAIM = rep.Raim;
this.Radio = rep.Radio;
}
#endregion
}
}

View File

@ -1,33 +1,16 @@
using log4net;
// Copyright (c) 2022 - schick Informatik
// bsmd.AIS2Service [AIS_BaseStationReport.cs]: Daniel Schick
// Description: Implementation of an AIS Base Station report incl. decoding
//
using log4net;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
namespace bsmd.AIS2Service
{
internal class AIS_BaseStationReport : AISClass
{
#region enums
public enum EPFDType
{
UNDEFINED,
GPS,
GLONASS,
COMBINED_GPS_GLONASS,
LORAN_C,
CHAYKA,
INTEGR_NAV_SYSTEM,
SURVEYED,
GALILEO
}
#endregion
{
#region fields
@ -36,7 +19,7 @@ namespace bsmd.AIS2Service
private bool _accuracy;
private int _latitude;
private int _longitude;
private EPFDType _epfdType;
private int _epfdType;
bool _raim;
private uint _radio;
@ -56,7 +39,7 @@ namespace bsmd.AIS2Service
public int Longitude { get { return _longitude; } }
public EPFDType EPFD { get { return _epfdType; } }
public int EPFD { get { return _epfdType; } }
public bool Raim { get { return _raim; } }
@ -90,9 +73,8 @@ namespace bsmd.AIS2Service
_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);
int epfd = GetInt(bits, 134, 137);
_epfdType = (EPFDType) epfd;
_latitude = GetInt(bits, 107, 133);
_epfdType = GetInt(bits, 134, 137);
_raim = GetInt(bits, 148, 148) == 1;
_radio = GetUInt(bits, 149, 167);
}

View File

@ -1,4 +1,8 @@

// Copyright (c) 2022 - schick Informatik
// bsmd.AIS2Service [Lookup.cs]: Daniel Schick
// Description: static lookups
//
using System.Collections.Generic;
namespace bsmd.AIS2Service

View File

@ -17,7 +17,7 @@ namespace bsmd.AIS2Service
{
AISManager.Start();
// TODO wait some
Thread.Sleep(720000);
Thread.Sleep(180000);
// Test finish..
AISManager.Stop();
}

View File

@ -1,9 +1,11 @@
using System;
// Copyright (c) 2022 - schick Informatik
// bsmd.AIS2Service [SitRep.cs]: Daniel Schick
// Description: Current, memory-mapped situation of what the receiver "sees"
//
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using log4net;
@ -25,6 +27,7 @@ namespace bsmd.AIS2Service
private static readonly ILog _log = LogManager.GetLogger(typeof(SitRep));
private readonly ConcurrentQueue<AISClass> _inputQueue;
private readonly ConcurrentDictionary<int, AIS_Target> _sitRep;
private readonly Dictionary<int, AIS_BaseStation> _baseStations = new Dictionary<int, AIS_BaseStation>();
private readonly ConcurrentQueue<AIS_Target> _dbQueue;
#endregion
@ -38,6 +41,15 @@ namespace bsmd.AIS2Service
#endregion
#region Properties
public Dictionary<int, AIS_BaseStation> BaseStations
{
get { return _baseStations; }
}
#endregion
#region mainloop thread
private void ReadMessages()
@ -115,6 +127,17 @@ namespace bsmd.AIS2Service
_dbQueue.Enqueue(_sitRep[bPosExt.MMSI]);
}
break;
case AISClass.AISType.BASE_STATION_REPORT:
{
AIS_BaseStationReport bsr = aisMessage as AIS_BaseStationReport;
if(!_baseStations.ContainsKey(bsr.MMSI))
{
AIS_BaseStation baseStation = new AIS_BaseStation(bsr.MMSI);
_baseStations[bsr.MMSI] = baseStation;
}
_baseStations[bsr.MMSI].Update(bsr);
}
break;
default:
_log.InfoFormat("currently discarding AIS message {0}", aisMessage.MessageType);
break;

View File

@ -94,6 +94,7 @@
<Compile Include="AISController.cs" />
<Compile Include="AISDecoder.cs" />
<Compile Include="AISManager.cs" />
<Compile Include="AIS_BaseStation.cs" />
<Compile Include="AIS_BaseStationReport.cs" />
<Compile Include="AIS_ClassB.cs" />
<Compile Include="AIS_ClassBExt.cs" />
@ -124,6 +125,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="App.config" />
<None Include="bsmd.AIS2Service.licenseheader" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@ -0,0 +1,16 @@
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
// Copyright (c) %CreationYear% - schick Informatik
// %Namespace% [%FileName%]: %UserDisplayName%
// Description:
//
extensions: .aspx .ascx
<%--
Copyright (c) 2022- schick Informatik
--%>
extensions: .vb
'Copyright (c) 2022- schick Informatik
extensions: .xml .config .xsd
<!--
Copyright (c) 2022- schick Informatik
-->