// 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; namespace bsmd.AIS2Service { internal class AIS_BaseStationReport : AISClass { #region fields private uint _repeatIndicator; private DateTime? _utcTimestamp; private bool _accuracy; private int _latitude; private int _longitude; private int _epfdType; bool _raim; private uint _radio; private static readonly ILog _log = LogManager.GetLogger(typeof(AIS_BaseStationReport)); #endregion #region Properties public uint RepeatIndicator { get { return _repeatIndicator; } } public DateTime? UTCTimestamp { get { return _utcTimestamp; } } public bool Accuracy { get { return _accuracy; } } public int Latitude { get { return _latitude; } } public int Longitude { get { return _longitude; } } public int EPFD { get { return _epfdType; } } public bool Raim { get { return _raim; } } public uint Radio { get { return _radio; } } #endregion #region abstract class implementation protected override Status Decode() { Status result = Status.OK; BitArray bits = DecodeBinary(_data); uint year = 0; uint month = 0; uint day = 0; uint hour = 0; uint minute = 0; uint second = 0; try { _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); _accuracy = GetInt(bits, 78, 78) == 1; _longitude = GetInt(bits, 79, 106); _latitude = GetInt(bits, 107, 133); _epfdType = GetInt(bits, 134, 137); _raim = GetInt(bits, 148, 148) == 1; _radio = GetUInt(bits, 149, 167); } catch(ArgumentOutOfRangeException) { _log.WarnFormat("Year: {0} Month: {1} Day: {2} Hour: {3} Minute: {4} Second: {5}", year, month, day, hour, minute, second); result = Status.PARSE_ERROR; } catch (Exception e) { _log.WarnFormat("Error decoding AIS base station report: {0}", e.Message); result = Status.PARSE_ERROR; } return result; } #endregion } }