Beispiel #1
0
        private void readStatusSystem(byte[] array)
        {
            Structures.FlashResult buffer = new Structures.FlashResult();
            object obj = new Structures.FlashResult();

            StructConvert.ByteArrayToStructure(array, ref obj);
            buffer = (Structures.FlashResult)obj;

            Enums.Status status;

/*			if (commandOut != Enums.Commands.StatusSystem)
 *                      {
 *                              if (commandOut == Enums.Commands.ReadFlash)
 *                              {
 *                                      MainWindow.Logger.Info("Чтение EEPROM завершено");
 *                                      Device.StatusProgress = Enums.StatusProgress.Finish;
 *                                      // TODO разрешить работать кнопке сохранить ЕЕПРОМ
 *                              }
 *                              commandOut = Enums.Commands.ZeroCommand;
 *                      }
 */         status = (Enums.Status)buffer.Status;
            if (status != Enums.Status.OK)
            {
                MainWindow.Logger.Error("Ошибка операции: {0}", status);
                commandOut            = Enums.Commands.ZeroCommand;
                Device.StatusProgress = Enums.StatusProgress.Alarm;                //Finish
                Function = Enums.FunctionalMode.Disable;
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        private void readProgramVerifyFlash(byte[] array)
        {
            Structures.FlashResult buffer = new Structures.FlashResult();
            object obj = new Structures.FlashResult();

            StructConvert.ByteArrayToStructure(array, ref obj);
            buffer = (Structures.FlashResult)obj;

            Enums.Status status = (Enums.Status)buffer.Status;
            if (status != Enums.Status.OK)
            {
                MainWindow.Logger.Error("Ошибка операции: {0}", status);
                commandOut            = Enums.Commands.ZeroCommand;
                Device.StatusProgress = Enums.StatusProgress.Alarm;
                Function = Enums.FunctionalMode.Disable;
            }
            //Device.AddressOffset += Device.LengthSend; // TODO uncomment
            if (TaskToProcess == 1)
            {
                TaskToProcess = 0;
            }
        }
Beispiel #6
0
        private void readVersionSoft(byte[] array)
        {
            Structures.FlashVersion buffer = new Structures.FlashVersion();
            object obj = new Structures.FlashVersion();

            StructConvert.ByteArrayToStructure(array, ref obj);
            buffer = (Structures.FlashVersion)obj;

            Device.InfoDevice.DeviceAddress     = buffer.FromNetAddress;
            Device.InfoDevice.VersionBootloader = buffer.VersionBootLoader;
            Device.InfoDevice.Machine           = (Enums.Machine)buffer.Machine;
            Device.InfoDevice.NumberMachine     = buffer.NumberMachine;
            Device.InfoDevice.TypeCpu           = (Enums.CpuIdentificator)buffer.TypeCpu;

            Device.InfoDevice.AddressUserCodeBegin = buffer.AddressUserCodeBegin;
            Device.InfoDevice.AddressUserCodeEnd   = buffer.AddressUserCodeEnd;

            Device.InfoDevice.AddressEepromBegin = buffer.AddressEepromBegin;
            Device.InfoDevice.AddressEepromEnd   = buffer.AddressEepromEnd;

            Function = Enums.FunctionalMode.Disable;
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        private void readEraseFlash(byte[] array)
        {
            Structures.FlashResult buffer = new Structures.FlashResult();
            object obj = new Structures.FlashResult();

            StructConvert.ByteArrayToStructure(array, ref obj);
            buffer = (Structures.FlashResult)obj;

            Enums.Status status = (Enums.Status)buffer.Status;
            if (status != Enums.Status.OK)
            {
                MainWindow.Logger.Error("Ошибка операции: {0}", status);
                Device.StatusProgress = Enums.StatusProgress.Alarm;
                Function = Enums.FunctionalMode.Disable;
            }
            else
            {
                MainWindow.Logger.Trace("Очистка завершена");
                Device.StatusProgress = Enums.StatusProgress.Finish;
                Function = Enums.FunctionalMode.Disable;
            }

            commandOut = Enums.Commands.ZeroCommand;
        }
Beispiel #9
0
        private void readReadFlash(byte[] array)
        {
            Structures.FlashReadWrite buffer = new Structures.FlashReadWrite();
            object obj = new Structures.FlashReadWrite();

            StructConvert.ByteArrayToStructure(array, ref obj);
            buffer = (Structures.FlashReadWrite)obj;

            if (Function == Enums.FunctionalMode.ReadEeprom)
            {
                if (buffer.LengthData == 0)                 // Чтение завершено
                {
                    MainWindow.Logger.Trace("Чтение EEPROM завершено");
                    Device.StatusProgress = Enums.StatusProgress.Finish;
                    Function = Enums.FunctionalMode.Disable;
                }

                for (int i = 0; i < buffer.LengthData * 2; i++)
                {
                    Device.EepromData.Add(buffer.Data[i]);
                }
            }
            else if (Function == Enums.FunctionalMode.ReadFlash)
            {
                for (int i = 0; i < buffer.LengthData * 2; i++)
                {
                    Device.FlashData.Add(buffer.Data[i]);
                }

                if (buffer.LengthData == 0)                 // Чтение завершено
                {
                    MainWindow.Logger.Trace("Чтение Flash завершено");
                    Device.StatusProgress = Enums.StatusProgress.Finish;
                    Function = Enums.FunctionalMode.Disable;
                }
            }
            else if (Function == Enums.FunctionalMode.ReadRegion)
            {
                for (int i = 0; i < buffer.LengthData * 2; i++)
                {
                    Device.RegionData.Add(buffer.Data[i]);
                }

                if (buffer.LengthData == 0)                 // Чтение завершено
                {
                    MainWindow.Logger.Trace("Чтение области завершено");
                    Device.StatusProgress = Enums.StatusProgress.Finish;
                    Function = Enums.FunctionalMode.Disable;
                }
            }

            if (buffer.LengthData != 0)
            {
                Device.StatusProgress = Enums.StatusProgress.Inderterminate;
            }

            if (TaskToProcess == 1)
            {
                TaskToProcess = 0;
            }
        }