public void TestAnalogOffsetSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            int expectedOffset = 6;

            var pins = new List<MockPin>();
            // We setup the board to have 10 total pins
            // on the 6th pin we start inserting analog pins
            for (uint i = 0; i < 10; i++)
            {
                var pin = new MockPin(i);

                if (i >= expectedOffset)
                    pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.ANALOG, 1));

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            // Assert
            Assert.AreEqual(expectedOffset, deviceUnderTest.DeviceHardwareProfile.AnalogOffset, "Total analog pin count on device was not communicated properly");
        }
        public void TestAnalogPinCountSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            int totalExpectedPins = 10;

            var pins = new List<MockPin>();
            for (uint i = 0; i < totalExpectedPins; i++)
            {
                var pin = new MockPin(i);
                pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.ANALOG, 1));
                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            // Assert
            Assert.AreEqual(totalExpectedPins, deviceUnderTest.DeviceHardwareProfile.AnalogPinCount, "Total analog pin count on device was not communicated properly");
        }
        public void TestAnalogPinSetModeSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            var expectedPinMode = PinMode.ANALOG;

            var pin = new MockPin(0);

            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.ANALOG, 1));

            var board = new MockBoard(new List <MockPin>()
            {
                pin
            });

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            deviceUnderTest.pinMode("A0", PinMode.ANALOG);

            // Assert
            Assert.AreEqual(expectedPinMode, deviceUnderTest.getPinMode("A0"), "Pin mode was not set properly");
        }
        public void TestDigitalPinSetModeSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            var expectedPinMode = PinMode.INPUT;
            byte pinUnderTest = 0;

            var pin = new MockPin(0);

            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.INPUT, 1));
            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.PULLUP, 1));
            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.OUTPUT, 1));

            var board = new MockBoard(new List<MockPin>() { pin });

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            deviceUnderTest.pinMode(pinUnderTest, expectedPinMode);
            var actualPinMode = deviceUnderTest.getPinMode(pinUnderTest);

            // Assert
            Assert.AreEqual(expectedPinMode, actualPinMode, "Pin mode was not set properly in cache");
            Assert.AreEqual(expectedPinMode, board.Pins[pinUnderTest].CurrentMode, "Pin mode was communicated to board properly");
        }
        public async Task TestDigitalPinReadValueSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            var pinMode = PinMode.INPUT;
            byte pinUnderTest = 0;
            PinState expectedPinState = PinState.HIGH;

            var pin = new MockPin(pinUnderTest);

            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.INPUT, 1));
            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.PULLUP, 1));
            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.OUTPUT, 1));

            var board = new MockBoard(new List<MockPin>() { pin });

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            deviceUnderTest.pinMode(pinUnderTest, pinMode);

            board.Pins[pinUnderTest].CurrentValue = (ushort)expectedPinState;

            // Wait for the mock board to report the state change
            await Task.Delay(100);

            var actualPinState = deviceUnderTest.digitalRead(pinUnderTest);

            // Assert
            Assert.AreEqual(expectedPinState, actualPinState, "Pin state was incorrect");
        }
        public void TestAnalogOffsetSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            int expectedOffset = 6;

            var pins = new List <MockPin>();

            // We setup the board to have 10 total pins
            // on the 6th pin we start inserting analog pins
            for (uint i = 0; i < 10; i++)
            {
                var pin = new MockPin(i);

                if (i >= expectedOffset)
                {
                    pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.ANALOG, 1));
                }

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            // Assert
            Assert.AreEqual(expectedOffset, deviceUnderTest.DeviceHardwareProfile.AnalogOffset, "Total analog pin count on device was not communicated properly");
        }
        public void TestTotalPinCountSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            int totalExpectedPins = 10;

            var pins = new List <MockPin>();

            for (uint i = 0; i < totalExpectedPins; i++)
            {
                var pin = new MockPin(i);

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            // Assert
            Assert.AreEqual(totalExpectedPins, deviceUnderTest.DeviceHardwareProfile.TotalPinCount, "Total pin count on device was not communicated properly");
        }
        public void TestPinCapabilityNoneSupportedSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            int totalExpectedPins = 1;

            var pins = new List <MockPin>();

            for (uint i = 0; i < totalExpectedPins; i++)
            {
                var pin = new MockPin(i);

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            // Assert
            Assert.AreEqual(totalExpectedPins, deviceUnderTest.DeviceHardwareProfile.TotalPinCount, "Total pin count on device was not communicated properly");

            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isAnalogSupported(0), "isAnalogSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isDigitalInputSupported(0), "isDigitalInputSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isDigitalInputPullupSupported(0), "isDigitalInputPullupSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isDigitalOutputSupported(0), "isDigitalOutputSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isI2cSupported(0), "isI2cSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isPwmSupported(0), "isPwmSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isServoSupported(0), "isServoSupported did not get set properly");
        }
        public void TestDigitalPinSetModeSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            var  expectedPinMode = PinMode.INPUT;
            byte pinUnderTest    = 0;

            var pin = new MockPin(0);

            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.INPUT, 1));
            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.PULLUP, 1));
            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.OUTPUT, 1));

            var board = new MockBoard(new List <MockPin>()
            {
                pin
            });

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            deviceUnderTest.pinMode(pinUnderTest, expectedPinMode);
            var actualPinMode = deviceUnderTest.getPinMode(pinUnderTest);

            // Assert
            Assert.AreEqual(expectedPinMode, actualPinMode, "Pin mode was not set properly in cache");
            Assert.AreEqual(expectedPinMode, board.Pins[pinUnderTest].CurrentMode, "Pin mode was communicated to board properly");
        }
        public async Task TestDigitalPinReadValueSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            var      pinMode          = PinMode.INPUT;
            byte     pinUnderTest     = 0;
            PinState expectedPinState = PinState.HIGH;

            var pin = new MockPin(pinUnderTest);

            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.INPUT, 1));
            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.PULLUP, 1));
            pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.OUTPUT, 1));

            var board = new MockBoard(new List <MockPin>()
            {
                pin
            });

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            deviceUnderTest.pinMode(pinUnderTest, pinMode);

            board.Pins[pinUnderTest].CurrentValue = (ushort)expectedPinState;

            // Wait for the mock board to report the state change
            await Task.Delay(100);

            var actualPinState = deviceUnderTest.digitalRead(pinUnderTest);

            // Assert
            Assert.AreEqual(expectedPinState, actualPinState, "Pin state was incorrect");
        }
