PX4 Firmware
PX4 Autopilot Software http://px4.io
dsm.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 dsm.h
36  *
37  * RC protocol definition for Spektrum RC
38  *
39  * @author Lorenz Meier <lorenz@px4.io>
40  */
41 
42 #pragma once
43 
44 #include <stdint.h>
45 
46 #include <px4_platform_common/px4_config.h>
47 #include <px4_platform_common/defines.h>
48 
50 
51 #define DSM_FRAME_SIZE 16 /**< DSM frame size in bytes */
52 #define DSM_FRAME_CHANNELS 7 /**< Max supported DSM channels per frame */
53 #define DSM_MAX_CHANNEL_COUNT 18 /**< Max channel count of any DSM RC */
54 #define DSM_BUFFER_SIZE (DSM_FRAME_SIZE + DSM_FRAME_SIZE / 2)
55 
56 
57 #pragma pack(push, 1)
58 typedef uint8_t dsm_frame_t[DSM_BUFFER_SIZE]; /**< DSM dsm frame receive buffer */
59 typedef uint8_t dsm_buf_t[DSM_FRAME_SIZE * 2]; // Define working buffer
60 
61 typedef struct dsm_decode_t {
64 } dsm_decode_t;
65 
66 #pragma pack(pop)
67 
68 __EXPORT int dsm_init(const char *device);
69 __EXPORT void dsm_deinit(void);
70 __EXPORT void dsm_proto_init(void);
71 __EXPORT int dsm_config(int dsm_fd);
72 __EXPORT bool dsm_input(int dsm_fd, uint16_t *values, uint16_t *num_values, bool *dsm_11_bit, uint8_t *n_bytes,
73  uint8_t **bytes, int8_t *rssi, unsigned max_values);
74 
75 __EXPORT bool dsm_parse(const uint64_t now, const uint8_t *frame, const unsigned len, uint16_t *values,
76  uint16_t *num_values, bool *dsm_11_bit, unsigned *frame_drops, int8_t *rssi_percent, uint16_t max_channels);
77 
78 #ifdef SPEKTRUM_POWER
79 __EXPORT void dsm_bind(uint16_t cmd, int pulses);
80 #endif
81 
82 enum DSM_CMD { /* DSM bind states */
88 };
89 
90 #define DSM2_BIND_PULSES 3 /* DSM_BIND_START parameter, pulses required to start dsm2 pairing */
91 #define DSMX_BIND_PULSES 7 /* DSM_BIND_START parameter, pulses required to start dsmx pairing */
92 #define DSMX8_BIND_PULSES 9 /* DSM_BIND_START parameter, pulses required to start 8 or more channel dsmx pairing */
93 
dsm_frame_t frame
Definition: dsm.h:62
struct dsm_decode_t dsm_decode_t
static int dsm_fd
File handle to the DSM UART.
Definition: dsm.cpp:70
#define __END_DECLS
Definition: visibility.h:59
Definition: I2C.hpp:51
uint8_t dsm_buf_t[DSM_FRAME_SIZE *2]
Definition: dsm.h:59
Namespace encapsulating all device framework classes, functions and data.
Definition: CDev.cpp:47
__EXPORT int dsm_config(int dsm_fd)
Definition: dsm.cpp:240
DSM_CMD
Definition: dsm.h:82
__EXPORT void dsm_deinit(void)
Definition: dsm.cpp:313
#define __BEGIN_DECLS
Definition: visibility.h:58
__EXPORT bool dsm_parse(const uint64_t now, const uint8_t *frame, const unsigned len, uint16_t *values, uint16_t *num_values, bool *dsm_11_bit, unsigned *frame_drops, int8_t *rssi_percent, uint16_t max_channels)
Definition: dsm.cpp:640
__EXPORT void dsm_proto_init(void)
Definition: dsm.cpp:273
#define DSM_FRAME_SIZE
DSM frame size in bytes.
Definition: dsm.h:51
dsm_buf_t buf
Definition: dsm.h:63
#define DSM_BUFFER_SIZE
Definition: dsm.h:54
uint8_t dsm_frame_t[DSM_BUFFER_SIZE]
DSM dsm frame receive buffer.
Definition: dsm.h:58
__EXPORT bool dsm_input(int dsm_fd, uint16_t *values, uint16_t *num_values, bool *dsm_11_bit, uint8_t *n_bytes, uint8_t **bytes, int8_t *rssi, unsigned max_values)
Called periodically to check for input data from the DSM UART.
Definition: dsm.cpp:593
__EXPORT int dsm_init(const char *device)
Initialize the DSM receive functionality.
Definition: dsm.cpp:293