Skip to content

Commit 3f64f11

Browse files
committed
Updated to namespace bfs, updated sensors::Sbus to SbusRx and actuators::Sbus to SbusTx.
1 parent b577d34 commit 3f64f11

File tree

6 files changed

+194
-126
lines changed

6 files changed

+194
-126
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Lint:
55
stage: lint
66
tags:
77
- bfs
8-
- mk66fx1m0
98
script:
10-
- cpplint.py --verbose=0 --filter=-whitespace,-line_length src/sbus/sbus.cc
11-
- cpplint.py --verbose=0 --filter=-whitespace,-line_length include/sbus/sbus.h
9+
- cpplint --verbose=0 src/sbus/sbus.cc
10+
- cpplint --verbose=0 include/sbus/sbus.h
1211

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v2.0.0
4+
- Updated to namespace *bfs*
5+
- Updated sensors::Sbus to SbusRx and actuators::Sbus to SbusTx
6+
37
## v1.1.6
48
- Added Channel 17 and 18 support
59
- Added ability to set lost_frame and failsafe for transmitting

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ These are known to work with the same packages used in Teensy products. Also swi
5252

5353
The *sbus_example* target creates an executable for communicating with sbus receivers and servos. This target also has a *_hex* for creating the hex file to upload to the microcontroller.
5454

55-
# Namespaces
56-
The Sbus object for receiving SBUS data from a receiver is within the namespace *sensors*. The Sbus object for sending SBUS commands to servos is within the namespace *actuators*.
55+
# Namespace
56+
This library is within the namespace *bfs*
5757

58-
# Methods
58+
# SbusRx
5959

60-
## Sensors
61-
62-
**Sbus(HardwareSerial *bus)** Creates an Sbus object. A pointer to the Serial object corresponding to the serial port used is passed. The RX pin of the serial port will receive SBUS packets.
60+
**SbusRx(HardwareSerial *bus)** Creates an *SbusRx* object. A pointer to the Serial object corresponding to the serial port used is passed. The RX pin of the serial port will receive SBUS packets.
6361

