Пример #1
0
            public async Task GetTheSameMessageAsSendAsync()
            {
                HeartbeatMessage     receivedHeartbeat   = default(HeartbeatMessage);
                IMavlinkCommunicator mavlinkCommunicator = MavlinkCommunicatorFactory.Create(Stream);
                IMessageNotifier     messageNotifier     = mavlinkCommunicator.SubscribeForReceive(m => m.Id == MessageId.Heartbeat);

                messageNotifier.MessageReceived += (s, e) =>
                {
                    receivedHeartbeat = (HeartbeatMessage)e.Message;
                };

                HeartbeatMessage sentHeartbetat = new HeartbeatMessage
                {
                    Autopilot = MavAutopilot.Ardupilotmega,
                    BaseMode  =
                        MavModeFlag.CustomModeEnabled | MavModeFlag.StabilizeEnabled | MavModeFlag.ManualInputEnabled,
                    MavlinkVersion = 3,
                    Type           = MavType.Quadrotor,
                    SystemStatus   = MavState.Active,
                    CustomMode     = 0
                };
                await mavlinkCommunicator.SendMessageAsync(sentHeartbetat, 1, 1);

                Stream.Seek(0, SeekOrigin.Begin);

                Thread.Sleep(3000);
                Assert.AreEqual(sentHeartbetat.Autopilot, receivedHeartbeat.Autopilot);
                Assert.AreEqual(sentHeartbetat.Type, receivedHeartbeat.Type);
                Assert.AreEqual(sentHeartbetat.CustomMode, receivedHeartbeat.CustomMode);
                Assert.AreEqual(sentHeartbetat.BaseMode, receivedHeartbeat.BaseMode);
                Assert.AreEqual(sentHeartbetat.SystemStatus, receivedHeartbeat.SystemStatus);
                Assert.AreEqual(sentHeartbetat.MavlinkVersion, receivedHeartbeat.MavlinkVersion);
                mavlinkCommunicator.Dispose();
                Thread.Sleep(1000);
            }
Пример #2
0
            public async Task GetTheSameMessageCountAsSendAsync()
            {
                int messagesToSend                       = 20;
                int messagesReceived                     = 0;
                int messagesSuccessfullySent             = 0;
                IMavlinkCommunicator mavlinkCommunicator = MavlinkCommunicatorFactory.Create(Stream);
                IMessageNotifier     messageNotifier     = mavlinkCommunicator.SubscribeForReceive(m => m.Id == MessageId.Heartbeat);

                messageNotifier.MessageReceived += (s, e) =>
                {
                    Interlocked.Increment(ref messagesReceived);
                };

                HeartbeatMessage sentHeartbeat = new HeartbeatMessage
                {
                    Autopilot = MavAutopilot.Ardupilotmega,
                    BaseMode  =
                        MavModeFlag.CustomModeEnabled | MavModeFlag.StabilizeEnabled | MavModeFlag.ManualInputEnabled,
                    MavlinkVersion = 3,
                    Type           = MavType.Quadrotor,
                    SystemStatus   = MavState.Active,
                    CustomMode     = 0
                };

                for (int i = 0; i < messagesToSend; i++)
                {
                    bool result = await mavlinkCommunicator.SendMessageAsync(sentHeartbeat, 1, 1);

                    if (result)
                    {
                        messagesSuccessfullySent++;
                    }
                }

                Stream.Seek(0, SeekOrigin.Begin);

                Thread.Sleep(8000);
                Assert.AreEqual(messagesSuccessfullySent, messagesReceived, 0,
                                $"Successfully sent {messagesSuccessfullySent}. Successfully received {messagesReceived}");
                mavlinkCommunicator.Dispose();
                Thread.Sleep(1000);
            }