/** * Add a publisher to this connection. There can be many publishers. */ public void AddPublisher(Type publisher) { IsValidStaticPublisher(publisher); string topicName = (string)publisher.GetMethod("GetMessageTopic", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).Invoke(null, new object[] { }); List <Type> topic_pubs; if (static_publishers.TryGetValue(topicName, out topic_pubs)) { if (!topic_pubs.Contains(publisher)) { topic_pubs.Add(publisher); } } else { topic_pubs = new List <Type>(2); topic_pubs.Add(publisher); static_publishers.Add(topicName, topic_pubs); } if (_connected) { _ws.Send(ROSBridgeMsg.Advertise(topicName, GetMessageType(publisher))); Debug.Log("Sending " + ROSBridgeMsg.Advertise(topicName, GetMessageType(publisher))); } }
private void Run() { _ws = new WebSocket(_host + ":" + _port); // _ws.Compression = CompressionMethod.Deflate; _ws.Log.Level = LogLevel.Trace; // _ws.Log.File = "socket.log"; _ws.OnError += (sender, e) => { UnityEngine.Debug.LogError("Error: " + e.Message); }; _ws.OnClose += (sender, e) => { UnityEngine.Debug.Log("Connection closed: " + e.Reason); }; _ws.OnMessage += (sender, e) => this.OnMessage(e.Data); _ws.Connect(); if (_ws != null) { foreach (Type p in _subscribers) { _ws.Send(ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); UnityEngine.Debug.Log("Sending " + ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); } foreach (Type p in _publishers) { _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); UnityEngine.Debug.Log("Sending " + ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); } } while (_applicationIsPlaying) { Thread.Sleep(1000); } }
private void Run() { _ws = new WebSocket(_host + ":" + _port); _ws.OnMessage += (sender, e) => this.OnMessage(e.Data); //_ws.CloseAsync(); _ws.Connect(); foreach (Type p in _subscribers) { _ws.Send(ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); if (_debug) { Debug.Log("Sending " + ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); } } foreach (Type p in _publishers) { _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); if (_debug) { Debug.Log("Sending " + ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); } } while (true) { Thread.Sleep(10000); } }
private void Run() { _ws = new WebSocket(_host + ":" + _port); _ws.OnMessage += (sender, e) => this.OnMessage(e.Data); _ws.Connect(); foreach (Type p in _subscribers) { _ws.Send(ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); Debug.Log("Sending " + ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); } foreach (Type p in _publishers) { _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); Debug.Log("Sending " + ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); } foreach (Pair <Type, String> p in _publishersNew) { _ws.Send(ROSBridgeMsg.Advertise(p.Second, GetMessageType(p.First))); Debug.Log("Sending " + ROSBridgeMsg.Publish(p.Second, GetMessageType(p.First))); } while (true) { Thread.Sleep(1000); } }
private void Run() { #if UNITY_EDITOR _ws = new WebSocket(_host + ":" + _port); _ws.OnMessage += (sender, e) => this.OnMessage(e.Data); //TODO connecting takes too long _ws.Connect(); foreach (Type p in _subscribers) { _ws.Send(ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); Debug.Log("Sending " + ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); } foreach (Type p in _publishers) { _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); Debug.Log("Sending " + ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); } _connected = true; while (true) { Thread.Sleep(1000); } #endif }
public void AddPublisher(ROSBridgePublisher publisher) { _publishers.Add(publisher); if (IsConnected && !IsDisconnecting) { WebSocket.Send(ROSBridgeMsg.Advertise(publisher.GetMessageTopic(), publisher.GetMessageType())); } }
/** * Add a publisher to this connection. There can be many publishers. */ public void AddPublisher(Type publisher) { IsValidPublisher(publisher); _publishers.Add(publisher); if (_running) { _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(publisher), GetMessageType(publisher))); } }
/// <summary> /// Advertise to the ROSBridge server that a topic will be published to. /// </summary> /// <param name="topicName">The name of the topic to be published to.</param> /// <param name="message_type">The message type of that topic.</param> public void AddPublisher(string topicName, string message_type) { if (publishTopic_to_messageType.ContainsKey(topicName)) { return; } publishTopic_to_messageType[topicName] = message_type; if (_connected) { _ws.Send(ROSBridgeMsg.Advertise(topicName, message_type)); Debug.Log("Sending " + ROSBridgeMsg.Advertise(topicName, message_type)); } }
private void Run(Action <string, bool> callback) { try { WebSocket = new WebSocket(_host + ":" + _port); WebSocket.OnMessage += (sender, e) => this.OnMessage(e.Data); WebSocket.Connect(); if (callback != null) { callback(_robotName, WebSocket.IsAlive); } if (!WebSocket.IsAlive) { return; } } catch (Exception e) { Debug.Log(e); return; } IsConnected = WebSocket.IsAlive; WebSocket.OnClose += (sender, args) => { if (OnDisconnect != null) { OnDisconnect(args.WasClean); } }; foreach (ROSBridgeSubscriber subscriber in _subscribers) { WebSocket.Send(ROSBridgeMsg.Subscribe(subscriber.GetMessageTopic(), subscriber.GetMessageType())); Debug.Log("Sending " + ROSBridgeMsg.Subscribe(subscriber.GetMessageTopic(), subscriber.GetMessageType())); } foreach (ROSBridgePublisher publisher in _publishers) { WebSocket.Send(ROSBridgeMsg.Subscribe(publisher.GetMessageTopic(), publisher.GetMessageType())); Debug.Log("Sending " + ROSBridgeMsg.Advertise(publisher.GetMessageTopic(), publisher.GetMessageType())); } while (true) { Thread.Sleep(1000); } }
/// <summary> /// The function run by the _myThread thread. Establishes WebSocket connection with the remote ROSBridge server. /// Performs all the topic subscriptions and advertisements calls made to this class prior to connection establishment. /// </summary> private void Run() { _ws = new WebSocket(_host + ":" + _port); _ws.OnMessage += (sender, e) => this.OnMessage(e.Data); _ws.Connect(); _connected = true; foreach (KeyValuePair <string, List <Type> > topic in static_subscribers) { _ws.Send(ROSBridgeMsg.Subscribe(topic.Key, GetMessageType(topic.Value[0]))); Debug.Log("Sending " + ROSBridgeMsg.Subscribe(topic.Key, GetMessageType(topic.Value[0]))); } foreach (KeyValuePair <string, List <ROSTopicSubscriber> > topic in subscribers) { if (!static_subscribers.ContainsKey(topic.Key)) { _ws.Send(ROSBridgeMsg.Subscribe(topic.Key, topic.Value[0].GetMessageType(topic.Key))); Debug.Log("Sending " + ROSBridgeMsg.Subscribe(topic.Key, topic.Value[0].GetMessageType(topic.Key))); } } foreach (KeyValuePair <string, List <Type> > topic in static_publishers) { _ws.Send(ROSBridgeMsg.Advertise(topic.Key, GetMessageType(topic.Value[0]))); Debug.Log("Sending " + ROSBridgeMsg.Advertise(topic.Key, GetMessageType(topic.Value[0]))); } foreach (KeyValuePair <string, string> topic in publishTopic_to_messageType) { if (!static_publishers.ContainsKey(topic.Key)) { _ws.Send(ROSBridgeMsg.Advertise(topic.Key, topic.Value)); Debug.Log("Sending " + ROSBridgeMsg.Advertise(topic.Key, topic.Value)); } } //while(true) { // Thread.Sleep (1000); //} }
private void Run() { _ws = new WebSocket(_host + ":" + _port); _ws.OnMessage += (sender, e) => this.OnMessage(e.Data); _ws.OnError += (sender, e) => OnError(sender, e); _ws.Connect(); CheckConnection(); _running = true; foreach (Type p in _subscribers) { _ws.Send(ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); //Debug.Log ("Sending " + ROSBridgeMsg.Subscribe (GetMessageTopic(p), GetMessageType (p))); } foreach (Type p in _publishers) { _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); //Debug.Log ("Sending " + ROSBridgeMsg.Advertise (GetMessageTopic(p), GetMessageType(p))); } while (true) { Thread.Sleep(10000); } }
//Successfull network connection handler on hololens #if !UNITY_EDITOR public void NetworkConnectedHandler(IAsyncAction asyncInfo, AsyncStatus status) { // Status completed is successful. if (status == AsyncStatus.Completed) { //Creating the writer that will be repsonsible to send a message through Rosbridge dataWriter = new DataWriter(messageWebSocket.OutputStream); //Connect to all topics in _subscribers and _publishers foreach (Type p in _subscribers) { dataWriter.WriteString(ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); dataWriter.StoreAsync(); Debug.Log("Sending " + ROSBridgeMsg.Subscribe(GetMessageTopic(p), GetMessageType(p))); } foreach (Type p in _publishers) { dataWriter.WriteString(ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); dataWriter.StoreAsync(); Debug.Log("Sending " + ROSBridgeMsg.Advertise(GetMessageTopic(p), GetMessageType(p))); } _connected = true; } }
public void AddPublisherOnline(Type publisher) { AddPublisher(publisher); _ws.Send(ROSBridgeMsg.Advertise(GetMessageTopic(publisher), GetMessageType(publisher))); }