示例#1
0
        public void Device_Should_WriteCorrectData_WhenClientCycles()
        {
            MockIncrementingClientsHandler clients = new MockIncrementingClientsHandler(lights);

            rs232Device = CreateRS232Device(clients);

            rs232Device.Run(255);
            rs232Device.StopThread();

            MockSerialPort mockSerialPort = MockSerialPort.Instance;

            string[] expectedResults = File.ReadAllLines(Path.Combine(_resultsFolderPath, "RS232CycleResults.txt"));

            Assert.AreEqual(expectedResults.Length, mockSerialPort.Writes.Count);

            for (int i = 0; i < expectedResults.Length; i++)
            {
                string[] resultPieces = expectedResults[i].Split(" ");

                Assert.AreEqual(resultPieces.Length, mockSerialPort.Writes[i].Length);

                for (int j = 0; j < resultPieces.Length; j++)
                {
                    Assert.AreEqual(int.Parse(resultPieces[j], System.Globalization.NumberStyles.HexNumber), mockSerialPort.Writes[i][j]);
                }
            }
        }
示例#2
0
        public void SolidColorTest()
        {
            IChannelDataProvider solidColorCycler = new CycleSolidColorChannelProvider();

            rs232Device = CreateRS232Device(solidColorCycler);

            rs232Device.Run(255);
        }
示例#3
0
        public void WalkingTest()
        {
            WalkingChannelProvider solidColorCycler = new WalkingChannelProvider();

            rs232Device = CreateRS232Device(solidColorCycler);

            solidColorCycler.NumberOfLights = lights.Count;

            rs232Device.Run(255);
        }
示例#4
0
        public void TearDown()
        {
            if (rs232Device != null)
            {
                rs232Device.StopThread();
                rs232Device = null;
            }

            lights  = null;
            devices = null;
            config  = null;
        }
示例#5
0
        public void Device_Should_BeConfiguredCorrectly()
        {
            rs232Device = CreateRS232Device(new CClientsHandler(lights));

            Assert.AreEqual("AmbiLight", rs232Device.Name);
            Assert.AreEqual(CDevice.MOMO, rs232Device.Type);
            Assert.AreEqual("SerialPortMock", rs232Device.Output);
            Assert.AreEqual(3, rs232Device.NrChannels);
            Assert.AreEqual(new int[] { 0x41, 0x64, 0x61, 0x00, 0x18, 0x4D }, rs232Device.m_prefix);
            Assert.AreEqual(new int[] { 0xF, 0xE, 0xD, 0xC, 0xB, 0xA }, rs232Device.m_postfix);
            Assert.AreEqual(20000, rs232Device.Interval);
            Assert.AreEqual(115200, rs232Device.Rate);
            Assert.AreEqual(false, rs232Device.Debug);
            Assert.AreEqual(100000, rs232Device.DelayAfterOpen);
        }
示例#6
0
        public void Device_Should_WriteCorrectData_WhenNoClientsAreConnected()
        {
            CClientsHandler clients = new CClientsHandler(lights);

            rs232Device = CreateRS232Device(clients);

            rs232Device.Run(2);

            MockSerialPort mockSerialPort = MockSerialPort.Instance;

            Assert.AreEqual(START_WRITES + 2 + CLOSE_WRITES, mockSerialPort.Writes.Count);

            byte[] expectedBytes = { 0x41, 0x64, 0x61, 0x00, 0x18, 0x4D, 0, 0, 0, 0xF, 0xE, 0xD, 0xC, 0xB, 0xA };

            Assert.AreEqual(expectedBytes, mockSerialPort.Writes[3]);
            Assert.AreEqual(expectedBytes, mockSerialPort.Writes[4]);
        }
示例#7
0
        private bool SetDeviceMax(CDeviceRS232 device, int devicenr)
        {
            string line, strvalue;
            int    linenr = GetLineWithKey("max", m_devicelines[devicenr].lines, out line);

            if (linenr == -1)
            {
                return(false);
            }

            Util.GetWord(ref line, out strvalue);

            Int64 max;

            max          = Int64.Parse(strvalue);
            device.m_max = max;

            return(true);
        }
示例#8
0
        private bool SetDeviceBits(CDeviceRS232 device, int devicenr)
        {
            string line, strvalue;
            int    linenr = GetLineWithKey("bits", m_devicelines[devicenr].lines, out line);

            if (linenr == -1)
            {
                return(false);
            }

            Util.GetWord(ref line, out strvalue);

            int bits;

            bits         = int.Parse(strvalue);
            device.m_max = (1 << bits) - 1; //TODO: verify ((1 << (int64_t)bits) - 1);

            return(true);
        }
示例#9
0
        public void Device_Should_WriteCorrectData_WhenClientIsConnected()
        {
            MockEmptyClientsHandler clients = new MockEmptyClientsHandler(lights, new Dictionary <int, float>
            {
                { 1, 0xFF0000 },
                { 2, 0x00FF00 },
                { 3, 0x0000FF }
            });

            rs232Device = CreateRS232Device(clients);

            rs232Device.Run(2);

            MockSerialPort mockSerialPort = MockSerialPort.Instance;

            Assert.AreEqual(START_WRITES + 2 + CLOSE_WRITES, mockSerialPort.Writes.Count);

            byte[] expectedBytes = { 0x41, 0x64, 0x61, 0x00, 0x18, 0x4D, 0xFF, 0xFF, 0xFF, 0xF, 0xE, 0xD, 0xC, 0xB, 0xA };

            int targetDataRow = START_WRITES + 2;

            Assert.AreEqual(expectedBytes, mockSerialPort.Writes[targetDataRow - 1]);
        }
示例#10
0
        private bool BuildRS232(out CDevice device, int devicenr, IChannelDataProvider clients, string type)
        {
            CDeviceRS232 rs232device = new CDeviceRS232(clients);

            device = rs232device;

            if (!SetDeviceName(rs232device, devicenr))
            {
                return(false);
            }

            if (!SetDeviceOutput(rs232device, devicenr))
            {
                return(false);
            }

            if (!SetDeviceChannels(rs232device, devicenr))
            {
                return(false);
            }

            if (!SetDeviceRate(rs232device, devicenr))
            {
                return(false);
            }

            if (!SetDeviceInterval(rs232device, devicenr))
            {
                return(false);
            }

            SetDeviceAllowSync(device, devicenr);
            SetDeviceDebug(device, devicenr);
            SetDeviceDelayAfterOpen(device, devicenr);
            SetDeviceThreadPriority(device, devicenr);

            bool hasbits = SetDeviceBits(rs232device, devicenr);
            bool hasmax  = SetDeviceMax(rs232device, devicenr);

            if (hasbits && hasmax)
            {
                Util.LogError($"{m_filename}: device {rs232device.Name} has both bits and max set");
                return(false);
            }

            if (type == "momo")
            {
                device.Type = CDevice.MOMO;
                SetDevicePrefix(rs232device, devicenr);
                SetDevicePostfix(rs232device, devicenr);
            }
            else if (type == "atmo")
            {
                device.Type = CDevice.ATMO;
            }
            else if (type == "karate")
            {
                device.Type = CDevice.KARATE;
            }
            else if (type == "sedu")
            {
                device.Type = CDevice.SEDU;
            }

            return(true);
        }