예제 #1
0
 private void ReadHeader()
 {
     byte[] header = DecodeHex(_reader.ReadLine());
     _siliconId    = EndianBitConverter.Big.ToUInt32(header, 0);
     _siliconRev   = header[4];
     _checksumType = (PacketChecksumType)header[5];
 }
예제 #2
0
 public ProgramRowCommand(PacketChecksumType checksumType, byte flashArrayId, UInt16 flashRowNumber, byte[] data)
     : base(checksumType)
 {
     this._flashArrayId   = flashArrayId;
     this._flashRowNumber = flashRowNumber;
     this._data           = data;
 }
예제 #3
0
        public void Deserialize(PacketChecksumType checksumType, byte[] data)
        {
            MemoryStream       ms     = new MemoryStream(data);
            EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Little, ms);

            if (reader.ReadByte() != 0x01)
            {
                throw new InvalidDataException("Message start byte must be 0x01");
            }
            StatusCode status = (StatusCode)reader.ReadByte();

            if (status != StatusCode.CYRET_SUCCESS)
            {
                throw new BootloaderError(status);
            }
            ushort length = reader.ReadUInt16();

            if (length > data.Length - 7)
            {
                throw new InvalidDataException("Invalid data length");
            }
            this.DeserializePayload(reader, length);
            ushort checksum = reader.ReadUInt16();

            if (checksum != PacketChecksum.ComputeChecksum(checksumType, data, length + 4))
            {
                throw new InvalidDataException("Invalid checksum");
            }
            if (reader.ReadByte() != 0x17)
            {
                throw new InvalidDataException("Message end byte must be 0x17");
            }
        }
예제 #4
0
 public I2CTransferCommand(PacketChecksumType checksumType, byte slaveAddress, byte[] writeData, byte writeLen, byte readLen)
     : base(checksumType)
 {
     this.slaveAddress = slaveAddress;
     this.writeData    = writeData;
     this.writeLen     = writeLen;
     this.readLen      = readLen;
 }
예제 #5
0
 public static UInt16 ComputeChecksum(PacketChecksumType type, byte[] data, long len)
 {
     switch (type)
     {
         case PacketChecksumType.Summation:
             return ComputeSummationChecksum(data, len);
         case PacketChecksumType.CRC16:
             return ComputeCRC16Checksum(data, len);
     }
     throw new ArgumentException();
 }
예제 #6
0
        public static UInt16 ComputeChecksum(PacketChecksumType type, byte[] data, long len)
        {
            switch (type)
            {
            case PacketChecksumType.Summation:
                return(ComputeSummationChecksum(data, len));

            case PacketChecksumType.CRC16:
                return(ComputeCRC16Checksum(data, len));
            }
            throw new ArgumentException();
        }
예제 #7
0
 public void Deserialize(PacketChecksumType checksumType, byte[] data)
 {
     MemoryStream ms = new MemoryStream(data);
     EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Little, ms);
     if (reader.ReadByte() != 0x01)
         throw new InvalidDataException("Message start byte must be 0x01");
     StatusCode status = (StatusCode) reader.ReadByte();
     if (status != StatusCode.CYRET_SUCCESS)
         throw new BootloaderError(status);
     ushort length = reader.ReadUInt16();
     if (length > data.Length - 7)
         throw new InvalidDataException("Invalid data length");
     this.DeserializePayload(reader, length);
     ushort checksum = reader.ReadUInt16();
     if (checksum != PacketChecksum.ComputeChecksum(checksumType, data, length + 4))
         throw new InvalidDataException("Invalid checksum");
     if (reader.ReadByte() != 0x17)
         throw new InvalidDataException("Message end byte must be 0x17");
 }
예제 #8
0
 public ProgramRowCommand(PacketChecksumType checksumType, byte flashArrayId, UInt16 flashRowNumber, byte[] data)
     : base(checksumType)
 {
     this._flashArrayId = flashArrayId;
     this._flashRowNumber = flashRowNumber;
     this._data = data;
 }
예제 #9
0
 public I2CTransferCommand(PacketChecksumType checksumType, byte slaveAddress, byte[] writeData, byte writeLen, byte readLen)
     : base(checksumType)
 {
     this.slaveAddress = slaveAddress;
     this.writeData = writeData;
     this.writeLen = writeLen;
     this.readLen = readLen;
 }
예제 #10
0
 public SendDataCommand(PacketChecksumType checksumType, byte[] data)
     : base(checksumType)
 {
     _data = data;
 }
예제 #11
0
 public BootloaderCommand(PacketChecksumType checksumType)
 {
     this._checksumType = checksumType;
 }
예제 #12
0
 public EnterBootloaderCommand(PacketChecksumType checksumType) : base(checksumType)
 {
 }
예제 #13
0
 public GetFlashSizeCommand(PacketChecksumType checksumType, byte flashArrayId) : base(checksumType)
 {
     this._flashArrayId = flashArrayId;
 }
예제 #14
0
 public VerifyChecksumCommand(PacketChecksumType checksumType) : base(checksumType)
 {
 }
예제 #15
0
 public SendDataCommand(PacketChecksumType checksumType, byte[] data)
     : base(checksumType)
 {
     _data = data;
 }
예제 #16
0
 public VerifyRowCommand(PacketChecksumType checksumType, byte flashArrayId, UInt16 flashRowNumber) : base(checksumType)
 {
     _flashArrayId   = flashArrayId;
     _flashRowNumber = flashRowNumber;
 }
예제 #17
0
 public BootloaderCommand(PacketChecksumType checksumType)
 {
     this._checksumType = checksumType;
 }
예제 #18
0
 public GetFlashSizeCommand(PacketChecksumType checksumType, byte flashArrayId)
     : base(checksumType)
 {
     this._flashArrayId = flashArrayId;
 }
예제 #19
0
 private void ReadHeader()
 {
     byte[] header = DecodeHex(_reader.ReadLine());
     _siliconId = EndianBitConverter.Big.ToUInt32(header, 0);
     _siliconRev = header[4];
     _checksumType = (PacketChecksumType) header[5];
 }
예제 #20
0
 public VerifyChecksumCommand(PacketChecksumType checksumType)
     : base(checksumType)
 {
 }
예제 #21
0
 public VerifyRowCommand(PacketChecksumType checksumType, byte flashArrayId, UInt16 flashRowNumber)
     : base(checksumType)
 {
     _flashArrayId = flashArrayId;
     _flashRowNumber = flashRowNumber;
 }
예제 #22
0
 public EnterBootloaderCommand(PacketChecksumType checksumType)
     : base(checksumType)
 {
 }