Esempio n. 1
0
        public void Encode(GarminPacket packet, Stream stream)
        {
            if (packet == null)
            {
                throw new ArgumentNullException(nameof(packet));
            }
            EndianBinaryWriter endianBinaryWriter = stream != null ? new EndianBinaryWriter(EndianBitConverter.Little, stream) : throw new ArgumentNullException(nameof(stream));

            endianBinaryWriter.Write((byte)16);
            endianBinaryWriter.Write(packet.Id);
            GarminFleetManagementPacket managementPacket = packet as GarminFleetManagementPacket;
            DLEStream dleStream = new DLEStream(stream);

            if (managementPacket != null)
            {
                dleStream.WriteByte((byte)packet.Payload.Length);
                dleStream.Write(packet.Payload);
            }
            else
            {
                dleStream.WriteByte((byte)packet.Payload.Length);
                dleStream.Write(packet.Payload);
            }
            byte num = CalcChecksum(packet);

            dleStream.WriteByte(num);
            endianBinaryWriter.Write((byte)16);
            endianBinaryWriter.Write((byte)3);
        }
Esempio n. 2
0
 static GarminEncoding()
 {
     foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
     {
         if (type.IsSubclassOf(typeof(GarminPacket)))
         {
             try
             {
                 GarminPacket garminPacket = (GarminPacket)type.GetConstructor(new Type[0]).Invoke(new object[0]);
                 if (garminPacket.Id == 161)
                 {
                     if (garminPacket is GarminFleetManagementPacket managementPacket)
                     {
                         garminFleetmanagementPacketIdToType[managementPacket.FleetManagementPacketId] = type;
                     }
                 }
                 else
                 {
                     garminPacketIdToType[garminPacket.Id] = type;
                 }
             }
             catch
             {
             }
         }
     }
 }
Esempio n. 3
0
 public byte[] Encode(GarminPacket packet)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         Encode(packet, memoryStream);
         memoryStream.Position = 0L;
         return(new BinaryReader(memoryStream).ReadBytes((int)memoryStream.Length));
     }
 }
Esempio n. 4
0
        private static byte CalcChecksum(GarminPacket packet)
        {
            byte num   = (byte)(packet.Id + (uint)packet.Payload.Length);
            int  index = 0;

            for (int length = packet.Payload.Length; index < length; ++index)
            {
                num += packet.Payload[index];
            }
            return((byte)((num ^ byte.MaxValue) + 1));
        }