/// <summary> /// Gets all currently published and subscribed topics and adds them to the topic list /// </summary> /// <param name="topics"> List to store topics</param> /// <returns></returns> public static bool getTopics(ref TopicInfo[] topics) { List<TopicInfo> topicss = new List<TopicInfo>(); XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, this_node.Name); args.Set(1, ""); if (!execute("getPublishedTopics", args, result, payload, true)) return false; topicss.Clear(); for (int i = 0; i < payload.Size; i++) topicss.Add(new TopicInfo(payload[i][0].Get<string>(), payload[i][1].Get<string>())); topics = topicss.ToArray(); return true; }
public MainWindow() { new Thread(() => { ROS.Init(new string[0], "dynamic_reconfigure_sharp_" + Environment.MachineName); nh = new NodeHandle(); Dispatcher.Invoke(new Action(() => { ConnecitonLabel.Content = "Connected"; })); }).Start(); try { InitializeComponent(); System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical; TargetBox.ItemsSource = knownConfigurations.Keys; knownConfigurations.Add("-", null); TargetBox.SelectedIndex = 0; } catch (Exception e) { EDB.WriteLine(e); Close(); } topicPoller = new Thread(() => { while (ROS.ok && !ROS.shutting_down) { TopicInfo[] topics = new TopicInfo[0]; master.getTopics(ref topics); string[] nodes = new string[0]; master.getNodes(ref nodes); List<string> prevlist = new List<string>(knownConfigurations.Keys); List<string> additions = new List<string>(); foreach (TopicInfo ti in topics) { if (ti.data_type == "dynamic_reconfigure/Config") { string prefix = ti.name.Replace("/parameter_updates", ""); if (!knownConfigurations.ContainsKey(prefix)) additions.Add(prefix); else prevlist.Remove(prefix); } } lock (this) { if (!ROS.ok || ROS.shutting_down) return; foreach (string prefix in additions) { string pfx = prefix; Dispatcher.Invoke(new Action(() => { knownConfigurations.Add(pfx, null); }), new TimeSpan(0,0,0,1)); } } Dispatcher.Invoke(new Action(TargetBox.Items.Refresh)); foreach (string s in prevlist) { if (!s.Equals("-")) { string pfx = s; Dispatcher.Invoke(new Action(() => { if (reconfigureview != null && s.Equals(reconfigureview.Namespace)) reconfigureview.Namespace = null; if (TargetBox.SelectedItem != null && ((string) TargetBox.SelectedItem).Equals(pfx)) { TargetBox.SelectedIndex = 0; } lock (this) { knownConfigurations.Remove(pfx); } }), new TimeSpan(0, 0, 0, 1)); } } Dispatcher.Invoke(new Action(TargetBox.Items.Refresh)); if (reconfigureview == null && nh != null) { Dispatcher.Invoke(new Action(() => { string target = null; if (TargetBox.SelectedItem != null && !String.Equals(TargetBox.SelectedItem.ToString(), "-")) target = TargetBox.SelectedItem.ToString(); reconfigureview = new DynamicReconfigurePage(nh, target); PageContainer.Children.Add(reconfigureview); })); } Thread.Sleep(500); } }); topicPoller.Start(); }