Example #1
0
        public MainWindowViewModel()
        {
            if (!InDesignMode.Check())
            {
                RTL.CallbackLog   += RTL_CallbackLog;
                RTL.CallbackError += RTL_CallbackError;

                Application.Current.MainWindow.Loaded += MainWindow_Loaded;
            }

            Сommand_UpdateCalibration = new RelayCommand((p) =>
            {
                CalibrationWindow ucw = new CalibrationWindow();

                ucw.Owner       = Application.Current.MainWindow;
                ucw.DataContext = this;
                ucw.ShowDialog();

                RTL.UpdateCalibrationRegion();
                RTL.CheckImages();
            }, (p) => (true));

            Сommand_WriteConfig = new RelayCommand((p) =>
            {
                if (p != null)
                {
                    switch ((string)p)
                    {
                    case "0":
                        byte[] data = RTL_FC.GetByteArray();
                        RTL.FlashWrite(RTL_FC.FlashAddr, (UInt32)data.Length, data);
                        break;

                    default:
                        break;
                    }
                }
            }, (p) => (RTL.IsInited));

            Сommand_ReadConfig = new RelayCommand((p) =>
            {
                if (p != null)
                {
                    switch ((string)p)
                    {
                    case "0":
                        byte[] data = new byte[RTL_FC.FlashSize];
                        if (RTL.FlashRead(RTL_FC.FlashAddr, RTL_FC.FlashSize, ref data))
                        {
                            RTL_FC.FromByteArray(data);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }, (p) => (RTL.IsInited));

            Сommand_EraseConfig = new RelayCommand((p) =>
            {
                if (p != null)
                {
                    switch ((string)p)
                    {
                    default:
                        break;
                    }
                }
            }, (p) => (RTL.IsInited));

            Сommand_Connect = new RelayCommand((p) =>
            {
                RTL.OpenDebugger();
                RTL.Connect();
            }, (p) => (!RTL.IsOpen));

            Сommand_Disconnect = new RelayCommand((p) =>
            {
                RTL.Disconnect();
            }, (p) => (RTL.IsConnected));

            Сommand_InitTargert = new RelayCommand((p) =>
            {
                RTL.InitTargert();
            }, (p) => (RTL.IsConnected));

            Сommand_RestartTargert = new RelayCommand((p) =>
            {
                RTL.Restart();
            }, (p) => (RTL.IsConnected));

            Сommand_EraseAll = new RelayCommand((p) =>
            {
                RTL.EraseAll();
            }, (p) => (RTL.IsConnected));

            Сommand_ReadIDRegs = new RelayCommand((p) =>
            {
                //RTL.ReadJedecID();
                RTL.ReadFlashID();
            }, (p) => (RTL.IsInited));

            Сommand_ReadFullFlash = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                    if (RTL.FlashRead())
                    {
                        RTL.CheckImages();
                        UpdateImagesPreview();
                    }
                }
            }, (p) => (RTL.IsConnected));

            Сommand_WriteFullFlash = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                    RTL.FlashWrite();
                }
            }, (p) => (RTL.IsConnected));

            Сommand_WriteParticleFlash = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                    ImagesSelectWindow isw = new ImagesSelectWindow();

                    isw.Owner       = Application.Current.MainWindow;
                    isw.DataContext = this;
                    isw.ShowDialog();

                    if (((ImagesToWrite & (UInt16)AmebaA_ParticleImageBits.System) > 0) & RTL.Image1SPICIsOK)
                    {
                        RTL.FlashWrite(AmebaA_Addresses.SystemDataAddr, AmebaA_Addresses.SystemDataSize);
                    }

                    if (((ImagesToWrite & (UInt16)AmebaA_ParticleImageBits.Calibration) > 0) & RTL.Image1CalibrationIsOK)
                    {
                        RTL.FlashWrite(AmebaA_Addresses.CalibrationDataAddr, AmebaA_Addresses.CalibrationDataSize);
                    }

                    if (((ImagesToWrite & (UInt16)AmebaA_ParticleImageBits.Image1) > 0) & RTL.Image1IsSignatureOK)
                    {
                        RTL.FlashWrite(RTL.Image1FlashAddr, RTL.Image1SegSize);
                    }

                    if (((ImagesToWrite & (UInt16)AmebaA_ParticleImageBits.Image2) > 0) & RTL.Image2IsSignatureOK)
                    {
                        RTL.FlashWrite(RTL.Image2FlashAddr, RTL.Image2SegSize);
                    }

                    if (((ImagesToWrite & (UInt16)AmebaA_ParticleImageBits.Image3) > 0) & RTL.Image3IsSignatureOK)
                    {
                        RTL.FlashWrite(RTL.Image3FlashAddr, RTL.Image3SegSize);
                    }

                    if (((ImagesToWrite & (UInt16)AmebaA_ParticleImageBits.OTA) > 0) & RTL.ImageOTAIsSignatureOK)
                    {
                        RTL.FlashWrite(RTL.ImageOTAFlashAddr, RTL.ImageOTASegSize);
                    }
                }
            }, (p) => (RTL.IsConnected));

            Сommand_LoadFullFlash = new RelayCommand((p) =>
            {
                if (RTL.LoadFromFile())
                {
                    RTL.CheckImages();
                    UpdateImagesPreview();
                }
            }, (p) => (true));

            Сommand_ReloadFullFlash = new RelayCommand((p) =>
            {
                if (RTL.ReloadFromFile())
                {
                    RTL.CheckImages();
                    UpdateImagesPreview();
                }
            }, (p) => (!String.IsNullOrEmpty(RTL.LastFilePath)));

            Сommand_SaveFullFlash = new RelayCommand((p) =>
            {
                RTL.SaveToFile();
            }, (p) => (true));

            Сommand_ShowConfigurator = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                    ConfiguratorWindow cw = new ConfiguratorWindow();

                    cw.Owner       = Application.Current.MainWindow;
                    cw.DataContext = this;
                    cw.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Error at Initializing SoC Flasher, check swd or jtag cable, speed settings, SoC reset...", "Error!");
                }
            }, (p) => (RTL.IsConnected));
        }
