The logical carding of gcs_mavlink under Apm::rover

Source: Internet
Author: User
Tags apm mavlink
Preface

The message passing process from the physical port of flight control to the application layer is sorted by combining the Mavlink message previously added.
By the passing of the whole frame in the comb again; here combined with Rover to narrate, May and copter some difference, start first ~ libraries

Here needs to explain, regarding the Mavlink the agreement and the generation part, here does not have the detailed description, after specially writes an article to narrate separately.
Or say back to Gcs_mavlink, first to analyze the file structure:

/ardupilot/libraries/gcs_mavlink
|--example
|--gcs_common.cpp
|--gcs_deviceop.cpp
|--gcs_ Logs.cpp
|--gcs_mavlink.cpp
|--gcs_mavlink.h
|--gcs_serial_control.cpp
|--gcs_signing.cpp
|--gcs.h
|--mavlink_routing.cpp
|--mavlink_routing.h

Here we'll sort by example to comb gcs_common.cpp

Here you can see the header file included, and some of the tool functions of the Mavlink itself:

It is obvious here that the processing functions of the data corresponding to the GCS uplink (gimbal, GPS, Mission, Param, Radio, RC, Set_mode ...). ):

The following are the data processing functions for the downlink of the flight control (accelcal, ahrs, version, battery, GPS, message, Heartbeat, home, radio_in, Power_status, Raw_imu, sensor _offsets ... , basically by receiving and sending these tool functions can probably correspond to the operation on the GCs interface (if you are familiar with a GCS);

Next is Gcs_deviceop: gcs_deviceop

Let's first list the structure of the packet.
Handle device operations over Mavlink
From this sentence translation look, almost can know, Gcs_deviceop is through the Mavlink, on the flight control equipment to read and write operations

typedef struct __MAVLINK_DEVICE_OP_READ_T {uint32_t request_id;    /*< request id-copied to reply*/uint8_t Target_system; /*< System id*/uint8_t target_component;          /*< Component id*/uint8_t bustype;              /*< the bus type*/uint8_t;          /*< bus number*/uint8_t address;         /*< bus address*/Char busname[40];         /*< Name of device on bus (for SPI) */uint8_t Regstart;           /*< to read*/uint8_t count;

/*< count of registers to read*/} mavlink_device_op_read_t;      typedef struct __MAVLINK_DEVICE_OP_WRITE_T {uint32_t request_id;    /*< request id-copied to reply*/uint8_t Target_system; /*< System id*/uint8_t target_component;          /*< Component id*/uint8_t bustype;              /*< the bus type*/uint8_t;          /*< bus number*/uint8_t address;   /*< bus address*/Char busname[40];      /*< Name of device on bus (for SPI) */uint8_t Regstart;            /*< to write*/uint8_t count;        /*< count of registers to write*/uint8_t data[128]; /*< write data*/}) mavlink_device_op_write_t;

And then there's gcs_logs.cpp: gcs_logs.cpp .

From the picture can obviously see this is the Log information processing set up, the operation of the object is DataFlash; to the GCS software, there is a log to download the window, in fact, this part is the main realization;
gcs_mavlink.cpp/h

Gcs_mavlink is mainly to the Mavlink itself protocol and communication interface processing, from the definition of Gcs_mavlink::serialmanager can see that the serial manager has been defined here, followed by the receiving/sending of the idle state and available state functions, As well as the received channel and so on ...

The rest of the source file I do not enumerate, here to summarize the idea, at least in the implementation of Gcs_mavlink, said the bottom is nothing more than: Serial Manager (in the framework of AP_HAL_PX4 to call the serial port, and provide the corresponding tool functions, corresponding Gcs_mavlink.cpp/h/gcs _serial_control) Functional functions (Applications on Mavlink protocol, corresponding gcs_common/gcs_deviceop/gcs_logs, etc.)

Application of different scenarios (placed under the Copter/rover/plane gcs_mavlink.cpp/.h)

Here need to pay attention to the next is the application of different scenarios, where the source file is the decision we will eventually through the Mavlink to achieve which applications, not the front of the gcs_mavlink inside all to use, different scenes flying control of the difference is reflected here, Corresponds to the same in GCs;
more specifically, the original function of the gcs_mavlink below libraries is parallel to the function of the gcs_mavlink.cpp placed under Copter/rover/plane. They are all layered applications based on the protocol package generated by the root XML file.

