41
41
42
42
#include < fcntl.h>
43
43
#include < unistd.h>
44
- #include < termios.h>
45
44
#include < string.h>
46
45
47
46
#ifdef TIOCSSINGLEWIRE
@@ -58,7 +57,9 @@ using namespace time_literals;
58
57
59
58
#if defined(__PX4_LINUX)
60
59
#include < sys/ioctl.h>
61
- #include < linux/serial_core.h>
60
+ #include < asm-generic/termbits.h>
61
+ #else
62
+ #include < termios.h>
62
63
#endif
63
64
64
65
#define SBUS_START_SYMBOL 0x0f
@@ -152,56 +153,40 @@ sbus_init(const char *device, bool singlewire)
152
153
int
153
154
sbus_config (int sbus_fd, bool singlewire)
154
155
{
155
- #if defined(__PX4_LINUX)
156
- struct termios options;
157
-
158
- if (tcgetattr (sbus_fd, &options) != 0 ) {
159
- return -1 ;
160
- }
161
-
162
- tcflush (sbus_fd, TCIFLUSH);
163
- bzero (&options, sizeof (options));
164
-
165
- options.c_cflag |= (CLOCAL | CREAD);
166
- options.c_cflag &= ~CSIZE;
167
- options.c_cflag |= CS8;
168
- options.c_cflag |= PARENB;
169
- options.c_cflag &= ~PARODD;
170
- options.c_iflag |= INPCK;
171
- options.c_cflag |= CSTOPB;
172
-
173
- options.c_cc [VTIME] = 0 ;
174
- options.c_cc [VMIN] = 0 ;
175
-
176
- cfsetispeed (&options, B38400);
177
- cfsetospeed (&options, B38400);
178
-
179
- tcflush (sbus_fd, TCIFLUSH);
156
+ int ret = -1 ;
180
157
181
- if ((tcsetattr (sbus_fd, TCSANOW, &options)) != 0 ) {
182
- return -1 ;
183
- }
158
+ #if defined(__PX4_LINUX)
184
159
185
- int baud = 100000 ;
186
- struct serial_struct serials;
160
+ struct termios2 tio = {};
187
161
188
- if (( ioctl (sbus_fd, TIOCGSERIAL , &serials)) < 0 ) {
189
- return - 1 ;
162
+ if (0 != ioctl (sbus_fd, TCGETS2 , &tio) ) {
163
+ return ret ;
190
164
}
191
165
192
- serials.flags = ASYNC_SPD_CUST;
193
- serials.custom_divisor = serials.baud_base / baud;
194
-
195
- if ((ioctl (sbus_fd, TIOCSSERIAL, &serials)) < 0 ) {
196
- return -1 ;
166
+ /* *
167
+ * Setting serial port,8E2, non-blocking.100Kbps
168
+ */
169
+ tio.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL
170
+ | IXON);
171
+ tio.c_iflag |= (INPCK | IGNPAR);
172
+ tio.c_oflag &= ~OPOST;
173
+ tio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
174
+ tio.c_cflag &= ~(CSIZE | CRTSCTS | PARODD | CBAUD);
175
+ /* *
176
+ * use BOTHER to specify speed directly in c_[io]speed member
177
+ */
178
+ tio.c_cflag |= (CS8 | CSTOPB | CLOCAL | PARENB | BOTHER | CREAD);
179
+ tio.c_ispeed = 100000 ;
180
+ tio.c_ospeed = 100000 ;
181
+ tio.c_cc [VMIN] = 25 ;
182
+ tio.c_cc [VTIME] = 0 ;
183
+
184
+ if (0 != ioctl (sbus_fd, TCSETS2, &tio)) {
185
+ return ret;
197
186
}
198
187
199
- ioctl (sbus_fd, TIOCGSERIAL, &serials);
200
-
201
- tcflush (sbus_fd, TCIFLUSH);
202
- return 0 ;
188
+ ret = 0 ;
203
189
#else
204
- int ret = -1 ;
205
190
206
191
if (sbus_fd >= 0 ) {
207
192
struct termios t;
@@ -221,16 +206,16 @@ sbus_config(int sbus_fd, bool singlewire)
221
206
#endif
222
207
}
223
208
224
- /* initialise the decoder */
225
- partial_frame_count = 0 ;
226
- last_rx_time = hrt_absolute_time ();
227
- sbus_frame_drops = 0 ;
228
-
229
209
ret = 0 ;
230
210
}
231
211
232
- return ret;
233
212
#endif
213
+ /* initialise the decoder */
214
+ partial_frame_count = 0 ;
215
+ last_rx_time = hrt_absolute_time ();
216
+ sbus_frame_drops = 0 ;
217
+
218
+ return ret;
234
219
}
235
220
236
221
void
0 commit comments