public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type) { throw new Exception(string.Format("Incorrect type, expected 24 but present:{0}", type)); } var timeStamp = DateTime.UtcNow.ToFileTimeUtc(); byte repeatIndicator = payload.DecodeByte(6, 7); uint mmsi = payload.DecodeUInt32(8, 37); byte partNumber = payload.DecodeByte(38, 39); if (partNumber == 0) { string vesselName = payload.DecodeString(40, 159).Trim(); return(new ClassBStaticAndVoyageDataMesageTypeA( type, timeStamp, repeatIndicator, mmsi, partNumber, vesselName)); } if (partNumber != 1) { throw new Exception(string.Format("Incorrect part number, only 0 and 1 allowed, but present:{0}", partNumber)); } //TypeB ShipType shipType = (ShipType)payload.DecodeByte(40, 47); string vendorId = payload.DecodeString(48, 65).Trim(); byte unitModel = payload.DecodeByte(66, 69); uint serial = payload.DecodeUInt32(70, 89); string callsign = payload.DecodeString(90, 131).Trim(); uint bow = payload.DecodeUInt32(132, 140); uint stern = payload.DecodeUInt32(141, 149); byte port = payload.DecodeByte(150, 155); byte starboard = payload.DecodeByte(156, 161); uint motherShipMmmsi = payload.DecodeUInt32(132, 161); return(new ClassBStaticAndVoyageDataMesageTypeB( type, timeStamp, repeatIndicator, mmsi, partNumber, shipType, vendorId, unitModel, serial, callsign, bow, stern, port, starboard, motherShipMmmsi)); }
public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type) { throw new Exception(string.Format("Incorrect type, expected 5 but present:{0}", type)); } var timeStamp = DateTime.UtcNow.ToFileTimeUtc(); byte repeatIndicator = payload.DecodeByte(6, 7); uint mmsi = payload.DecodeUInt32(8, 37); byte aisVersion = payload.DecodeByte(38, 39); uint imo = payload.DecodeUInt32(40, 69);; string callsign = payload.DecodeString(70, 111).Trim(); string vesselName = payload.DecodeString(112, 231).Trim(); ShipType shipType = (ShipType)payload.DecodeByte(232, 239); uint bow = payload.DecodeUInt32(240, 248); uint stern = payload.DecodeUInt32(249, 257); byte port = payload.DecodeByte(258, 263); byte starboard = payload.DecodeByte(264, 269); EpfdFixType positionFixType = (EpfdFixType)payload.DecodeByte(270, 273); byte etaMonth = payload.DecodeByte(274, 277); byte etaDay = payload.DecodeByte(278, 282); byte etaHour = payload.DecodeByte(283, 287); byte etaMinute = payload.DecodeByte(288, 293); float draught = (float)payload.DecodeUInt32(294, 301) / 10; string destination = payload.DecodeString(302, 421).Trim(); bool dataTerminalReady = payload.DecodeBool(422); bool spare = payload.DecodeBool(423); return(new ClassAStaticAndVoyageDataMesage( type, timeStamp, repeatIndicator, mmsi, aisVersion, imo, callsign, vesselName, shipType, bow, stern, port, starboard, positionFixType, etaMonth, etaDay, etaHour, etaMinute, draught, destination, dataTerminalReady, spare)); }
public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type) { throw new Exception(string.Format("Incorrect type, expected 19 but present:{0}", type)); } var timeStamp = DateTime.UtcNow.ToFileTimeUtc(); byte repeatIndicator = payload.DecodeByte(6, 7); uint mmsi = payload.DecodeUInt32(8, 37); float sog = (float)payload.DecodeUInt32(46, 55) / 10; bool posAccuracy = payload.DecodeBool(56); float longtitude = (float)payload.DecodeFloat(57, 84) / 600000; float latitude = (float)payload.DecodeFloat(85, 111) / 600000; float cog = (float)payload.DecodeUInt32(112, 123) / 10; ushort heading = payload.DecodeUShort(124, 132); byte utcSeconds = payload.DecodeByte(133, 138); string vesselName = payload.DecodeString(143, 262).Trim(); ShipType shipType = (ShipType)payload.DecodeByte(263, 270); uint bow = payload.DecodeUInt32(271, 279); uint stern = payload.DecodeUInt32(280, 288); byte port = payload.DecodeByte(289, 294); byte starboard = payload.DecodeByte(295, 300); EpfdFixType positionFixType = (EpfdFixType)payload.DecodeByte(301, 304); bool raim = payload.DecodeBool(305); bool dataTerminalReady = payload.DecodeBool(306); bool assigned = payload.DecodeBool(307); byte spare = payload.DecodeByte(308, 311); return(new ClassBExtendedPositionReportMessage( type, timeStamp, repeatIndicator, mmsi, sog, posAccuracy, longtitude, latitude, cog, heading, utcSeconds, vesselName, shipType, bow, stern, port, starboard, positionFixType, raim, dataTerminalReady, assigned, spare)); }