public SerialPacketManager(SerialPort port, SerialConfig config) : this(port)
 {
     receiverStart = PACKET_SIZED_START_BYTE;
     if (config.RxPacketType == PacketType.SimpleCRC || config.RxPacketType == PacketType.SizedCRC || config.RxPacketType == PacketType.SizedCRC_old)
     {
         receiverCRCValue = config.ReceiverCRC;
     }
     if (config.TxPacketType == PacketType.SimpleCRC || config.TxPacketType == PacketType.SizedCRC || config.TxPacketType == PacketType.SizedCRC_old)
     {
         transmitterCRCValue = config.TransmitterCRC;
     }
     if (config.RxPacketType == PacketType.SizedOld || config.RxPacketType == PacketType.SizedCRC_old)
     {
         receiverEnd = PACKET_END_TRANSMIT;
     }
     if (config.TxPacketType == PacketType.SizedOld || config.TxPacketType == PacketType.SizedCRC_old)
     {
         transmitterEnd = PACKET_END_TRANSMIT;
     }
     if (config.RxPacketType == PacketType.Simple || config.RxPacketType == PacketType.SimpleCoded || config.RxPacketType == PacketType.SimpleCRC)
     {
         receiverStart = PACKET_UNSIZED_START_BYTE;
         receiverEnd = PACKET_END_TEXT;
     }
     if (config.TxPacketType == PacketType.Simple || config.TxPacketType == PacketType.SimpleCoded || config.TxPacketType == PacketType.SimpleCRC)
     {
         transmitterStart = PACKET_UNSIZED_START_BYTE;
         transmitterEnd = PACKET_END_TEXT;
     }
 }
Example #2
0
        internal static State Simulate(this State s, int transitionToUse = 0, params byte?[] inputChars)
        {
            if (inputChars == null)
                inputChars = new byte?[] {null};

            State currentState = s;
            int pos = 0;

            foreach (var inputChar in inputChars)
            {
                var ic = inputChar == null ? InputChar.Epsilon() : InputChar.For((byte) inputChar);
                List<State> transitions;
                if (!currentState.Transitions.TryGetValue(ic, out transitions))
                    ThrowSimulationException(inputChar, pos);

                if (transitions.Count > transitionToUse)
                {
                    currentState = transitions[transitionToUse];
                }
                else if (transitions.Count > 0)
                {
                    currentState = transitions[0];
                }
                else
                {
                    ThrowSimulationException(inputChar, pos);
                }
                pos++;
            }

            return currentState;
        }
Example #3
0
        public int GetMetadataLength()
        {
            if (this._streamId <= byte.MaxValue)
                this._slen = 0x00;
            else if (this._streamId <= ushort.MaxValue)
                this._slen = 0x01;
            else if (this._streamId <= 16777215)
                this._slen = 0x02;
            else
                this._slen = 0x03;

            if (this._offset == 0)
                this._olen = 0x00;
            else if (this._offset < 65536) // 16 bits
                this._olen = 0x01;
            else if (this._offset < 16777216) // 24 bits
                this._olen = 0x02;
            else if (this._offset < 4294967296) // 32 bits
                this._olen = 0x03;
            else if (this._offset < 1099511627776) // 40 bits
                this._olen = 0x04;
            else if (this._offset < 281474976710656) // 48 bits
                this._olen = 0x05;
            else if (this._offset < 72057594037927936) // 56 bits
                this._olen = 0x06;
            else // 64 bits
                this._olen = 0x07;

            // INFO: We're going to just always send data length (+2)
            this._metadataLength = 1 + (this._slen.Value + 1) * 8 + (this._olen.Value == 0 ? 0 : (this._olen.Value + 1) * 8) + 2;
            return this._metadataLength.Value;
        }
Example #4
0
 public HslPixel(float hue, float saturation, float luminance)
 {
     this.hue = hue;
     this.saturation = saturation;
     this.luminance = luminance;
     this.normalizedValue = null;
 }
