Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sbus_dual.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Christophe De Wagter
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
29 #include BOARD_CONFIG
30 #include "mcu_periph/uart.h"
31 #include "mcu_periph/gpio.h"
32 #include <string.h>
33 
34 
36 struct Sbus sbus1, sbus2;
37 
38 // Telemetry function
39 #if PERIODIC_TELEMETRY
41 
42 static void send_sbus(struct transport_tx *trans, struct link_device *dev)
43 {
44  // Using PPM message
45  pprz_msg_send_PPM(trans, dev, AC_ID,
47 }
48 #endif
49 
50 // Init function
52 {
53  sbus_common_init(&sbus1, &SBUS1_UART_DEV);
54  sbus_common_init(&sbus2, &SBUS2_UART_DEV);
55 
56  // Register telemetry message
57 #if PERIODIC_TELEMETRY
58  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_PPM, send_sbus);
59 #endif
60 }
61 
62 static inline void sbus_dual_decode_event(void)
63 {
64  sbus_common_decode_event(&sbus1, &SBUS1_UART_DEV);
65  sbus_common_decode_event(&sbus2, &SBUS2_UART_DEV);
66 }
67 
68 void radio_control_impl_event(void (* _received_frame_handler)(void))
69 {
71  if (sbus2.frame_available) {
74  if (radio_control.radio_ok_cpt > 0) {
76  } else {
78  NormalizePpmIIR(sbus2.pulses, radio_control);
79  _received_frame_handler();
80  }
82  }
83  if (sbus1.frame_available) {
86  if (radio_control.radio_ok_cpt > 0) {
88  } else {
90  NormalizePpmIIR(sbus1.pulses, radio_control);
91  _received_frame_handler();
92  }
93  sbus1.frame_available = FALSE;
94  }
95 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void sbus_common_decode_event(struct Sbus *sbus_p, struct uart_periph *dev)
Decoding event function.
Definition: sbus_common.c:115
Generic transmission transport header.
Definition: transport.h:89
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: sbus_dual.c:68
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t radio_ok_cpt
Definition: radio_control.h:55
uint8_t status
Definition: radio_control.h:53
uint16_t pulses[SBUS_NB_CHANNEL]
decoded values
Definition: sbus_common.h:79
Some architecture independent helper functions for GPIOs.
void radio_control_impl_init(void)
Definition: sbus_dual.c:51
Radio control via two SBUS receivers.
#define FALSE
Definition: std.h:5
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
void sbus_common_init(struct Sbus *sbus_p, struct uart_periph *dev)
Init function.
Definition: sbus_common.c:57
struct RadioControl radio_control
Definition: radio_control.c:30
struct Sbus sbus1 sbus2
SBUS struct.
Definition: sbus_dual.c:36
#define RC_OK
Definition: radio_control.h:48
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
uint8_t time_since_last_frame
Definition: radio_control.h:54
#define SBUS_NB_CHANNEL
Definition: sbus_common.h:62
SBUS structure.
Definition: sbus_common.h:78
static void sbus_dual_decode_event(void)
Definition: sbus_dual.c:62
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:57
uint8_t frame_rate
Definition: radio_control.h:56
bool_t frame_available
new frame available
Definition: sbus_common.h:81