예제 #1
0
        public void AddTopic_MultipleTopicSuccess()
        {
            MRosTopicClient <std_msgs.String> .AllInstances.StartAsyncSocketBoolean =
                (t1, t2, t3) => Task <IObservable <byte[]> > .Factory.StartNew(Observable.Empty <byte[]>);

            MRosTopicClient <std_msgs.String> .AllInstances.SendAsyncTMessage =
                (t1, t2) => Task.Factory.StartNew(() => t2.SerializeLength);

            var sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var sock2 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var pub   = new Publisher <std_msgs.String>("test", "testnode");

            pub.AddTopic(sock1).Wait();
            pub.AddTopic(sock2).Wait();

            pub.OnNext(new std_msgs.String()
            {
                data = "test"
            });
            pub.OnNext(new std_msgs.String()
            {
                data = "test"
            });
            pub.OnNext(new std_msgs.String()
            {
                data = "test"
            });
        }
예제 #2
0
        public void AddTopic_Success()
        {
            MRosTopicClient<std_msgs.String>.AllInstances.StartAsyncSocketBoolean = (t1, t2, t3) => Task<IObservable<byte[]>>.Factory.StartNew(Observable.Empty<byte[]>);

            var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var pub = new Publisher<std_msgs.String>("test", "testnode");

            pub.AddTopic(sock).Wait();
        }
예제 #3
0
        public void AddTopic_MultipleTopicSuccess()
        {
            MRosTopicClient<std_msgs.String>.AllInstances.StartAsyncSocketBoolean =
                (t1, t2, t3) => Task<IObservable<byte[]>>.Factory.StartNew(Observable.Empty<byte[]>);
            MRosTopicClient<std_msgs.String>.AllInstances.SendAsyncTMessage =
                (t1, t2) => Task.Factory.StartNew(() => t2.SerializeLength);

            var sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var sock2 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var pub = new Publisher<std_msgs.String>("test", "testnode");

            pub.AddTopic(sock1).Wait();
            pub.AddTopic(sock2).Wait();

            pub.OnNext(new std_msgs.String() { data = "test" });
            pub.OnNext(new std_msgs.String() { data = "test" });
            pub.OnNext(new std_msgs.String() { data = "test" });
        }
예제 #4
0
        public void AddTopic_Success()
        {
            MRosTopicClient <std_msgs.String> .AllInstances.StartAsyncSocketBoolean = (t1, t2, t3) => Task <IObservable <byte[]> > .Factory.StartNew(Observable.Empty <byte[]>);

            var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var pub  = new Publisher <std_msgs.String>("test", "testnode");

            pub.AddTopic(sock).Wait();
        }
예제 #5
0
        public void AddTopic_Error()
        {
            MRosTopicClient<std_msgs.String>.AllInstances.StartAsyncSocketBoolean =
                (t1, t2, t3) => Task<IObservable<byte[]>>.Factory.StartNew(() => { throw new InvalidOperationException("Start Error"); });

            var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var pub = new Publisher<std_msgs.String>("test", "testnode");
            var ex = AssertEx.Throws<AggregateException>(() => pub.AddTopic(sock).Wait());
            //ex.InnerException.GetType().Is(typeof(InvalidOperationException));
        }
예제 #6
0
        public void AddTopic_Error()
        {
            MRosTopicClient <std_msgs.String> .AllInstances.StartAsyncSocketBoolean =
                (t1, t2, t3) => Task <IObservable <byte[]> > .Factory.StartNew(() => { throw new InvalidOperationException("Start Error"); });

            var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var pub  = new Publisher <std_msgs.String>("test", "testnode");
            var ex   = AssertEx.Throws <AggregateException>(() => pub.AddTopic(sock).Wait());
            //ex.InnerException.GetType().Is(typeof(InvalidOperationException));
        }
예제 #7
0
        /// <summary>
        ///   Create a ROS Topic Publisher
        /// </summary>
        /// <typeparam name="TMessage"> Topic Message Type </typeparam>
        /// <param name="topicName"> Topic Name </param>
        /// <param name="latching"> true: send the latest published message when subscribed topic </param>
        /// <returns> Publisher </returns>
        public Task <Publisher <TMessage> > PublisherAsync <TMessage>(string topicName, bool latching = false)
            where TMessage : IMessage, new()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Node");
            }

            if (_topicContainer.HasPublisher(topicName))
            {
                throw new InvalidOperationException(topicName + " is already created.");
            }

            _logger.InfoFormat("Create Publisher: {0}", topicName);

            var publisher = new Publisher <TMessage>(topicName, NodeId, latching);

            _topicContainer.AddPublisher(publisher);
            publisher.Disposing += DisposePublisherAsync;

            var tcpRosListener = new TcpRosListener(0);

            _slaveServer.AddListener(topicName, tcpRosListener);

            var acceptDisposable = tcpRosListener.AcceptAsync()
                                   .Do(_ => _logger.Debug("Accepted for Publisher"))
                                   .Subscribe(socket => publisher.AddTopic(socket),
                                              ex => _logger.Error("Accept Error", ex));

            _publisherDisposables.Add(topicName, acceptDisposable);

            var tcs = new TaskCompletionSource <Publisher <TMessage> >();

            _logger.Debug("RegisterPublisher");
            _masterClient
            .RegisterPublisherAsync(NodeId, topicName, publisher.MessageType, _slaveServer.SlaveUri)
            .ContinueWith(task =>
            {
                _logger.Debug("Registered Publisher");

                if (task.Status == TaskStatus.RanToCompletion)
                {
                    publisher.UpdateSubscribers(task.Result);
                    tcs.SetResult(publisher);
                }
                else if (task.Status == TaskStatus.Faulted)
                {
                    _logger.Error("RegisterPublisher: Failure", task.Exception.InnerException);
                    tcs.SetException(task.Exception.InnerException);
                }
            });

            return(tcs.Task);
        }