Beispiel #1
0
        private void FileSelectButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog FWOpenFile = new OpenFileDialog()
            {
                Title            = "请选择固件文件",
                InitialDirectory = "",
                Filter           =
                    "二进制bin文件|*.bin|十六进制hex文件|*.hex",
                ValidateNames   = true,
                CheckPathExists = true,
                CheckFileExists = true,
                Multiselect     = false,
            };

            if (FWOpenFile.ShowDialog() != true)
            {
                Log.warn("未选择文件,取消下载!");
                return;
            }

            List <ParameterGrid> pgList = new List <ParameterGrid>();

            pgList.Add(new ParameterGrid(
                           "Address",
                           "存放地址",
                           @"^[0-9A-Fa-f]*$",
                           8,
                           "输入四字节的存放地址",
                           FlashWriteAddress.ToString("X08"),
                           null
                           )
                       );

            ParameterWindow pw = new ParameterWindow(this, "配置固件存放地址", pgList);

            if (pw.ShowDialog() != true)
            {
                Log.warn("未配置存放地址,取消下载!");
                return;
            }

            FlashWriteAddress = uint.Parse(pw.ParaValueResult["Address"], NumberStyles.HexNumber);

            string FileRealName = FWOpenFile.SafeFileName;
            string FileFullName = FWOpenFile.FileName;

            string FileName = FileRealName.ToLower();

            fw.IsCheckSection = false;
            fw.FirmwareName   = FileFullName;
            FileLabel.Content = FileRealName;
        }
Beispiel #2
0
        private void FlashReadButton_Click(object sender, RoutedEventArgs e)
        {
            List <ParameterGrid> pgList = new List <ParameterGrid>();

            pgList.Add(new ParameterGrid(
                           "Address",
                           "读取基址",
                           @"^[0-9A-Fa-f]*$",
                           8,
                           "输入读取Flash基址",
                           FlashReadAddress.ToString("X08"),
                           null
                           )
                       );
            pgList.Add(new ParameterGrid(
                           "Length",
                           "读取长度(KB)",
                           @"^[0-9]*$",
                           0,
                           "输入读取Flash长度",
                           FlashFileLength.ToString(),
                           null
                           )
                       );

            ParameterWindow pw = new ParameterWindow(this, "读取Flash配置", pgList);

            if (pw.ShowDialog() != true)
            {
                Log.warn("取消读取!");
                return;
            }
            FlashReadAddress = uint.Parse(pw.ParaValueResult["Address"], NumberStyles.HexNumber);
            int ReadLength = int.Parse(pw.ParaValueResult["Length"]);

            ReadLength      = (ReadLength / 4 + (ReadLength % 4 == 0 ? 0 : 1)) * 4;
            FlashFileLength = ReadLength;
            FlashFileList   = new List <byte>();

            MessageBox.Show(this, "读取文件从 0x" + FlashReadAddress.ToString("X08") + "到 0x" + (FlashReadAddress + ReadLength * 1024).ToString("X08"));
            for (uint offset = 0; offset < (FlashFileLength * 1024); offset += 4096)
            {
                var cmd = new FlashCmd("Read", FlashReadAddress + offset, null);
                Serialcon.Cmd.Add(cmd);
            }
            Serialcon.Cmd.Start();
        }
Beispiel #3
0
        private void FlashEraseButton_Click(object sender, RoutedEventArgs e)
        {
            List <ParameterGrid> pgList = new List <ParameterGrid>();

            pgList.Add(new ParameterGrid(
                           "Address",
                           "擦除基址",
                           @"^[0-9A-Fa-f]*$",
                           8,
                           "输入擦除Flash基址",
                           FlashEraseAddress.ToString("X08"),
                           null
                           )
                       );
            pgList.Add(new ParameterGrid(
                           "Length",
                           "擦除长度(KB)",
                           @"^[0-9]*$",
                           0,
                           "输入擦除Flash长度",
                           FlashEraseLength.ToString(),
                           null
                           )
                       );

            ParameterWindow pw = new ParameterWindow(this, "擦除Flash配置", pgList);

            if (pw.ShowDialog() != true)
            {
                Log.warn("取消擦除!");
                return;
            }
            FlashEraseAddress = uint.Parse(pw.ParaValueResult["Address"], NumberStyles.HexNumber);
            FlashEraseLength  = int.Parse(pw.ParaValueResult["Length"]);
            FlashEraseLength  = (FlashEraseLength / 4 + (FlashEraseLength % 4 == 0 ? 0 : 1)) * 4;
            FlashFileList     = new List <byte>();

            MessageBox.Show(this, "擦除从 0x" + FlashEraseAddress.ToString("X08") + "到 0x" + (FlashEraseAddress + FlashEraseLength * 1024).ToString("X08"));
            byte[] EraseLength = BitConverter.GetBytes(FlashEraseLength / 4);
            Array.Reverse(EraseLength);
            var cmd = new FlashCmd("Erase", FlashEraseAddress, EraseLength);

            Serialcon.Cmd.Add(cmd);
            Serialcon.Cmd.Start();
        }
Beispiel #4
0
        private void CheckSumButton_Click(object sender, RoutedEventArgs e)
        {
            List <ParameterGrid> pgList = new List <ParameterGrid>();

            pgList.Add(new ParameterGrid(
                           "CheckSum",
                           "校验内容",
                           @"^[0-9A-Fa-f ]*$",
                           0,
                           "输入需要检验的内容",
                           CheckString,
                           null
                           )
                       );

            ParameterWindow pw = new ParameterWindow(this, "计算校验和", pgList);

            if (pw.ShowDialog() != true)
            {
                Log.warn("取消校验!");
                return;
            }
            CheckString = pw.ParaValueResult["CheckSum"].Trim();
            byte[] CheckBytes = Tool.StringToHex(CheckString);
            byte   sum        = 0;
            ushort intelsum   = 0x0000;

            for (int i = 0; i < CheckBytes.Length; i++)
            {
                sum += CheckBytes[i];
                if (i % 2 == 1)
                {
                    intelsum += BitConverter.ToUInt16(CheckBytes, i - 1);
                }
            }
            Log.info("========== Sum Report ==========");
            Log.info("Sum : " + sum.ToString("X02"));
            Log.info("PPIDSum : " + ((byte)(0xA0 - sum)).ToString("X02"));
            Log.info("InvSum : " + ((byte)~sum).ToString("X02"));
            Log.info("UShort Sum : " + intelsum.ToString("X04"));
            Log.info("Intel Sum : " + ((ushort)(0xBABA - intelsum)).ToString("X04"));
        }
Beispiel #5
0
 public void RegisterOwner(ParameterWindow pw)
 {
     Owner = pw;
 }