Example #5
0
        public ID3v1Tag(byte[] bytes)
        {
            if (bytes.Length < TagLength || Encoding.ASCII.GetString(bytes, bytes.Length - TagLength, 3) != "TAG")
                throw new InvalidDataException("No ID3 tag found");

            ArraySegment<byte> tag = new ArraySegment<byte>(bytes, bytes.Length - TagLength, TagLength);

            _title = Encoding.ASCII.GetString(tag.Array, tag.Offset + TitleOffset, MaxFieldLength).TrimEnd('\0');
            _artist = Encoding.ASCII.GetString(tag.Array, tag.Offset + ArtistOffset, MaxFieldLength).TrimEnd('\0');
            _album = Encoding.ASCII.GetString(tag.Array, tag.Offset + AlbumOffset, MaxFieldLength).TrimEnd('\0');

            short year;
            if (short.TryParse(Encoding.ASCII.GetString(tag.Array, tag.Offset + YearOffset, 4), out year))
                _year = year;

            if (tag.Array[tag.Offset + TrackOffset - 1] == 0)
            {
                _comment = Encoding.ASCII.GetString(tag.Array, tag.Offset + CommentOffset, MaxFieldLength - 2).TrimEnd('\0');
                _track = tag.Array[tag.Offset + TrackOffset];
            }
            else
            {
                _comment = Encoding.ASCII.GetString(tag.Array, tag.Offset + CommentOffset, MaxFieldLength).TrimEnd('\0');
            }

            Genre = (Genre)tag.Array[tag.Offset + GenreOffset];
        }
 public override void Refresh(bool volatileOnly)
 {
     base.Refresh(volatileOnly);
     if (!volatileOnly)
         cachedFanData = null;
     ((ControllerBase)Controller).Refresh(this);
 }
Example #7
0
 public void FlushBits()
 {
     if (_buffer != null)
         Write(_buffer.Value);
     _buffer = null;
     _bufferPosition = 0;
 }
Example #8
0
        public byte ReadBits(int count)
        {
            Guard.ArgumentBetweenInclusive("count", count, 0, 8);

            if (_streamPositionAfterBitReading != this.BaseStream.Position) // there was byte reading operation
                ClearBuffer();

            if (_buffer == null || BitsInBuffer == 0)
            {
                _buffer = ReadByte();
                _bufferPosition = 0;
                _streamPositionAfterBitReading = this.BaseStream.Position;
            }

            byte result;
            if (BitsInBuffer >= count)
            {
                result = GetValueFromBuffer(count);
            }
            else
            {
                byte nextByteBitsCount = (byte) (count - BitsInBuffer);
                byte value = GetValueFromBuffer(BitsInBuffer);

                byte lowBits = ReadBits(nextByteBitsCount);
                result = (byte)((value << nextByteBitsCount) + lowBits);
            }
            return result;
        }
Example #9
0
 public Rgb(String Raw)
 {
     string[] val = Raw.Split(';');
     this.redByte = Convert.ToByte(val[0]);
     this.greenByte = Convert.ToByte(val[1]);
     this.blueByte = Convert.ToByte(val[2]);
 }
        private DateTimePropertyConfiguration(DateTimePropertyConfiguration source)
            : base(source)
        {
            Contract.Requires(source != null);

            Precision = source.Precision;
        }
        public void Setup()
        {
            //Instance Fields Setup
            BooleanField = null;
            ByteField = null;
            SByteField = null;
            IntField = null;
            LongField = null;
            Int16Field = null;
            UInt16Field = null;
            Int32Field = null;
            UInt32Field = null;
            Int64Field = null;
            UInt64Field = null;
            CharField = null;
            DoubleField = null;
            FloatField = null;

            //Static Fields Setup
            BooleanFieldStatic = null;
            ByteFieldStatic = null;
            SByteFieldStatic = null;
            IntFieldStatic = null;
            LongFieldStatic = null;
            Int16FieldStatic = null;
            UInt16FieldStatic = null;
            Int32FieldStatic = null;
            UInt32FieldStatic = null;
            Int64FieldStatic = null;
            UInt64FieldStatic = null;
            CharFieldStatic = null;
            DoubleFieldStatic = null;
            FloatFieldStatic = null;
        }
        private DateTimePropertyConfiguration(DateTimePropertyConfiguration source)
            : base(source)
        {
            DebugCheck.NotNull(source);

            Precision = source.Precision;
        }
