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 "system.h"
36 
37 #include "rc_base.h"
38 #include "gpio.h"
39 #include "uart.h"
40 
41 class RC_SBUS : public RC_BASE
42 {
43 
44 private:
45 
46  enum
47  {
48  START_BYTE = 0x0F,
49  END_BYTE = 0x00
50  };
51 
52  typedef enum
53  {
58 
59  struct dataFrame_s
60  {
61  uint8_t startByte;
62  unsigned int chan0 : 11;
63  unsigned int chan1 : 11;
64  unsigned int chan2 : 11;
65  unsigned int chan3 : 11;
66  unsigned int chan4 : 11;
67  unsigned int chan5 : 11;
68  unsigned int chan6 : 11;
69  unsigned int chan7 : 11;
70  unsigned int chan8 : 11;
71  unsigned int chan9 : 11;
72  unsigned int chan10 : 11;
73  unsigned int chan11 : 11;
74  unsigned int chan12 : 11;
75  unsigned int chan13 : 11;
76  unsigned int chan14 : 11;
77  unsigned int chan15 : 11;
78  uint8_t digichannels;
79  uint8_t endByte;
80  } __attribute__((__packed__));
81 
82  typedef union
83  {
84  uint8_t data[25];
85  struct dataFrame_s frame;
86  } SBUS_t;
87 
88  SBUS_t sbus_union_;
89 
90  failsafe_state_t failsafe_status_;
91 
94  uint32_t raw_[18];
95  uint32_t frame_start_ms_ = 0;
96  uint8_t buffer_[25];
97  uint8_t buffer_pos_ = 0;
98  uint32_t errors_ = 0;
99  uint8_t prev_byte_ = 0;
100  bool frame_started_ = false;
101 
102  void decode_buffer();
103 
104 public:
105 
106  void init(GPIO *inv_pin, UART *uart);
107  void read_cb(uint8_t byte);
108  float read(uint8_t channel);
109  bool lost();
110  inline uint32_t get_errors()
111  {
112  return errors_;
113  }
114 
115 };
116 
117 #endif // RC_SBUS_H
typedef __attribute__
unsigned int chan2
Definition: rc_sbus.h:64
GPIO * inv_pin_
Definition: rc_sbus.h:92
unsigned int chan12
Definition: rc_sbus.h:74
bool lost()
Definition: rc_sbus.cpp:62
void decode_buffer()
Definition: rc_sbus.cpp:67
unsigned int chan7
Definition: rc_sbus.h:69
unsigned int chan5
Definition: rc_sbus.h:67
unsigned int chan0
Definition: rc_sbus.h:62
unsigned int chan11
Definition: rc_sbus.h:73
uint32_t frame_start_ms_
Definition: rc_sbus.h:95
uint8_t startByte
Definition: rc_sbus.h:61
uint32_t get_errors()
Definition: rc_sbus.h:110
uint32_t errors_
Definition: rc_sbus.h:98
uint8_t prev_byte_
Definition: rc_sbus.h:99
unsigned int chan3
Definition: rc_sbus.h:65
unsigned int chan14
Definition: rc_sbus.h:76
void read_cb(uint8_t byte)
Definition: rc_sbus.cpp:110
unsigned int chan1
Definition: rc_sbus.h:63
failsafe_state_t failsafe_status_
Definition: rc_sbus.h:90
Definition: uart.h:43
UART * uart_
Definition: rc_sbus.h:93
SBUS_t sbus_union_
Definition: rc_sbus.h:88
Definition: gpio.h:37
uint32_t raw_[18]
Definition: rc_sbus.h:94
failsafe_state_t
Definition: rc_sbus.h:52
unsigned int chan4
Definition: rc_sbus.h:66
unsigned int chan8
Definition: rc_sbus.h:70
void init(GPIO *inv_pin, UART *uart)
Definition: rc_sbus.cpp:42
unsigned int chan15
Definition: rc_sbus.h:77
bool frame_started_
Definition: rc_sbus.h:100
unsigned int chan13
Definition: rc_sbus.h:75
uint8_t buffer_pos_
Definition: rc_sbus.h:97
uint8_t digichannels
Definition: rc_sbus.h:78
unsigned int chan6
Definition: rc_sbus.h:68
float read(uint8_t channel)
Definition: rc_sbus.cpp:57
unsigned int chan9
Definition: rc_sbus.h:71
uint8_t buffer_[25]
Definition: rc_sbus.h:96
unsigned int chan10
Definition: rc_sbus.h:72


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25