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


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19