Paparazzi UAS  v5.15_devel-99-g2ff7410
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
29 #include BOARD_CONFIG
30 
31 #ifndef RC_POLARITY_GPIO_PORT
32 #define RC_POLARITY_GPIO_PORT 0
33 #endif
34 #ifndef RC_POLARITY_GPIO_PIN
35 #define RC_POLARITY_GPIO_PIN 0
36 #endif
37 
39 struct Sbus sbus;
40 
41 // Telemetry function
42 #if PERIODIC_TELEMETRY
44 
45 static void send_sbus(struct transport_tx *trans, struct link_device *dev)
46 {
47  // Using PPM message
48  pprz_msg_send_PPM(trans, dev, AC_ID,
50 }
51 #endif
52 
53 // Init function
55 {
57 
58  // Register telemetry message
59 #if PERIODIC_TELEMETRY
61 #endif
62 }
63 
64 
65 // Decoding event function
66 // Reading from UART
67 static inline void sbus_decode_event(void)
68 {
69  sbus_common_decode_event(&sbus, &SBUS_UART_DEV);
70 }
71 
72 void radio_control_impl_event(void (* _received_frame_handler)(void))
73 {
75 
76  if (sbus.frame_available) {
77  //With Sbus one can still have a receiver sent valid frames generated by the
78  //failsafe mode of the receiver, having frames in this case does not guarantee having RC link
79  if (sbus.rc_lost) {
81  if (radio_control.radio_ok_cpt > 0) {
83  }
84  } else {
87  if (radio_control.radio_ok_cpt > 0) {
89  } else {
91  NormalizePpmIIR(sbus.pulses, radio_control);
92  _received_frame_handler();
93  }
94  }
95  sbus.frame_available = false;
96  }
97 
98 }
void sbus_common_decode_event(struct Sbus *sbus_p, struct uart_periph *dev)
Decoding event function.
Definition: sbus_common.c:135
void radio_control_impl_init(void)
Definition: sbus.c:54
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t radio_ok_cpt
Definition: radio_control.h:66
uint8_t status
Definition: radio_control.h:64
#define RC_POLARITY_GPIO_PIN
Definition: sbus.c:35
uint16_t pulses[SBUS_NB_CHANNEL]
Decoded values.
Definition: sbus_common.h:80
bool rc_lost
RC reception is lost.
Definition: sbus_common.h:84
static void sbus_decode_event(void)
Definition: sbus.c:67
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: sbus.c:72
static void send_sbus(struct transport_tx *trans, struct link_device *dev)
Definition: sbus.c:45
struct Sbus sbus
SBUS struct.
Definition: sbus.c:39
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:70
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
struct RadioControl radio_control
Definition: radio_control.c:30
uint16_t ppm[SBUS_NB_CHANNEL]
Decoded and converted to ppm values.
Definition: sbus_common.h:81
#define RC_REALLY_LOST
Definition: radio_control.h:58
#define RC_OK
Definition: radio_control.h:56
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define RC_POLARITY_GPIO_PORT
Definition: sbus.c:32
Radio control via single SBUS receiver.
uint8_t time_since_last_frame
Definition: radio_control.h:65
bool frame_available
A data frame is available.
Definition: sbus_common.h:82
#define SBUS_NB_CHANNEL
Definition: sbus_common.h:63
SBUS structure.
Definition: sbus_common.h:79
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
uint8_t frame_cpt
Definition: radio_control.h:68
uint8_t frame_rate
Definition: radio_control.h:67