Example #13
0
 public TileFrame(string tf)
 {
     TileFrame TF;
     TryParse(tf, out TF);
     _tile  = TF.Tile;
     _frame = TF.Frame;
 }
 public static void Draw(GameTime Time)
 {
     PrivateDrawFramesPerSecond++;
     SecondTimer += (float) Time.ElapsedGameTime.TotalSeconds;
     if (SecondTimer >= 1)
     {
         SecondTimer--;
         DrawFramesPerSecond = PrivateDrawFramesPerSecond;
         PrivateDrawFramesPerSecond = 0;
         if (DrawFramesPerSecondBuffer != null)
         {
             DrawFramesPerSecondBuffer[(DrawFramesPerSecondBufferIndex ?? (DrawFramesPerSecondBuffer.Length - 1))
                 ] = DrawFramesPerSecond;
             if (DrawFramesPerSecondBufferIndex == null) DrawFramesPerSecondBufferIndex = 0;
             else
             {
                 if (DrawFramesPerSecondBufferIndex >= (DrawFramesPerSecondBuffer.Length - 1))
                     DrawFramesPerSecondBufferIndex = null;
                 else DrawFramesPerSecondBufferIndex++;
             }
             if (DrawFramesPerSecondBufferRecorded < DrawFramesPerSecondBuffer.Length)
                 DrawFramesPerSecondBufferRecorded++;
         }
     }
 }
        private DecimalPropertyConfiguration(DecimalPropertyConfiguration source)
            : base(source)
        {
            DebugCheck.NotNull(source);

            Precision = source.Precision;
            Scale = source.Scale;
        }
 public static void CheckUnaryArithmeticNegateNullableByteTest(bool useInterpreter)
 {
     byte?[] values = new byte?[] { null, 0, 1, byte.MaxValue };
     for (int i = 0; i < values.Length; i++)
     {
         VerifyArithmeticNegateNullableByte(values[i], useInterpreter);
     }
 }
 public static void CheckUnaryBitwiseNotNullableByteTest()
 {
     byte?[] values = new byte?[] { null, 0, 1, byte.MaxValue };
     for (int i = 0; i < values.Length; i++)
     {
         VerifyBitwiseNotNullableByte(values[i]);
     }
 }
 public static void CheckUnaryArithmeticNegateCheckedNullableByteTest()
 {
     byte?[] values = new byte?[] { null, 0, 1, byte.MaxValue };
     for (int i = 0; i < values.Length; i++)
     {
         VerifyArithmeticNegateCheckedNullableByte(values[i]);
     }
 }
        private DecimalPropertyConfiguration(DecimalPropertyConfiguration source)
            : base(source)
        {
            Contract.Requires(source != null);

            Precision = source.Precision;
            Scale = source.Scale;
        }
    public static void Main()
    {
        // First variant
        // Console.WriteLine(Convert.ToString(number, 2));

        // Second variant
        byte?[] N = new byte?[32];                  // the number is type int, so the length is 32bits
        for (byte i = 0; i < N.Length; i++)         // fills the array with 0s
        {
            N[i] = 0;
        }
        Console.Write("Please, enter some integer number: ");
        Console.ForegroundColor = ConsoleColor.Yellow;
        int num = int.Parse(Console.ReadLine());
        Console.ResetColor();
        int temp = num;
        if (num < 0)                                // if the number is negative
        {
            num = int.MaxValue + num + 1;
            N[N.Length - 1] = 1;                    // sets 1 on the leftmost bit
        }
        while (num > 0)                             // checks where are the 1s
        {
            for (int i = 0; i < int.MaxValue; i++)
            {
                if (Math.Pow(2, i + 1) > num)       // this finds where has to be 1
                {
                    N[i] = 1;                       // sets 1 for this bit
                    num -= (int)Math.Pow(2, i);     // decrease the number by this bit
                    break;
                }
            }
        }
        Array.Reverse(N);                           // reverses the array
        for (int i = 0; i < N.Length; i++)          // removes the first 0s from positive numbers
        {
            if (N[i] == 0) N[i] = null;
            else break;
        }

        // Prints the result
        Console.Write("Binary representation of this number is: ");
        if (temp != 0)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            foreach (var item in N)
            {
                Console.Write(item);
            }
        }
        else
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(0);
        }
        Console.ResetColor();
        Console.WriteLine();
    }
