Esempio n. 1
0
        public void OneLineTest()
        {
            var scheduler = new TestScheduler();

            var observer = scheduler.CreateObserver <int>();

            var sub = new OneLineCacheSubject <int>();

            sub.OnNext(1);

            var d1 = sub.Subscribe(observer);

            sub.OnNext(2);

            d1.Dispose();

            sub.OnNext(3);
            sub.OnNext(4);
            sub.OnNext(5);

            var d2 = sub.Subscribe(observer);

            d2.Dispose();

            var d3 = sub.Subscribe(observer);

            sub.OnNext(6);

            observer.Messages.Select(x => x.Value.Value).
            Is(new List <int>()
            {
                1, 2, 3, 4, 5, 6
            });
        }
        public void OneLineTest()
        {
            var scheduler = new TestScheduler();

            var observer = scheduler.CreateObserver<int>();

            var sub = new OneLineCacheSubject<int>();

            sub.OnNext(1);

            var d1 = sub.Subscribe(observer);
            sub.OnNext(2);

            d1.Dispose();

            sub.OnNext(3);
            sub.OnNext(4);
            sub.OnNext(5);

            var d2 = sub.Subscribe(observer);

            d2.Dispose();

            var d3 = sub.Subscribe(observer);
            sub.OnNext(6);

            observer.Messages.Select(x => x.Value.Value).
                Is(new List<int>() {1, 2, 3, 4, 5, 6});
        }
Esempio n. 3
0
        public void LargeData()
        {
            var observer = new OneLineCacheSubject <std_msgs.ByteMultiArray>();

            var node = Ros.InitNodeAsync("test").Result;

            var publisher  = node.PublisherAsync <std_msgs.ByteMultiArray>("test_topic").Result;
            var subscriber = node.SubscriberAsync <std_msgs.ByteMultiArray>("test_topic").Result;

            publisher.WaitForConnection(TestTimeout);
            subscriber.WaitForConnection(TestTimeout);

            subscriber.Subscribe(observer);

            publisher.OnNext(new ByteMultiArray()
            {
                data = Enumerable.Range(0, 5000).Select(x => (byte)(x % 256)).ToList()
            });

            var data = observer.Timeout(TestTimeout).First();

            data.data.Count.Is(5000);

            subscriber.Dispose();
            publisher.Dispose();

            node.Dispose();
        }
Esempio n. 4
0
        public void PublishAndSubscribe()
        {
            var scheduler = new TestScheduler();

            var observer = new OneLineCacheSubject <std_msgs.String>();

            var obs = scheduler.CreateHotObservable(
                OnNext(10, new std_msgs.String()
            {
                data = "abc"
            }),
                OnNext(20, new std_msgs.String()
            {
                data = "defg"
            }),
                OnNext(30, new std_msgs.String()
            {
                data = "hijklmn"
            })
                );

            var node = Ros.InitNodeAsync("test").Result;

            var publisher  = node.PublisherAsync <std_msgs.String>("test_topic").Result;
            var subscriber = node.SubscriberAsync <std_msgs.String>("test_topic").Result;

            publisher.WaitForConnection(TestTimeout);
            subscriber.WaitForConnection(TestTimeout);

            subscriber.Subscribe(observer);
            obs.Subscribe(publisher);

            scheduler.AdvanceBy(10);
            observer.Timeout(TestTimeout).First().data.Is("abc");

            scheduler.AdvanceBy(10);
            observer.Timeout(TestTimeout).First().data.Is("defg");

            scheduler.AdvanceBy(10);
            observer.Timeout(TestTimeout).First().data.Is("hijklmn");



            subscriber.Dispose();
            publisher.Dispose();

            node.Dispose();
        }
Esempio n. 5
0
        public IObservable<byte[]> ReceiveAsync(int offset = 0)
        {
            if(_oneLineCacheSubject ==null)
            {
                _oneLineCacheSubject = new OneLineCacheSubject<byte[]>();
                _receiveDisposable = _socket.ReceiveAsObservable(_scheduler).Subscribe(_oneLineCacheSubject);
            }
            return Observable.Create<byte[]>(observer =>
            {
                var disposable = _oneLineCacheSubject
                    .Where(x => x != null)
                    .Scan(new byte[] {}, (abs, bs) =>
                    {
                        var rest = AppendData(abs, bs);

                        //_logger.Debug(m => m("Receive Data Size = {0}", bs.Length));
                        //_logger.Debug(m => m("Receive Data = {0}", Encoding.ASCII.GetString(bs)));
                        //_logger.Debug(m => m("Receive Data = {0}", bs.Dump()));

                        byte[] current;
                        if (CompleteMessage(offset, out current, ref rest))
                        {
                            //_logger.Debug(m => m("OnNext Data = {0}", current.Dump()));
                            //_logger.Debug(m => m("OnNext Data Size= {0}", current.Length));
                            observer.OnNext(current);
                        }

                        return rest;
                    })
                    .Subscribe(_ => { }, observer.OnError, observer.OnCompleted);

                return disposable;
            });
        }
