public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type) { throw new Exception(string.Format("Incorrect type, expected 18 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); CsUnitType csUnit = payload.DecodeBool(141) ? CsUnitType.ClassBCarrierSense : CsUnitType.ClassBSotdma; bool display = payload.DecodeBool(142); bool dsc = payload.DecodeBool(143); bool band = payload.DecodeBool(144); bool message22 = payload.DecodeBool(145); bool assigned = payload.DecodeBool(146); bool raim = payload.DecodeBool(147); uint radioStatus = payload.DecodeUInt32(148, 167); return(new ClassBPositionReportMessage( type, timeStamp, repeatIndicator, mmsi, sog, posAccuracy, longtitude, latitude, cog, heading, utcSeconds, raim, radioStatus, csUnit, display, dsc, band, message22, assigned)); }
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 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)); }
private AisMessage CreateAisMessageFromBitPayload(BitArray payload) { var messageType = payload.DecodeByte(0, 5); IAisMessageFactory factory; if (!m_factories.TryGetValue(messageType, out factory)) { return(new UnsupportedMessage(messageType, DateTime.UtcNow.ToFileTimeUtc())); } return(factory.CreateMessage(payload)); }
public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type1) { throw new Exception(string.Format("Incorrect type, expected 27 but present:{0}", type)); } var timeStamp = DateTime.UtcNow.ToFileTimeUtc(); byte repeatIndicator = payload.DecodeByte(6, 7); uint mmsi = payload.DecodeUInt32(8, 37); bool posAccuracy = payload.DecodeBool(38); bool raim = payload.DecodeBool(39); NavigationStatus navStatus = (NavigationStatus)payload.DecodeByte(40, 43); float longtitude = (float)payload.DecodeFloat(44, 61) / 600000; float latitude = (float)payload.DecodeFloat(62, 78) / 600000; float sog = (float)payload.DecodeUInt32(79, 84) / 10; float cog = (float)payload.DecodeUInt32(85, 93) / 10; bool gnss = payload.DecodeBool(94); bool spare = payload.DecodeBool(95); return(new ClassAPositionReportLongRangeMessage( type, timeStamp, repeatIndicator, mmsi, posAccuracy, raim, navStatus, longtitude, latitude, sog, cog, gnss, spare)); }
public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type1) { throw new Exception($"Incorrect type, expected 4 but present:{type}"); } var timeStamp = DateTime.UtcNow.ToFileTimeUtc(); byte repeatIndicator = payload.DecodeByte(6, 7); uint mmsi = payload.DecodeUInt32(8, 37); uint year = payload.DecodeUInt32(38, 51); byte month = payload.DecodeByte(52, 55); byte day = payload.DecodeByte(56, 60); byte hour = payload.DecodeByte(61, 65); byte minute = payload.DecodeByte(66, 71); byte second = payload.DecodeByte(72, 77); bool posAccuracy = payload.DecodeBool(78); float longtitude = (float)payload.DecodeFloat(79, 106) / 600000; float latitude = (float)payload.DecodeFloat(107, 133) / 600000; EpfdFixType positionFixType = (EpfdFixType)payload.DecodeByte(134, 137); bool raim = payload.DecodeBool(148); uint radioStatus = payload.DecodeUInt32(149, 167); return(new BaseStationReportMessage( type, timeStamp, repeatIndicator, mmsi, year, month, day, hour, minute, second, posAccuracy, longtitude, latitude, positionFixType, raim, radioStatus)); }
public static Sscc96Tag FromBinary(BitArray rawBits) { uint header = rawBits.DecodeUInt32(0, 8); if (header != BinaryHeader) { throw new FormatException(string.Format("Invalid EPC Header: 0x{0:X2} (expected 0x{1:X2)", header, BinaryHeader)); } string companyPrefix; string extensionAndSerial; byte partition; byte filter = rawBits.DecodeByte(8, 3); rawBits.DecodePartition(PartitionTable, 11, out partition, out companyPrefix, out extensionAndSerial); return(new Sscc96Tag(filter, partition, companyPrefix, extensionAndSerial)); }
/// <summary> /// Converts the specified bit array into a binary EPC string representation /// </summary> /// <param name="bits"></param> /// <returns></returns> public static string BitArrayToBinaryString(BitArray bits) { var bitCount = bits.Length + (16 - bits.Length % 16) % 16; var charCount = bitCount / 4; StringBuilder sb = new StringBuilder(charCount); for (int i = 0; i < charCount; i++) { int start = i * 4; int len = Math.Min(4, bits.Length - start); if (len > 0) { sb.Append(EncodeHexChar(bits.DecodeByte(start, len))); } else { sb.Append('0'); } } return(sb.ToString()); }
public AisMessage CreateMessage(BitArray payload) { var type = payload.DecodeByte(0, 5); if (type != c_type1 && type != c_type2 && type != c_type3) { throw new Exception(string.Format("Incorrect type, expected 1,2,3 but present:{0}", type)); } var timeStamp = DateTime.UtcNow.ToFileTimeUtc(); byte repeatIndicator = payload.DecodeByte(6, 7); uint mmsi = payload.DecodeUInt32(8, 37); NavigationStatus navStatus = (NavigationStatus)payload.DecodeByte(38, 41); int rot = payload.DecodeInt32(42, 49); float sog = (float)payload.DecodeUInt32(50, 59) / 10; bool posAccuracy = payload.DecodeBool(60); float longtitude = (float)payload.DecodeFloat(61, 88) / 600000; float latitude = (float)payload.DecodeFloat(89, 115) / 600000; float cog = (float)payload.DecodeUInt32(116, 127) / 10; ushort heading = payload.DecodeUShort(128, 136); byte utcSeconds = payload.DecodeByte(137, 142); ManeuverIndicator manuevrIndicator = (ManeuverIndicator)payload.DecodeByte(143, 144); byte spare = payload.DecodeByte(145, 147); bool raim = payload.DecodeBool(148); uint radioStatus = payload.DecodeUInt32(149, 167); return(new ClassAPositionReportMessage( type, timeStamp, repeatIndicator, mmsi, navStatus, rot, sog, posAccuracy, longtitude, latitude, cog, heading, utcSeconds, manuevrIndicator, spare, raim, radioStatus)); }
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)); }