Beispiel #1
0
        /// <summary>
        /// Decode Gps element
        /// </summary>
        /// <returns></returns>
        private GpsElementExt DecodeGpsElement()
        {
            var mask = (GpsElementMaskCodec7)_reader.ReadByte();

            float x = 0;
            float y = 0;

            if (mask.HasFlag(GpsElementMaskCodec7.Coordinates))
            {
                var lat = EndianBitConverter.Int32ToSingle(_reader.ReadInt32());
                var lng = EndianBitConverter.Int32ToSingle(_reader.ReadInt32());

                if (!GpsElement.IsLatValid(lat))
                {
                    lat = 0;
                }
                if (!GpsElement.IsLngValid(lng))
                {
                    lng = 0;
                }

                y = lat;
                x = lng;
            }

            short altitude = 0;

            if (mask.HasFlag(GpsElementMaskCodec7.Altitude))
            {
                altitude = _reader.ReadInt16();
            }

            short angle = 0;

            if (mask.HasFlag(GpsElementMaskCodec7.Angle))
            {
                angle = (short)Math.Round(((double)_reader.ReadByte() * 360 / 256));
            }

            short speed = 0;

            if (mask.HasFlag(GpsElementMaskCodec7.Speed))
            {
                speed = _reader.ReadByte();
            }

            var satellites = mask.HasFlag(GpsElementMaskCodec7.Satellites) ? _reader.ReadByte() : (byte)3;

            var properties = new List <IoProperty>(3);

            if (mask.HasFlag(GpsElementMaskCodec7.CellId))
            {
                var cellId = _reader.ReadInt32();
                properties.Add(IoProperty.Create(Constants.CellIdPropertyId, cellId));
            }

            if (mask.HasFlag(GpsElementMaskCodec7.SignalQuality))
            {
                var signalQuality = _reader.ReadByte();
                properties.Add(IoProperty.Create(Constants.SignalQualityPropertyId, signalQuality));
            }

            if (mask.HasFlag(GpsElementMaskCodec7.OperatorCode))
            {
                var code = _reader.ReadInt32();
                properties.Add(IoProperty.Create(Constants.OperatorCodePropertyId, code));
            }

            // set the N/A position if it's not available
            if (x == 0 && y == 0)
            {
                speed      = GpsElement.InvalidGpsSpeed;
                satellites = 0;
            }

            var gps = GpsElement.Create(x, y, altitude, speed, angle, satellites);

            var io = IoElement.Create(0, properties.Count, properties);

            return(new GpsElementExt(gps: gps, io: io));
        }