using System; using System.Collections; using System.Text; using log4net; namespace bsmd.AIS2Service { internal class AIS_ClassBStatic : AISClass { #region private members private int repeatIndicator; private int partNumber; private string name; private int shipType; private string vendorId; private string callsign; private int dimension; private int spare; private static readonly ILog _log = LogManager.GetLogger(typeof(AIS_ClassBStatic)); #endregion #region Properties public bool IsPartA { get { return this.partNumber == 0; } } public bool IsPartB { get { return this.partNumber == 1; } } public string Name { get { return this.name; } } public string VendorId { get { return this.vendorId; } } public string Callsign { get { return this.callsign; } } public int ShipTypeVal { get { return this.shipType; } } public int Dimension { get { return this.dimension; } } public int Spare { get { return this.spare; } } public int? UnitModelCode {get; private set;} public int? Serial { get; private set; } public int Length { get; private set; } public int Breadth { get; private set; } public int? MothershipMMSI { get; private set; } #endregion #region abstract method implementation protected override Status Decode() { BitArray bits = DecodeBinary(_data); Status result = Status.OK; try { int type = GetInt(bits, 0, 5); if (type != 24) { result = Status.ILLEGAL_ARGUMENT; } else { this.repeatIndicator = GetInt(bits, 6, 7); _mmsi = GetInt(bits, 8, 37); this.partNumber = GetInt(bits, 38, 39); if (this.IsPartA) { StringBuilder sb_name = new StringBuilder(20); for (int i = 0; i < 20; i++) { int cval = GetInt(bits, 40 + (6 * i), 45 + (6 * i)); char ch = GetAISChar(cval); if (ch == '@') ch = ' '; sb_name.Append(ch); } this.name = sb_name.ToString().Trim(); } else { this.shipType = GetInt(bits, 40, 47); StringBuilder sb_vendor = new StringBuilder(7); for (int i = 0; i < 3; i++) { int cval = GetInt(bits, 48 + (6 * i), 53 + (6 * i)); char ch = GetAISChar(cval); if (ch == '@') ch = ' '; sb_vendor.Append(ch); } this.vendorId = sb_vendor.ToString().Trim(); this.UnitModelCode = GetInt(bits, 66, 69); this.Serial = GetInt(bits, 70, 89); StringBuilder sb_callsign = new StringBuilder(7); for (int i = 0; i < 7; i++) { int cval = GetInt(bits, 90 + (6 * i), 95 + (6 * i)); char ch = GetAISChar(cval); if (ch == '@') ch = ' '; sb_callsign.Append(ch); } this.callsign = sb_callsign.ToString().Trim(); int toBow = GetInt(bits, 132, 140); int toStern = GetInt(bits, 141, 149); this.Length = toBow + toStern; int toPort = GetInt(bits, 150, 155); int toStarboard = GetInt(bits, 156, 161); this.Breadth = toPort + toStarboard; this.dimension = GetInt(bits, 141, 161); this.spare = GetInt(bits, 162, 167); } } } catch (Exception e) { _log.WarnFormat("Error decoding AIS class B static data: {0}", e.Message); result = Status.PARSE_ERROR; } return result; } #endregion } }