git_bsmd/AIS/bsmd.AIS2Service/AIS_BaseStationReport.cs

104 lines
2.9 KiB
C#

using log4net;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
namespace bsmd.AIS2Service
{
internal class AIS_BaseStationReport : AISClass
{
#region enums
public enum EPFDType
{
UNDEFINED,
GPS,
GLONASS,
COMBINED_GPS_GLONASS,
LORAN_C,
CHAYKA,
INTEGR_NAV_SYSTEM,
SURVEYED,
GALILEO
}
#endregion
#region fields
private uint _repeatIndicator;
private DateTime? _utcTimestamp;
private bool _accuracy;
private int _latitude;
private int _longitude;
private EPFDType _epfdType;
bool _raim;
private uint _radio;
private static readonly ILog _log = LogManager.GetLogger(typeof(AIS_BaseStationReport));
#endregion
#region Properties
public uint RepeatIndicator { get { return _repeatIndicator; } }
public DateTime? UTCTimestamp { get { return _utcTimestamp; } }
public bool Accuracy { get { return _accuracy; } }
public int Latitude { get { return _latitude; } }
public int Longitude { get { return _longitude; } }
public EPFDType EPFD { get { return _epfdType; } }
public bool Raim { get { return _raim; } }
public uint Radio { get { return _radio; } }
#endregion
#region abstract class implementation
protected override Status Decode()
{
Status result = Status.OK;
BitArray bits = DecodeBinary(_data);
try
{
_repeatIndicator = GetUInt(bits, 6, 7);
_mmsi = GetInt(bits, 8, 37);
uint year = GetUInt(bits, 38, 51);
uint month = GetUInt(bits, 52, 55);
uint day = GetUInt(bits, 56, 60);
uint hour = GetUInt(bits, 61, 65);
uint minute = GetUInt(bits, 66, 71);
uint second = GetUInt(bits, 72, 77);
_utcTimestamp = new DateTime((int) year, (int) month, (int) day, (int) hour, (int) minute, (int) second, DateTimeKind.Utc);
_accuracy = GetInt(bits, 78, 78) == 1;
_longitude = GetInt(bits, 79, 106);
_latitude = GetInt(bits, 107, 133);
int epfd = GetInt(bits, 134, 137);
_epfdType = (EPFDType) epfd;
_raim = GetInt(bits, 148, 148) == 1;
_radio = GetUInt(bits, 149, 167);
}
catch (Exception e)
{
_log.WarnFormat("Error decoding AIS base station report: {0}", e.Message);
result = Status.PARSE_ERROR;
}
return result;
}
#endregion
}
}