示例#1
0
        private static bool VerifyBlock(IProgrammer programmer, HexBlock block, AvrMemoryType memType, DeviceOperation op)
        {
            var actualData = new byte[block.Data.Length];

            programmer.ReadPage(block.Address, memType, actualData, 0, actualData.Length);
            for (var i = 0; i < block.Data.Length; i++)
            {
                var actual   = actualData[i];
                var expected = block.Data[i];
                var address  = i + block.Address;
                if (!op.Device.Verify(memType, address, actual, expected))
                {
                    op.CurrentState = string.Format("Verification failed at {0}:0x{1:x4}.\r\nExpected 0x{2:x2} but was 0x{3:x2}", memType, i + block.Address, expected, actual);
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        public void ReadPage(int address, AvrMemoryType memType, byte[] data, int dataStart, int dataLength)
        {
            var offset = address;
            var end    = address + dataLength;

            while (offset < end)
            {
                var cnt = Math.Min(end - offset, BLOCK_SIZE);
                _deviceOperation.CurrentState = string.Format("Reading {0} memory {1}-{2}", memType, offset, offset + cnt - 1);
                _inner.ReadPage(offset, memType, data, offset - address + dataStart, cnt);
                offset += cnt;

                _deviceOperation.IncrementDone(cnt, memType);
                if (_deviceOperation.CancellationToken.IsCancellationRequested)
                {
                    _deviceOperation.CurrentState = "Operation is cancelled";
                }
                _deviceOperation.CancellationToken.ThrowIfCancellationRequested();
            }
        }