131 lines
4.1 KiB
C#
131 lines
4.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Text;
|
|
using System.Diagnostics;
|
|
|
|
namespace bsmd.AISService.AIS
|
|
{
|
|
/// <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
|
|
public class AIS_ClassBExt : AIS
|
|
{
|
|
#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;
|
|
|
|
#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 AIS.Status Decode()
|
|
{
|
|
BitArray bits = AIS.DecodeBinary(this.data);
|
|
Status result = Status.OK;
|
|
|
|
try
|
|
{
|
|
int type = AIS.GetInt(bits, 0, 5);
|
|
if (type != 19)
|
|
{
|
|
result = Status.ILLEGAL_ARGUMENT;
|
|
}
|
|
else
|
|
{
|
|
this.repeatIndicator = AIS.GetInt(bits, 6, 7);
|
|
this.userId = AIS.GetInt(bits, 8, 37);
|
|
this.spare1 = AIS.GetInt(bits, 38, 45);
|
|
this.sog = AIS.GetInt(bits, 46, 55);
|
|
this.accuracy = AIS.GetInt(bits, 56, 56);
|
|
this.longitude = AIS.GetInt(bits, 57, 84);
|
|
this.latitude = AIS.GetInt(bits, 85, 111);
|
|
this.cog = AIS.GetInt(bits, 112, 123);
|
|
this.trueHeading = AIS.GetInt(bits, 124, 132);
|
|
this.utcTimestampSecond = AIS.GetInt(bits, 133, 138);
|
|
this.timestamp = DateTime.Now;
|
|
this.spare2 = AIS.GetInt(bits, 139, 142);
|
|
|
|
StringBuilder sb_name = new StringBuilder(20);
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
int cval = AIS.GetInt(bits, 143 + (6 * i), 148 + (6 * i));
|
|
char ch = AIS.GetAISChar(cval);
|
|
if (ch == '@') ch = ' ';
|
|
sb_name.Append(ch);
|
|
}
|
|
this.name = sb_name.ToString().Trim();
|
|
|
|
this.shipType = AIS.GetInt(bits, 263, 270);
|
|
this.dimension = AIS.GetInt(bits, 271, 300);
|
|
this.typeofDevice = AIS.GetInt(bits, 301, 304);
|
|
this.raimFlag = AIS.GetInt(bits, 305, 305);
|
|
this.dte = AIS.GetInt(bits, 306, 306);
|
|
this.assignedMode = AIS.GetInt(bits, 307, 307);
|
|
this.spare3 = AIS.GetInt(bits, 308, 311);
|
|
}
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
Trace.WriteLine(string.Format("Error decoding AIS class B Ext posreport: {0}", e.Message));
|
|
result = Status.PARSE_ERROR;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|