Exemple #1
0
        public void FirmwareParse(FwTools.FwFormat format, TestData.Fw fw_paths, bool fill_FF)
        {
            foreach (TestData.Fw fw in fw_paths.GetFlags())
            {
                FwTools.Firmware ret = FwTools.Parse(TestData.GetFwPath(fw), format, fill_FF);

                Assert.NotNull(ret);
                Assert.NotNull(ret.Nodes);
                Assert.NotNull(ret.Info);
                Assert.True(ret.Nodes.Count > 0);
                Assert.True(ret.Info.SizeCode > 0);
            }
        }
Exemple #2
0
        public void FirmwareCreate(FwTools.FwFormat format, TestData.Fw fw_paths)
        {
            foreach (TestData.Fw fw in fw_paths.GetFlags())
            {
                FwTools.Firmware parsed = FwTools.Parse(TestData.GetFwPath(fw), FwTools.FwFormat.AUTO);
                string           ret    = FwTools.Create(parsed, format);

                Assert.NotNull(parsed);
                Assert.NotNull(parsed.Nodes);
                Assert.NotNull(parsed.Info);
                Assert.True(parsed.Nodes.Count > 0);
                Assert.True(parsed.Info.SizeCode > 0);
                Assert.True(ret.Length > 0);
            }
        }
Exemple #3
0
        public void HexView()
        {
            if (this.FwPath != "" && File.Exists(this.FwPath))
            {
                try
                {
                    FwTools.Firmware fw = null;
                    if (hexViewClosed)
                    {
                        fw = FwTools.Parse(this.FwPath, FillFF: true);
                    }

                    if (this.hexView == null)
                    {
                        this.hexView = new HexView((IOnHexViewClose)this, themeProvider.IsDarkMode())
                        {
                            DataContext = hexViewModel
                        };
                    }

                    if (hexViewClosed)
                    {
                        this.hexViewModel.FwPath = this.FwPath;
                        this.hexViewModel.FwInfo = fw.Info;
                        if (fw.Info != null && fw.Info.Format == FwTools.FwFormat.ELF)
                        {
                            this.hexViewModel.ELF = true;
                        }
                        else
                        {
                            this.hexViewModel.ELF = false;
                        }

                        this.IhexView = this.hexView;
                        this.hexView.SetAddrOffset(fw.Info.AddrFirst);
                        this.hexViewModel.Iview = IhexView;

                        if (this.hexViewModel.StreamCache != null)
                        {
                            this.hexViewModel.StreamCache.Close();
                        }
                        this.hexViewModel.StreamCache = new MemoryStream();
                        fw.MemoryStream.CopyTo(hexViewModel.StreamCache);

                        if (this.hexView.HexEditor.Stream != null)
                        {
                            this.hexView.HexEditor.Stream.Close();
                        }
                        this.hexView.HexEditor.Stream = fw.MemoryStream;
                    }

                    this.IsDialogOpen  = true;
                    this.hexViewClosed = false;
                    this.hexView.ShowDialog();
                    //this.hexView.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetExceptionMsg(), "BSL430.NET", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show(ERR1, "BSL430.NET", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            this.IsDialogOpen = false;
        }
Exemple #4
0
            private Status ParseFirmware(string firmware_path, out List <Rx_Block> rx_blocks, out FwTools.FwInfo fw_info)
            {
                fw_info   = null;
                rx_blocks = new List <Rx_Block>();
                FwTools.Firmware code_to_upload    = null;
                FwTools.Firmware code_full_for_crc = null;
                bool             fill_FF           = false;

                if (protocol == Protocol.USB_5_6)
                {
                    fill_FF = true;
                }

                try
                {
                    code_to_upload    = FwTools.Parse(firmware_path, FillFF: fill_FF);
                    code_full_for_crc = FwTools.Parse(firmware_path, FillFF: true);

                    // slice data to bigger blocks that fit buffer size
                    int buff_size = GetBufferSize(protocol);
                    if (fill_FF)
                    {
                        for (int i = 0; i < code_to_upload.Nodes.Count; i += buff_size)
                        {
                            rx_blocks.Add(new Rx_Block
                            {
                                addr = (int)code_to_upload.Nodes[i].Addr,
                                data = code_to_upload.Nodes.Skip(i).Take(buff_size).Select(nod => nod.Data).ToArray()
                            });
                        }
                    }
                    else
                    {
                        for (int i = 0, j = 0; i < code_to_upload.Nodes.Count; i++)
                        {
                            if (i == code_to_upload.Nodes.Count - 1 ||
                                code_to_upload.Nodes[i + 1].Addr - code_to_upload.Nodes[i].Addr > 1 ||
                                j + 1 >= buff_size)
                            {
                                rx_blocks.Add(new Rx_Block
                                {
                                    addr = (int)code_to_upload.Nodes[i - j].Addr,
                                    data = code_to_upload.Nodes.Skip(i - j).Take(j + 1).Select(nod => nod.Data).ToArray()
                                });
                                j = 0;
                            }
                            else
                            {
                                j++;
                            }
                        }
                    }

                    code_to_upload.Info.Crc16 = code_full_for_crc.Info.Crc16;
                    fw_info = code_to_upload.Info;

                    if (rx_blocks == null || rx_blocks.Count < 1)
                    {
                        throw new Bsl430NetException(445);
                    }
                    else
                    {
                        return(Utils.StatusCreate(0));
                    }
                }
                catch (Exception ex)
                {
                    if (ex is Bsl430NetException)
                    {
                        return(Utils.StatusCreate(450, ((Bsl430NetException)ex).Status));
                    }
                    else if (ex is FirmwareToolsException)
                    {
                        Status fw_ex = new Status()
                        {
                            Error = ((FirmwareToolsException)ex).Error,
                            Msg   = ((FirmwareToolsException)ex).Msg
                        };
                        return(Utils.StatusCreate(450, fw_ex));
                    }
                    else
                    {
                        return(Utils.StatusCreate(450, ex.Message));
                    }
                }
            }