示例#1
0
        public RosPort(string topicName, RosNetwork network)
            : base(topicName)
        {
            if (network == null) throw new ArgumentNullException("network");

            this.packetAvailable = new AutoResetEvent(false);
            this.messageReceived = MessageReceived;
            this.subscriber = CreateSubscriber(network.Node, topicName, 0x100, messageReceived);

            Initialize();
        }
示例#2
0
        public Session(Timer timer, IEnumerable<string> portStrings)
        {
            List<string> textPortStrings = new List<string>();
            List<string> yarpPortStrings = new List<string>();
            List<string> rosPortStrings = new List<string>();

            foreach (string portString in portStrings)
            {
                if (portString.Length < 2) throw new InvalidOperationException("\"" + portString + "\" is not a valid port string");

                switch (portString.Substring(0, 2))
                {
                    case "t:": textPortStrings.Add(portString.Substring(2)); break;
                    case "y:": yarpPortStrings.Add(portString.Substring(2)); break;
                    case "r:": rosPortStrings.Add(portString.Substring(2)); break;
                    default: throw new InvalidOperationException("\"" + portString + "\" is not a valid port string");
                }
            }

            if (yarpPortStrings.Any()) this.yarpNetwork = new YarpNetwork();
            if (rosPortStrings.Any()) this.rosNetwork = new RosNetwork();

            List<Receiver> receivers = new List<Receiver>();
            foreach (string portString in textPortStrings)
            {
                string name = portString.Split(':').First();
                Port port = name == "-" ? new TextReaderPort() : new TextReaderPort(name);
                receivers.Add(new Receiver(port, timer, portString));
            }
            foreach (string portString in yarpPortStrings)
            {
                string name = portString.Split(':').First();
                Port port = new YarpReaderPort(name, yarpNetwork);
                receivers.Add(new Receiver(port, timer, portString));
            }
            foreach (string portString in rosPortStrings)
            {
                string name = portString.Split(':').First();
                Port port = new RosPort(name, rosNetwork);
                receivers.Add(new Receiver(port, timer, portString));
            }
            this.receivers = receivers;

            if (receivers.Count(receiver => receiver.HasTimer) > 1) throw new ArgumentException("More than one timer stream was found.");

            this.capture = new Capture
            (
                from receiver in receivers
                select new PortData(receiver.PortName, receiver.PortStreams)
            );
        }