/// <summary> /// Procedure to run when payload is received from stream. Data is cast to the appropriate data type, and the OnPayloadReceived_Callback is invoked on all subscriptions that involves the given attribute /// </summary> /// <param name="payload">The data being received from the data stream</param> /// <param name="attribute">The attribute being received</param> /// <param name="data_type">The data type that the received data is represented as</param> public void ReceivePayload(object payload, string attribute, string data_type, string stream_label) { if (subscriptions.Count > 0 && HasSubscription(attribute) && OnPayloadReceived_Callback != null) { DataSubscription subscription = subscriptions[attribute]; payload = Utils.Cast.ToType(payload, data_type); OnPayloadReceived_Callback.Invoke(payload, attribute, stream_label); if (observe_values) { if (!observedValues.ContainsLabel(attribute)) { if (observedValues.AddWithType(attribute, data_type) != null) { observedValues[attribute].OnUpdate(onObservableValueChanged_cb); } } if (observedValues.ContainsLabel(attribute)) { IObservableNumericValue observedAttribute = observedValues[attribute]; observedAttribute = observedValues[attribute]; observedAttribute.Value = payload; } } } }
public void TestInterfaceArray() { IObservableNumericValue[] array = new IObservableNumericValue[5]; array[0] = new ObservableInt { Value = 1, Min = -1, Max = 1 }; array[1] = new ObservableFloat { Value = 1.0f, Min = -1.0f, Max = 2.0f }; array[2] = new ObservableDouble { Value = 1.5d, Min = -1.5d, Max = 2.0d }; array[3] = new ObservableInt { Value = 1, Min = -1, Max = 1 }; array[4] = new ObservableFloat { Value = 1.0f, Min = -1.0f, Max = 1.0f }; foreach (IObservableNumericValue val in array) { Assert.IsFalse(val.Over()); Assert.IsFalse(val.Under()); Assert.IsTrue(val.Stable()); } }
public void SetCollection(ObservableNumericValueCollection c) { Collection = new IObservableNumericValue[c.Count]; for (int i = 0; i < c.Count; i++) { Collection[i] = c[i]; } }
private void UIParameterControlInput_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { // Implement better UI response to error handling so that user understands when an invalid input is entered UIParameterControlInput.CurrentCell.ErrorText = ""; if (activeParameterControlTemplate == null) { activeParameterControlTemplate = new ParameterControlTemplate(); } if (UIParameterControlInput.Rows[e.RowIndex].IsNewRow) { return; } if (!double.TryParse(e.FormattedValue.ToString(), out double numericValue) && e.ColumnIndex > 0) { UIParameterControlInput.CurrentCell.ErrorText = "The value must be a number"; } else { DataGridViewCell current = UIParameterControlInput.CurrentCell; string tag = current.OwningRow.Tag.ToString(); if (dataReceiver.ObservedValues.ContainsLabel(tag)) { IObservableNumericValue obsValue = dataReceiver.ObservedValues[tag]; object castNumericValue = Convert.ChangeType(numericValue, obsValue.type); if (current.OwningColumn.Name == "ParamMin") { if (obsValue.PlotAnnotationMinLine != null) { RemovePlotAnnotationLine(obsValue.PlotAnnotationMinLine); } obsValue.Min = castNumericValue; obsValue.PlotAnnotationMinLine = AddPlotAnnotationLine(Convert.ToDouble(numericValue), tag, OxyColors.Red); } else if (current.OwningColumn.Name == "ParamMax") { if (obsValue.PlotAnnotationMaxLine != null) { RemovePlotAnnotationLine(obsValue.PlotAnnotationMaxLine); } obsValue.Max = castNumericValue; obsValue.PlotAnnotationMaxLine = AddPlotAnnotationLine(Convert.ToDouble(numericValue), tag, OxyColors.Red); } } } }
/// <summary> /// A method to invoke once an observable value is changed /// </summary> /// <param name="val">The observed value</param> public void OnObservedValueChange(IObservableNumericValue val) { if (currentInstructionEntry.instruction != null && currentInstructionEntry.observedValueLabels != null) { if (currentInstructionEntry.observedValueLabels.Contains(val.Label)) { currentInstructionEntry.instruction.feedbackStatus = val.Status(); Debug.Log("==============================="); Debug.Log("Observed " + val.Label + " as " + val.Status()); Debug.Log(val.Value + "," + val.Min + "," + val.Max); Debug.Log("==============================="); } } }
private void ReceiveSensorList(object _sensor_list, string attribute, string label) { Debug.Log("Receive sensor list " + attribute); JObject sensor_list = (JObject)_sensor_list; ThreadHelper.UI_Invoke(this, null, UISensorCheckboxList, (data) => { autoObservableValues = new ObservableNumericValueCollection(); foreach (var elem in (JObject)data["sensor_list"]) { if (!sensor_information.ContainsKey(elem.Key)) { //string sensor_name = label + ": " + elem.Key; string sensor_name = elem.Key; sensor_information.Add(sensor_name, elem.Value.ToString()); UISensorCheckboxList.Items.Add(sensor_name); if (DataReceiver.Observe) { AddParameterControlRow(new ObservedDataRow { name = elem.Key, value = "" } ); IObservableNumericValue o = autoObservableValues.AddWithType(elem.Key, elem.Value.ToString()); o.OnUpdate(ObservedValueChanged); } } } if (autoObservableValues.Count > 0) { autoParamControlTemplate.SetCollection(autoObservableValues); DataReceiver.SetObservableNumericValues(autoObservableValues); } }, new Hashtable { { "form", this }, { "panel", null }, { "control", UISensorCheckboxList }, { "sensor_list", sensor_list } }); }
public void ObservedValueChanged(IObservableNumericValue val) { DataGridViewRow row = null; foreach (DataGridViewRow r in UIObservedValuesOuputGrid.Rows) { if (r.Tag.Equals(val.Label)) { row = r; break; } } if (row != null) { row.Cells["observedValue"].Value = val.Value; row.Cells["status"].Value = val.Status().ToString(); row.Cells["difference"].Value = val.Diff().ToString(); } }
private void UITestConfigOutputParamChecklist_SelectedIndexChanged(object sender, EventArgs e) { if (UITestConfigOutputParamChecklist.SelectedItem != null) { IObservableNumericValue observableValue = (IObservableNumericValue)UITestConfigOutputParamChecklist.SelectedItem; bool is_checked = UITestConfigOutputParamChecklist.CheckedItems.IndexOf(observableValue) > -1; if (is_checked) { if (!observedValues.Contains(observableValue)) { observedValues.Add(observableValue); } } else { if (observedValues.Contains(observableValue)) { observedValues.Remove(observableValue); } } } }