Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mavlink.c File Reference

Basic MAVLink datalink implementation. More...

#include "modules/datalink/mavlink.h"
#include "mavlink/ardupilotmega/mavlink.h"
#include "modules/datalink/telemetry_common.h"
#include "generated/periodic_telemetry.h"
#include "generated/airframe.h"
#include "generated/modules.h"
#include "generated/settings.h"
#include "generated/flight_plan.h"
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "modules/energy/electrical.h"
#include "state.h"
#include "pprz_version.h"
#include "autopilot.h"
#include "autopilot_guided.h"
#include "modules/radio_control/radio_control.h"
#include "modules/datalink/missionlib/mission_manager.h"
#include <stdint.h>
#include <string.h>
#include "modules/gps/gps.h"
#include "modules/core/commands.h"
Include dependency graph for mavlink.c:

Go to the source code of this file.

Macros

#define PERIODIC_C_MAVLINK
#define MAV_AUTOPILOT_ID   MAV_AUTOPILOT_PPZ
#define MAVLINK_SYSID   AC_ID
 MAVLink initialization.
#define UAV_SENSORS   (MAV_SYS_STATUS_SENSOR_3D_GYRO|MAV_SYS_STATUS_SENSOR_3D_ACCEL|MAV_SYS_STATUS_SENSOR_3D_MAG|MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE)
#define RC_CHANNELS   RADIO_CONTROL_NB_CHANNEL
#define PPM_OF_PPRZ(_v)
#define PPM_PULSES(_i)

Functions

