Esempio n. 1
0
        /// <summary>
        /// Decode Gps element
        /// </summary>
        /// <returns></returns>
        private GpsElement DecodeGpsElement()
        {
            var longitude  = _reader.ReadInt32();
            var latitude   = _reader.ReadInt32();
            var altitude   = _reader.ReadInt16();
            var angle      = _reader.ReadInt16();
            var satellites = _reader.ReadByte();
            var speed      = _reader.ReadInt16();

            return(GpsElement.Create(longitude, latitude, altitude, speed, angle, satellites));
        }
Esempio n. 2
0
        /// <summary>
        /// Decode single AVL data
        /// </summary>
        /// <returns></returns>
        private AvlData DecodeAvlData()
        {
            var priorityAndTimestamp = _reader.ReadInt32();

            // priority
            var priorityMapIndex = 0x03 & (priorityAndTimestamp >> 30);
            var priority         = (GhAvlDataPriority)priorityMapIndex;

            // timestamp
            var timestamp = (long)(priorityAndTimestamp & 0x3FFFFFFF);
            var dateTime  = GHepoch.AddSeconds(timestamp);

            var eventId = 0;

            IoProperty?alarmProperty = null;

            if (priority == GhAvlDataPriority.Alarm)
            {
                eventId       = Constants.AlarmPropertyId;
                alarmProperty = IoProperty.Create(Constants.AlarmPropertyId, 1);
            }

            // global mask Codec7
            var mask = (GlobalMaskCodec7)_reader.ReadByte();

            var gps = GpsElement.Default;

            var gpsIo = new IoElement();


            if (mask.HasFlag(GlobalMaskCodec7.GpsElement))
            {
                var element = DecodeGpsElement();
                gps   = element.GPS;
                gpsIo = element.IO;
            }

            var ioInt8  = GetProperties(mask, GlobalMaskCodec7.IoInt8, FieldEncoding.Int8);
            var ioInt16 = GetProperties(mask, GlobalMaskCodec7.IoInt16, FieldEncoding.Int16);
            var ioInt32 = GetProperties(mask, GlobalMaskCodec7.IoInt32, FieldEncoding.Int32);

            var properties = new List <IoProperty>();

            if (alarmProperty != null)
            {
                properties.Add(alarmProperty.Value);
            }

            properties.AddRange(gpsIo.Properties);

            properties.AddRange(ioInt8 ?? Enumerable.Empty <IoProperty>());
            properties.AddRange(ioInt16 ?? Enumerable.Empty <IoProperty>());
            properties.AddRange(ioInt32 ?? Enumerable.Empty <IoProperty>());

            var ioElement = IoElement.Create(eventId, properties.Count(), properties);

            return(AvlData.Create(priority.ToString(), dateTime, gps, ioElement));
        }