aboutsummaryrefslogtreecommitdiff
path: root/unittests/st24_test.cpp
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-12-20 13:54:58 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-12-20 13:54:58 +0100
commit6e0cf5002914e9045082bdfe1d3acc484a37f7fb (patch)
treedceede05053ad0fb51e641e7e26509b4d1309dee /unittests/st24_test.cpp
parent19d5383c56b78132e63ea30ef1625b0aaa4a0dee (diff)
downloadpx4-firmware-6e0cf5002914e9045082bdfe1d3acc484a37f7fb.tar.gz
px4-firmware-6e0cf5002914e9045082bdfe1d3acc484a37f7fb.tar.bz2
px4-firmware-6e0cf5002914e9045082bdfe1d3acc484a37f7fb.zip
Move unittests into a more perceivable directory
Diffstat (limited to 'unittests/st24_test.cpp')
-rw-r--r--unittests/st24_test.cpp76
1 files changed, 76 insertions, 0 deletions
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 <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <systemlib/err.h>
+#include <drivers/drv_hrt.h>
+#include <rc/st24.h>
+#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<uint8_t>(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<int>(val), static_cast<int>(val));
+ }
+ }
+ }
+
+ if (ret == EOF) {
+ warnx("Test finished, reached end of file");
+
+ } else {
+ warnx("Test aborted, errno: %d", ret);
+ }
+
+}