/// <summary> /// Anderer Parameter wurde ausgewählt /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cb_Parameter_SelectedIndexChanged(object sender, EventArgs e) { if (cb_Parameter.SelectedIndex != -1) { try { selectedParameter = core.currentUAV.uavData.GetFromPath(Convert.ToString(cb_Parameter.SelectedItem)); if (selectedParameter == null) { throw new Exception("Parameter not found in the given Path"); } this.valueTracker.TickFrequency = 100; this.valueTracker.TickStyle = TickStyle.Both; valueTracker.Minimum = Convert.ToDecimal(selectedParameter.Min); valueTracker.Maximum = Convert.ToDecimal(selectedParameter.Max); this.ValueBar.Minimum = Convert.ToDecimal(valueTracker.Minimum); this.ValueBar.Maximum = Convert.ToDecimal(valueTracker.Maximum); this.tb_max.Text = Convert.ToString(selectedParameter.Max); this.tb_min.Text = Convert.ToString(selectedParameter.Min); this.lbl_value.Text = selectedParameter.Value.ToString(); if ((selectedParameter.DoubleValue >= selectedParameter.MinDoubleValue) && (selectedParameter.DoubleValue <= selectedParameter.MaxDoubleValue)) { ValueBar.Value = Convert.ToDecimal(selectedParameter.DoubleValue); valueTracker.Value = Convert.ToDecimal(selectedParameter.DoubleValue); } } catch (Exception ex) { MessageBox.Show("Cannot select Value for Parameter Control: " + ex.Message); } } }
/// <summary> /// This Method is used to send the filtered Eventstream to the CommunicationEndpoints /// </summary> /// <param name="param"></param> /// <param name="isremote"></param> void SendDataForwardNow(UAVSingleParameter param, bool isremote) { try{ if (!isremote) { foreach (CommunicationEndpoint myendpoint in knownEndpoints) { //if (param is UAVStructure) //{ // // param.ValueChanged+=new UAVParameter.ValueChangedHandler(param_ValueChanged); // foreach (UAVSingleParameter myparam in ((UAVStructure)param).values.Values) // { // myendpoint.SendData(myparam); // SendEventCounter++; // } //} myendpoint.SendData(param); SendEventCounter++; } } }catch (Exception ex) { Console.WriteLine("Error on send forward " + ex.Message + ex.StackTrace.ToString()); } }
/// <summary> /// Something has been changed to queue the Event /filter it using the Send Regulator /// </summary> /// <param name="param">The Parameter Object which has been changed</param> /// <param name="isremote">A boolean Variable to determine if the event comes from here or is an remote event</param> public void uavData_ValueChanged(UAVSingleParameter param, bool isremote) { if (!isremote) { mySendRegulator.EventRecieved(param, isremote); } }
protected void gpsValues_ValueChanged(UAVSingleParameter param, bool isremote) { if (ValueChanged != null) { ValueChanged(param, isremote); } }
//public void FireValueChangedEvent(UAVSingleParameter param, bool isremote) //{ // if (ValueChanged != null) ValueChanged(param, isremote); //} /// <summary> /// Fires the changed event. /// </summary> /// <param name='param'> /// Parameter. /// </param> /// <param name='isremote'> /// Isremote. /// </param> public void FireDataRecievedEvent(UAVSingleParameter param, bool isremote) { if (DataRecieved != null) { DataRecieved(param, isremote); } }
/// <summary> /// Sieht nach welcher Parameter in wie abgelegt werden soll /// </summary> /// <param name="param"></param> /// <param name="isremote"></param> void Source_ValueChanged(UAVSingleParameter param, bool isremote) { if (param.GetStringPath() == GetStringPath()) { return; } lock (Syncobj) { // Console.WriteLine(param.Name + " " + param.Value); if (mapping.ContainsKey(param.Name)) { if (values.ContainsKey(mapping[param.Name])) { if (values[mapping[param.Name]].GetStringPath() != param.GetStringPath()) { values[mapping[param.Name]].Value = param.Value; } } else { values.Add(mapping[param.Name], new UAVParameter(mapping[param.Name], param.Value, param.Min, param.Max)); values[mapping[param.Name]].updateRate = 40; } } } }
public void Value_ValueChanged(UAVSingleParameter param, bool isremote) { if (ValueChanged != null) { ValueChanged(param, isremote); } }
private static void NormaliseStructure(UAVSingleParameter param, List <UAVSingleParameter> remotedata) { if (param is UAVStructure) { UAVStructure mystructure = ((UAVStructure)param); foreach (UAVSingleParameter myparams in mystructure.values.Values) { NormaliseStructure(myparams, remotedata); UAVSingleParameter structparam = new UAVSingleParameter(param.GetStringPath(), myparams.Value, myparams.Min, myparams.Max); if (remotedata.Count(m => m.Name.Equals(structparam.Name)) == 0) { remotedata.Add(structparam); } } // UAVSingleParameter param1 = new UAVSingleParameter(param.Name, param.Value, param.Min, param.Max); // remotedata.Add(param1); } else if (param is UAVSingleParameter) { UAVSingleParameter newparam = new UAVSingleParameter(param.Name, param.Value); newparam.Name = param.GetStringPath(); newparam.Min = param.Min; newparam.Max = param.Max; newparam.Parent = param.Parent; newparam.updateRate = param.updateRate; newparam.Value = param.Value; if (remotedata.Count(m => m.Name.Equals(newparam.Name)) == 0) { remotedata.Add(newparam); } } }
void MonitoredDictionary_ValueChanged(UAVSingleParameter param, bool isremote) { if (ValueChanged != null) { ValueChanged(param, isremote); } }
public void Add(string key, UAVSingleParameter value) { lock (SyncObj) { if (uavData.ContainsKey(key)) { uavData[key].Min = value.Min; uavData[key].Max = value.Max; uavData[key].updateRate = value.updateRate; uavData[key].Value = value.Value; } else { value.Parent = owner; uavData.Add(key, value); if (value is UAVStructure) { ((UAVStructure)(value)).ValueChanged += new UAVStructure.ValueChangedHandler(MonitoredDictionary_ValueChanged); // value.ValueChanged += new UAVSingleParameter.ValueChangedHandler(Value_ValueChanged); } else { value.ValueChanged += new UAVSingleParameter.ValueChangedHandler(Value_ValueChanged); } if (ValueChanged != null) { ValueChanged(value, false); } if (NewValue != null) { NewValue(value, false); } } } }
public override void SendData(UAVSingleParameter param) { if (param.updateRate == Int32.MaxValue) { return; } try { lock (SendSync) { if (commType == Communicationtype.Send) { if (server != null) { if (server is TCPServer.DataTcpServer) { ((TCPServer.DataTcpServer)server).Send(param); } } if (client != null) { if (client is TcpDataClient) { ((TcpDataClient)(client)).Send(param); } } } } } catch (Exception ex) { } }
public ParameterControl(GroundControlCore.GroundControlCore core, UAVCommons.UAVSingleParameter parameter) : base() { InitializeComponent(); this.core = core; core.currentUAV.uavData.NewValue += new UAVCommons.MonitoredDictionary<string, UAVCommons.UAVSingleParameter>.NewValueHandler(uavData_NewValue); if (parameter != null) selectedParameter = parameter; Update_Combobox(); if (parameter != null) { cb_Parameter.SelectedItem = parameter.GetStringPath(); } btn_output.ForeColor = Color.Blue; btn_output.Text = "Input"; output = false; if (parameter != null) { ValueBar.Step = 1; valueTracker.TickFrequency = 10; valueTracker.TickStyle = TickStyle.Both; valueTracker.Maximum = Convert.ToDecimal(parameter.Max); valueTracker.Minimum = Convert.ToDecimal(parameter.Min); ValueBar.Minimum = valueTracker.Minimum; ValueBar.Maximum = valueTracker.Maximum; if (parameter.Max != null) tb_max.Text = parameter.Max.ToString(); if (parameter.Min != null) tb_min.Text = parameter.Min.ToString(); if ((parameter.Value != null) && (parameter.Value.ToString() != "")) { if ((parameter.DoubleValue >= parameter.MinDoubleValue) && (parameter.DoubleValue <= parameter.MaxDoubleValue)) { valueTracker.Value = Convert.ToDecimal(parameter.Value); ValueBar.Value = Convert.ToDecimal(valueTracker.Value); lbl_value.Text = parameter.Value.ToString(); } else { lbl_value.Text = "Value out of Bounds " + parameter.Value.ToString(); } } } else { ValueBar.Minimum = 0; valueTracker.Minimum = 0; ValueBar.Maximum = 100; valueTracker.Maximum = 100; ValueBar.Value = 50; valueTracker.Value = 50; lbl_value.Text = "50"; } this.valueTracker.Factor = 0.0001m; }
void uavData_NewValue(UAVCommons.UAVSingleParameter param, bool isremote) { if (cb_Parameter.InvokeRequired) { cb_Parameter.Invoke(new MethodInvoker(Update_Combobox)); } // param.ValueChanged += new UAVCommons.UAVParameter.ValueChangedHandler(parameter_ValueChanged); }
public static void LoadValues(XmlElement elem, UAVBase target) { if (System.Threading.Thread.CurrentThread.CurrentCulture.Name != "en-US") { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); } foreach (XmlElement val in elem.ChildNodes) { LoadValues(val, target); } string value = null; string path = null; try { path = elem.GetAttribute("Path"); if (elem.HasAttribute("Value")) { string strval = elem.GetAttribute("Value"); if (strval == "[[NULL]]") { value = null; } else { value = strval; } } if (path == "") { return; } UAVSingleParameter param = target.uavData.SilentUpdate(path, value, false); param.LoadValues(elem); if (elem.HasAttribute("Max")) { param.Max = elem.GetAttribute("Max"); } if (elem.HasAttribute("Min")) { param.Min = elem.GetAttribute("Min"); } if (elem.HasAttribute("URate")) { param.updateRate = Convert.ToInt32(elem.GetAttribute("URate")); } } catch (Exception ex) { Console.WriteLine("Error on loading Values for " + path + " value was " + value); throw ex; } }
public static void NormaliseStructure(UAVSingleParameter param, List <UAVSingleParameter> remotedata) { if (param is UAVStructure) { UAVStructure mystructure = ((UAVStructure)param); foreach (UAVSingleParameter myparams in mystructure.values.Values) { if (myparams is UAVStructure) { NormaliseStructure(myparams, remotedata); UAVSingleParameter temp = new UAVSingleParameter(myparams.GetStringPath(), myparams.Value); temp.Max = myparams.Max; temp.Min = myparams.Min; temp.updateRate = myparams.updateRate; temp.Value = myparams.Value; remotedata.Add(temp); } else { UAVSingleParameter temp = new UAVSingleParameter(myparams.GetStringPath(), myparams.Value); temp.Max = myparams.Max; temp.Min = myparams.Min; // temp.Value = myparams.Value; temp.updateRate = myparams.updateRate; remotedata.Add(temp); } } //Eigen Wert UAVSingleParameter temp2 = new UAVSingleParameter(param.GetStringPath(), param.Value); temp2.Max = param.Max; temp2.Min = param.Min; // temp.Value = myparams.Value; temp2.updateRate = param.updateRate; remotedata.Add(temp2); } else if (param is UAVSingleParameter) { UAVSingleParameter newparam = new UAVSingleParameter(param.Name, param.Value); newparam.Name = param.GetStringPath(); newparam.Min = param.Min; newparam.Max = param.Max; // if (!(param.Parent is UAVBase)) // { // newparam.Parent = param.Parent; // } newparam.updateRate = param.updateRate; newparam.Value = param.Value; remotedata.Add(newparam); } }
private void CreateProperties(object Min, object Max, int rate) { minparam = new UAVSingleParameter("Min", Min, Int16.MinValue, Int16.MaxValue, rate); maxparam = new UAVSingleParameter("Max", Max, Int16.MinValue, Int16.MaxValue, rate); urateparam = new UAVSingleParameter("UpdateRate", rate, int.MinValue, int.MaxValue, rate); urateparam.Value = updateRate; values.Add(minparam); values.Add(maxparam); values.Add(urateparam); minparam.ValueChanged += new UAVSingleParameter.ValueChangedHandler(minparam_ValueChanged); maxparam.ValueChanged += new UAVSingleParameter.ValueChangedHandler(maxparam_ValueChanged); urateparam.ValueChanged += new UAVSingleParameter.ValueChangedHandler(urateparam_ValueChanged); }
public void Send(UAVSingleParameter param) { if (param.Value == null) { return; } lock (SendSync) { if (client != null) { UTF8Encoding encoder = new UTF8Encoding(); byte[] buffer = encoder.GetBytes(param.GetStringPath() + "|" + DateTime.UtcNow.Ticks.ToString() + "|" + param.Value.ToString() + "\n"); client.Send(buffer, buffer.Length); } } }
/// <summary> /// We have recieved Data from an CommunicationEndpoint, now we process it /// </summary> /// <param name="timestamp"></param> /// <param name="data"></param> private void mycomm_DataRecieved(DateTime timestamp, List <UAVParameter> data) { if (initialised) { lock (SynclockRecieve) { foreach (UAVParameter param in data) { string name = ""; // Console.WriteLine(param.Name + ": " + param.Value); RecieveEventCounter++; if (recievedParameters.ContainsKey(timestamp.Ticks.ToString() + param.Name)) { continue; } UAVSingleParameter result = uavData.SilentUpdate(param.Name, param.Value, true); if (DataArrived != null) { DataArrived(null, result); } recievedParameters.Add(timestamp.Ticks.ToString() + param.Name, timestamp); } List <string> deletelist = new List <string>(); foreach (KeyValuePair <string, DateTime> pair in recievedParameters) { if (pair.Value < DateTime.UtcNow.AddSeconds(-10)) { deletelist.Add(pair.Key); } } foreach (string key in deletelist) { recievedParameters.Remove(key); } deletelist.Clear(); } } }
public void Send(UAVSingleParameter param) { if (System.Threading.Thread.CurrentThread.CurrentCulture.Name != "en-US") { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); } if (param.Value == null) { return; } lock (SendSync) { if (clientStream != null) { UTF8Encoding encoder = new UTF8Encoding(); byte[] buffer = encoder.GetBytes(param.GetStringPath() + "|" + DateTime.UtcNow.Ticks.ToString() + "|" + param.Value.ToString() + "\n"); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); } } }
public override void SendData(UAVSingleParameter param) { if (param.updateRate == Int32.MaxValue) { return; } try { lock (SendSync) { if (commType == Communicationtype.Send) { if ((client is UDPDataClient) && (client != null)) { ((UDPDataClient)(client)).Send(param); } } } } catch (Exception ex) { } }
/// <summary> /// Anderer Parameter wurde ausgewählt /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cb_Parameter_SelectedIndexChanged(object sender, EventArgs e) { if (cb_Parameter.SelectedIndex != -1) { try { selectedParameter = core.currentUAV.uavData.GetFromPath(Convert.ToString(cb_Parameter.SelectedItem)); if (selectedParameter == null) throw new Exception("Parameter not found in the given Path"); this.valueTracker.TickFrequency = 100; this.valueTracker.TickStyle = TickStyle.Both; valueTracker.Minimum = Convert.ToDecimal(selectedParameter.Min); valueTracker.Maximum = Convert.ToDecimal(selectedParameter.Max); this.ValueBar.Minimum = Convert.ToDecimal(valueTracker.Minimum); this.ValueBar.Maximum = Convert.ToDecimal(valueTracker.Maximum); this.tb_max.Text = Convert.ToString(selectedParameter.Max); this.tb_min.Text = Convert.ToString(selectedParameter.Min); this.lbl_value.Text = selectedParameter.Value.ToString(); if ((selectedParameter.DoubleValue >= selectedParameter.MinDoubleValue) && (selectedParameter.DoubleValue <= selectedParameter.MaxDoubleValue)) { ValueBar.Value = Convert.ToDecimal(selectedParameter.DoubleValue); valueTracker.Value = Convert.ToDecimal(selectedParameter.DoubleValue); } } catch (Exception ex) { MessageBox.Show("Cannot select Value for Parameter Control: " + ex.Message); } } }
void urateparam_ValueChanged(UAVSingleParameter param, bool isremote) { updateRate = urateparam.IntValue; }
void parameter_ValueChanged(UAVSingleParameter param, bool isremote) { Value_ValueChanged(param, isremote); }
void maxparam_ValueChanged(UAVSingleParameter param, bool isremote) { max = maxparam.Value; }
void minparam_ValueChanged(UAVSingleParameter param, bool isremote) { min = minparam.Value; }
public void Add(UAVSingleParameter value) { value.Parent = owner; Add(value.Name, value); }
public UAVSingleParameter SilentUpdate(string key, object value, bool isremote) { string newpath = ""; GetKeyPath(ref key, ref newpath); if (uavData.ContainsKey(key)) { // Cut away current level return(uavData[key].SilentUpdate(newpath, value, isremote)); } else { UAVSingleParameter parameter; if (newpath == key) { if (owner is UAVParameter) { parameter = new UAVSingleParameter(key, value); } else { if ((key == "Min") || (key == "Max") || (key == "UpdateRate")) { parameter = new UAVSingleParameter(key, value); } else { if (owner.Name != key) { parameter = new UAVParameter(key, value); } else { return((UAVSingleParameter)owner); } } } } else { parameter = new UAVStructure(key, ""); parameter.Parent = owner; parameter.ValueChanged += new UAVSingleParameter.ValueChangedHandler(parameter_ValueChanged); uavData.Add(key, parameter); UAVSingleParameter child = parameter.SilentUpdate(newpath, value, isremote); child.Parent = parameter; child.ValueChanged += new UAVSingleParameter.ValueChangedHandler(parameter_ValueChanged); return(child); } parameter.ValueChanged += new UAVSingleParameter.ValueChangedHandler(parameter_ValueChanged); parameter.Parent = owner; uavData.Add(key, parameter); if (NewValue != null) { NewValue(parameter, isremote); } return(parameter); } }
public bool TryGetValue(string key, out UAVSingleParameter value) { return(uavData.TryGetValue(key, out value)); }
private void UpdateValue(UAVCommons.UAVSingleParameter param) { if (param != null) { double min = 0; double max = 0; UAVSingleParameter p = selectedParameter; // Check if is Servo if ((selectedParameter is UAVStructure) && (((UAVStructure)selectedParameter).values.ContainsKey("Value"))) { p = ((UAVStructure)selectedParameter)["Value"]; } if ((p is UAVStructure) && (((UAVStructure)p)["Min"] != null)) { min = Convert.ToDouble(((UAVStructure)p)["Min"].Value.ToString()); } else { min = Convert.ToDouble(p.Min.ToString()); } if ((p is UAVStructure) && (((UAVStructure)p)["Max"] != null)) { max = Convert.ToDouble(((UAVStructure)p)["Max"].Value); } else { max = Convert.ToDouble(p.Max.ToString()); } double result = 0; if (Double.TryParse(Convert.ToString(param.Value), out result)) { if (output) { if (ValueBar.InvokeRequired) { ValueBar.Invoke((MethodInvoker) delegate { ValueBar.Minimum = Convert.ToDecimal(min); ValueBar.Maximum = Convert.ToDecimal(max); if ((Convert.ToDouble(param.Value) > min) && (Convert.ToDouble(param.Value) < max)) { ValueBar.Value = Convert.ToDecimal(Convert.ToDouble(param.Value)); } ValueBar.Refresh(); }); } else { ValueBar.Minimum = Convert.ToDecimal(min); ValueBar.Maximum = Convert.ToDecimal(max); if ((Convert.ToDouble(param.Value) > min) && (Convert.ToDouble(param.Value) < max)) { ValueBar.Value = Convert.ToDecimal(Convert.ToDouble(param.Value)); } ValueBar.Invalidate(); } } else { if (valueTracker.InvokeRequired) { valueTracker.Invoke((MethodInvoker) delegate { valueTracker.Maximum = Convert.ToDecimal(max); valueTracker.Minimum = Convert.ToDecimal(min); if ((Convert.ToDouble(param.Value) > min) && (Convert.ToDouble(param.Value) < max)) { valueTracker.Value = Convert.ToDecimal(Convert.ToDouble(param.Value)); } valueTracker.TickFrequency = 10; valueTracker.TickStyle = TickStyle.Both; }); valueTracker.Invalidate(); } else { // valueTracker.Value = Convert.ToDecimal(param.Value); valueTracker.TickFrequency = 10; valueTracker.TickStyle = TickStyle.Both; valueTracker.Maximum = Convert.ToDecimal(max); valueTracker.Minimum = Convert.ToDecimal(min); if ((param.DoubleValue > min) && (param.DoubleValue < max)) { valueTracker.Value = Convert.ToDecimal(param.Value); } valueTracker.Invalidate(); } } if (lbl_value.InvokeRequired) { // lbl_value.Invoke((MethodInvoker)(() => lbl_value.Text = param.Value.ToString())); tb_max.Invoke((MethodInvoker)(() => tb_max.Text = max.ToString())); tb_min.Invoke((MethodInvoker)(() => tb_min.Text = min.ToString())); // lbl_value.Invalidate(); } else { tb_max.Text = max.ToString(); tb_min.Text = min.ToString(); lbl_value.Text = param.Value.ToString(); lbl_value.Invalidate(); } } } }
public ParameterControl(GroundControlCore.GroundControlCore core, UAVCommons.UAVSingleParameter parameter) : base() { InitializeComponent(); this.core = core; core.currentUAV.uavData.NewValue += new UAVCommons.MonitoredDictionary <string, UAVCommons.UAVSingleParameter> .NewValueHandler(uavData_NewValue); if (parameter != null) { selectedParameter = parameter; } Update_Combobox(); if (parameter != null) { cb_Parameter.SelectedItem = parameter.GetStringPath(); } btn_output.ForeColor = Color.Blue; btn_output.Text = "Input"; output = false; if (parameter != null) { ValueBar.Step = 1; valueTracker.TickFrequency = 10; valueTracker.TickStyle = TickStyle.Both; valueTracker.Maximum = Convert.ToDecimal(parameter.Max); valueTracker.Minimum = Convert.ToDecimal(parameter.Min); ValueBar.Minimum = valueTracker.Minimum; ValueBar.Maximum = valueTracker.Maximum; if (parameter.Max != null) { tb_max.Text = parameter.Max.ToString(); } if (parameter.Min != null) { tb_min.Text = parameter.Min.ToString(); } if ((parameter.Value != null) && (parameter.Value.ToString() != "")) { if ((parameter.DoubleValue >= parameter.MinDoubleValue) && (parameter.DoubleValue <= parameter.MaxDoubleValue)) { valueTracker.Value = Convert.ToDecimal(parameter.Value); ValueBar.Value = Convert.ToDecimal(valueTracker.Value); lbl_value.Text = parameter.Value.ToString(); } else { lbl_value.Text = "Value out of Bounds " + parameter.Value.ToString(); } } } else { ValueBar.Minimum = 0; valueTracker.Minimum = 0; ValueBar.Maximum = 100; valueTracker.Maximum = 100; ValueBar.Value = 50; valueTracker.Value = 50; lbl_value.Text = "50"; } this.valueTracker.Factor = 0.0001m; }
public abstract void SendData(UAVSingleParameter param);