Beispiel #11
0
        public void TestAnalogPinSetModeSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            var expectedPinMode = PinMode.ANALOG;

            var pin = new MockPin(0);

            pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.ANALOG, 1));

            var board = new MockBoard(new List<MockPin>() { pin });

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            deviceUnderTest.pinMode("A0", PinMode.ANALOG);

            // Assert
            Assert.AreEqual(expectedPinMode, deviceUnderTest.getPinMode("A0"), "Pin mode was not set properly");
        }
        public void TestPinCapabilityNoneSupportedSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            int totalExpectedPins = 1;

            var pins = new List<MockPin>();
            for (uint i = 0; i < totalExpectedPins; i++)
            {
                var pin = new MockPin(i);

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            // Assert
            Assert.AreEqual(totalExpectedPins, deviceUnderTest.DeviceHardwareProfile.TotalPinCount, "Total pin count on device was not communicated properly");

            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isAnalogSupported(0), "isAnalogSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isDigitalInputSupported(0), "isDigitalInputSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isDigitalInputPullupSupported(0), "isDigitalInputPullupSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isDigitalOutputSupported(0), "isDigitalOutputSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isI2cSupported(0), "isI2cSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isPwmSupported(0), "isPwmSupported did not get set properly");
            Assert.IsFalse(deviceUnderTest.DeviceHardwareProfile.isServoSupported(0), "isServoSupported did not get set properly");
        }
        public void TestPinArraysProperlyPopulatedSuccess()
        {
            // Arrange
            RemoteDevice deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper = new RemoteDeviceHelper();
            int totalExpectedPins = 10;
            int totalExpectedAnalogPins = 1;
            int totalExpectedDigitalPins = 2;
            int totalExpectedI2cPins = 3;
            int totalExpectedPwmPins = 4;
            int totalExpectedServoPins = 5;

            // Since we only have 5 pins with capabilities the left over will be disabled
            int totalExpectedDisabledPins = totalExpectedPins - totalExpectedServoPins;

            var pins = new List<MockPin>();
            for (uint i = 0; i < totalExpectedPins; i++)
            {
                var pin = new MockPin(i);

                if (i < totalExpectedAnalogPins)
                    pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.ANALOG, 1));

                if (i < totalExpectedDigitalPins)
                    pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.OUTPUT, 1));

                if (i < totalExpectedI2cPins)
                    pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.I2C, 1));

                if (i < totalExpectedPwmPins)
                    pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.PWM, 1));

                if (i < totalExpectedServoPins)
                    pin.SupportedModes.Add(new KeyValuePair<PinMode, ushort>(PinMode.SERVO, 1));

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return deviceHelper.DeviceState == DeviceState.Ready; }, 100000);

            // Assert
            Assert.AreEqual(totalExpectedPins, deviceUnderTest.DeviceHardwareProfile.TotalPinCount, "Total pin count on device was not communicated properly");

            Assert.AreEqual(totalExpectedAnalogPins, deviceUnderTest.DeviceHardwareProfile.AnalogPins.Count(), "Analog pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedDigitalPins, deviceUnderTest.DeviceHardwareProfile.DigitalPins.Count(), "Digital pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedDisabledPins, deviceUnderTest.DeviceHardwareProfile.DisabledPins.Count(), "Disabled pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedI2cPins, deviceUnderTest.DeviceHardwareProfile.I2cPins.Count(), "I2c pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedPwmPins, deviceUnderTest.DeviceHardwareProfile.PwmPins.Count(), "Pwm pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedServoPins, deviceUnderTest.DeviceHardwareProfile.ServoPins.Count(), "Servo pins were not correctly enumerated");
        }
        public void TestPinArraysProperlyPopulatedSuccess()
        {
            // Arrange
            RemoteDevice       deviceUnderTest = null;
            RemoteDeviceHelper deviceHelper    = new RemoteDeviceHelper();
            int totalExpectedPins        = 10;
            int totalExpectedAnalogPins  = 1;
            int totalExpectedDigitalPins = 2;
            int totalExpectedI2cPins     = 3;
            int totalExpectedPwmPins     = 4;
            int totalExpectedServoPins   = 5;

            // Since we only have 5 pins with capabilities the left over will be disabled
            int totalExpectedDisabledPins = totalExpectedPins - totalExpectedServoPins;

            var pins = new List <MockPin>();

            for (uint i = 0; i < totalExpectedPins; i++)
            {
                var pin = new MockPin(i);

                if (i < totalExpectedAnalogPins)
                {
                    pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.ANALOG, 1));
                }

                if (i < totalExpectedDigitalPins)
                {
                    pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.OUTPUT, 1));
                }

                if (i < totalExpectedI2cPins)
                {
                    pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.I2C, 1));
                }

                if (i < totalExpectedPwmPins)
                {
                    pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.PWM, 1));
                }

                if (i < totalExpectedServoPins)
                {
                    pin.SupportedModes.Add(new KeyValuePair <PinMode, ushort>(PinMode.SERVO, 1));
                }

                pins.Add(pin);
            }
            var board = new MockBoard(pins);

            // Act
            deviceUnderTest = deviceHelper.CreateDeviceUnderTestAndConnect(board);

            // Wait until the mock board is ready
            SpinWait.SpinUntil(() => { return(deviceHelper.DeviceState == DeviceState.Ready); }, 100000);

            // Assert
            Assert.AreEqual(totalExpectedPins, deviceUnderTest.DeviceHardwareProfile.TotalPinCount, "Total pin count on device was not communicated properly");

            Assert.AreEqual(totalExpectedAnalogPins, deviceUnderTest.DeviceHardwareProfile.AnalogPins.Count(), "Analog pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedDigitalPins, deviceUnderTest.DeviceHardwareProfile.DigitalPins.Count(), "Digital pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedDisabledPins, deviceUnderTest.DeviceHardwareProfile.DisabledPins.Count(), "Disabled pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedI2cPins, deviceUnderTest.DeviceHardwareProfile.I2cPins.Count(), "I2c pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedPwmPins, deviceUnderTest.DeviceHardwareProfile.PwmPins.Count(), "Pwm pins were not correctly enumerated");
            Assert.AreEqual(totalExpectedServoPins, deviceUnderTest.DeviceHardwareProfile.ServoPins.Count(), "Servo pins were not correctly enumerated");
        }