Beispiel #1
0
        public DebuggerClient(MainWindowViewModel viewModel)
        {
            _packetValidator = new PacketValidator();
            _viewModel       = viewModel;

            _packetValidator = new PacketValidator();
            _packetsFactory  = new PacketsFactory();

            _packetHandler = new Dictionary <PacketType, PacketHandlerBase>
            {
                { PacketType.Registers, new RegistersHandler(viewModel) },
                { PacketType.Pins, new PinsHandler(viewModel) },
                { PacketType.Cycles, new CyclesHandler(viewModel) },
                { PacketType.Memory, new MemoryHandler(viewModel) }
            };

            _pinsRequestPacketGenerator            = new PinsRequestPacketGenerator();
            _pinsPacketGenerator                   = new PinsPacketGenerator();
            _registersRequestPacketGenerator       = new RegistersRequestPacketGenerator();
            _registersPacketGenerator              = new RegistersPacketGenerator();
            _cyclesRequestPacketGenerator          = new CyclesRequestPacketGenerator();
            _stopCommandPacketGenerator            = new StopCommandPacketGenerator();
            _continueCommandPacketGenerator        = new ContinueCommandPacketGenerator();
            _nextCycleCommandPacketGenerator       = new NextCycleCommandPacketGenerator();
            _nextInstructionCommandPacketGenerator = new NextInstructionCommandPacketGenerator();
            _memoryRequestPacketGenerator          = new MemoryRequestPacketGenerator();
            _runToAddressCommandPacketGenerator    = new RunToAddressCommandPacketGenerator();
            _runUntilLoopCommandPacketGenerator    = new RunUntilLoopCommandPacketGenerator();
        }
        private async Task Receiving()
        {
            DebugUtil.LogNormal <GsTcpClient>(
                Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command, "Receiving",
                "GsTcpClient -> Start Receiving...");

            while (IsConnected())
            {
                try
                {
                    BufferReceivedBytes += await _clientStream.ReadAsync(Buffer, BufferOffset,
                                                                         Buffer.Length - BufferOffset, OperationCancellationToken.Token);

                    if (!IsConnected())
                    {
                        break;
                    }

                    DataBuilder.Append(Encoding.UTF8.GetString(Buffer, BufferOffset, BufferReceivedBytes));
                    var packets = PacketValidator.ValidateDataAndReturn(DataBuilder);

                    foreach (var packet in packets)
                    {
                        OnDataReceived(new SocketDataReceived
                        {
                            Packet = PacketDeserializer.Deserialize(packet, Key, Type == GSLiveType.Command)
                        });
                    }

                    BufferReceivedBytes = 0;
                }
                catch (Exception e)
                {
                    if (!(e is OperationCanceledException || e is ObjectDisposedException ||
                          e is ArgumentOutOfRangeException))
                    {
                        e.LogException <GsTcpClient>(
                            Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command,
                            "Receiving");

                        OnClosed(new ErrorArg {
                            Error = e.ToString()
                        });
                    }

                    break;
                }
            }

            DebugUtil.LogNormal <GsTcpClient>(
                Type == GSLiveType.TurnBased ? DebugLocation.TurnBased : DebugLocation.Command, "Receiving",
                "GsTcpClient -> Receiving Done!");
        }
Beispiel #3
0
        public XModemToolFactory()
        {
            int polynomial = XModemProtocolConfigurationSection.Settings.Polynomial.Value;

            _table = new LookUpTable(polynomial);
            _normalChecksumValidator = new NormalChecksumValidator(_calculator);
            _validator           = new PacketValidator(_normalChecksumValidator);
            _normalPacketBuilder = new NormalPacketBuilder(_calculator);

            _checksumTool = new XModemTool {
                Builder   = _normalPacketBuilder,
                Validator = _validator
            };

            TableChanged();
        }
Beispiel #4
0
        void TableChanged()
        {
            _cRCCalculator        = new CRCChecksumCalculator(_table);
            _crcChecksumValidator = new CRCChecksumValidator(_cRCCalculator);
            _CRCvalidator         = new PacketValidator(_crcChecksumValidator);

            _CRCPacketBuilder  = new CRCPacketBuilder(_cRCCalculator);
            _oneKPacketBuilder = new OneKPacketBuilder(_cRCCalculator);

            _oneKTool = new XModemTool {
                Builder   = _oneKPacketBuilder,
                Validator = _CRCvalidator
            };

            _CRCTool = new XModemTool {
                Builder   = _CRCPacketBuilder,
                Validator = _CRCvalidator
            };
        }
            public void PacketInvalidReturnsFalse()
            {
                /*
                 * hdr len seq sys cmp id   payload (len 9)------------------  crc---
                 * 0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f  10
                 * FE  09  4E  01  01  00  01  00  00  00  02  03  51  04  03  1C  7F
                 */
                Packet invalidPacket = new Packet
                {
                    PayloadLength  = 0x09,
                    SequenceNumber = 0x4E,
                    SystemId       = 0x01,
                    ComponentId    = 0x01,
                    MessageId      = MessageId.Heartbeat,
                    Payload        = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x02, 0x03, 0x51, 0x04, 0x03 },
                    Checksum       = new byte[] { 0x1C, 0x7F }
                };

                bool result = PacketValidator.Validate(invalidPacket);

                Assert.AreEqual(false, result);
            }
Beispiel #6
0
        public DebuggerServer(M6502Core core, ushort port)
        {
            _port            = port;
            _packetValidator = new PacketValidator();
            _packetsFactory  = new PacketsFactory();

            _packetHandler = new Dictionary <PacketType, PacketHandlerBase>
            {
                { PacketType.RegistersRequest, new RegistersRequestHandler(core) },
                { PacketType.Registers, new RegistersHandler(core) },
                { PacketType.PinsRequest, new PinsRequestHandler(core) },
                { PacketType.Pins, new PinsHandler(core) },
                { PacketType.CyclesRequest, new CyclesRequestHandler(core) },
                { PacketType.StopCommand, new StopCommandHandler(core) },
                { PacketType.ContinueCommand, new ContinueCommandHandler(core) },
                { PacketType.NextCycleCommand, new NextCycleCommandHandler(core) },
                { PacketType.NextInstructionCommand, new NextInstructionCommandHandler(core) },
                { PacketType.MemoryRequest, new MemoryRequestHandler(core) },
                { PacketType.RunToAddressCommand, new RunToAddressCommandHandler(core) },
                { PacketType.RunUntilLoopCommand, new RunUntilLoopCommandHandler(core) }
            };
        }
            public void GetChechsumReturnsCorrectCrc()
            {
                /*
                 * hdr len seq sys cmp id   payload (len 9)------------------  crc---
                 * 0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f  10
                 * FE  09  4E  01  01  00  00  00  00  00  02  03  51  04  03  1C  7F
                 */
                Packet packetWithoutChecksum = new Packet
                {
                    PayloadLength  = 0x09,
                    SequenceNumber = 0x4E,
                    SystemId       = 0x01,
                    ComponentId    = 0x01,
                    MessageId      = MessageId.Heartbeat,
                    Payload        = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x51, 0x04, 0x03 },
                    Checksum       = new byte[] { 0x00, 0x00 }
                };

                byte[] expectedChecksum = { 0x1C, 0x7F };

                byte[] checksum = PacketValidator.GetChecksum(packetWithoutChecksum);

                Assert.AreEqual(expectedChecksum, checksum);
            }
 public void PacketNullThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => PacketValidator.Validate(null));
 }