protected override void Loop(CancellationToken token) { int sequenceNumber = 1; ConcurrentQueueHelper.Flush(_commandQueue); using (var udpClient = new UdpClient(CommandPort)) { udpClient.Connect(_configuration.DroneHostname, CommandPort); byte[] firstMessage = BitConverter.GetBytes(1); udpClient.Send(firstMessage, firstMessage.Length); Stopwatch swKeepAlive = Stopwatch.StartNew(); while (token.IsCancellationRequested == false) { ATCommand command; if (_commandQueue.TryDequeue(out command)) { byte[] payload = command.CreatePayload(sequenceNumber); Trace.WriteIf((command is COMWDGCommand) == false, Encoding.ASCII.GetString(payload)); udpClient.Send(payload, payload.Length); sequenceNumber++; swKeepAlive.Restart(); } else if (swKeepAlive.ElapsedMilliseconds > KeepAliveTimeout) { _commandQueue.Enqueue(new COMWDGCommand()); } Thread.Sleep(1); } } }
protected override void Loop(CancellationToken token) { ConcurrentQueueHelper.Flush(_packetQueue); using (var recorder = new PacketWriter(_path)) { while (token.IsCancellationRequested == false) { object packet; while (_packetQueue.TryDequeue(out packet)) { recorder.Write(packet); } Thread.Sleep(1); } } }
protected override void Loop(CancellationToken token) { // flush packet queue ConcurrentQueueHelper.Flush(_packetQueue); using (var videoDecoder = new VideoPacketDecoder(_pixelFormat)) while (token.IsCancellationRequested == false) { VideoPacket packet; if (_packetQueue.TryDequeue(out packet)) { VideoFrame frame; if (videoDecoder.TryDecode(ref packet, out frame)) { _onFrameDecoded(frame); } } Thread.Sleep(10); } }