From 6e0cf5002914e9045082bdfe1d3acc484a37f7fb Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 20 Dec 2014 13:54:58 +0100 Subject: Move unittests into a more perceivable directory --- unittests/st24_test.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 unittests/st24_test.cpp (limited to 'unittests/st24_test.cpp') diff --git a/unittests/st24_test.cpp b/unittests/st24_test.cpp new file mode 100644 index 000000000..25a9355e2 --- /dev/null +++ b/unittests/st24_test.cpp @@ -0,0 +1,76 @@ + +#include +#include +#include +#include +#include +#include +#include "../../src/systemcmds/tests/tests.h" + +int main(int argc, char *argv[]) +{ + warnx("ST24 test started"); + + if (argc < 2) { + errx(1, "Need a filename for the input file"); + } + + warnx("loading data from: %s", argv[1]); + + FILE *fp; + + fp = fopen(argv[1], "rt"); + + if (!fp) { + errx(1, "failed opening file"); + } + + float f; + unsigned x; + int ret; + + // Trash the first 20 lines + for (unsigned i = 0; i < 20; i++) { + char buf[200]; + (void)fgets(buf, sizeof(buf), fp); + } + + float last_time = 0; + + while (EOF != (ret = fscanf(fp, "%f,%x,,", &f, &x))) { + if (((f - last_time) * 1000 * 1000) > 3000) { + // warnx("FRAME RESET\n\n"); + } + + uint8_t b = static_cast(x); + + last_time = f; + + // Pipe the data into the parser + hrt_abstime now = hrt_absolute_time(); + + uint8_t rssi; + uint8_t rx_count; + uint16_t channel_count; + uint16_t channels[20]; + + + if (!st24_decode(b, &rssi, &rx_count, &channel_count, channels, sizeof(channels) / sizeof(channels[0]))) { + warnx("decoded: %u channels (converted to PPM range)", (unsigned)channel_count); + + for (unsigned i = 0; i < channel_count; i++) { + + int16_t val = channels[i]; + warnx("channel %u: %d 0x%03X", i, static_cast(val), static_cast(val)); + } + } + } + + if (ret == EOF) { + warnx("Test finished, reached end of file"); + + } else { + warnx("Test aborted, errno: %d", ret); + } + +} -- cgit v1.2.3