예제 #1
0
파일: MainForm.cs 프로젝트: Colmea/AR.Drone
        private void OnNavigationPacketAcquired(NavigationPacket packet)
        {
            if (_packetRecorderWorker.IsAlive)
                _packetRecorderWorker.EnqueuePacket(packet);

            _navigationPacket = packet;
        }
예제 #2
0
 public NavigationPacket ReadNavigationPacket()
 {
     var packet = new NavigationPacket();
     packet.Timestamp = ReadInt64();
     int dataSize = ReadInt32();
     packet.Data = ReadBytes(dataSize);
     return packet;
 }
예제 #3
0
        protected override void Loop(CancellationToken token)
        {
            _isAcquiring = false;
            using (var udpClient = new UdpClient(NavdataPort))
                try
                {
                    udpClient.Connect(_configuration.DroneHostname, NavdataPort);

                    SendKeepAliveSignal(udpClient);

                    var remoteEp = new IPEndPoint(IPAddress.Any, NavdataPort);
                    Stopwatch swKeepAlive = Stopwatch.StartNew();
                    Stopwatch swNavdataTimeout = Stopwatch.StartNew();
                    while (token.IsCancellationRequested == false &&
                           swNavdataTimeout.ElapsedMilliseconds < NavdataTimeout)
                    {
                        if (udpClient.Available == 0)
                        {
                            Thread.Sleep(1);
                        }
                        else
                        {
                            byte[] data = udpClient.Receive(ref remoteEp);
                            var packet = new NavigationPacket
                                {
                                    Timestamp = DateTime.UtcNow.Ticks,
                                    Data = data
                                };

                            swNavdataTimeout.Restart();

                            _isAcquiring = true;
                            _onAcquisitionStarted();

                            _packetAcquired(packet);
                        }

                        if (swKeepAlive.ElapsedMilliseconds > KeepAliveTimeout)
                        {
                            SendKeepAliveSignal(udpClient);
                            swKeepAlive.Restart();
                        }
                    }
                }
                catch (Exception e)
                {

                }
                finally
                {
                    if (_isAcquiring)
                    {
                        _isAcquiring = false;
                        _onAcquisitionStopped();
                    }
                }
        }
예제 #4
0
        private void UpdateNavigationData(NavigationPacket packet)
        {
            NavigationData navigationData;
            if (NavigationPacketParser.TryParse(ref packet, out navigationData))
            {
                OnNavigationDataAcquired(navigationData);

                _navigationData = navigationData;

                ProcessStateTransitions(navigationData.State);
            }
        }
예제 #5
0
        private void OnNavdataPacketAcquired(NavigationPacket packet)
        {
            if (NavigationPacketAcquired != null)
                NavigationPacketAcquired(packet);

            UpdateNavigationData(packet);
        }
예제 #6
0
 public void EnqueuePacket(NavigationPacket packet)
 {
     _packetQueue.Enqueue(packet);
 }
예제 #7
0
        private void UpdateNavigationData(NavigationPacket packet)
        {
            NavigationData navigationData;
            if (NavigationPacketParser.TryParse(ref packet, out navigationData))
            {
                _navigationData = navigationData;


                ProcessTransition();

                if (NavigationDataUpdated != null)
                    NavigationDataUpdated(_navigationData);
            }
        }
예제 #8
0
 public void Write(NavigationPacket packet)
 {
     Write(packet.Timestamp);
     Write(packet.Data.Length);
     Write(packet.Data);
 }
예제 #9
0
 private void OnNavigationPacketAcquired(NavigationPacket obj)
 {
     // do nothing
 }
예제 #10
0
        private void OnNavigationPacketAcquired(NavigationPacket packet)
        {
            if (packetRecorderWorker != null && packetRecorderWorker.IsAlive)
                packetRecorderWorker.EnqueuePacket(packet);

            navigationPacket = packet;
        }
예제 #11
0
 private static void OnNavigationPacketAcquired(NavigationPacket packet)
 {
     _navigationPacket = packet;
 }