Example #21
0
 public BasicMidiChordDef(BasicMidiChordDef original, int msDuration)
 {
     _msDuration = msDuration; // read-only!
     BankIndex = original.BankIndex;
     PatchIndex = original.PatchIndex;
     HasChordOff = original.HasChordOff;
     Pitches = new List<byte>(original.Pitches);
     Velocities = new List<byte>(original.Velocities);
 }
 internal override void CopyFrom(PrimitivePropertyConfiguration other)
 {
     base.CopyFrom(other);
     var strConfigRhs = other as DateTimePropertyConfiguration;
     if (strConfigRhs != null)
     {
         Precision = strConfigRhs.Precision;
     }
 }
Example #23
0
 /// <summary>
 /// Copies this object's properties from another
 /// </summary>
 /// <param name="other">The object to copy from</param>
 public override void CopyFrom(object other)
 {
     var di = other as DeviceInfo;
     if(di != null)
     {
         base.CopyFrom(di);
         this.DatabaseRevision = di.DatabaseRevision;
     }
 }
Example #24
0
        public PeekStream(Stream inner)
        {
            if (inner == null) {
                throw new ArgumentNullException("inner");
            }

            this.inner = inner;
            this.peek = null;
        }
 internal override void FillFrom(PrimitivePropertyConfiguration other, bool inCSpace)
 {
     base.FillFrom(other, inCSpace);
     var strConfigRhs = other as DateTimePropertyConfiguration;
     if (strConfigRhs != null
         && Precision == null)
     {
         Precision = strConfigRhs.Precision;
     }
 }
Example #26
0
 public ID3v1Tag()
 {
     _title = String.Empty;
     _artist = String.Empty;
     _album = String.Empty;
     _year = null;
     _comment = String.Empty;
     _track = null;
     Genre = Genre.None;
 }
 internal override void CopyFrom(PrimitivePropertyConfiguration other)
 {
     base.CopyFrom(other);
     var lenConfigRhs = other as DecimalPropertyConfiguration;
     if (lenConfigRhs != null)
     {
         Precision = lenConfigRhs.Precision;
         Scale = lenConfigRhs.Scale;
     }
 }
 public static void CheckNonLiftedComparisonEqualNullableByteTest(bool useInterpreter)
 {
     byte?[] values = new byte?[] { null, 0, 1, byte.MaxValue };
     for (int i = 0; i < values.Length; i++)
     {
         for (int j = 0; j < values.Length; j++)
         {
             VerifyComparisonEqualNullableByte(values[i], values[j], useInterpreter);
         }
     }
 }
 public static void CheckLiftedAddNullableByteTest()
 {
     byte?[] values = new byte?[] { null, 0, 1, byte.MaxValue };
     for (int i = 0; i < values.Length; i++)
     {
         for (int j = 0; j < values.Length; j++)
         {
             VerifyAddNullableByte(values[i], values[j]);
         }
     }
 }
 public static void CheckNullableBytePowerTest()
 {
     byte?[] array = new byte?[] { null, 0, 1, byte.MaxValue };
     for (int i = 0; i < array.Length; i++)
     {
         for (int j = 0; j < array.Length; j++)
         {
             VerifyNullableBytePower(array[i], array[j]);
         }
     }
 }