Ejemplo n.º 1
0
 /// <summary>
 /// Creates an instance with the specified values
 /// </summary>
 public NavigationStatus()
 {
     Fix     = FixStatus.NoFix;
     Flags   = new BitField8();
     Flags2  = new BitField8();
     FixStat = new BitField8();
 }
        /// <summary>
        /// Creates a new BitField from the specified array of bytes.
        /// </summary>
        /// <param name="data">The array of bytes to create the BitField from.</param>
        /// <returns></returns>
        public new static BitField8 FromBytes(byte[] data)
        {
            var bf = new BitField8();

            Array.Copy(data, bf._field, data.Length);
            return(bf);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        private object Read(Type type, int size = 0)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            BinaryReader reader = BinaryReader;

            if (type == typeof(byte)) //U1
            {
                return(reader.ReadByte());
            }
            else if (type == typeof(byte[])) //CH
            {
                return(reader.ReadBytes(size));
            }
            else if (type == typeof(short)) //I2
            {
                return(reader.ReadInt16());
            }
            else if (type == typeof(ushort)) //U2
            {
                return(reader.ReadUInt16());
            }
            else if (type == typeof(long) || type == typeof(int)) //I4
            {
                return(reader.ReadInt32());
            }
            else if (type == typeof(ulong) || type == typeof(uint)) //U4
            {
                return(reader.ReadUInt32());
            }
            else if (type == typeof(float)) //R4
            {
                return(reader.ReadSingle());
            }
            else if (type == typeof(double)) //R8
            {
                return(reader.ReadDouble());
            }
            else if (type == typeof(BitField8)) //X1
            {
                return(BitField8.FromBytes(reader.ReadBytes(1)));
            }
            else if (type == typeof(BitField16)) //X2
            {
                return(BitField16.FromBytes(reader.ReadBytes(2)));
            }
            else if (type == typeof(BitField32)) //X4
            {
                return(BitField32.FromBytes(reader.ReadBytes(4)));
            }
            else
            {
                throw new NotSupportedException(nameof(type));
            }
        }
 /// <summary>
 /// Creates an instance with the specified values
 /// </summary>
 public ReceiverStatus()
 {
     Flags = new BitField8();
 }