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 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"); }