added Class B support

This commit is contained in:
Daniel Schick 2022-10-17 10:51:32 +02:00
parent 5577fd22b5
commit e213afbab9
5 changed files with 129 additions and 6 deletions

View File

@ -36,6 +36,8 @@ namespace bsmd.AIS2Service
public Guid Id { get { if (!this.id.HasValue) this.id = Guid.NewGuid(); return this.id.Value; } }
public int Accuracy { get { return accuracy; } }
public int CogVal { get { return this.cog; } }
public int SogVal { get { return this.sog; } }
public int LatitudeVal { get { return this.latitude; } }

View File

@ -72,6 +72,29 @@ namespace bsmd.AIS2Service
get { return (double)this.cog / 10.0f; }
}
public double Sog
{
get { return (double)this.sog / 10.0f; }
}
public int Accuracy
{
get { return this.accuracy; }
}
public int ShipType
{
get { return this.shipType; }
}
public int Length { get; private set; }
public int Breadth { get; private set; }
public int DTE { get { return dte; } }
public int RAIM { get { return raimFlag; } }
#endregion
protected override Status Decode()
@ -113,6 +136,13 @@ namespace bsmd.AIS2Service
this.shipType = GetInt(bits, 263, 270);
this.dimension = GetInt(bits, 271, 300);
int toBow = GetInt(bits, 271, 279);
int toStern = GetInt(bits, 280, 288);
this.Length = toBow + toStern;
int toPort = GetInt(bits, 289, 294);
int toStarboard = GetInt(bits, 295, 300);
this.Breadth = toPort + toStarboard;
this.typeofDevice = GetInt(bits, 301, 304);
this.raimFlag = GetInt(bits, 305, 305);
this.dte = GetInt(bits, 306, 306);

View File

@ -17,7 +17,7 @@ namespace bsmd.AIS2Service
private string callsign;
private int dimension;
private int spare;
private static ILog _log = LogManager.GetLogger(typeof(AIS_ClassBStatic));
private static readonly ILog _log = LogManager.GetLogger(typeof(AIS_ClassBStatic));
#endregion
@ -57,7 +57,15 @@ namespace bsmd.AIS2Service
public int Spare { get { return this.spare; } }
// Todo: Dimensions..
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
@ -97,7 +105,7 @@ namespace bsmd.AIS2Service
this.shipType = GetInt(bits, 40, 47);
StringBuilder sb_vendor = new StringBuilder(7);
for (int i = 0; i < 7; i++)
for (int i = 0; i < 3; i++)
{
int cval = GetInt(bits, 48 + (6 * i), 53 + (6 * i));
char ch = GetAISChar(cval);
@ -105,6 +113,8 @@ namespace bsmd.AIS2Service
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++)
@ -114,7 +124,15 @@ namespace bsmd.AIS2Service
if (ch == '@') ch = ' ';
sb_callsign.Append(ch);
}
this.callsign = sb_callsign.ToString().Trim();
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);
}

View File

@ -209,7 +209,7 @@ namespace bsmd.AIS2Service
#endregion
#region public methods
#region internal update methods
internal void Update(AIS_PosReport posReport)
{
@ -249,8 +249,53 @@ namespace bsmd.AIS2Service
internal void Update(AIS_ClassBStatic staticData)
{
this.IsClassB = true;
if(staticData.IsPartA)
{
this.Name = staticData.Name;
}
if(staticData.IsPartB)
{
this.ShipType = staticData.ShipTypeVal;
// this.VendorId = staticData.VendorId;
this.Callsign = staticData.Callsign;
this.Length = staticData.Length;
this.Breadth = staticData.Breadth;
}
this.LastUpdate = DateTime.Now;
}
internal void Update(AIS_ClassB bPos)
{
this.IsClassB = true;
this.SOG = bPos.Sog;
this.Accuracy = bPos.Accuracy == 1;
this.Longitude = bPos.Longitude;
this.Latitude = bPos.Latitude;
this.COG = bPos.Cog;
this.Heading = bPos.TrueHeading;
this.RAIM = bPos.Raim == 1;
this.Radio = bPos.CommState;
this.LastUpdate = DateTime.Now;
}
internal void Update(AIS_ClassBExt bPosExt)
{
this.IsClassB = true;
this.SOG = bPosExt.Sog;
this.Accuracy = bPosExt.Accuracy == 1;
this.Longitude = bPosExt.Longitude;
this.Latitude = bPosExt.Latitude;
this.COG = bPosExt.Cog;
this.Name = bPosExt.Name;
this.Heading = bPosExt.TrueHeading;
this.ShipType = bPosExt.ShipType;
this.Length = bPosExt.Length;
this.Breadth = bPosExt.Breadth;
this.RAIM = bPosExt.RAIM == 1;
this.DTE = bPosExt.DTE == 1;
this.LastUpdate = DateTime.Now;
}

View File

@ -38,6 +38,8 @@ namespace bsmd.AIS2Service
#endregion
#region mainloop thread
private void ReadMessages()
{
try
@ -89,6 +91,30 @@ namespace bsmd.AIS2Service
_dbQueue.Enqueue(_sitRep[bStaticData.MMSI]);
}
break;
case AISClass.AISType.POSITION_REPORT_B_EQUIP:
{
AIS_ClassB bPos = aisMessage as AIS_ClassB;
if(!_sitRep.ContainsKey(bPos.MMSI))
{
AIS_Target target = new AIS_Target(bPos.MMSI);
_sitRep[bPos.MMSI] = target;
}
_sitRep[bPos.MMSI].Update(bPos);
_dbQueue.Enqueue(_sitRep[bPos.MMSI]);
}
break;
case AISClass.AISType.POSITION_REPORT_B_EQUIP_EXT:
{
AIS_ClassBExt bPosExt = aisMessage as AIS_ClassBExt;
if (!_sitRep.ContainsKey(bPosExt.MMSI))
{
AIS_Target target = new AIS_Target(bPosExt.MMSI);
_sitRep[bPosExt.MMSI] = target;
}
_sitRep[bPosExt.MMSI].Update(bPosExt);
_dbQueue.Enqueue(_sitRep[bPosExt.MMSI]);
}
break;
default:
_log.InfoFormat("currently discarding AIS message {0}", aisMessage.MessageType);
break;
@ -108,6 +134,8 @@ namespace bsmd.AIS2Service
}
}
#endregion
#region IAISThread implementation
public string Name { get { return "Sit rep"; } }