Esempio n. 1
0
        public static ViofoGpsPoint Parse(IBufferReader reader, uint expectedSize)
        {
            long start = reader.Position;

            uint   size  = reader.ReadUintBE();
            string type  = reader.ReadString(4);
            string magic = reader.ReadString(4);

            if (expectedSize != size || type != "free" || magic != "GPS ")
            {
                return(null);
            }

            ViofoGpsPoint gps = new ViofoGpsPoint();

            //# checking for weird Azdome 0xAA XOR "encrypted" GPS data.
            //This portion is a quick fix.
            int  payload_size = 254;
            byte c            = reader.ReadByte();

            if (c == 0x05)
            {
                if (size < 254)
                {
                    payload_size = (int)+size;
                }

                reader.Position += 5; //???
                byte[] payload = reader.ReadBuffer(payload_size);
            }
            else if ((char)c == 'L')
            {
                const uint OFFSET_V2 = 48, OFFSET_V1 = 16;
                reader.Position = start + OFFSET_V2;

                //# Datetime data
                int hour   = (int)reader.ReadUintLE();
                int minute = (int)reader.ReadUintLE();
                int second = (int)reader.ReadUintLE();
                int year   = (int)reader.ReadUintLE();
                int month  = (int)reader.ReadUintLE();
                int day = (int)reader.ReadUintLE();

                try { gps.Date = new DateTime(2000 + year, month, day, hour, minute, second); }
                catch (Exception err) { Debug.WriteLine(err.ToString()); return(null); }

                //# Coordinate data
                char active = (char)reader.ReadByte();
                gps.IsActive = (active == 'A');

                gps.Latitude_hemisphere   = (char)reader.ReadByte();
                gps.Longtitude_hemisphere = (char)reader.ReadByte();
                gps.Unknown = reader.ReadByte();

                float lat = reader.ReadFloatLE();
                gps.Latitude = FixCoordinate(lat, gps.Latitude_hemisphere);

                float lon = reader.ReadFloatLE();
                gps.Longtitude = FixCoordinate(lon, gps.Longtitude_hemisphere);

                gps.Speed   = reader.ReadFloatLE();
                gps.Bearing = reader.ReadFloatLE();

                return(gps);
            }

            return(null);
        }