private void ProcessSendQueue(object state)
        {
            byte seq = 0;

            using (FileStream s = new FileStream(_recordFileName, FileMode.Create))
            {
                using (BinaryWriter writer = new BinaryWriter(s))
                {
                    while (true)
                    {
                        UasMessage msg;

                        if (mSendQueue.TryDequeue(out msg))
                        {
                            //SendMavlinkMessage(msg);
                            writer.Write(MavLinkPacket.GetBytesForMessage(
                                             msg, MavlinkSystemId, MavlinkComponentId, seq++, MavLinkGenericPacketWalker.PacketSignalByte));
                        }
                        else
                        {
                            // Queue is empty, sleep until signalled
                            mSendSignal.WaitOne();

                            if (!mIsActive)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            isEndSignal.Set();
        }
Esempio n. 2
0
        /// <summary>
        /// Generates the buffer bytes to be sent on the wire for given message.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="systemId"></param>
        /// <param name="componentId"></param>
        /// <param name="includeSignalMark">Whether to include the Packet signal in the buffer or not.</param>
        /// <param name="sequenceNumber">A sequence number for the message, if needed.</param>
        /// <returns></returns>
        public byte[] SerializeMessage(
            UasMessage msg, byte systemId, byte componentId,
            bool includeSignalMark, byte sequenceNumber = 1)
        {
            byte mark = includeSignalMark ? PacketSignalByte : (byte)0;

            return(MavLinkPacket.GetBytesForMessage(
                       msg, systemId, componentId, sequenceNumber, mark));
        }