11 #define termios asmtermios 13 #include <asm/termios.h> 29 #define K_SBUS_PORT_SIM "/dev/ttyUSB0" 31 #define K_SBUS_PORT_MC "/dev/ttyS4" 34 if ((sbus_data[0] == 0xF) && (sbus_data[24] == 0x0)) {
35 channels_[0] = ((sbus_data[1]) | ((sbus_data[2] & 0x7) << 8));
36 channels_[1] = (sbus_data[2] >> 3) | ((sbus_data[3] & 0x3F) << 5);
37 channels_[2] = ((sbus_data[3] & 0xC0) >> 6) | (sbus_data[4] << 2) |
38 ((sbus_data[5] & 0x1) << 10);
39 channels_[3] = ((sbus_data[5] & 0xFE) >> 1) | ((sbus_data[6] & 0xF) << 7);
40 channels_[4] = ((sbus_data[6] & 0xF0) >> 4) | ((sbus_data[7] & 0x7F) << 4);
41 channels_[5] = ((sbus_data[7] & 0x80) >> 7) | (sbus_data[8] << 1) |
42 ((sbus_data[9] & 0x3) << 9);
43 channels_[6] = ((sbus_data[9] & 0xFC) >> 2) | ((sbus_data[10] & 0x1F) << 6);
44 channels_[7] = ((sbus_data[10] & 0xE0) >> 5) | (sbus_data[11] << 3);
46 channels_[8] = ((sbus_data[12]) | ((sbus_data[13] & 0x7) << 8));
47 channels_[9] = (sbus_data[13] >> 3) | ((sbus_data[14] & 0x3F) << 5);
48 channels_[10] = ((sbus_data[14] & 0xC0) >> 6) | (sbus_data[15] << 2) |
49 ((sbus_data[16] & 0x1) << 10);
51 ((sbus_data[16] & 0xFE) >> 1) | ((sbus_data[17] & 0xF) << 7);
53 ((sbus_data[17] & 0xF0) >> 4) | ((sbus_data[18] & 0x7F) << 4);
54 channels_[13] = ((sbus_data[18] & 0x80) >> 7) | (sbus_data[19] << 1) |
55 ((sbus_data[20] & 0x3) << 9);
57 ((sbus_data[20] & 0xFC) >> 2) | ((sbus_data[21] & 0x1F) << 6);
58 channels_[15] = ((sbus_data[21] & 0xE0) >> 5) | (sbus_data[22] << 3);
60 channels_[16] = (sbus_data[23] & 0x80) >> 7;
61 channels_[17] = (sbus_data[23] & 0x40) >> 6;
64 for (
int i = 0; i < 18; i++) {
72 printf(
"Bad Packet\n");
77 uint8_t packet_full = 0;
78 uint8_t read_byte[1] = {0};
79 int timeout_counter = 0;
81 while ((!packet_full) && (timeout_counter < 50)) {
84 int n = read(port, read_byte,
sizeof(read_byte));
87 for (
int i = 0; i < 24; i++) {
88 sbus_data[i] = sbus_data[i + 1];
90 sbus_data[24] = read_byte[0];
93 if ((sbus_data[0] == 15) && (sbus_data[24] == 0)) {
109 uint16_t read_buff[25] = {0};
114 printf(
"SBUS tried read 50 bytes without seeing a packet\n");
129 printf(
"Failed to initialize sbus data mutex.\n");
132 int fd1 = open(port1.c_str(), O_RDWR | O_NOCTTY | O_SYNC);
134 printf(
"Error opening %s: %s\n", port1.c_str(), strerror(errno));
void unpack_sbus_data(uint8_t sbus_data[], uint16_t *channels_)
int init_sbus(int is_simulator)
#define K_SBUS_PORT_SIM
Name of SBUS serial port in simulator.
int set_interface_attribs_custom_baud(int fd, int speed, int parity, int port)
Configure serial port.
int receive_sbus(int port)
int read_sbus_data(int port, uint8_t *sbus_data)
pthread_mutex_t sbus_data_m
#define K_SBUS_PORT_MC
Name of SBUS serial port on the mini cheetah.
uint16_t channel_data[18]
int read_sbus_channel(int channel)