23 #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO || \ 24 CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_AERO || \ 25 CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OCPOC_ZYNQ || \ 26 CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ 33 #include <asm/termbits.h> 37 using namespace Linux;
39 #define SBUS_FRAME_SIZE 25 47 struct termios2 tio {};
49 if (ioctl(fd, TCGETS2, &tio) != 0) {
54 tio.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR
55 | IGNCR | ICRNL | IXON);
56 tio.c_iflag |= (INPCK | IGNPAR);
57 tio.c_oflag &= ~OPOST;
58 tio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
59 tio.c_cflag &= ~(CSIZE | CRTSCTS | PARODD | CBAUD);
61 tio.c_cflag |= (CS8 | CSTOPB | CLOCAL | PARENB | BOTHER | CREAD);
62 tio.c_ispeed = 100000;
63 tio.c_ospeed = 100000;
67 if (ioctl(fd, TCSETS2, &tio) != 0) {
78 printf(
"Set SBUS device path %s\n", path);
81 #define SBUS_DEBUG_LOG 0 82 #define SBUS_CAUSE_CORRUPTION 0 105 if (select(
fd+1, &fds,
nullptr,
nullptr, &tv) != 1) {
110 static int logfd = -1;
112 logfd =
open(
"sbus.log", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
116 #if SBUS_CAUSE_CORRUPTION 118 static unsigned corruption_counter;
119 if (corruption_counter++ % 1000 == 0) {
120 uint8_t nn = corruption_counter/1000;
122 dprintf(logfd,
"throw %u\n", (
unsigned)n2);
129 nread =
::read(
fd, bytes,
sizeof(bytes));
130 }
while (nread ==
sizeof(bytes));
151 int n2 =
::read(
fd, bytes+nread,
sizeof(bytes)-nread);
159 dprintf(logfd,
"discard %u\n", (
unsigned)nread);
168 dprintf(logfd,
"%06u %u: ", (
unsigned)
AP_HAL::millis(), (
unsigned)nread);
169 for (uint8_t i=0; i<nread; i++) {
170 dprintf(logfd,
"%02x ", (
unsigned)bytes[i]);
172 dprintf(logfd,
"\n");
179 #endif // CONFIG_HAL_BOARD_SUBTYPE
int printf(const char *fmt,...)
int open(const char *pathname, int flags)
POSIX Open a file with integer mode flags.
int close(int fileno)
POSIX Close a file with fileno handel.
virtual void delay_microseconds(uint16_t us)=0
AP_HAL::Scheduler * scheduler