rc_sbus.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef RC_SBUS_H
33 #define RC_SBUS_H
34 
35 #include "gpio.h"
36 #include "rc_base.h"
37 #include "system.h"
38 #include "uart.h"
39 
40 class RC_SBUS : public RC_BASE
41 {
42 private:
43  enum
44  {
45  START_BYTE = 0x0F,
46  END_BYTE = 0x00
47  };
48 
49  typedef enum
50  {
55 
56  struct dataFrame_s
57  {
58  uint8_t startByte;
59  unsigned int chan0 : 11;
60  unsigned int chan1 : 11;
61  unsigned int chan2 : 11;
62  unsigned int chan3 : 11;
63  unsigned int chan4 : 11;
64  unsigned int chan5 : 11;
65  unsigned int chan6 : 11;
66  unsigned int chan7 : 11;
67  unsigned int chan8 : 11;
68  unsigned int chan9 : 11;
69  unsigned int chan10 : 11;
70  unsigned int chan11 : 11;
71  unsigned int chan12 : 11;
72  unsigned int chan13 : 11;
73  unsigned int chan14 : 11;
74  unsigned int chan15 : 11;
75  uint8_t digichannels;
76  uint8_t endByte;
77  } __attribute__((__packed__));
78 
79  typedef union
80  {
81  uint8_t data[25];
82  struct dataFrame_s frame;
83  } SBUS_t;
84 
85  SBUS_t sbus_union_;
86 
87  failsafe_state_t failsafe_status_;
88 
91  uint32_t raw_[18];
92  uint32_t frame_start_ms_ = 0;
93  uint8_t buffer_[25];
94  uint8_t buffer_pos_ = 0;
95  uint32_t errors_ = 0;
96  uint8_t prev_byte_ = 0;
97  bool frame_started_ = false;
98 
99  void decode_buffer();
100 
101 public:
102  void init(GPIO* inv_pin, UART* uart);
103  void read_cb(uint8_t byte);
104  float read(uint8_t channel);
105  bool lost();
106  inline uint32_t get_errors() { return errors_; }
107 };
108 
109 #endif // RC_SBUS_H
typedef __attribute__
unsigned int chan2
Definition: rc_sbus.h:61
GPIO * inv_pin_
Definition: rc_sbus.h:89
unsigned int chan12
Definition: rc_sbus.h:71
bool lost()
Definition: rc_sbus.cpp:62
void decode_buffer()
Definition: rc_sbus.cpp:67
unsigned int chan7
Definition: rc_sbus.h:66
unsigned int chan5
Definition: rc_sbus.h:64
unsigned int chan0
Definition: rc_sbus.h:59
unsigned int chan11
Definition: rc_sbus.h:70
uint32_t frame_start_ms_
Definition: rc_sbus.h:92
uint8_t startByte
Definition: rc_sbus.h:58
uint32_t get_errors()
Definition: rc_sbus.h:106
uint32_t errors_
Definition: rc_sbus.h:95
uint8_t prev_byte_
Definition: rc_sbus.h:96
unsigned int chan3
Definition: rc_sbus.h:62
unsigned int chan14
Definition: rc_sbus.h:73
void read_cb(uint8_t byte)
Definition: rc_sbus.cpp:109
unsigned int chan1
Definition: rc_sbus.h:60
failsafe_state_t failsafe_status_
Definition: rc_sbus.h:87
Definition: uart.h:42
UART * uart_
Definition: rc_sbus.h:90
SBUS_t sbus_union_
Definition: rc_sbus.h:85
Definition: gpio.h:37
uint32_t raw_[18]
Definition: rc_sbus.h:91
failsafe_state_t
Definition: rc_sbus.h:49
unsigned int chan4
Definition: rc_sbus.h:63
unsigned int chan8
Definition: rc_sbus.h:67
void init(GPIO *inv_pin, UART *uart)
Definition: rc_sbus.cpp:42
unsigned int chan15
Definition: rc_sbus.h:74
bool frame_started_
Definition: rc_sbus.h:97
unsigned int chan13
Definition: rc_sbus.h:72
uint8_t buffer_pos_
Definition: rc_sbus.h:94
uint8_t digichannels
Definition: rc_sbus.h:75
unsigned int chan6
Definition: rc_sbus.h:65
float read(uint8_t channel)
Definition: rc_sbus.cpp:57
unsigned int chan9
Definition: rc_sbus.h:68
uint8_t buffer_[25]
Definition: rc_sbus.h:93
unsigned int chan10
Definition: rc_sbus.h:69


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Sep 3 2020 03:22:15