void mavlink_common_message_handler (const mavlink_message_t *msg)
static void mavlink_send_extended_sys_state (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_heartbeat (struct transport_tx *trans, struct link_device *dev)
 Send a heartbeat.
static void mavlink_send_sys_status (struct transport_tx *trans, struct link_device *dev)
 Send the system status.
static void mavlink_send_system_time (struct transport_tx *trans, struct link_device *dev)
 Send SYSTEM_TIME.
static void mavlink_send_attitude (struct transport_tx *trans, struct link_device *dev)
 Send the attitude.
static void mavlink_send_local_position_ned (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_global_position_int (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_params (struct transport_tx *trans, struct link_device *dev)
 Send the parameters.
static void mavlink_send_autopilot_version (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_attitude_quaternion (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_gps_raw_int (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_rc_channels (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_battery_status (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_gps_global_origin (struct transport_tx *trans, struct link_device *dev)
static void mavlink_send_gps_status (struct transport_tx *trans, struct link_device *dev)
 Send gps status.
static void mavlink_send_vfr_hud (struct transport_tx *trans, struct link_device *dev)
 Send Metrics typically displayed on a HUD for fixed wing aircraft.
void mavlink_init (void)
 Module functions.
void mavlink_periodic_telemetry (void)
 Send periodic mavlink messages as defined in Mavlink process of telemetry xml file.
void mavlink_periodic (void)
 Periodic MAVLink calls.
static int16_t settings_idx_from_param_id (char *param_id)
void mavlink_event (void)
 Event MAVLink calls.

Variables

mavlink_system_t mavlink_system
static uint8_t mavlink_params_idx = NB_SETTING
 Transmitting parameters index.
static char mavlink_param_names [NB_SETTING][16+1] = SETTINGS_NAMES_SHORT
 mavlink parameter names.
static uint8_t custom_version [8]
 first 8 bytes (16 chars) of GIT SHA1
mavlink_mission_mgr mission_mgr

Detailed Description

Basic MAVLink datalink implementation.

Definition in file mavlink.c.

Macro Definition Documentation

◆ MAV_AUTOPILOT_ID

#define MAV_AUTOPILOT_ID   MAV_AUTOPILOT_PPZ

Definition at line 65 of file mavlink.c.

Referenced by mavlink_send_heartbeat().

◆ MAVLINK_SYSID

#define MAVLINK_SYSID   AC_ID

MAVLink initialization.

Definition at line 110 of file mavlink.c.

Referenced by jevois_mavlink_init(), and mavlink_init().

◆ PERIODIC_C_MAVLINK

#define PERIODIC_C_MAVLINK

Definition at line 38 of file mavlink.c.

◆ PPM_OF_PPRZ

#define PPM_OF_PPRZ ( _v)
Value:
((_v) / 19.2 + 1500)

Definition at line 843 of file mavlink.c.

◆ PPM_PULSES

#define PPM_PULSES ( _i)
Value:
((_i) < RADIO_CONTROL_NB_CHANNEL ? PPM_OF_PPRZ(radio_control.values[(_i)]) + MAX_PPRZ : UINT16_MAX)
#define RADIO_CONTROL_NB_CHANNEL
#define MAX_PPRZ
Definition paparazzi.h:8
struct RadioControl radio_control

Definition at line 844 of file mavlink.c.

Referenced by mavlink_send_rc_channels().

◆ RC_CHANNELS

#define RC_CHANNELS   RADIO_CONTROL_NB_CHANNEL

Definition at line 842 of file mavlink.c.

Referenced by mavlink_send_rc_channels().

◆ UAV_SENSORS

#define UAV_SENSORS   (MAV_SYS_STATUS_SENSOR_3D_GYRO|MAV_SYS_STATUS_SENSOR_3D_ACCEL|MAV_SYS_STATUS_SENSOR_3D_MAG|MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE)

Referenced by mavlink_send_sys_status().

Function Documentation

◆ mavlink_common_message_handler()

◆ mavlink_event()

void mavlink_event ( void )

Event MAVLink calls.

Definition at line 217 of file mavlink.c.

References mavlink_common_message_handler(), mavlink_mission_message_handler(), MAVLinkChAvailable, MAVLinkGetch, and status.

Here is the call graph for this function:

◆ mavlink_init()

◆ mavlink_periodic()

◆ mavlink_periodic_telemetry()

void mavlink_periodic_telemetry ( void )

Send periodic mavlink messages as defined in Mavlink process of telemetry xml file.

Called at TELEMETRY_FREQUENCY

Definition at line 150 of file mavlink.c.

◆ mavlink_send_attitude()

void mavlink_send_attitude ( struct transport_tx * trans,
struct link_device * dev )
static

Send the attitude.

Definition at line 632 of file mavlink.c.

References dev, get_sys_time_msec(), MAVLinkSendMessage, p, stateGetBodyRates_f(), and stateGetNedToBodyEulers_f().

Referenced by mavlink_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_attitude_quaternion()

void mavlink_send_attitude_quaternion ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 744 of file mavlink.c.

References dev, get_sys_time_msec(), MAVLinkSendMessage, p, stateGetBodyRates_f(), and stateGetNedToBodyQuat_f().

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_autopilot_version()

void mavlink_send_autopilot_version ( struct transport_tx * trans,
struct link_device * dev )
static

TODO: fill in versions correctly, how should they be encoded?

Definition at line 718 of file mavlink.c.

References dev, MAVLinkSendMessage, and mcu_get_uid().

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_battery_status()

void mavlink_send_battery_status ( struct transport_tx * trans,
struct link_device * dev )
static

TODO: check what all these fields are supposed to represent

Definition at line 875 of file mavlink.c.

References dev, electrical, and MAVLinkSendMessage.

Referenced by mavlink_init(), and mavlink_periodic().

Here is the caller graph for this function:

◆ mavlink_send_extended_sys_state()

void mavlink_send_extended_sys_state ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 584 of file mavlink.c.

References autopilot_in_flight(), dev, and MAVLinkSendMessage.

Referenced by mavlink_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_global_position_int()

void mavlink_send_global_position_int ( struct transport_tx * trans,
struct link_device * dev )
static

TODO: check/ask what coordinate system vel is supposed to be in, not clear from docs

Definition at line 658 of file mavlink.c.

References LlaCoor_i::alt, dev, get_sys_time_msec(), heading, LtpDef_i::lla, MAVLinkSendMessage, stateGetHmslOrigin_i(), stateGetLlaOrigin_i(), stateGetNedOrigin_i(), stateGetNedToBodyEulers_f(), stateGetPositionLla_i(), and stateGetSpeedNed_f().

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_gps_global_origin()

void mavlink_send_gps_global_origin ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 686 of file mavlink.c.

References dev, get_sys_time_usec(), MAVLinkSendMessage, state, stateGetHmslOrigin_i(), and stateGetLlaOrigin_i().

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_gps_raw_int()

void mavlink_send_gps_raw_int ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 764 of file mavlink.c.

References course, dev, get_sys_time_usec(), gps, and MAVLinkSendMessage.

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_gps_status()

void mavlink_send_gps_status ( struct transport_tx * trans,
struct link_device * dev )
static

Send gps status.

The GPS status message consists of:

  • satellites visible
  • satellite pnr[] (ignored)
  • satellite used[] (ignored)
  • satellite elevation[] (ignored)
  • satellite azimuth[] (ignored)
  • satellite snr[] (ignored)

Definition at line 802 of file mavlink.c.

References dev, gps, GPS_NB_CHANNELS, MAVLinkSendMessage, and Min.

Referenced by mavlink_init(), and mavlink_periodic().

Here is the caller graph for this function:

◆ mavlink_send_heartbeat()

void mavlink_send_heartbeat ( struct transport_tx * trans,
struct link_device * dev )
static

◆ mavlink_send_local_position_ned()

void mavlink_send_local_position_ned ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 645 of file mavlink.c.

References dev, get_sys_time_msec(), MAVLinkSendMessage, stateGetPositionNed_f(), and stateGetSpeedNed_f().

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_params()

void mavlink_send_params ( struct transport_tx * trans,
struct link_device * dev )
static

Send the parameters.

Definition at line 701 of file mavlink.c.

References dev, mavlink_param_names, mavlink_params_idx, and MAVLinkSendMessage.

Referenced by mavlink_periodic().

Here is the caller graph for this function:

◆ mavlink_send_rc_channels()

void mavlink_send_rc_channels ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 848 of file mavlink.c.

References dev, get_sys_time_msec(), MAVLinkSendMessage, PPM_PULSES, and RC_CHANNELS.

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_sys_status()

void mavlink_send_sys_status ( struct transport_tx * trans,
struct link_device * dev )
static

Send the system status.

TODO: FIXME

Definition at line 593 of file mavlink.c.

References dev, electrical, MAVLinkSendMessage, and UAV_SENSORS.

Referenced by mavlink_init(), and mavlink_periodic().

Here is the caller graph for this function:

◆ mavlink_send_system_time()

void mavlink_send_system_time ( struct transport_tx * trans,
struct link_device * dev )
static

Send SYSTEM_TIME.

  • time_unix_usec
  • time_boot_ms

Definition at line 623 of file mavlink.c.

References dev, get_sys_time_msec(), and MAVLinkSendMessage.

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mavlink_send_vfr_hud()

void mavlink_send_vfr_hud ( struct transport_tx * trans,
struct link_device * dev )
static

Send Metrics typically displayed on a HUD for fixed wing aircraft.

Definition at line 903 of file mavlink.c.

References LlaCoor_f::alt, commands, dev, heading, MAVLinkSendMessage, MAX_PPRZ, stateGetAirspeed_f(), stateGetHmslOrigin_f(), stateGetHorizontalSpeedNorm_f(), stateGetLlaOrigin_f(), stateGetNedToBodyEulers_f(), stateGetPositionLla_f(), and stateGetSpeedNed_f().

Referenced by mavlink_init(), and mavlink_periodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ settings_idx_from_param_id()

int16_t settings_idx_from_param_id ( char * param_id)
static

Definition at line 189 of file mavlink.c.

References mavlink_param_names.

Referenced by mavlink_common_message_handler().

Here is the caller graph for this function:

Variable Documentation

◆ custom_version

uint8_t custom_version[8]
static

first 8 bytes (16 chars) of GIT SHA1

Definition at line 81 of file mavlink.c.

Referenced by mavlink_init().

◆ mavlink_param_names

char mavlink_param_names[NB_SETTING][16+1] = SETTINGS_NAMES_SHORT
static

mavlink parameter names.

16 chars + 1 NULL termination.

Definition at line 80 of file mavlink.c.

Referenced by mavlink_common_message_handler(), mavlink_send_params(), and settings_idx_from_param_id().

◆ mavlink_params_idx

uint8_t mavlink_params_idx = NB_SETTING
static

Transmitting parameters index.

Definition at line 76 of file mavlink.c.

Referenced by mavlink_common_message_handler(), and mavlink_send_params().

◆ mavlink_system

mavlink_system_t mavlink_system

◆ mission_mgr