git_bsmd/AIS/bsmd.AIS2Service/NMEA_AIS_Sentence.cs

94 lines
2.5 KiB
C#

using System;
namespace bsmd.AIS2Service
{
internal class NMEA_AIS_Sentence : NMEA
{
#region fields
private int total_sentence_nr;
private int msg_sentence_nr;
private string seq_message_ident;
private string ais_channel_nr;
private string ais_message;
private int fillbits;
#endregion
#region Properties
/// <summary>
/// 1-based total number of sentences for this ais message
/// </summary>
public int Total_Sentence_Nr
{
get { return this.total_sentence_nr; }
}
/// <summary>
/// 1-based fragment number of sentences
/// </summary>
public int Msg_Sentence_Nr
{
get { return this.msg_sentence_nr; }
}
/// <summary>
/// sequential message id for multi-sentence messages (can be empty)
/// </summary>
public string Seq_Message_Ident
{
get { return this.seq_message_ident; }
}
/// <summary>
/// 'A' = 161.975Mhz (87B),
/// 'B' = 162.025Mhz (88B)
/// </summary>
public string AIS_Channel_nr
{
get { return this.ais_channel_nr; }
}
/// <summary>
/// AIS message data
/// </summary>
public string AIS_Message
{
get { return this.ais_message; }
}
public int FillBits
{
get { return this.fillbits; }
}
#endregion
#region abstract method implementation
protected override void Decode()
{
this.total_sentence_nr = Convert.ToInt32(this.elements[1]);
this.msg_sentence_nr = Convert.ToInt32(this.elements[2]);
this.seq_message_ident = this.elements[3]; // can be an empty string
this.ais_channel_nr = this.elements[4];
this.ais_message = this.elements[5];
try
{
string fillbits_string = this.elements[6].Substring(0, this.elements[6].IndexOf('*'));
if(!Int32.TryParse(fillbits_string, out this.fillbits))
_log.Warn("AIS_Sentence.Decode(): fillbits are no integer");
}
catch (ArgumentOutOfRangeException)
{
_log.Warn("AIS_Sentence.Decode(): split() problem, trouble decoding fillbits");
}
}
#endregion
}
}