PX4 Firmware
PX4 Autopilot Software http://px4.io
sbus.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2015 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file sbus.h
36  *
37  * RC protocol definition for S.BUS
38  *
39  * @author Lorenz Meier <lorenz@px4.io>
40  */
41 
42 #pragma once
43 
44 #include <stdint.h>
45 #include <stdbool.h>
46 
48 
49 #define SBUS_FRAME_SIZE 25
50 #define SBUS_BUFFER_SIZE (SBUS_FRAME_SIZE + SBUS_FRAME_SIZE / 2)
51 
52 typedef uint8_t sbus_frame_t[SBUS_FRAME_SIZE + (SBUS_FRAME_SIZE / 2)];
53 
54 
55 __EXPORT int sbus_init(const char *device, bool singlewire);
56 
57 /**
58  * Parse serial bytes on the S.BUS bus
59  *
60  * The S.bus protocol doesn't provide reliable framing,
61  * so we detect frame boundaries by the inter-frame delay.
62  *
63  * The minimum frame spacing is 7ms; with 25 bytes at 100000bps
64  * frame transmission time is ~2ms.
65  *
66  * If an interval of more than 4ms (7 ms frame spacing plus margin)
67  * passes between calls, the first byte we read will be the first
68  * byte of a frame.
69  *
70  * In the case where byte(s) are dropped from a frame, this also
71  * provides a degree of protection. Of course, it would be better
72  * if we didn't drop bytes...
73  */
74 __EXPORT int sbus_config(int sbus_fd, bool singlewire);
75 __EXPORT bool sbus_input(int sbus_fd, uint16_t *values, uint16_t *num_values, bool *sbus_failsafe,
76  bool *sbus_frame_drop,
77  uint16_t max_channels);
78 __EXPORT bool sbus_parse(uint64_t now, uint8_t *frame, unsigned len, uint16_t *values,
79  uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, unsigned *frame_drops, uint16_t max_channels);
80 __EXPORT void sbus1_output(int sbus_fd, uint16_t *values, uint16_t num_values);
81 __EXPORT void sbus2_output(int sbus_fd, uint16_t *values, uint16_t num_values);
82 __EXPORT void sbus1_set_output_rate_hz(uint16_t rate_hz);
83 
84 /**
85  * The number of incomplete frames we encountered
86  */
87 __EXPORT unsigned sbus_dropped_frames(void);
88 
__EXPORT unsigned sbus_dropped_frames(void)
The number of incomplete frames we encountered.
Definition: sbus.cpp:128
#define __END_DECLS
Definition: visibility.h:59
Definition: I2C.hpp:51
#define SBUS_FRAME_SIZE
Definition: sbus.h:49
Namespace encapsulating all device framework classes, functions and data.
Definition: CDev.cpp:47
__EXPORT bool sbus_parse(uint64_t now, uint8_t *frame, unsigned len, uint16_t *values, uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, unsigned *frame_drops, uint16_t max_channels)
Definition: sbus.cpp:343
__EXPORT bool sbus_input(int sbus_fd, uint16_t *values, uint16_t *num_values, bool *sbus_failsafe, bool *sbus_frame_drop, uint16_t max_channels)
Definition: sbus.cpp:282
#define __BEGIN_DECLS
Definition: visibility.h:58
__EXPORT int sbus_init(const char *device, bool singlewire)
Definition: sbus.cpp:138
__EXPORT void sbus1_set_output_rate_hz(uint16_t rate_hz)
Definition: sbus.cpp:705
__EXPORT int sbus_config(int sbus_fd, bool singlewire)
Parse serial bytes on the S.BUS bus.
Definition: sbus.cpp:153
uint8_t sbus_frame_t[SBUS_FRAME_SIZE+(SBUS_FRAME_SIZE/2)]
Definition: sbus.h:52
__EXPORT void sbus2_output(int sbus_fd, uint16_t *values, uint16_t num_values)
Definition: sbus.cpp:276
__EXPORT void sbus1_output(int sbus_fd, uint16_t *values, uint16_t num_values)
Definition: sbus.cpp:237