private byte[] prepareReadFlash(ushort task) { Structures.FlashRead buffer = new Structures.FlashRead(); buffer.ToNetAddress = NetAddressDevice; buffer.FromNetAddress = NetAddressPc; buffer.LengthMessage = StructConvert.LengthStruct(buffer); buffer.Command = Enums.Commands.ReadFlash; buffer.Task = task; if (Function == Enums.FunctionalMode.ReadFlash) { buffer.AddressBegin = Device.InfoDevice.AddressUserCodeBegin; buffer.AddressEnd = Device.InfoDevice.AddressUserCodeEnd; } else if (Function == Enums.FunctionalMode.ReadEeprom) { buffer.AddressBegin = Device.InfoDevice.AddressEepromBegin; buffer.AddressEnd = Device.InfoDevice.AddressEepromEnd; } else if (Function == Enums.FunctionalMode.ReadRegion) { buffer.AddressBegin = Device.Region.BeginAddress; buffer.AddressEnd = Device.Region.EndAddress; } buffer.Crc = CalculateCrc.CreateCRC(buffer); byte[] array = StructConvert.StructureToByteArray(buffer); return(array); }
private byte[] prepareProgramVerifyFlash(ushort task) { Structures.FlashReadWrite buffer = new Structures.FlashReadWrite(); buffer.ToNetAddress = NetAddressDevice; buffer.FromNetAddress = NetAddressPc; buffer.LengthMessage = StructConvert.LengthStruct(buffer); buffer.Command = Enums.Commands.ProgramVerifyFlash; if (task == 0 || task == 1) // Новые данные { Device.AddressOffset += Device.LengthSend; int delta = (int)Device.DataToWrite.Count - (int)Device.AddressOffset; if (delta > 230) { Device.LengthSend = 230; } else if (delta != 0) { Device.LengthSend = (uint)delta; } else // Переданы все данные { Device.LengthSend = 0; } byte[] data = Device.DataToWrite.GetRange((int)Device.AddressOffset, (int)Device.LengthSend).ToArray(); if (data.Length < 230) { Array.Resize(ref data, 230); } Device.DataArray = data; } else if (task == 3) // Ошибка { } else // task = 2, Повтор данных { } buffer.AddressBegin = Device.AddressBegin; buffer.AddressOffset = Device.AddressOffset; buffer.LengthData = Device.LengthSend / 2; buffer.Data = Device.DataArray; buffer.rsrv = 0; buffer.Crc = CalculateCrc.CreateCRC(buffer); byte[] array = StructConvert.StructureToByteArray(buffer); return(array); }
private byte[] prepareStatusSystem() { Structures.FlashResult buffer = new Structures.FlashResult(); buffer.ToNetAddress = NetAddressDevice; buffer.FromNetAddress = NetAddressPc; buffer.LengthMessage = StructConvert.LengthStruct(buffer); buffer.Command = Enums.Commands.StatusSystem; buffer.Task = 0; buffer.Status = 0; buffer.Crc = CalculateCrc.CreateCRC(buffer); byte[] array = StructConvert.StructureToByteArray(buffer); return(array); }
private byte[] prepareEraseFlash(ushort task) { Structures.FlashErase buffer = new Structures.FlashErase(); buffer.ToNetAddress = NetAddressDevice; buffer.FromNetAddress = NetAddressPc; buffer.LengthMessage = StructConvert.LengthStruct(buffer); buffer.Command = Enums.Commands.EraseFlash; buffer.AddressBegin = Device.AddressBegin; buffer.AddressEnd = Device.AddressEnd; buffer.Task = task; if (TaskToProcess == 1) { TaskToProcess = 0; } buffer.Crc = CalculateCrc.CreateCRC(buffer); byte[] array = StructConvert.StructureToByteArray(buffer); return(array); }