diff --git a/AIS/bsmd.AIS2Service/AIS_BaseStation.cs b/AIS/bsmd.AIS2Service/AIS_BaseStation.cs new file mode 100644 index 00000000..656a6cf3 --- /dev/null +++ b/AIS/bsmd.AIS2Service/AIS_BaseStation.cs @@ -0,0 +1,66 @@ +using System; + +namespace bsmd.AIS2Service +{ + + /// + /// Simple container for BaseStation Reports (Type 4). This class just exists to decouple from + /// the actual AIS messages. + /// + 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 + + } +} diff --git a/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs b/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs index 0ea9d860..5025bfdf 100644 --- a/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs +++ b/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs @@ -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); } diff --git a/AIS/bsmd.AIS2Service/Lookup.cs b/AIS/bsmd.AIS2Service/Lookup.cs index 21ac114b..8bce10c3 100644 --- a/AIS/bsmd.AIS2Service/Lookup.cs +++ b/AIS/bsmd.AIS2Service/Lookup.cs @@ -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 diff --git a/AIS/bsmd.AIS2Service/Program.cs b/AIS/bsmd.AIS2Service/Program.cs index a6b67bd8..581fea4a 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(720000); + Thread.Sleep(180000); // Test finish.. AISManager.Stop(); } diff --git a/AIS/bsmd.AIS2Service/SitRep.cs b/AIS/bsmd.AIS2Service/SitRep.cs index 1a64fc94..4af3edb5 100644 --- a/AIS/bsmd.AIS2Service/SitRep.cs +++ b/AIS/bsmd.AIS2Service/SitRep.cs @@ -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 _inputQueue; private readonly ConcurrentDictionary _sitRep; + private readonly Dictionary _baseStations = new Dictionary(); private readonly ConcurrentQueue _dbQueue; #endregion @@ -38,6 +41,15 @@ namespace bsmd.AIS2Service #endregion + #region Properties + + public Dictionary 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; diff --git a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj index df15c6ff..1f8ab1a1 100644 --- a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj +++ b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj @@ -94,6 +94,7 @@ + @@ -124,6 +125,7 @@ PreserveNewest + SettingsSingleFileGenerator diff --git a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.licenseheader b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.licenseheader new file mode 100644 index 00000000..f219dd07 --- /dev/null +++ b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.licenseheader @@ -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 +