Esempio n. 6
0
        public void MultiplePublisher()
        {
            var scheduler = new TestScheduler();

            var observer = new OneLineCacheSubject <std_msgs.String>();

            var obs1 = scheduler.CreateHotObservable(
                OnNext(110, new std_msgs.String()
            {
                data = "abc1"
            }),
                OnNext(210, new std_msgs.String()
            {
                data = "defg1"
            }),
                OnNext(310, new std_msgs.String()
            {
                data = "hijklmn1"
            })
                );
            var obs2 = scheduler.CreateHotObservable(
                OnNext(120, new std_msgs.String()
            {
                data = "abc2"
            }),
                OnNext(220, new std_msgs.String()
            {
                data = "defg2"
            }),
                OnNext(320, new std_msgs.String()
            {
                data = "hijklmn2"
            })
                );
            var obs3 = scheduler.CreateHotObservable(
                OnNext(130, new std_msgs.String()
            {
                data = "abc3"
            }),
                OnNext(230, new std_msgs.String()
            {
                data = "defg3"
            }),
                OnNext(330, new std_msgs.String()
            {
                data = "hijklmn3"
            })
                );

            var node1 = Ros.InitNodeAsync("test1").Result;
            var node2 = Ros.InitNodeAsync("test2").Result;
            var node3 = Ros.InitNodeAsync("test3").Result;

            var publisher1 = node1.PublisherAsync <std_msgs.String>("test_topic").Result;
            var publisher2 = node2.PublisherAsync <std_msgs.String>("test_topic").Result;
            var subscriber = node1.SubscriberAsync <std_msgs.String>("test_topic").Result;
            var publisher3 = node3.PublisherAsync <std_msgs.String>("test_topic").Result;

            publisher1.WaitForConnection(TestTimeout);
            publisher2.WaitForConnection(TestTimeout);
            publisher3.WaitForConnection(TestTimeout);
            subscriber.WaitForConnection(TestTimeout);

            subscriber.Subscribe(observer);
            obs1.Subscribe(publisher1);
            obs2.Subscribe(publisher2);
            obs3.Subscribe(publisher3);

            scheduler.AdvanceTo(110);
            observer.Timeout(TestTimeout).First().data.Is("abc1");

            scheduler.AdvanceTo(120);
            observer.Timeout(TestTimeout).First().data.Is("abc2");

            scheduler.AdvanceTo(130);
            observer.Timeout(TestTimeout).First().data.Is("abc3");

            scheduler.AdvanceTo(210);
            observer.Timeout(TestTimeout).First().data.Is("defg1");

            scheduler.AdvanceTo(220);
            observer.Timeout(TestTimeout).First().data.Is("defg2");

            scheduler.AdvanceTo(230);
            observer.Timeout(TestTimeout).First().data.Is("defg3");

            scheduler.AdvanceTo(310);
            observer.Timeout(TestTimeout).First().data.Is("hijklmn1");

            scheduler.AdvanceTo(320);
            observer.Timeout(TestTimeout).First().data.Is("hijklmn2");

            scheduler.AdvanceTo(330);
            observer.Timeout(TestTimeout).First().data.Is("hijklmn3");


            subscriber.Dispose();
            publisher1.Dispose();
            publisher2.Dispose();
            publisher3.Dispose();

            node1.Dispose();
            node2.Dispose();
            node3.Dispose();
        }
Esempio n. 7
0
        public void MultipleSubscriber()
        {
            var scheduler = new TestScheduler();

            var observer1 = new OneLineCacheSubject <std_msgs.String>();
            var observer2 = new OneLineCacheSubject <std_msgs.String>();
            var observer3 = new OneLineCacheSubject <std_msgs.String>();

            var obs = scheduler.CreateHotObservable(
                OnNext(10, new std_msgs.String()
            {
                data = "abc"
            }),
                OnNext(20, new std_msgs.String()
            {
                data = "defg"
            }),
                OnNext(30, new std_msgs.String()
            {
                data = "hijklmn"
            })
                );

            var node1 = Ros.InitNodeAsync("test1").Result;
            var node2 = Ros.InitNodeAsync("test2").Result;
            var node3 = Ros.InitNodeAsync("test3").Result;

            var subscriber1 = node1.SubscriberAsync <std_msgs.String>("test_topic").Result;
            var subscriber2 = node2.SubscriberAsync <std_msgs.String>("test_topic").Result;
            var publisher   = node1.PublisherAsync <std_msgs.String>("test_topic").Result;
            var subscriber3 = node3.SubscriberAsync <std_msgs.String>("test_topic").Result;

            publisher.WaitForConnection(TestTimeout);
            subscriber1.WaitForConnection(TestTimeout);
            subscriber2.WaitForConnection(TestTimeout);
            subscriber3.WaitForConnection(TestTimeout);

            subscriber1.Subscribe(observer1);
            subscriber2.Subscribe(observer2);
            subscriber3.Subscribe(observer3);
            obs.Subscribe(publisher);

            scheduler.AdvanceBy(10);
            observer1.Timeout(TestTimeout).First().data.Is("abc");
            observer2.Timeout(TestTimeout).First().data.Is("abc");
            observer3.Timeout(TestTimeout).First().data.Is("abc");

            observer1.Dispose();
            scheduler.AdvanceBy(10);
            AssertEx.Throws <TimeoutException>(() => observer1.Timeout(TestTimeout).First());
            observer2.Timeout(TestTimeout).First().data.Is("defg");
            observer3.Timeout(TestTimeout).First().data.Is("defg");

            observer2.Dispose();
            scheduler.AdvanceBy(10);
            AssertEx.Throws <TimeoutException>(() => observer1.Timeout(TestTimeout).First());
            AssertEx.Throws <TimeoutException>(() => observer2.Timeout(TestTimeout).First());
            observer3.Timeout(TestTimeout).First().data.Is("hijklmn");


            subscriber1.Dispose();
            subscriber2.Dispose();
            subscriber3.Dispose();
            publisher.Dispose();

            node1.Dispose();
            node2.Dispose();
            node3.Dispose();
        }