Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "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 
40 struct Sbus sbus;
41 
42 // Telemetry function
43 #if PERIODIC_TELEMETRY
45 
46 static 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,
51 }
52 #endif
53 
54 // Init function
55 void sbus_init(void)
56 {
59 
60  // Register telemetry message
61 #if PERIODIC_TELEMETRY
63 #endif
64 }
65 
66 
67 // Decoding event function
68 // Reading from UART
69 static inline void sbus_decode_event(void)
70 {
71  sbus_common_decode_event(&sbus, &SBUS_UART_DEV);
72 }
73 
74 void 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) {
85  }
86  } else {
89  if (radio_control.radio_ok_cpt > 0) {
91  } else {
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
struct RadioControl radio_control
Definition: radio_control.c:33
Generic interface for radio control modules.
uint8_t time_since_last_frame
Definition: radio_control.h:62
#define RC_REALLY_LOST
Definition: radio_control.h:51
uint8_t status
Definition: radio_control.h:61
uint8_t radio_ok_cpt
Definition: radio_control.h:63
uint8_t frame_rate
Definition: radio_control.h:64
uint8_t frame_cpt
Definition: radio_control.h:65
#define RC_OK
Definition: radio_control.h:49
uint8_t nb_channel
Definition: radio_control.h:66
#define RC_POLARITY_GPIO_PORT
Definition: sbus.c:33
static void send_sbus(struct transport_tx *trans, struct link_device *dev)
Definition: sbus.c:46
#define RC_POLARITY_GPIO_PIN
Definition: sbus.c:36
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.
Definition: sbus_common.c:139
uint16_t ppm[SBUS_NB_CHANNEL]
Decoded and converted to ppm values.
Definition: sbus_common.h:70
uint16_t pulses[SBUS_NB_CHANNEL]
Decoded values.
Definition: sbus_common.h:69
bool rc_lost
RC reception is lost.
Definition: sbus_common.h:73
bool rc_failsafe
Receiver set to in failsafe mode.
Definition: sbus_common.h:72
bool frame_available
A data frame is available.
Definition: sbus_common.h:71
#define SBUS_NB_CHANNEL
Definition: sbus_common.h:63
SBUS structure.
Definition: sbus_common.h:68
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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