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 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 ShipType { get { return AIS_StaticData.GetShipType(this.shipType); } } 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; } } // Todo: Dimensions.. #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 < 7; 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(); 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(); 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 } }