Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Frsky_Telem/AP_Frsky_D.cpp
Views: 1798
#include "AP_Frsky_D.h"12#if AP_FRSKY_D_TELEM_ENABLED34#include <AP_AHRS/AP_AHRS.h>5#include <AP_BattMonitor/AP_BattMonitor.h>6#include <AP_GPS/AP_GPS.h>7#include <GCS_MAVLink/GCS.h>89/*10send 1 byte and do byte stuffing11*/12void AP_Frsky_D::send_byte(uint8_t byte)13{14if (byte == START_STOP_D) {15_port->write(0x5D);16_port->write(0x3E);17} else if (byte == BYTESTUFF_D) {18_port->write(0x5D);19_port->write(0x3D);20} else {21_port->write(byte);22}23}2425/*26* send one uint16 frame of FrSky data - for FrSky D protocol (D-receivers)27*/28void AP_Frsky_D::send_uint16(uint16_t id, uint16_t data)29{30_port->write(START_STOP_D); // send a 0x5E start byte31uint8_t *bytes = (uint8_t*)&id;32send_byte(bytes[0]);33bytes = (uint8_t*)&data;34send_byte(bytes[0]); // LSB35send_byte(bytes[1]); // MSB36}3738/*39* send frame1 and frame2 telemetry data40* one frame (frame1) is sent every 200ms with baro alt, nb sats, batt volts and amp, control_mode41* a second frame (frame2) is sent every second (1000ms) with gps position data, and ahrs.yaw_sensor heading (instead of GPS heading)42* for FrSky D protocol (D-receivers)43*/44void AP_Frsky_D::send(void)45{46const AP_BattMonitor &_battery = AP::battery();47uint32_t now = AP_HAL::millis();48// send frame1 every 200ms49if (now - _D.last_200ms_frame >= 200) {50_D.last_200ms_frame = now;51send_uint16(DATA_ID_TEMP2, (uint16_t)(AP::gps().num_sats() * 10 + AP::gps().status())); // send GPS status and number of satellites as num_sats*10 + status (to fit into a uint8_t)52send_uint16(DATA_ID_TEMP1, gcs().custom_mode()); // send flight mode53uint8_t percentage = 0;54IGNORE_RETURN(_battery.capacity_remaining_pct(percentage));55send_uint16(DATA_ID_FUEL, (uint16_t)roundf(percentage)); // send battery remaining56send_uint16(DATA_ID_VFAS, (uint16_t)roundf(_battery.voltage() * 10.0f)); // send battery voltage57float current;58if (!_battery.current_amps(current)) {59current = 0;60}61send_uint16(DATA_ID_CURRENT, (uint16_t)roundf(current * 10.0f)); // send current consumption62calc_nav_alt();63send_uint16(DATA_ID_BARO_ALT_BP, _SPort_data.alt_nav_meters); // send nav altitude integer part64send_uint16(DATA_ID_BARO_ALT_AP, _SPort_data.alt_nav_cm); // send nav altitude decimal part65}66// send frame2 every second67if (now - _D.last_1000ms_frame >= 1000) {68_D.last_1000ms_frame = now;69AP_AHRS &_ahrs = AP::ahrs();70send_uint16(DATA_ID_GPS_COURS_BP, (uint16_t)((_ahrs.yaw_sensor / 100) % 360)); // send heading in degree based on AHRS and not GPS71calc_gps_position();72if (AP::gps().status() >= 3) {73send_uint16(DATA_ID_GPS_LAT_BP, _SPort_data.latdddmm); // send gps latitude degree and minute integer part74send_uint16(DATA_ID_GPS_LAT_AP, _SPort_data.latmmmm); // send gps latitude minutes decimal part75send_uint16(DATA_ID_GPS_LAT_NS, _SPort_data.lat_ns); // send gps North / South information76send_uint16(DATA_ID_GPS_LONG_BP, _SPort_data.londddmm); // send gps longitude degree and minute integer part77send_uint16(DATA_ID_GPS_LONG_AP, _SPort_data.lonmmmm); // send gps longitude minutes decimal part78send_uint16(DATA_ID_GPS_LONG_EW, _SPort_data.lon_ew); // send gps East / West information79send_uint16(DATA_ID_GPS_SPEED_BP, _SPort_data.speed_in_meter); // send gps speed integer part80send_uint16(DATA_ID_GPS_SPEED_AP, _SPort_data.speed_in_centimeter); // send gps speed decimal part81send_uint16(DATA_ID_GPS_ALT_BP, _SPort_data.alt_gps_meters); // send gps altitude integer part82send_uint16(DATA_ID_GPS_ALT_AP, _SPort_data.alt_gps_cm); // send gps altitude decimal part83}84}85}8687#endif // AP_FRSKY_D_TELEM_ENABLED888990