当前位置: 首页>>代码示例>>C#>>正文


C# MAVLink.ToStructure方法代码示例

本文整理汇总了C#中MAVLink.ToStructure方法的典型用法代码示例。如果您正苦于以下问题:C# MAVLink.ToStructure方法的具体用法?C# MAVLink.ToStructure怎么用?C# MAVLink.ToStructure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MAVLink的用法示例。


在下文中一共展示了MAVLink.ToStructure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReceviedPacket

        bool ReceviedPacket(MAVLink.MAVLinkMessage rawpacket)
        {
            if (rawpacket.msgid == (byte) MAVLink.MAVLINK_MSG_ID.TERRAIN_REQUEST)
            {
                MAVLink.mavlink_terrain_request_t packet =
                    rawpacket.ToStructure<MAVLink.mavlink_terrain_request_t>();

                if (issending)
                    return false;

                lastmessage = rawpacket;
                lastrequest = packet;

                log.Info("received TERRAIN_REQUEST " + packet.lat/1e7 + " " + packet.lon/1e7 + " space " +
                         packet.grid_spacing + " " + Convert.ToString((long) packet.mask, 2));

                System.Threading.ThreadPool.QueueUserWorkItem(QueueSendGrid);
            }
            else if (rawpacket.msgid == (byte) MAVLink.MAVLINK_MSG_ID.TERRAIN_REPORT)
            {
                MAVLink.mavlink_terrain_report_t packet =
                    rawpacket.ToStructure<MAVLink.mavlink_terrain_report_t>();
                log.Info("received TERRAIN_REPORT " + packet.lat/1e7 + " " + packet.lon/1e7 + " " + packet.loaded + " " +
                         packet.pending);
            }
            return false;
        }
开发者ID:AndersonRayner,项目名称:MissionPlanner,代码行数:27,代码来源:TerrainFollow.cs

示例2: ReceviedPacket

        private bool ReceviedPacket(MAVLink.MAVLinkMessage arg)
        {
            if (arg.msgid == (byte) MAVLink.MAVLINK_MSG_ID.DATA_TRANSMISSION_HANDSHAKE)
            {
                var packet = arg.ToStructure<MAVLink.mavlink_data_transmission_handshake_t>();
                msgDataTransmissionHandshake = packet;
                imageBuffer.Close();
                imageBuffer = new MemoryStream((int)packet.size);
            }
            else if (arg.msgid == (byte)MAVLink.MAVLINK_MSG_ID.ENCAPSULATED_DATA)
            {
                var packet = arg.ToStructure<MAVLink.mavlink_encapsulated_data_t>();
                msgEncapsulatedData = packet;
                int start = msgDataTransmissionHandshake.payload * msgEncapsulatedData.seqnr;
                int left = (int)msgDataTransmissionHandshake.size - start;
                var writeamount = Math.Min(msgEncapsulatedData.data.Length, left);

                imageBuffer.Seek(start, SeekOrigin.Begin);
                imageBuffer.Write(msgEncapsulatedData.data, 0, writeamount);

                // we have a complete image
                if ((msgEncapsulatedData.seqnr+1) == msgDataTransmissionHandshake.packets)
                {
                    using (
                        Bitmap bmp = new Bitmap(msgDataTransmissionHandshake.width, msgDataTransmissionHandshake.height,
                            PixelFormat.Format8bppIndexed))
                    {
                        SetGrayscalePalette(bmp);

                        var bitmapData = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadWrite,
                            bmp.PixelFormat);

                        if (imageBuffer.Length > msgDataTransmissionHandshake.size)
                            return true;

                        var buffer = imageBuffer.ToArray();

                        Marshal.Copy(buffer, 0, bitmapData.Scan0, buffer.Length);
                        bmp.UnlockBits(bitmapData);

                        if (newImage != null)
                            newImage(this, new ImageEventHandle(bmp));

                        //bmp.Save("test.bmp", ImageFormat.Bmp);
                    }
                }
            }

            return true;
        }
开发者ID:ArduPilot,项目名称:MissionPlanner,代码行数:50,代码来源:OpticalFlow.cs

示例3: receivedPacket

        private bool receivedPacket(MAVLink.MAVLinkMessage arg)
        {
            if (arg.msgid == (uint)MAVLink.MAVLINK_MSG_ID.STATUSTEXT)
            {
                var message = ASCIIEncoding.ASCII.GetString(arg.ToStructure<MAVLink.mavlink_statustext_t>().text);

                UpdateUserMessage(message);

                if (message.ToLower().Contains("calibration successful") ||
                 message.ToLower().Contains("calibration failed"))
                {
                    try
                    {
                        Invoke((MethodInvoker)delegate
                        {
                            BUT_calib_accell.Text = Strings.Done;
                            BUT_calib_accell.Enabled = false;
                        });

                        _incalibrate = false;
                        MainV2.comPort.UnSubscribeToPacketType(MAVLink.MAVLINK_MSG_ID.STATUSTEXT, receivedPacket);
                    }
                    catch
                    {
                    }
                }
            }

            return true;
        }
开发者ID:ArduPilot,项目名称:MissionPlanner,代码行数:30,代码来源:ConfigAccelerometerCalibration.cs

