diff --git a/AIS/ReadMe.md b/AIS/ReadMe.md new file mode 100644 index 00000000..2ac63b91 --- /dev/null +++ b/AIS/ReadMe.md @@ -0,0 +1,29 @@ +# AIS Service + +___ + +## Übersicht + +### Architektur Entwurf + +![Übersichtsbild der geplanten Architektur](architektur.jpg "Architektur") + +## Stand Sep/Okt.22 + +Entscheidung, den leidlich laufenden AIS Service zu verbessern, da aktiv nicht mehr an WETRIS weitergearbeitet wird. Aufgaben: + +* Prüfen und Debuggen des aktuellen Stands (sinnvoll?) +* Anlage einer neuen, effizienteren Datenbankstruktur (kein SQL Server!) +* Vollständige Implementierung aller Telegramm-Arten +* verbesserte Architektur (s.u. Bild) +* Webservice-Endpunkt, der aktuelle Lage als Liste liefert +* Zonen Alarm +* Einfaches Frontend zur Einrichtung von Zonen +* (Backup) Evaluierung alternativer Datenquellen + +## Referenzen + +* [NMEA 0183](https://de.wikipedia.org/wiki/NMEA_0183) +* [AIS Wikipedia](https://en.wikipedia.org/wiki/Automatic_identification_system) +* [AIVDM/AIVDO protocol decoding](https://gpsd.gitlab.io/gpsd/AIVDM.html) +* [AIS Documentation (PDF)](itu-m.1371-4-201004.pdf) \ No newline at end of file diff --git a/AIS/architektur.jpg b/AIS/architektur.jpg new file mode 100644 index 00000000..9c769d1f Binary files /dev/null and b/AIS/architektur.jpg differ diff --git a/AIS/bsmd.AIS2Service/AIS2_Service.Designer.cs b/AIS/bsmd.AIS2Service/AIS2_Service.Designer.cs index 7c2d1b5c..4503811a 100644 --- a/AIS/bsmd.AIS2Service/AIS2_Service.Designer.cs +++ b/AIS/bsmd.AIS2Service/AIS2_Service.Designer.cs @@ -1,4 +1,8 @@ -namespace bsmd.AIS2Service +// Copyright (c) 2022- schick Informatik +// Description: Windows Service Main File +// + +namespace bsmd.AIS2Service { partial class AIS2_Service { @@ -18,7 +22,7 @@ components.Dispose(); } base.Dispose(disposing); - } + } #region Component Designer generated code @@ -28,8 +32,11 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - this.ServiceName = "Service1"; + // + // AIS2_Service + // + this.ServiceName = "BSMD AIS Service"; + } #endregion diff --git a/AIS/bsmd.AIS2Service/AIS2_Service.cs b/AIS/bsmd.AIS2Service/AIS2_Service.cs index 269eea9e..2b9c767d 100644 --- a/AIS/bsmd.AIS2Service/AIS2_Service.cs +++ b/AIS/bsmd.AIS2Service/AIS2_Service.cs @@ -7,11 +7,14 @@ using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; +using log4net; namespace bsmd.AIS2Service { public partial class AIS2_Service : ServiceBase { + private readonly ILog _log = LogManager.GetLogger(typeof(AIS2_Service)); + public AIS2_Service() { InitializeComponent(); @@ -19,10 +22,19 @@ namespace bsmd.AIS2Service protected override void OnStart(string[] args) { + this.EventLog.Source = this.ServiceName; + this.EventLog.Log = "Application"; + this.EventLog.WriteEntry("BSMD AIS Service started.", EventLogEntryType.Information); + System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); + FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); + string version = fvi.FileVersion; + _log.InfoFormat("Starting AIS2 Service. v.{0} -------------- ", version); + } protected override void OnStop() { + _log.Info("AIS2 Service stopped."); } } } diff --git a/AIS/bsmd.AIS2Service/AIS2_Service.resx b/AIS/bsmd.AIS2Service/AIS2_Service.resx new file mode 100644 index 00000000..e5858cc2 --- /dev/null +++ b/AIS/bsmd.AIS2Service/AIS2_Service.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/App.config b/AIS/bsmd.AIS2Service/App.config index 193aecc6..cf891f51 100644 --- a/AIS/bsmd.AIS2Service/App.config +++ b/AIS/bsmd.AIS2Service/App.config @@ -1,6 +1,21 @@  + + +
+ + + + + + 192.168.2.24 + + + 0 + + + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/IAISThread.cs b/AIS/bsmd.AIS2Service/IAISThread.cs new file mode 100644 index 00000000..1778cae1 --- /dev/null +++ b/AIS/bsmd.AIS2Service/IAISThread.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bsmd.AIS2Service +{ + internal interface IAISThread + { + /// + /// regular start request + /// + void Start(); + + /// + /// regular stop request + /// + void Stop(); + + /// + /// if this happens the whole show must be stopped + /// + event EventHandler FatalErrorOccurred; + } +} diff --git a/AIS/bsmd.AIS2Service/Properties/Settings.Designer.cs b/AIS/bsmd.AIS2Service/Properties/Settings.Designer.cs new file mode 100644 index 00000000..0ccdbc3e --- /dev/null +++ b/AIS/bsmd.AIS2Service/Properties/Settings.Designer.cs @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace bsmd.AIS2Service.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("192.168.2.24")] + public string DataSourceHost { + get { + return ((string)(this["DataSourceHost"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public uint DataSourcePort { + get { + return ((uint)(this["DataSourcePort"])); + } + } + } +} diff --git a/AIS/bsmd.AIS2Service/Properties/Settings.settings b/AIS/bsmd.AIS2Service/Properties/Settings.settings new file mode 100644 index 00000000..e76be480 --- /dev/null +++ b/AIS/bsmd.AIS2Service/Properties/Settings.settings @@ -0,0 +1,12 @@ + + + + + + 192.168.2.24 + + + 0 + + + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/SerialTCPReader.cs b/AIS/bsmd.AIS2Service/SerialTCPReader.cs new file mode 100644 index 00000000..04df3ea2 --- /dev/null +++ b/AIS/bsmd.AIS2Service/SerialTCPReader.cs @@ -0,0 +1,80 @@ +using log4net; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace bsmd.AIS2Service +{ + internal class SerialTCPReader : IAISThread + { + private readonly string _host; + private readonly uint _port; + + private NetworkStream tcpStream; + private TcpClient tcpSocket; + private Thread _thread; + + private static readonly ILog _log = LogManager.GetLogger(typeof(SerialTCPReader)); + + + public SerialTCPReader(string host, uint port) + { + _host = host; _port = port; + } + + private void ReadData() + { + try + { + while (true) + { + if (this.tcpSocket == null || !this.tcpSocket.Connected) this.Connect(); + + + } + } + + catch(Exception ex) + { + _log.ErrorFormat("Something bad has happened: {0}", ex.Message); + if(this.FatalErrorOccurred != null) + this.FatalErrorOccurred(this, new EventArgs()); + } + + } + + private void Connect() + { + this.tcpSocket = new TcpClient(_host, (int)_port); + this.tcpStream = tcpSocket.GetStream(); + _log.InfoFormat("TCP stream connected ({0}:{1})", _host, _port); + } + + + + #region IAISThread implementation + + public event EventHandler FatalErrorOccurred; + + public void Start() + { + if (_thread != null) return; // may not run twice + ThreadStart runReader = new ThreadStart(this.ReadData); + _thread = new Thread(runReader); + + + } + + public void Stop() + { + + } + + #endregion + + } +} diff --git a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj index fc46c0ed..66f045b6 100644 --- a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj +++ b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj @@ -33,8 +33,13 @@ 4 + + packages\log4net.2.0.15\lib\net45\log4net.dll + + + @@ -50,11 +55,31 @@ AIS2_Service.cs + + + True + True + Settings.settings + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + AIS2_Service.cs + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/packages.config b/AIS/bsmd.AIS2Service/packages.config new file mode 100644 index 00000000..4ec372e3 --- /dev/null +++ b/AIS/bsmd.AIS2Service/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/AIS/itu-m.1371-4-201004.pdf b/AIS/itu-m.1371-4-201004.pdf new file mode 100644 index 00000000..87d53c40 Binary files /dev/null and b/AIS/itu-m.1371-4-201004.pdf differ