199 lines
5.5 KiB
C#
199 lines
5.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Diagnostics;
|
|
using log4net;
|
|
|
|
namespace bsmd.AIS2Service
|
|
{
|
|
internal class AIS_PosReport : AISClass
|
|
{
|
|
private Guid? id;
|
|
private int navstatus;
|
|
private int rot;
|
|
private int sog;
|
|
private int accur;
|
|
private int longitude;
|
|
private int latitude;
|
|
private int cog;
|
|
private int trueheading;
|
|
private DateTime timestamp;
|
|
private int utcTimeSecond;
|
|
private int maneuver_indicator;
|
|
private int spare;
|
|
private int raim;
|
|
private int commstate;
|
|
|
|
private static readonly ILog _log = LogManager.GetLogger(typeof(AIS_PosReport));
|
|
|
|
#region Properties
|
|
|
|
public Guid Id { get { if (!this.id.HasValue) this.id = Guid.NewGuid(); return this.id.Value; } }
|
|
|
|
public int NavStatusVal { get { return this.navstatus; } }
|
|
public int ROTVal { get { return this.rot; } }
|
|
public int SOGVal { get { return this.sog; } }
|
|
public int COGVal { get { return this.cog; } }
|
|
public int Accuracy { get { return this.accur; } }
|
|
public int LatitudeVal { get { return this.latitude; } }
|
|
public int LongitudeVal { get { return this.longitude; } }
|
|
public string DBTimestamp
|
|
{
|
|
get
|
|
{
|
|
return this.timestamp.ToString("yyyy-MM-ddTHH:mm:ss.000Z");
|
|
}
|
|
}
|
|
|
|
public double SOG
|
|
{
|
|
get
|
|
{
|
|
return ((double)this.sog) / 10.0f;
|
|
}
|
|
}
|
|
|
|
public double COG
|
|
{
|
|
get
|
|
{
|
|
return ((double)this.cog) / 10.0f;
|
|
}
|
|
}
|
|
|
|
public int ROT
|
|
{
|
|
get
|
|
{
|
|
return (int)((double)(this.rot * this.rot) / 22.401289);
|
|
}
|
|
}
|
|
|
|
public double Latitude
|
|
{
|
|
get
|
|
{
|
|
return ((double)this.latitude) / 600000.0f;
|
|
}
|
|
}
|
|
|
|
public double Longitude
|
|
{
|
|
get
|
|
{
|
|
return ((double)this.longitude) / 600000.0f;
|
|
}
|
|
}
|
|
|
|
|
|
public string NavStatus
|
|
{
|
|
get { return GetNavStatus(this.navstatus); }
|
|
}
|
|
|
|
public DateTime Timestamp
|
|
{
|
|
get { return this.timestamp; }
|
|
}
|
|
|
|
public int? TrueHeading
|
|
{
|
|
get
|
|
{
|
|
if (this.trueheading == 511) return null;
|
|
return this.trueheading;
|
|
}
|
|
}
|
|
|
|
public int ManeuverIndicator { get { return this.maneuver_indicator; } }
|
|
|
|
public int Spare { get { return this.spare; } }
|
|
|
|
public int Raim { get { return this.raim; } }
|
|
|
|
public int CommState { get { return this.commstate; } }
|
|
|
|
#endregion
|
|
|
|
#region static methods
|
|
|
|
public static string GetNavStatus(int navstatus)
|
|
{
|
|
switch (navstatus)
|
|
{
|
|
case 0:
|
|
return "under way using engine";
|
|
case 1:
|
|
return "at anchor";
|
|
case 2:
|
|
return "not under command";
|
|
case 3:
|
|
return "restricted manoeuvrability";
|
|
case 4:
|
|
return "contrained by her draught";
|
|
case 5:
|
|
return "moored";
|
|
case 6:
|
|
return "aground";
|
|
case 7:
|
|
return "engaged in fishing";
|
|
case 8:
|
|
return "under way sailing";
|
|
case 9:
|
|
return "reserved for future amendment of Navigational Status for HSC";
|
|
case 10:
|
|
return "reserved for future amendment of Navigational Status for WIG";
|
|
case 11:
|
|
case 12:
|
|
case 13:
|
|
case 14:
|
|
return "reserved for future use";
|
|
default:
|
|
return "not defined";
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region overrides
|
|
|
|
protected override Status Decode()
|
|
{
|
|
Status result = Status.OK;
|
|
BitArray bits = DecodeBinary(_data);
|
|
|
|
try
|
|
{
|
|
_mmsi = GetInt(bits, 8, 37);
|
|
this.navstatus = GetInt(bits, 38, 41);
|
|
this.rot = GetInt(bits, 42, 49);
|
|
this.sog = GetInt(bits, 50, 59);
|
|
this.accur = GetInt(bits, 60, 60);
|
|
this.longitude = GetInt(bits, 61, 88);
|
|
this.latitude = GetInt(bits, 89, 115);
|
|
this.cog = GetInt(bits, 116, 127);
|
|
this.trueheading = GetInt(bits, 128, 136);
|
|
this.utcTimeSecond = GetInt(bits, 137, 142);
|
|
this.maneuver_indicator = GetInt(bits, 143, 144);
|
|
this.spare = GetInt(bits, 145, 147);
|
|
this.raim = GetInt(bits, 148, 148);
|
|
this.commstate = GetInt(bits, 149, 167);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_log.WarnFormat("Error decoding AIS pos report: {0}", e.Message);
|
|
result = Status.PARSE_ERROR;
|
|
}
|
|
|
|
this.timestamp = DateTime.Now;
|
|
return result;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0} - MMSI {1}", base.ToString(), this.MMSI);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|