Пример #1
0
        public void GetBytesFromInt_Functions_Correctly()
        {
            for (int i = 0; i < Math.Pow(2, 14); i++)
            {
                byte lsb, msb;
                BitHelper.IntToBytes(i, out lsb, out msb);
                var bytes = BitHelper.GetBytesFromInt(i).ToArray();
                Assert.AreEqual(bytes, new byte[] { lsb, msb });
            }

            // 1011010101011001 -> B559 -> 46425
            var newBytes = BitHelper.GetBytesFromInt(46425).ToArray();

            Assert.AreEqual(newBytes[0], 0xB559 & 0x7f);
            Assert.AreEqual(newBytes[1], 0xB559 >> 7 & 0x7f);
            Assert.AreEqual(newBytes[2], 0xB559 >> 14 & 0x7f);
        }
        public override byte[] CreateMessage(SamplingIntervalMessage message)
        {
            if (message == null)
            {
                throw new MessageCreatorException("This is not a valid Sampling Interval Message");
            }

            var bytes = new List <byte>()
            {
                MessageConstants.SYSEX_START,
                SysexCommands.SAMPLING_INTERVAL,
            };

            bytes.AddRange(BitHelper.GetBytesFromInt(message.Interval));
            bytes.Add(MessageConstants.SYSEX_END);

            return(bytes.ToArray());
        }
        public override byte[] CreateMessage(ExtendedAnalogMessage message)
        {
            if (message == null)
            {
                throw new MessageCreatorException("This is not an Extended Analog message");
            }

            if (message.Pin > MessageConstants.MAX_PINS)
            {
                throw new MessageCreatorException("Pin should be less than " + MessageConstants.MAX_PINS);
            }

            var bytes = new List <byte> {
                MessageConstants.SYSEX_START, SysexCommands.EXTENDED_ANALOG, message.Pin
            };

            bytes.AddRange(BitHelper.GetBytesFromInt(message.Value));
            bytes.Add(MessageConstants.SYSEX_END);

            return(bytes.ToArray());
        }
Пример #4
0
        public override byte[] CreateMessage(ServoConfigMessage message)
        {
            if (message == null)
            {
                throw new MessageCreatorException("This is not a valid Servo Config Message");
            }

            var bytes = new List <byte>
            {
                MessageConstants.SYSEX_START,
                SysexCommands.SERVO_CONFIG,
                message.Pin
            };

            bytes.AddRange(BitHelper.GetBytesFromInt(message.MinPulse));
            bytes.AddRange(BitHelper.GetBytesFromInt(message.MaxPulse));
            bytes.AddRange(BitHelper.GetBytesFromInt(message.Angle));
            bytes.Add(MessageConstants.SYSEX_END);

            return(bytes.ToArray());
        }