Esempio n. 1
0
        /// <summary>
        /// 更新声纳配置,true从文件中读出,false更新到文件
        /// </summary>
        /// <param name="bRead"></param>
        /// <returns></returns>
        public bool UpdateSonarConfig(bool bRead = true, string configfile = null)
        {
            string conf = configfile;

            if (conf == null)
            {
                conf = BasicConf.MyExecPath + "\\" + "DefConf.dat";
            }

            if (bRead)
            {
                return(SonarConfiguration.Parse(File.ReadAllBytes(conf)));
            }
            else
            {
                try
                {
                    var bw = new FileStream(conf, FileMode.OpenOrCreate);
                    bw.Write(SonarConfiguration.SavePackage(), 0, SonarConfiguration.SavePackage().Length);
                    bw.Close();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
 private void ExecuteLoadCommand(object sender, ExecutedRoutedEventArgs eventArgs)
 {
     try
     {
         var sc = new SonarConfig();
         Microsoft.Win32.OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.CheckFileExists = true;
         openFileDialog.CheckPathExists = true;
         openFileDialog.Title           = "选择参数文件";
         openFileDialog.Filter          = "参数文件 (*.dat)|*.dat";
         if (openFileDialog.ShowDialog() == true)
         {
             if (!sc.Parse(File.ReadAllBytes(openFileDialog.FileName)))
             {
                 throw new Exception("声纳参数读取失败");
             }
         }
         else
         {
             return;
         }
         uint velcmd = sc.VelCmd;
         SurVelSrcIndex = velcmd & 0x03;
         AvgVelIndex    = (velcmd >> 2) & 0x01;
         SurVel         = sc.SurVel;
         AvgVel         = sc.AvgVel;
         FixedGain      = sc.FixedGain;
         TVGCmd         = sc.TVGCmd;
         FixedTVG       = sc.FixedTVG;
         TVGSampling    = sc.TVGSampling;
         TVGSamples     = sc.TVGSamples;
         TVGA1          = sc.TVGA1;
         TVGA2          = sc.TVGA2;
         TVGA3          = sc.TVGA3;
         PingPeriod     = sc.PingPeriod;
         ADSaved        = sc.ADSaved;
         PoseSaved      = sc.PoseSaved;
         PosSaved       = sc.PosSaved;
         SonarDepth     = sc.SonarDepth;
         SonarGPSx      = sc.SonarGPSx;
         SonarGPSy      = sc.SonarGPSy;
         SonarGPSz      = sc.SonarGPSz;
         Pitchfixed     = sc.Pitchfixed;
         Rollfixed      = sc.Rollfixed;
         Headingfixed   = sc.Headingfixed;
     }
     catch (Exception ex)
     {
         UnitCore.Instance.EventAggregator.PublishMessage(new ErrorEvent(ex, LogType.Both));
         return;
     }
 }