diff --git a/libraries/AP_HAL/utility/dsm.cpp b/libraries/AP_HAL/utility/dsm.cpp index 4ba811e20c..71c6d91035 100644 --- a/libraries/AP_HAL/utility/dsm.cpp +++ b/libraries/AP_HAL/utility/dsm.cpp @@ -38,8 +38,7 @@ #include #include - -#include +#include #include "dsm.h" @@ -47,7 +46,9 @@ #define DSM_FRAME_CHANNELS 7 /** 5000) { + printf("resync %u\n", dsm_partial_frame_count); + dsm_decode_state = DSM_DECODE_STATE_SYNC; + dsm_partial_frame_count = 0; + dsm_chan_count = 0; + dsm_frame[dsm_partial_frame_count++] = frame[d]; + } + + break; + + case DSM_DECODE_STATE_SYNC: { + dsm_frame[dsm_partial_frame_count++] = frame[d]; + + /* decode whatever we got and expect */ + if (dsm_partial_frame_count < DSM_FRAME_SIZE) { + break; + } + + /* + * Great, it looks like we might have a frame. Go ahead and + * decode it. + */ + decode_ret = dsm_decode(now, dsm_frame, values, &dsm_chan_count, max_channels); + +#if 1 + printf("%u %u: ", ((unsigned)(now/1000)) % 1000000, len); + for (uint8_t i=0; i +#include +#include +#include +#include +#include +#include +#include + +static uint64_t micros64(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return 1.0e6*((ts.tv_sec + (ts.tv_nsec*1.0e-9))); +} + +int main(int argc, const char *argv[]) +{ + int fd = open(argv[1], O_RDONLY); + if (fd == -1) { + perror(argv[1]); + exit(1); + } + + struct termios options; + + tcgetattr(fd, &options); + + cfsetispeed(&options, B115200); + cfsetospeed(&options, B115200); + + options.c_cflag &= ~(PARENB|CSTOPB|CSIZE); + options.c_cflag |= CS8; + + options.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG); + options.c_iflag &= ~(IXON|IXOFF|IXANY); + options.c_oflag &= ~OPOST; + + if (tcsetattr(fd, TCSANOW, &options) != 0) { + perror("tcsetattr"); + exit(1); + } + tcflush(fd, TCIOFLUSH); + + uint16_t values[18]; + memset(values, 0, sizeof(values)); + + while (true) { + uint8_t b[16]; + uint16_t num_values = 0; + fd_set fds; + struct timeval tv; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + + tv.tv_sec = 1; + tv.tv_usec = 0; + + // check if any bytes are available + if (select(fd+1, &fds, NULL, NULL, &tv) != 1) { + break; + } + + ssize_t nread; + if ((nread = read(fd, b, sizeof(b))) < 1) { + break; + } + + bool dsm_11_bit; + unsigned frame_drops; + + if (dsm_parse(micros64(), b, nread, values, &num_values, &dsm_11_bit, &frame_drops, 18)) { +#if 1 + printf("%u: ", num_values); + for (uint8_t i=0; i + +int main(int argc, const char *argv[]) +{ + uint8_t b[16]; + uint64_t t = 0; + + for (uint8_t i=1; i 255) { + printf("Bad hex value at %u : %s\n", (unsigned)i, argv[i]); + return 1; + } + b[i-1] = v; + } + uint16_t values[18]; + memset(values, 0, sizeof(values)); + + while (true) { + uint16_t num_values = 0; + bool dsm_11_bit; + unsigned frame_drops; + + t += 11000; + + if (dsm_parse(t, b, sizeof(b), values, &num_values, &dsm_11_bit, &frame_drops, 18)) { +#if 1 + printf("%u: ", num_values); + for (uint8_t i=0; i