示例#1
0
        private bool QueueProcessor()
        {
            if (KillMe)
            {
                return(true);
            }
            var queue = new List <byte>();

            if (_recievedData.Count != 0)
            {
                var f = DeQueueByte(); //_recievedData.Dequeue();
                if (f == 0xE0)
                {
                    var  count = 0;
                    byte size  = 0;
                    while (true)
                    {
                        if (KillMe)
                        {
                            return(true);
                        }
                        if (count == 0)
                        {
                            queue.Add(f);
                            count++;
                        }
                        else if (_recievedData.Count > 2 && count == 1)
                        {
                            queue.Add(DeQueueByte()); // _recievedData.Dequeue());
                            size = DeQueueByte();     //_recievedData.Dequeue();
                            queue.Add(size);
                            count++;
                        }
                        else if (count == 2 && _recievedData.Count >= size)
                        {
                            for (int i = 0; i < size; i++)
                            {
                                queue.Add(DeQueueByte()); //_recievedData.Dequeue());
                            }
                            //_lastPackage.Clear();
                            //_lastPackage.AddRange(queue);
                            var reply = JvsPackageEmulator.GetReply(queue.ToArray());
                            if (reply.Length != 0)
                            {
                                _stream.Write(reply, 0, reply.Length);
                                //Console.WriteLine(reply.Length);
                            }
                            break;
                        }
                    }
                }
            }
            Thread.Sleep(10);
            return(false);
        }
        public void JVS_RESET_ShouldReturnNothing()
        {
            // Arrange
            var requestBytes = JvsHelper.CraftJvsPackage((byte)JVSPacket.BROADCAST, new byte[] { (byte)JVSPacket.OP_RESET, 0xD9 });

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Empty(reply);
        }
        public void JVS_GET_IDENTIFIER_ShouldReturnIdentifier()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { (byte)JVSRead.ID_DATA });
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, Encoding.ASCII.GetBytes(JVSIdentifiers.Sega2005Jvs14572));

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_ADDRESS_2_ShouldReturnPackage()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage((byte)JVSPacket.BROADCAST, new byte[] { (byte)JVSPacket.OP_ADDRESS, 0x02 }); // 0x01 = Bus address
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { });

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_GENERALPURPOSEOUTPUT2_ShouldReturnJVSOK_REPORTOK()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { 0x32, 0x03, 0x00, 0x00, 0x00 });
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { });

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_GET_COMMUNICATIONVERSION_JVSVERSION_COMMANDREV_ShouldReturnRightValues()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { 0x13, 0x12, 0x11 });
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x10, 0x01, 0x20, 0x01, 0x13 });

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_GET_COMMUNICATIONVERSION_ShouldReturnVersionTwoPointZero()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { 0x13 });
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x10 }); // Version 1.0

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_GET_COMMANDREV_ShouldReturnVersionOnePointThree()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { 0x11 });
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x13 }); // Revision 1.3

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_READ_COIN_ShouldReturnOneCoinSlotWithOkStatus(byte slots, byte[] expected)
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new[] { (byte)JVSRead.COIN, slots }); // 22 = Request coin slots, 1 slot
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, expected);         // Coin Normal Operation, 0 coins inserted.

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_GETMULTIPLEPACKAGES_ShouldReturnJVSOK_REPORTOK()
        {
            // Arrange
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { 0x20, 0x02, 0x02, 0x32, 0x03, 0x00, 0x00, 0x00, 0x30, 0x01, 0xf0, 0x0d, 0x21, 0x02, 0x22, 0x08 });
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { });

            // Act
            var    reply = JvsPackageEmulator.GetReply(requestBytes);
            string str   = "";

            foreach (var b in reply)
            {
                str += b.ToString("X2") + " ";
            }
            Console.WriteLine(reply);
        }
        public void JVS_READ_DIGINAL_ShouldReturnPlayerOne()
        {
            // Arrange
            InputCode.PlayerDigitalButtons[0].Button1 = true;
            InputCode.PlayerDigitalButtons[0].Test    = true;
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { (byte)JVSRead.DIGITAL, 0x01, 0x01 }); // 22 = REQUEST DIGITAL, 1 = Player Count, 1 Bytes Per Player
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x80, 0x02 });     // Special Switches, P1

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_GET_ANALOG_ShouldReturnThreeChannels()
        {
            // Arrange
            InputCode.AnalogBytes[0] = 0xBA;
            InputCode.AnalogBytes[2] = 0xBE;
            InputCode.AnalogBytes[4] = 0xBE;
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { (byte)JVSRead.ANALOG, 0x03 }); // 22 = REQUEST ANALOG, 3 = 3 Channels
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { (byte)InputCode.AnalogBytes[0], 0x00, (byte)InputCode.AnalogBytes[2], 0x00, (byte)InputCode.AnalogBytes[4], 0x00 });

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }
        public void JVS_READ_DIGINAL_READ_ANALOG_ShouldReturnPlayerOneAndPlayerTwoButtonsAndExtAndThreeAnalogChannels()
        {
            // Arrange
            InputCode.PlayerDigitalButtons[0].Button1 = true;
            InputCode.PlayerDigitalButtons[0].Button4 = true;
            InputCode.PlayerDigitalButtons[1].Button1 = true;
            InputCode.PlayerDigitalButtons[1].Button4 = true;
            InputCode.PlayerDigitalButtons[0].Test    = true;
            InputCode.AnalogBytes[0] = 0xBA;
            InputCode.AnalogBytes[2] = 0xBE;
            InputCode.AnalogBytes[4] = 0xBE;
            var requestBytes  = JvsHelper.CraftJvsPackage(1, new byte[] { (byte)JVSRead.DIGITAL, 0x02, 0x02, (byte)JVSRead.ANALOG, 0x03 });                                                                                                           // 22 = REQUEST DIGITAL, 2 = Player Count, 2 Bytes Per Player, 22 = REQUEST ANALOG, 3 = 3 Channels
            var espectedBytes = JvsHelper.CraftJvsPackageWithStatusAndReport(0, new byte[] { 0x80, 0x02, 0x40, 0x02, 0x40, 0x01, (byte)InputCode.AnalogBytes[0], 0x00, (byte)InputCode.AnalogBytes[2], 0x00, (byte)InputCode.AnalogBytes[4], 0x00 }); // Special Switches, P1, P1Ext, P2, P2Ext

            // Act
            var reply = JvsPackageEmulator.GetReply(requestBytes);

            // Assert
            Assert.NotNull(reply);
            Assert.Equal(reply.Length, espectedBytes.Length);
            Assert.True(reply.SequenceEqual(espectedBytes));
        }