示例4: ReceviedPacket

        private bool ReceviedPacket(MAVLink.MAVLinkMessage packet)
        {
            if (packet.msgid == (byte) MAVLink.MAVLINK_MSG_ID.MAG_CAL_PROGRESS)
            {
                var mprog = packet.ToStructure<MAVLink.mavlink_mag_cal_progress_t>();

                lock (this.mprog)
                {
                    this.mprog.Add(mprog);
                }

                return true;
            }
            else if (packet.msgid == (byte) MAVLink.MAVLINK_MSG_ID.MAG_CAL_REPORT)
            {
                var mrep = packet.ToStructure<MAVLink.mavlink_mag_cal_report_t>();

                lock (this.mrep)
                {
                    this.mrep.Add(mrep);
                }

                return true;
            }

            return true;
        }
开发者ID:nitbot,项目名称:MissionPlanner,代码行数:27,代码来源:ConfigHWCompass.cs

示例5: ReceviedPacket

        bool ReceviedPacket(MAVLink.MAVLinkMessage packet)
        {
            if (packetcounttimer.Second != DateTime.Now.Second)
            {
                log.Info("packet count " + packetcount + " with data " + packetwithdata + " " + buffer.Size);
                packetcount = 0;
                packetwithdata = 0;
                packetcounttimer = DateTime.Now;
            }

            packetcount++;

            MAVLink.mavlink_serial_control_t item = packet.ToStructure<MAVLink.mavlink_serial_control_t>();

            if (item.count == 0)
                return true;

            packetwithdata++;

            Console.WriteLine(DateTime.Now.Millisecond + "data count " + item.count);
                // ASCIIEncoding.ASCII.GetString(item.data, 0, item.count)

            lock (buffer)
            {
                buffer.AllowOverflow = true;
                buffer.Put(item.data, 0, item.count);
            }

            // we just received data, so do a request again
            GetData(true);

            return true;
        }
开发者ID:AndersonRayner,项目名称:MissionPlanner,代码行数:33,代码来源:MAVLinkSerialPort.cs

示例6: ReceviedPacket

        static bool ReceviedPacket(MAVLink.MAVLinkMessage rawpacket)
        {
            if (rawpacket.msgid == (byte) MAVLink.MAVLINK_MSG_ID.SCALED_IMU2)
            {
                MAVLink.mavlink_scaled_imu2_t packet = rawpacket.ToStructure<MAVLink.mavlink_scaled_imu2_t>();

                // filter dataset
                string item = (int) (packet.xmag/div) + "," +
                              (int) (packet.ymag/div) + "," +
                              (int) (packet.zmag/div);

                if (filtercompass2.ContainsKey(item))
                {
                    filtercompass2[item] = (int) filtercompass2[item] + 1;

                    if ((int) filtercompass2[item] > 3)
                        return false;
                }
                else
                {
                    filtercompass2[item] = 1;
                }

                // values - offsets are 0
                float rawmx = packet.xmag;
                float rawmy = packet.ymag;
                float rawmz = packet.zmag;

                // add data
                lock (datacompass2)
                {
                    if (rawmx == 0 || rawmy == 0 || rawmz == 0)
                        return true;

                    datacompass2.Add(new Tuple<float, float, float>(rawmx, rawmy, rawmz));
                }

                return true;
            }
            else if (rawpacket.msgid == (byte) MAVLink.MAVLINK_MSG_ID.SCALED_IMU3)
            {
                MAVLink.mavlink_scaled_imu3_t packet = rawpacket.ToStructure<MAVLink.mavlink_scaled_imu3_t>();

                // filter dataset
                string item = (int) (packet.xmag/div) + "," +
                              (int) (packet.ymag/div) + "," +
                              (int) (packet.zmag/div);

                if (filtercompass3.ContainsKey(item))
                {
                    filtercompass3[item] = (int) filtercompass3[item] + 1;

                    if ((int) filtercompass3[item] > 3)
                        return false;
                }
                else
                {
                    filtercompass3[item] = 1;
                }

                // values - offsets are 0
                float rawmx = packet.xmag;
                float rawmy = packet.ymag;
                float rawmz = packet.zmag;

                // add data
                lock (datacompass3)
                {
                    if (rawmx == 0 || rawmy == 0 || rawmz == 0)
                        return true;

                    datacompass3.Add(new Tuple<float, float, float>(rawmx, rawmy, rawmz));
                }

                return true;
            }
            else if (rawpacket.msgid == (byte) MAVLink.MAVLINK_MSG_ID.RAW_IMU)
            {
                MAVLink.mavlink_raw_imu_t packet = rawpacket.ToStructure<MAVLink.mavlink_raw_imu_t>();

                if (packet.xmag == 0 && packet.ymag == 0)
                    return false;

                // filter dataset
                string item = (int) (packet.xmag/div) + "," +
                              (int) (packet.ymag/div) + "," +
                              (int) (packet.zmag/div);

                if (filtercompass1.ContainsKey(item))
                {
                    filtercompass1[item] = (int) filtercompass1[item] + 1;

                    if ((int) filtercompass1[item] > 3)
                        return false;
                }
                else
                {
                    filtercompass1[item] = 1;
                }

//.........这里部分代码省略.........
开发者ID:ArduPilot,项目名称:MissionPlanner,代码行数:101,代码来源:MagCalib.cs


注:本文中的MAVLink.ToStructure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。