134 lines
3.9 KiB
C#
134 lines
3.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Text;
|
|
using System.Diagnostics;
|
|
using log4net;
|
|
|
|
namespace bsmd.AIS2Service
|
|
{
|
|
/// <summary>
|
|
/// Diese Nachricht wird normalerweise von Class B Geräten nicht verschickt.
|
|
/// Sie wird nur als Antwort auf einen sog. "Base station poll" gesendet.
|
|
/// Wir lesen sie trotzdem ;)
|
|
/// </summary>
|
|
// Todo
|
|
internal class AIS_ClassBExt : AISClass
|
|
{
|
|
#region private members
|
|
|
|
private int repeatIndicator;
|
|
private int spare1;
|
|
private int sog;
|
|
private int accuracy;
|
|
private int longitude;
|
|
private int latitude;
|
|
private int cog;
|
|
private int trueHeading;
|
|
private int utcTimestampSecond;
|
|
private DateTime timestamp;
|
|
private int spare2;
|
|
private string name;
|
|
private int shipType;
|
|
private int dimension;
|
|
private int typeofDevice;
|
|
private int raimFlag;
|
|
private int dte;
|
|
private int assignedMode;
|
|
private int spare3;
|
|
|
|
private static ILog _log = LogManager.GetLogger(typeof(AIS_ClassBExt));
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public string Name
|
|
{
|
|
get { return this.name; }
|
|
}
|
|
|
|
public DateTime Timestamp
|
|
{
|
|
get { return this.timestamp; }
|
|
}
|
|
|
|
public double Latitude
|
|
{
|
|
get { return this.latitude / 600000.0f; }
|
|
}
|
|
|
|
public double Longitude
|
|
{
|
|
get { return this.longitude / 600000.0f; }
|
|
}
|
|
|
|
public int TrueHeading
|
|
{
|
|
get { return this.trueHeading; }
|
|
}
|
|
|
|
public double Cog
|
|
{
|
|
get { return (double)this.cog / 10.0f; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected override Status Decode()
|
|
{
|
|
BitArray bits = DecodeBinary(_data);
|
|
Status result = Status.OK;
|
|
|
|
try
|
|
{
|
|
int type = GetInt(bits, 0, 5);
|
|
if (type != 19)
|
|
{
|
|
result = Status.ILLEGAL_ARGUMENT;
|
|
}
|
|
else
|
|
{
|
|
this.repeatIndicator = GetInt(bits, 6, 7);
|
|
_mmsi = GetInt(bits, 8, 37);
|
|
this.spare1 = GetInt(bits, 38, 45);
|
|
this.sog = GetInt(bits, 46, 55);
|
|
this.accuracy = GetInt(bits, 56, 56);
|
|
this.longitude = GetInt(bits, 57, 84);
|
|
this.latitude = GetInt(bits, 85, 111);
|
|
this.cog = GetInt(bits, 112, 123);
|
|
this.trueHeading = GetInt(bits, 124, 132);
|
|
this.utcTimestampSecond = GetInt(bits, 133, 138);
|
|
this.timestamp = DateTime.Now;
|
|
this.spare2 = GetInt(bits, 139, 142);
|
|
|
|
StringBuilder sb_name = new StringBuilder(20);
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
int cval = GetInt(bits, 143 + (6 * i), 148 + (6 * i));
|
|
char ch = GetAISChar(cval);
|
|
if (ch == '@') ch = ' ';
|
|
sb_name.Append(ch);
|
|
}
|
|
this.name = sb_name.ToString().Trim();
|
|
|
|
this.shipType = GetInt(bits, 263, 270);
|
|
this.dimension = GetInt(bits, 271, 300);
|
|
this.typeofDevice = GetInt(bits, 301, 304);
|
|
this.raimFlag = GetInt(bits, 305, 305);
|
|
this.dte = GetInt(bits, 306, 306);
|
|
this.assignedMode = GetInt(bits, 307, 307);
|
|
this.spare3 = GetInt(bits, 308, 311);
|
|
}
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
_log.WarnFormat("Error decoding AIS class B Ext posreport: {0}", e.Message);
|
|
result = Status.PARSE_ERROR;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|