The framework of the comb almost, the following will enter the actual combat, to see how the flow of data flows;
Data flow
The source of APM is a little bit better, the task (only the senses) can give people a clear, for example, we can clearly find the relevant code for Gcs_mavlink:

Obviously, the entrance we're looking for is in gcs_update ():

 /* Look for  incoming commands on the GCS links
/void Rover::gcs_update (void)
{for
    uint8_t i=0; i < Num_gcs; i++ {
        if (gcs_chan[i].initialised) {
#if cli_enabled = = ENABLED
            gcs_chan[i].update (g.cli_enabled = 1?) Functor_bind_member (&rover::run_cli, void, Ap_hal::uartdriver *): nullptr);
#else
            gcs_chan[i].update (nullptr);
#endif
        }}}

Gcs_chan[i].update (nullptr), the inside continue to go down, before the next to pave the ground point source:

    Serial manager, the specific features do not say in detail here, a look will understand ...
Ap_serialmanager Serial_manager; Class Ap_serialmanager {public:enum Serialprotocol {serialprotocol_none =-1, serialprotocol_cons OLE = 0,//unused Serialprotocol_mavlink = 1, Serialprotocol_mavlink2 = 2,//Don't use -use Mavlink and provide instance of 1 Serialprotocol_frsky_d = 3,//FRSky D Protocol (D-RECEIV  ERS) Serialprotocol_frsky_sport = 4,//FRSky Sport Protocol (x-receivers) Serialprotocol_gps = 5, SERIALPROTOCOL_GPS2 = 6,//Do not use-use GPS and provide instance of 1 seria Lprotocol_alexmos = 7, Serialprotocol_storm32 = 8, Serialprotocol_lidar = 9, Serialprotocol_frsky_                Sport_passthrough = ten,//FRSky Sport Passthrough (OPENTX) protocol (x-receivers) serialprotocol_lidar360 = 11, Lightware sf40c or Teraranger Tower serialprotocol_aErotenna_ulanding =,//ulanding support Serialprotocol_beacon = 13};

    Constructor Ap_serialmanager ();

    Init_console-initialise Console at default baud rate void Init_console ();

    Init-initialise serial ports void init (); Find_serial-searches available serial ports that allows the given protocol//instance should is zero if Searchi 
    Ng for the "instance, 1 for" second, etc//returns UART on success, nullptr if a serial port cannot is found

    Ap_hal::uartdriver *find_serial (enum Serialprotocol protocol, uint8_t instance) const; Find_baudrate-searches available serial ports for the ' the ' the ' the ' the ' instance allows ' given//protocol  Should is zero if searching for the "the", 1 for the second, etc//returns the baudrate of this Protocol on Success, 0 if a serial port cannot be found uint32_t find_baudrate (enum Serialprotocol protocol, uint8_t instance) CO

   Nst Get_mavlink_channel-provides the Mavlink channel associated with a given protocol (and instance)//instance SH Ould be zero if searching for the "the" the "the", 1 for the second, etc.//returns TRUE if a channel is found, false If not bool Get_mavlink_channel (enum Serialprotocol protocol, uint8_t instance, mavlink_channel_t &mav_chan) const

    ;  Get_mavlink_protocol-provides the specific Mavlink protocol for A//given channel, or serialprotocol_none if not

    Found Serialprotocol get_mavlink_protocol (mavlink_channel_t mav_chan) const; Set_blocking_writes_all-sets block_writes to all serial channels void Set_blocking_writes_all (bool Blo

    cking); Set_console_baud-sets the console ' s baud rate to the rate specified by the Protocol void Set_console_baud (enum Se

    Rialprotocol protocol, uint8_t instance) const;

parameter var table static const struct AP_PARAM::GROUPINFO var_info[]; Private://array of UART Info struct {AP_INT8 protocol;
        Ap_int32 baud;
    ap_hal::uartdriver* UART;

    } State[serialmanager_num_ports];

    uint32_t map_baudrate (int32_t rate) const; Protocol_match-returns true if the protocols match bool Protocol_match (enum Serialprotocol protocol1, enum serial
Protocol protocol2) const;
 };
Gcs_mavlink_rover Gcs_chan[mavlink_comm_num_buffers];
Let's take care of the relationship:
class Gcs_mavlink_rover:public Gcs_mavlink
Gcs_mavlink This before we have enumerated the specific functions;

class Gcs_mavlink_ Rover:public gcs_mavlink
{public

:

    void Data_stream_send (void) override;

Protected:

    uint32_t Telem_delay () const override;
    BOOL Accept_packet (const mavlink_status_t &status, mavlink_message_t &msg) override;

Private:

    void Handlemessage (mavlink_message_t * msg) override;//here is the bool Handle_guided_request we will focus on later.
    (Ap_mission::mission_command &cmd) override;
    void Handle_change_alt_request (Ap_mission::mission_command &cmd) override;
    BOOL Try_send_message (enum Ap_message id) override;

All right, go back to Gcs_chan[i].update (nullptr); Soon we can find the source code/libraries/gcs_mavlink/gcs_common.cpp

void Gcs_mavlink::update (Run_cli_fn run_cli) {//Receive new packets mavlink_message_t msg;
    mavlink_status_t status;

    Status.packet_rx_drop_count = 0; Process received bytes uint16_t nbytes = Comm_get_available (chan);//read serial channel all cached data for (uint16_t i=0; i<nbyte S i++) {uint8_t c = Comm_receive_ch (chan);//Read characters to C if (RUN_CLI) {/* Allow CLI to is STA RTed by hitting Enter 3, if no * heartbeat packets have been */if (Received
                ve==0) && (Ap_hal::millis ()-_cli_timeout) < 20000 && Comm_is_idle (chan)) {
                if (c = = ' \ n ' | | c = = ' \ r ') {crlf_count++;
                else {crlf_count = 0;
                } if (Crlf_count = = 3) {run_cli (_port); }///Try to get a new message, parse data by Byte, and save in MSG; if (MAVLink_parse_char (Chan, C, &msg, &status)) {packetreceived (status, MSG);//processing of a whole packet of valid data after each processing of a frame of data
    } if (!waypoint_receiving) {return;
    } uint32_t Tnow = Ap_hal::millis ();

    uint32_t wp_recv_time = 1000U + (stream_slowdown*20); Stop waypoint Receiving if timeout if (waypoint_receiving && (tnow-waypoint_timelast_receive) > Wp_rec
    V_time+waypoint_receive_timeout) {waypoint_receiving = false; else if (waypoint_receiving && (tnow-waypoint_timelast_request) > wp_recv_time) {WA
        Ypoint_timelast_request = Tnow;
    Send_message (Msg_next_waypoint); }

}

Continue to expand the packetreceived, the previous data validation first, let's look at the Handlemessage (&msg); This is the last place to buy, from here to the specific implementation of each business where the Handlemessage This function has 700+ line of code, understand what is inside what is done? ~

void Gcs_mavlink::p acketreceived (const mavlink_status_t &status, mavlink_message_t &A MP;MSG) {//We exclude radio packets to make it possible to ' use the '//CLI over the radio if (Msg.msgid!= MA Vlink_msg_id_radio && msg.msgid!= mavlink_msg_id_radio_status) {mavlink_active |= (1u<< (Chan-MAVLI
    NK_COMM_0)); } if (! ( Status.flags & Mavlink_status_flag_in_mavlink1) && (Status.flags & Mavlink_status_flag_out_mavlink 1) && serialmanager_p && serialmanager_p->get_mavlink_protocol (chan) = = Ap_serialmanage R::SERIALPROTOCOL_MAVLINK2) {//If we receive any MAVLINK2 packets on a connection//currently sending M
        AVLINK1 then switch to sending//MAVLink2 mavlink_status_t *cstatus = Mavlink_get_channel_status (chan);
        if (cstatus!= nullptr) {cstatus->flags &= ~mavlink_status_flag_out_mavlink1;
  }  //If a Snoop handler has been setup then use it if (Msg_snoop!= nullptr) {msg_snoop (&msg); } if (Routing.check_and_forward (Chan, &msg) && accept_packet (Status, msg)) {Handlemessag
    E (&msg); }
}

To the uplink of the data on the analysis completed, the downlink data, there is no time to update it ~, in general APM on the use of Mavlink, the software framework is still relatively clear:
Gcs_mavlink_xxx (such as Class Gcs_mavlink_ Rover:public gcs_mavlink)
^
|
Gcs_mavlink (Common/logs/deviceop ...)
^
|
mavlink2.0 Protocol Package (XML build)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.