6462
```C++
65-
sensors::Sbus sbus(&Serial1);
63+
bfs::SbusRx sbus(&Serial1);
6664
```
6765
6866
**void Begin()** Initializes SBUS communication.
@@ -109,12 +107,12 @@ bool lost_frame = sbus.lost_frame();
109107
bool failsafe = sbus.failsafe();
110108
```
111109

112-
## Actuators
110+
## SbusTx
113111

114-
**Sbus(HardwareSerial *bus)** Creates an Sbus object. A pointer to the Serial object corresponding to the serial port used is passed. The TX pin of the serial port will transmit SBUS packets.
112+
**SbusTx(HardwareSerial *bus)** Creates an *SbusTx* object. A pointer to the Serial object corresponding to the serial port used is passed. The TX pin of the serial port will transmit SBUS packets.
115113

116114
```C++
117-
actuators::Sbus sbus(&Serial1);
115+
bfs::SbusTx sbus(&Serial1);
118116
```
119117
120118
**void Begin()** Initializes SBUS communication.

examples/sbus_example.cc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,33 @@
22
* Brian R Taylor
33
44
*
5-
* Copyright (c) 2020 Bolder Flight Systems
5+
* Copyright (c) 2021 Bolder Flight Systems Inc
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the “Software”), to
9+
* deal in the Software without restriction, including without limitation the
10+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11+
* sell copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23+
* IN THE SOFTWARE.
624
*/
725

826
#include "sbus/sbus.h"
927

1028
/* SBUS object, reading SBUS */
11-
sensors::Sbus sbus_rx(&Serial1);
29+
bfs::SbusRx sbus_rx(&Serial1);
1230
/* SBUS object, writing SBUS */
13-
actuators::Sbus sbus_tx(&Serial1);
31+
bfs::SbusTx sbus_tx(&Serial1);
1432

1533
int main() {
1634
/* Serial to display data */

include/sbus/sbus.h

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22
* Brian R Taylor
33
44
*
5-
* Copyright (c) 2020 Bolder Flight Systems
5+
* Copyright (c) 2021 Bolder Flight Systems Inc
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the “Software”), to
9+
* deal in the Software without restriction, including without limitation the
10+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11+
* sell copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23+
* IN THE SOFTWARE.
624
*/
725

826
#ifndef INCLUDE_SBUS_SBUS_H_
@@ -11,14 +29,14 @@
1129
#include <array>
1230
#include "core/core.h"
1331

14-
namespace sensors {
32+
namespace bfs {
1533

16-
class Sbus {
34+
class SbusRx {
1735
public:
18-
explicit Sbus(HardwareSerial *bus) : bus_(bus) {}
36+
explicit SbusRx(HardwareSerial *bus) : bus_(bus) {}
1937
void Begin();
2038
bool Read();
21-
inline std::array<uint16_t, 16> rx_channels() const {return rx_channels_;}
39+
inline std::array<uint16_t, 16> rx_channels() const {return ch_;}
2240
inline bool failsafe() const {return failsafe_;}
2341
inline bool lost_frame() const {return lost_frame_;}
2442
inline bool ch17() const {return ch17_;}
@@ -29,61 +47,57 @@ class Sbus {
2947
HardwareSerial *bus_;
3048
static constexpr uint32_t BAUD_ = 100000;
3149
/* Parsing */
32-
static constexpr uint8_t SBUS_HEADER_ = 0x0F;
33-
static constexpr uint8_t SBUS_FOOTER_ = 0x00;
34-
static constexpr uint8_t SBUS2_FOOTER_ = 0x04;
35-
static constexpr uint8_t SBUS_LENGTH_ = 25;
36-
static constexpr uint8_t SBUS_CH17_ = 0x01;
37-
static constexpr uint8_t SBUS_CH18_ = 0x02;
38-
static constexpr uint8_t SBUS_LOST_FRAME_ = 0x04;
39-
static constexpr uint8_t SBUS_FAILSAFE_ = 0x08;
40-
unsigned int parser_state_ = 0;
41-
uint8_t previous_byte_ = SBUS_FOOTER_;
42-
uint8_t rx_buffer_[SBUS_LENGTH_];
50+
static constexpr uint8_t HEADER_ = 0x0F;
51+
static constexpr uint8_t FOOTER_ = 0x00;
52+
static constexpr uint8_t FOOTER2_ = 0x04;
53+
static constexpr uint8_t LEN_ = 25;
54+
static constexpr uint8_t CH17_ = 0x01;
55+
static constexpr uint8_t CH18_ = 0x02;
56+
static constexpr uint8_t LOST_FRAME_ = 0x04;
57+
static constexpr uint8_t FAILSAFE_ = 0x08;
58+
unsigned int state_ = 0;
59+
uint8_t prev_byte_ = FOOTER_;
60+
uint8_t buf_[LEN_];
4361
/* Data */
44-
std::array<uint16_t, 16> rx_channels_;
62+
std::array<uint16_t, 16> ch_;
4563
bool failsafe_ = false, lost_frame_ = false, ch17_ = false, ch18_ = false;
4664
bool Parse();
4765
};
4866

49-
} // namespace sensors
50-
51-
namespace actuators {
52-
53-
class Sbus {
67+
class SbusTx {
5468
public:
55-
explicit Sbus(HardwareSerial *bus) : bus_(bus) {}
69+
explicit SbusTx(HardwareSerial *bus) : bus_(bus) {}
5670
void Begin();
5771
void Write();
58-
inline void failsafe(bool val) {failsafe_ = val;}
59-
inline void lost_frame(bool val) {lost_frame_ = val;}
60-
inline void ch17(bool val) {ch17_ = val;}
61-
inline void ch18(bool val) {ch18_ = val;}
62-
inline void tx_channels(const std::array<uint16_t, 16> &val) {tx_channels_ = val;}
72+
inline void failsafe(const bool val) {failsafe_ = val;}
73+
inline void lost_frame(const bool val) {lost_frame_ = val;}
74+
inline void ch17(const bool val) {ch17_ = val;}
75+
inline void ch18(const bool val) {ch18_ = val;}
76+
inline void tx_channels(const std::array<uint16_t, 16> &val) {ch_ = val;}
6377
inline bool failsafe() const {return failsafe_;}
6478
inline bool lost_frame() const {return lost_frame_;}
6579
inline bool ch17() const {return ch17_;}
6680
inline bool ch18() const {return ch18_;}
67-
inline std::array<uint16_t, 16> tx_channels() const {return tx_channels_;}
81+
inline std::array<uint16_t, 16> tx_channels() const {return ch_;}
6882

6983
private:
7084
/* Communication */
7185
HardwareSerial *bus_;
7286
static constexpr uint32_t BAUD_ = 100000;
7387
/* Parsing */
74-
static constexpr uint8_t SBUS_HEADER_ = 0x0F;
75-
static constexpr uint8_t SBUS_FOOTER_ = 0x00;
76-
static constexpr uint8_t SBUS_LENGTH_ = 25;
77-
static constexpr uint8_t SBUS_CH17_ = 0x01;
78-
static constexpr uint8_t SBUS_CH18_ = 0x02;
79-
static constexpr uint8_t SBUS_LOST_FRAME_ = 0x04;
80-
static constexpr uint8_t SBUS_FAILSAFE_ = 0x08;
81-
uint8_t tx_buffer_[SBUS_LENGTH_];
88+
static constexpr uint8_t HEADER_ = 0x0F;
89+
static constexpr uint8_t FOOTER_ = 0x00;
90+
static constexpr uint8_t LEN_ = 25;
91+
static constexpr uint8_t CH17_ = 0x01;
92+
static constexpr uint8_t CH18_ = 0x02;
93+
static constexpr uint8_t LOST_FRAME_ = 0x04;
94+
static constexpr uint8_t FAILSAFE_ = 0x08;
95+
uint8_t buf_[LEN_];
8296
/* Data */
83-
std::array<uint16_t, 16> tx_channels_;
97+
std::array<uint16_t, 16> ch_;
8498
bool failsafe_ = false, lost_frame_ = false, ch17_ = false, ch18_ = false;
8599
};
86100

87-
} // namespace actuators
101+
} // namespace bfs
88102

89103
#endif // INCLUDE_SBUS_SBUS_H_

0 commit comments

Comments
 (0)