public void StartAsync_SendHeaderError() { var str = new std_msgs.String(); var header = new { callerid = "test", topic = "mytopic", md5sum = str.Md5Sum, type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => { throw new InvalidOperationException("Send Error"); }; var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic"); var ex = AssertEx.Throws <AggregateException>(() => topic.StartAsync(sock).Wait()); ex.InnerException.GetType().Is(typeof(InvalidOperationException)); ex.InnerException.Message.Is("Send Error"); }
public void StartAsync_ReceiveHeaderMismatch() { var str = new std_msgs.String(); var header = new { callerid = "test", topic = "mytopic", md5sum = "aaaaaaaaaaaaa", type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task <int> .Factory.StartNew(() => t2.Length); var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws <AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(RosTopicException)); ex.InnerException.Message.Is("MD5Sum mismatch error"); }
public void SendTaskAsync_Success() { var str = new std_msgs.String(); var header = new { callerid = "test", topic = "mytopic", md5sum = str.Md5Sum, type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task.Factory.StartNew(() => t2.Length); var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic"); topic.StartAsync(sock).Wait(); topic.SendAsync(new std_msgs.String() { data = "test" }).Result.Is(12); }
public void StartAsync_ReceiveHeaderMismatch() { var str = new std_msgs.String(); var header = new { callerid = "test", topic = "mytopic", md5sum = "aaaaaaaaaaaaa", type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task<int>.Factory.StartNew(() => t2.Length); var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var ex = AssertEx.Throws<AggregateException>(() => task.Wait()); ex.InnerException.GetType().Is(typeof(RosTopicException)); ex.InnerException.Message.Is("MD5Sum mismatch error"); }
public void StartAsync_Success() { var str = new std_msgs.String() { data = "test message" }; var header = new { callerid = "test", topic = "mytopic", md5sum = str.Md5Sum, type = str.MessageType }; var headerStream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(headerStream, header); var dataStream = new MemoryStream(); var bw = new BinaryWriter(dataStream); bw.Write(str.SerializeLength); str.Serialize(bw); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); // 1.Receive Header, 2.Receive Data(std_msgs.String) int count = 0; MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => { if (count == 0) { count++; return(Observable.Return(headerStream.ToArray())); } else { return(Observable.Return(dataStream.ToArray())); } }; MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task <int> .Factory.StartNew(() => t2.Length); var server = new RosTopicServer <std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var subscriber = task.Result; var rec = subscriber.Timeout(TimeSpan.FromSeconds(3)).First(); rec.data.Is("test message"); }
void Start() { if (!ConfigManager.Instance.configInfo.rosbridgeIP.Equals(string.Empty)) { this.rosBridgeIP = ConfigManager.Instance.configInfo.rosbridgeIP; this.rosBridgePort = ConfigManager.Instance.configInfo.rosbridgePort; } this.webSocketConnection = new RosBridgeWebSocketConnection(rosBridgeIP, rosBridgePort); this.stringPublisher = this.webSocketConnection.Advertise <std_msgs.String>(topicName); // Connect to ROSbridge server this.webSocketConnection.Connect(); this.stringMessage = new std_msgs.String(); }
public void SerializeSubscriberHeader_Success() { var data = new std_msgs.String() { data = "test" }; var header = new { callerid = "test", topic = "/chatter", md5sum = data.Md5Sum, type = data.MessageType }; var ms = new MemoryStream(); TcpRosHeaderSerializer.Serialize(ms, header); var array = ms.ToArray(); array.Is(new byte[] { // length 102, 0, 0, 0, // caller_id length 13, 0, 0, 0, // caller_id=test 99, 97, 108, 108, 101, 114, 105, 100, 61, 116, 101, 115, 116, // topci length 14, 0, 0, 0, // topic=/chatter 116, 111, 112, 105, 99, 61, 47, 99, 104, 97, 116, 116, 101, 114, // md5sum length 39, 0, 0, 0, // md5sum=992ce8a1687cec8c8bd883ec73ca41d1 109, 100, 53, 115, 117, 109, 61, 57, 57, 50, 99, 101, 56, 97, 49, 54, 56, 55, 99, 101, 99, 56, 99, 56, 98, 100, 56, 56, 51, 101, 99, 55, 51, 99, 97, 52, 49, 100, 49, // type length 20, 0, 0, 0, // type=std_msgs/String 116, 121, 112, 101, 61, 115, 116, 100, 95, 109, 115, 103, 115, 47, 83, 116, 114, 105, 110, 103 }); ms.Close(); }
public void StartAsync_ReceiveHeaderNotEnoughtMemberError() { var str = new std_msgs.String(); var header = new { callerid = "test", type = str.MessageType }; var stream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(stream, header); MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => Observable.Return(stream.ToArray()); var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var topic = new RosTopicClient <std_msgs.String>("mynode", "mytopic"); var ex = AssertEx.Throws <AggregateException>(() => topic.StartAsync(sock).Wait()); ex.InnerException.GetType().Is(typeof(RuntimeBinderException)); }
public void DesrializeSubscriberHeader_Success() { var msg = new byte[] { // length 102, 0, 0, 0, // caller_id length 13, 0, 0, 0, // caller_id=test 99, 97, 108, 108, 101, 114, 105, 100, 61, 116, 101, 115, 116, // topci length 14, 0, 0, 0, // topic=/chatter 116, 111, 112, 105, 99, 61, 47, 99, 104, 97, 116, 116, 101, 114, // md5sum length 39, 0, 0, 0, // md5sum=992ce8a1687cec8c8bd883ec73ca41d1 109, 100, 53, 115, 117, 109, 61, 57, 57, 50, 99, 101, 56, 97, 49, 54, 56, 55, 99, 101, 99, 56, 99, 56, 98, 100, 56, 56, 51, 101, 99, 55, 51, 99, 97, 52, 49, 100, 49, // type length 20, 0, 0, 0, // type=std_msgs/String 116, 121, 112, 101, 61, 115, 116, 100, 95, 109, 115, 103, 115, 47, 83, 116, 114, 105, 110, 103 }; var ms = new MemoryStream(msg); dynamic header = TcpRosHeaderSerializer.Deserialize(ms); var data = new std_msgs.String() { data = "test" }; AssertEx.Is(header.callerid, "test"); AssertEx.Is(header.topic, "/chatter"); AssertEx.Is(header.md5sum, data.Md5Sum); AssertEx.Is(header.type, data.MessageType); ms.Close(); }
public void DesrializeSubscriberHeader_Success() { var msg = new byte[] { // length 102,0,0,0, // caller_id length 13,0,0,0, // caller_id=test 99,97,108,108,101,114,105,100,61,116,101,115,116, // topci length 14,0,0,0, // topic=/chatter 116,111,112,105,99,61,47,99,104,97,116,116,101,114, // md5sum length 39,0,0,0, // md5sum=992ce8a1687cec8c8bd883ec73ca41d1 109,100,53,115,117,109,61,57,57,50,99,101,56,97,49,54,56,55,99,101,99,56,99,56,98,100,56,56,51,101,99,55,51,99,97,52,49,100,49, // type length 20,0,0,0, // type=std_msgs/String 116,121,112,101,61,115,116,100,95,109,115,103,115,47,83,116,114,105,110,103 }; var ms = new MemoryStream(msg); dynamic header = TcpRosHeaderSerializer.Deserialize(ms); var data = new std_msgs.String() { data = "test" }; AssertEx.Is(header.callerid, "test"); AssertEx.Is(header.topic,"/chatter"); AssertEx.Is(header.md5sum,data.Md5Sum); AssertEx.Is(header.type, data.MessageType); ms.Close(); }
public void StartAsync_Success() { var str = new std_msgs.String(){data = "test message"}; var header = new { callerid = "test", topic = "mytopic", md5sum = str.Md5Sum, type = str.MessageType }; var headerStream = new MemoryStream(); TcpRosHeaderSerializer.Serialize(headerStream, header); var dataStream = new MemoryStream(); var bw = new BinaryWriter(dataStream); bw.Write(str.SerializeLength); str.Serialize(bw); MTcpRosClient.AllInstances.ConnectAsyncStringInt32 = (t1, t2, t3) => Task.Factory.StartNew(() => { }); // 1.Receive Header, 2.Receive Data(std_msgs.String) int count = 0; MTcpRosClient.AllInstances.ReceiveAsyncInt32 = (t1, t2) => { if(count == 0) { count++; return Observable.Return(headerStream.ToArray()); } else { return Observable.Return(dataStream.ToArray()); } }; MTcpRosClient.AllInstances.SendAsyncByteArray = (t1, t2) => Task<int>.Factory.StartNew(() => t2.Length); var server = new RosTopicServer<std_msgs.String>("mynode", "mytopic", new Uri("http://localhost")); var task = server.StartAsync(new TopicParam() { HostName = "test", PortNumber = 1234, ProtocolName = "TCPROS" }); var subscriber = task.Result; var rec = subscriber.Timeout(TimeSpan.FromSeconds(3)).First(); rec.data.Is("test message"); }
public void SerializeSubscriberHeader_Success() { var data = new std_msgs.String() { data = "test" }; var header = new { callerid = "test", topic = "/chatter", md5sum = data.Md5Sum, type = data.MessageType }; var ms = new MemoryStream(); TcpRosHeaderSerializer.Serialize(ms, header); var array = ms.ToArray(); array.Is(new byte[] { // length 102,0,0,0, // caller_id length 13,0,0,0, // caller_id=test 99,97,108,108,101,114,105,100,61,116,101,115,116, // topci length 14,0,0,0, // topic=/chatter 116,111,112,105,99,61,47,99,104,97,116,116,101,114, // md5sum length 39,0,0,0, // md5sum=992ce8a1687cec8c8bd883ec73ca41d1 109,100,53,115,117,109,61,57,57,50,99,101,56,97,49,54,56,55,99,101,99,56,99,56,98,100,56,56,51,101,99,55,51,99,97,52,49,100,49, // type length 20,0,0,0, // type=std_msgs/String 116,121,112,101,61,115,116,100,95,109,115,103,115,47,83,116,114,105,110,103 }); ms.Close(); }