// ControlMode 返回对应字符串 控制方式 private ModeManager GetControlModeStr(int mode) { ModeManager _controlMode = new ModeManager(); if (ControlModeList.Count <= mode) { _controlMode.ModeNo = -1; _controlMode.ModeName = "未定义"; _controlMode.Reset = false; return(_controlMode); } _controlMode = ControlModeList.Find( delegate(ModeManager _modeManager) { return(_modeManager.ModeNo == mode); }); return(_controlMode); }
// XML/Setting.xml浏览 private void InitModeName() { System.Diagnostics.Debug.WriteLine(""); ControlModeList = new List <ModeManager>(); // 初始化 FlightModeList = new List <string>(); // 初始化 // 读取XML文件的XML数据 XDocument xml = XDocument.Load(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\ACSL\X-Monitor\Setting\GUI\Settings.xml"); // 按Ctrl方式阅读 var elements = xml.Root.XPathSelectElements("Settings/UAV/Sys/Mode/Ctrl"); foreach (var element in elements) { ModeManager _controlMode = new ModeManager(); // 阅读属性 if (element.Attribute("i") != null) { int i; string _attVal = element.Attribute("i").Value; if (int.TryParse(_attVal, out i)) { _controlMode.ModeNo = int.Parse(_attVal); // 模式号 _controlMode.ModeName = element.Value; // 模式名 System.Diagnostics.Debug.WriteLine("ControlModeList :(" + _attVal + ")" + element.Value); } else { _controlMode.ModeNo = -1; // 模式号 _controlMode.ModeName = "未定义"; // 模式名 } } else { _controlMode.ModeNo = -1; // 控制名 _controlMode.ModeName = "未定义"; // 控制名 } // 重置属性加载 if (element.Attribute("reset") != null) { string _attVal = element.Attribute("reset").Value; if (_attVal == "Y") { _controlMode.Reset = true; // 目标值复位 (true) System.Diagnostics.Debug.WriteLine("reset-:" + _attVal); } else { _controlMode.Reset = false; // 目标值复位 (true) System.Diagnostics.Debug.WriteLine("reset-:" + _attVal); } } else { _controlMode.Reset = false; // 目标值复位 (true) System.Diagnostics.Debug.WriteLine("reset-:" + "没有"); } ControlModeList.Add(_controlMode); } // 自动模式下阅读 elements = xml.Root.XPathSelectElements("Settings/UAV/Sys/Mode/Auto"); for (int i = 0; i < elements.Count(); i++) { foreach (var element in elements) { // i属性的阅读 string _attVal = element.Attribute("i").Value; if (_attVal == i.ToString()) { System.Diagnostics.Debug.WriteLine("FlightModeList :(" + i.ToString() + ")" + element.Value); FlightModeList.Add(element.Value); } } } }
// XML/Setting.xml読み込み private void InitModeName() { System.Diagnostics.Debug.WriteLine(""); ControlModeList = new List <ModeManager>(); // 初期化 FlightModeList = new List <string>(); // 初期化 // XMLファイルからxmlデータに読み込む XDocument xml = XDocument.Load(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\ACSL\X-Monitor\Setting\GUI\Settings.xml"); // Ctrlモード読み込み var elements = xml.Root.XPathSelectElements("Settings/UAV/Sys/Mode/Ctrl"); foreach (var element in elements) { ModeManager _controlMode = new ModeManager(); // i属性の読み込み if (element.Attribute("i") != null) { int i; string _attVal = element.Attribute("i").Value; if (int.TryParse(_attVal, out i)) { _controlMode.ModeNo = int.Parse(_attVal); // モードNo _controlMode.ModeName = element.Value; // モード名 System.Diagnostics.Debug.WriteLine("ControlModeList :(" + _attVal + ")" + element.Value); } else { _controlMode.ModeNo = -1; // モードNo _controlMode.ModeName = "未定義"; // モード名 } } else { _controlMode.ModeNo = -1; // モードNo _controlMode.ModeName = "未定義"; // モード名 } // reset属性の読み込み if (element.Attribute("reset") != null) { string _attVal = element.Attribute("reset").Value; if (_attVal == "Y") { _controlMode.Reset = true; // 目標値リセット(true) System.Diagnostics.Debug.WriteLine("reset-:" + _attVal); } else { _controlMode.Reset = false; // 目標値リセット(true) System.Diagnostics.Debug.WriteLine("reset-:" + _attVal); } } else { _controlMode.Reset = false; // 目標値リセット(false) System.Diagnostics.Debug.WriteLine("reset-:" + "なし"); } ControlModeList.Add(_controlMode); } // Autoモード読み込み elements = xml.Root.XPathSelectElements("Settings/UAV/Sys/Mode/Auto"); for (int i = 0; i < elements.Count(); i++) { foreach (var element in elements) { // i属性の読み込み string _attVal = element.Attribute("i").Value; if (_attVal == i.ToString()) { System.Diagnostics.Debug.WriteLine("FlightModeList :(" + i.ToString() + ")" + element.Value); FlightModeList.Add(element.Value); } } } }
///////////////////////////////////////////////////////////////////////////////////////// //如果读消息中获取的UAV数据采集列表有变化,添加在这里。意思是在这里添加每个数据到相应的变量 public int XmlConvert(int _getMode = 0) { try { if (dataUAV == "") { return(-1); } int cnt = 0; //int row = dataUAV.ToList().Where(c => c.Equals('\n')).Count(); ////System.Diagnostics.Debug.WriteLine("XmlConvert-------------------Start " + dataUAV.Length + "[" + get_Size + ">" + row + "]"); //if ((row == get_Size)) //{ XDocument xml = XDocument.Parse(dataUAV); //阅读文本数据的XML数据 //dataUAV = string.Empty; // クリア var xmlRoot = xml.Root.Element("message"); //从XML 获得数据 // IMU _BindingData.UAVpoint.Roll = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/IMU/Att", "i", "0")); _BindingData.UAVpoint.Pitch = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/IMU/Att", "i", "1")); _BindingData.UAVpoint.Yaw = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/IMU/Att", "i", "2")); // Ctrl // Nav _BindingData.UAVpoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Lon")); _BindingData.UAVpoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Lat")); _BindingData.UAVpoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Alt")); double _x = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Vel", "i", "0")); double _y = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Vel", "i", "1")); double _z = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Vel", "i", "2")); double _xx = _x * _x; double _yy = _y * _y; double _zz = _z * _z; double _spd = Math.Sqrt(_xx + _yy + _zz); _BindingData.UAVpoint.Speed = _spd; // Ref // Wpt _BindingData.NWaypoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Lon")); _BindingData.NWaypoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Lat")); _BindingData.NWaypoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Alt")); _BindingData.NWaypoint.Yaw = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Yaw")); _BindingData.NWaypoint.Speed = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Spd")); _BindingData.NWaypoint.No = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/No")); // Home _BindingData.Homepoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Lon")); _BindingData.Homepoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Lat")); _BindingData.Homepoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Alt")); _BindingData.Homepoint.Yaw = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Yaw")); // Sys _BindingData.nControlMode = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/Mode/Ctrl")); ModeManager _controlMode = new ModeManager(); _controlMode = GetControlModeStr(_BindingData.nControlMode); _BindingData.nControlModeName = _controlMode.ModeName; _BindingData.nReset = _controlMode.Reset; _BindingData.nFlightMode = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/Mode/Auto")); _BindingData.nFlightModeName = GetFlightModeStr(_BindingData.nFlightMode); _BindingData.nDriveMode = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/Mode/Drv")); _BindingData.Health.LowLvMcuProcTime = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/CPU", "a", "L")); _BindingData.Health.HighLvMcuProcTime = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/CPU", "a", "H")); // Voltage _BindingData.BatteryVoltage = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Voltage")); // Health //// LowerLevelMCU _BindingData.Health.LLMCU_RcReceiverCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ReceiverComm")); _BindingData.Health.LLMCU_RcReceiverReception = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ReceiverRecep")); _BindingData.Health.LLMCU_GyroSensorCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GyroComm")); _BindingData.Health.LLMCU_GyroSensorMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GyroMeas")); //// LowerLevelMCU - HigherLevelMCU Communication _BindingData.Health.McuComm_LowToHigh = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/McuComm", "a", "H")); _BindingData.Health.McuComm_HighToLow = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/McuComm", "a", "L")); //// HigherLevelMCU _BindingData.Health.HLMCU_IMUCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuComm")); _BindingData.Health.HLMCU_IMUGyroMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuGyroMeas")); _BindingData.Health.HLMCU_IMUAccMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuAccMeas")); _BindingData.Health.HLMCU_IMUMagMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuMagMeas")); _BindingData.Health.HLMCU_PresSensorCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/PsComm")); _BindingData.Health.HLMCU_PresSensorMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/PsMeas")); _BindingData.Health.HLMCU_GpsReceiverCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GpsComm")); _BindingData.Health.HLMCU_GpsMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GpsMeas")); //// UAV - Ground Control Station Cummunication _BindingData.Health.MainLink_UavToGcs = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/Datalink", "a", "D")); _BindingData.Health.MainLink_GcsToUav = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/Datalink", "a", "U")); // RSSI // Propo // Time // GPS _BindingData.nSat = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Sats")); switch (_getMode) { case 0: break; case 1: _BindingData.SubPoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Lat")); _BindingData.SubPoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Lon")); _BindingData.SubPoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Alt")); _BindingData.SubPoint.Yaw = _BindingData.UAVpoint.Yaw; _BindingData.SubPoint.Pitch = _BindingData.UAVpoint.Pitch; _BindingData.SubPoint.Roll = _BindingData.UAVpoint.Roll; _x = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Vel", "i", "0")); _y = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Vel", "i", "1")); _z = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Vel", "i", "2")); _xx = _x * _x; _yy = _y * _y; _zz = _z * _z; _spd = Math.Sqrt(_xx + _yy + _zz); _BindingData.SubPoint.Speed = _spd; break; } // ERROR for (int i = 0; i < 2; i++) { _BindingData.ErrorID[i] = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Error/ID", "i", i.ToString())); _BindingData.ErrorLevel[i] = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Error/Level", "i", i.ToString())); _BindingData.ErrorTicks[i] = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Error/Ticks", "i", i.ToString())); _BindingData.ErrorCategory[i] = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Error/Category", "i", i.ToString())); _BindingData.ErrorParam[i] = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Error/Param", "i", i.ToString())); } if (mode == 2) { _BindingData.CurrentTime = _BindingData.CurrentTime = double.Parse(XmlDataGet(xmlRoot, "FlightLog/Play/CurrentTime")); } #region Plot Data // 绘图数据列表 if (_BindingData.PlotWindow.Count > 0) { for (int i = 0; i < _BindingData.PlotWindow.Count; i++) { for (int j = 0; j < _BindingData.PlotWindow[i].PlotName.Count; j++) { int match = _BindingData.PlotWindow[i].PlotName[j].CompareTo("CPU使用率"); if (match == 0) { } else { BindingData.PlotWindow[i].PlotValue[j] = double.Parse(PlotDataGet(xmlRoot, "Data/UAV/" + _BindingData.PlotWindow[i].PlotName[j])); } } } } #endregion // 指令到达确认对话框 _BindingData.CommandReplay = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Command/Response")); //固件版本 GetFirmwareVersion(xmlRoot); // 清除 dataUAV = string.Empty; //System.Diagnostics.Debug.WriteLine("XmlConvert-------------------End " + cnt); return(cnt); //} //else //{ // System.Diagnostics.Debug.WriteLine("XmlConvert-------------------End *******"); // return (-1); //} } //返回一个异常信息 catch (System.Xml.XmlException ex) { //System.Diagnostics.Debug.WriteLine("XmlConvert: " + ex.Message); System.Windows.Forms.MessageBox.Show("(801) Xml Convert Error : " + ex.Message); return(-1); } }
///////////////////////////////////////////////////////////////////////////////////////// // 取得したメッセージ内のデータの読込み<---UAVデータ取得リストに変更がある場合、ココに追加すること public int XmlConvert() { try { if (dataUAV == "") { return(-1); } int cnt = 0; int row = dataUAV.ToList().Where(c => c.Equals('\n')).Count(); //System.Diagnostics.Debug.WriteLine("XmlConvert-------------------Start " + dataUAV.Length + "[" + get_Size + ">" + row + "]"); if ((row == get_Size)) { XDocument xml = XDocument.Parse(dataUAV); // textデータをxmlデータに読み込む //dataUAV = string.Empty; // クリア var xmlRoot = xml.Root.Element("message"); // xmlからデータを取得 // IMU _BindingData.UAVpoint.Roll = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/IMU/Att", "i", "0")); _BindingData.UAVpoint.Pitch = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/IMU/Att", "i", "1")); _BindingData.UAVpoint.Yaw = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/IMU/Att", "i", "2")); // Ctrl // Nav _BindingData.UAVpoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Lon")); _BindingData.UAVpoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Lat")); _BindingData.UAVpoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Nav/Alt")); // Ref // Wpt _BindingData.NWaypoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Lon")); _BindingData.NWaypoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Lat")); _BindingData.NWaypoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Alt")); _BindingData.NWaypoint.Yaw = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Yaw")); _BindingData.NWaypoint.Speed = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Wpt/Spd")); // Home _BindingData.Homepoint.Lon = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Lon")); _BindingData.Homepoint.Lat = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Lat")); _BindingData.Homepoint.Alt = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Alt")); _BindingData.Homepoint.Yaw = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Home/Yaw")); // Sys _BindingData.nControlMode = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/Mode/Ctrl")); ModeManager _controlMode = new ModeManager(); _controlMode = GetControlModeStr(_BindingData.nControlMode); _BindingData.nControlModeName = _controlMode.ModeName; _BindingData.nReset = _controlMode.Reset; _BindingData.nFlightMode = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/Mode/Auto")); _BindingData.nFlightModeName = GetFlightModeStr(_BindingData.nFlightMode); _BindingData.nDriveMode = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/Mode/Drv")); _BindingData.Health.LowLvMcuProcTime = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/CPU", "a", "L")); _BindingData.Health.HighLvMcuProcTime = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Sys/CPU", "a", "H")); // Voltage _BindingData.BatteryVoltage = double.Parse(XmlDataGet(xmlRoot, "Data/UAV/Voltage")); // Health //// LowerLevelMCU _BindingData.Health.LLMCU_RcReceiverCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ReceiverComm")); _BindingData.Health.LLMCU_RcReceiverReception = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ReceiverRecep")); _BindingData.Health.LLMCU_GyroSensorCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GyroComm")); _BindingData.Health.LLMCU_GyroSensorMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GyroMeas")); //// LowerLevelMCU - HigherLevelMCU Communication _BindingData.Health.McuComm_LowToHigh = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/McuComm", "a", "H")); _BindingData.Health.McuComm_HighToLow = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/McuComm", "a", "L")); //// HigherLevelMCU _BindingData.Health.HLMCU_IMUCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuComm")); _BindingData.Health.HLMCU_IMUGyroMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuGyroMeas")); _BindingData.Health.HLMCU_IMUAccMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuAccMeas")); _BindingData.Health.HLMCU_IMUMagMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/ImuMagMeas")); _BindingData.Health.HLMCU_PresSensorCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/PsComm")); _BindingData.Health.HLMCU_PresSensorMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/PsMeas")); _BindingData.Health.HLMCU_GpsReceiverCommunication = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GpsComm")); _BindingData.Health.HLMCU_GpsMeasurement = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/GpsMeas")); //// UAV - Ground Control Station Cummunication _BindingData.Health.MainLink_UavToGcs = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/Datalink", "a", "D")); _BindingData.Health.MainLink_GcsToUav = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/Health/Datalink", "a", "U")); // RSSI // Propo // Time // GPS _BindingData.nSat = int.Parse(XmlDataGet(xmlRoot, "Data/UAV/GPS/Sats")); if (mode == 2) { _BindingData.CurrentTime = _BindingData.CurrentTime = double.Parse(XmlDataGet(xmlRoot, "FlightLog/Play/CurrentTime")); } #region Plot Data // プロットデータリスト if (_BindingData.PlotWindow.Count > 0) { for (int i = 0; i < _BindingData.PlotWindow.Count; i++) { for (int j = 0; j < _BindingData.PlotWindow[i].PlotName.Count; j++) { int match = _BindingData.PlotWindow[i].PlotName[j].CompareTo("CPU使用率"); if (match == 0) { } else { BindingData.PlotWindow[i].PlotValue[j] = double.Parse(PlotDataGet(xmlRoot, "Data/UAV/" + _BindingData.PlotWindow[i].PlotName[j])); } } } } #endregion //dataUAV = string.Empty; //System.Diagnostics.Debug.WriteLine("XmlConvert-------------------End " + cnt); return(cnt); } else { System.Diagnostics.Debug.WriteLine("XmlConvert-------------------End *******"); return(-1); } } catch (System.Xml.XmlException ex) { //System.Diagnostics.Debug.WriteLine("XmlConvert: " + ex.Message); System.Windows.Forms.MessageBox.Show("(801) Xml Convert Error : " + ex.Message); return(-1); } }