Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
sbus.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
26
29#include "modules/core/abi.h"
30#include BOARD_CONFIG
31
32#ifndef RC_POLARITY_GPIO_PORT
33#define RC_POLARITY_GPIO_PORT 0
34#endif
35#ifndef RC_POLARITY_GPIO_PIN
36#define RC_POLARITY_GPIO_PIN 0
37#endif
38
40struct Sbus sbus;
41
42// Telemetry function
43#if PERIODIC_TELEMETRY
45
46static void send_sbus(struct transport_tx *trans, struct link_device *dev)
47{
48 // Using PPM message
49 pprz_msg_send_PPM(trans, dev, AC_ID,
50 &radio_control.frame_rate, SBUS_NB_CHANNEL, sbus.ppm);
51}
52#endif
53
54// Init function
55void sbus_init(void)
56{
58 radio_control.nb_channel = SBUS_NB_CHANNEL;
59
60 // Register telemetry message
61#if PERIODIC_TELEMETRY
63#endif
64}
65
66
67// Decoding event function
68// Reading from UART
69static inline void sbus_decode_event(void)
70{
71 sbus_common_decode_event(&sbus, &SBUS_UART_DEV);
72}
73
74void sbus_event(void)
75{
77
78 if (sbus.frame_available) {
79 //With Sbus one can still have a receiver sent valid frames generated by the
80 //failsafe mode of the receiver, having frames in this case does not guarantee having RC link
81 if (sbus.rc_lost || sbus.rc_failsafe) {
83 if (radio_control.radio_ok_cpt > 0) {
84 radio_control.radio_ok_cpt--;
85 }
86 } else {
87 radio_control.frame_cpt++;
88 radio_control.time_since_last_frame = 0;
89 if (radio_control.radio_ok_cpt > 0) {
90 radio_control.radio_ok_cpt--;
91 } else {
92 radio_control.status = RC_OK;
93 NormalizePpmIIR(sbus.pulses, radio_control);
94 AbiSendMsgRADIO_CONTROL(RADIO_CONTROL_SBUS_ID, &radio_control);
95 }
96 }
97 sbus.frame_available = false;
98 }
99
100}
Main include for ABI (AirBorneInterface).
#define RADIO_CONTROL_SBUS_ID
#define RC_POLARITY_GPIO_PORT
Definition board.h:154
#define RC_POLARITY_GPIO_PIN
Definition board.h:155
static struct uart_periph * dev
struct RadioControl radio_control
Generic interface for radio control modules.
#define RC_REALLY_LOST
#define RC_OK
static void send_sbus(struct transport_tx *trans, struct link_device *dev)
Definition sbus.c:46
void sbus_event(void)
RC event function.
Definition sbus.c:74
void sbus_init(void)
RC init function.
Definition sbus.c:55
static void sbus_decode_event(void)
Definition sbus.c:69
struct Sbus sbus
SBUS struct.
Definition sbus.c:40
Radio control via single SBUS receiver.
void sbus_common_init(struct Sbus *sbus_p, struct uart_periph *dev, gpio_port_t gpio_polarity_port, uint16_t gpio_polarity_pin)
Init function.
Definition sbus_common.c:74
void sbus_common_decode_event(struct Sbus *sbus_p, struct uart_periph *dev)
Decoding event function.
#define SBUS_NB_CHANNEL
Definition sbus_common.h:63
SBUS structure.
Definition sbus_common.h:68
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66