Example #2
0
        public MainWindowViewModel()
        {
            if (!InDesignMode.Check())
            {
                RTL.CallbackLog   += RTL_CallbackLog;
                RTL.CallbackError += RTL_CallbackError;

                Application.Current.MainWindow.Loaded += MainWindow_Loaded;
            }

            Сommand_WriteConfig = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                    if (p != null)
                    {
                        switch ((string)p)
                        {
                        case "0":
                            byte[] data = RTL_FC.GetByteArray();
                            RTL.FlashWrite(RTL_FC.FlashAddr, (UInt32)data.Length, data);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }, (p) => (RTL.IsConnected));

            Сommand_ReadConfig = new RelayCommand((p) =>
            {
                if (p != null)
                {
                    switch ((string)p)
                    {
                    case "0":
                        byte[] data = new byte[RTL_FC.FlashSize];
                        if (RTL.FlashRead(RTL_FC.FlashAddr, RTL_FC.FlashSize, ref data))
                        {
                            RTL_FC.FromByteArray(data);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }, (p) => (RTL.IsConnected));

            Сommand_EraseConfig = new RelayCommand((p) =>
            {
                if (p != null)
                {
                    switch ((string)p)
                    {
                    default:
                        break;
                    }
                }
            }, (p) => (RTL.IsInited));

            Сommand_Connect = new RelayCommand((p) =>
            {
                RTL.OpenDebugger();
                RTL.Connect();
            }, (p) => (!RTL.IsOpen));

            Сommand_Disconnect = new RelayCommand((p) =>
            {
                RTL.Disconnect();
            }, (p) => (RTL.IsConnected));

            Сommand_InitTargert = new RelayCommand((p) =>
            {
                RTL.InitTargert();
            }, (p) => (RTL.IsConnected));

            Сommand_RestartTargert = new RelayCommand((p) =>
            {
                RTL.Restart();
            }, (p) => (RTL.IsConnected));

            Сommand_EraseAll = new RelayCommand((p) =>
            {
                RTL.EraseAll();
            }, (p) => (RTL.IsConnected));

            Сommand_ReadIDRegs = new RelayCommand((p) =>
            {
                RTL.ReadFlashID();
            }, (p) => (RTL.IsInited));

            Сommand_ReadFullFlash = new RelayCommand((p) =>
            {
                if (RTL.FlashRead())
                {
                    RTL.CheckImages();
                    UpdateImagesPreview();
                }
            }, (p) => (RTL.IsConnected));

            Сommand_WriteFullFlash = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                    RTL.FlashWrite();

                    /*
                     * // Flasher Test
                     * Random r = new Random();
                     * Int32 len = r.Next(12, 80);
                     * len = len - len % 4;
                     *
                     * byte[] test = new byte[len];
                     * r.NextBytes(test);
                     * //byte[] test = new byte[] { 0x23, 0x24, 0x25, 0x26, 0x27, 0x3, 0xff, 0xaa, 0x43, 0x3, 0xff, 0xaa };
                     *
                     * RTL.FlashWrite(0x0000, (UInt32)len, test);
                     *
                     * byte[] test_read = new byte[len];
                     * RTL.FlashRead(AmebaZ_Addresses.FlashAddr + 0x0000, (UInt32)len, ref test_read);
                     */
                }
            }, (p) => (RTL.IsConnected));

            Сommand_WriteParticleFlash = new RelayCommand((p) =>
            {
                if (RTL.InitTargert())
                {
                }
            }, (p) => (RTL.IsConnected));

            Сommand_LoadFullFlash = new RelayCommand((p) =>
            {
                if (RTL.LoadFromFile())
                {
                    RTL.CheckImages();
                    UpdateImagesPreview();
                }
            }, (p) => (true));

            Сommand_ReloadFullFlash = new RelayCommand((p) =>
            {
                if (RTL.ReloadFromFile())
                {
                    RTL.CheckImages();
                    UpdateImagesPreview();
                }
            }, (p) => (!String.IsNullOrEmpty(RTL.LastFilePath)));

            Сommand_SaveFullFlash = new RelayCommand((p) =>
            {
                RTL.SaveToFile();
            }, (p) => (true));

            Сommand_ShowConfigurator = new RelayCommand((p) =>
            {
                ConfiguratorWindow cw = new ConfiguratorWindow();

                cw.Owner       = Application.Current.MainWindow;
                cw.DataContext = this;
                cw.ShowDialog();
            }, (p) => (RTL.IsConnected));
        }