Files
bizhang_-obav/Tools/tests-host/st24_test.cpp

77 lines
1.5 KiB
C++
Raw Normal View History

2014-10-06 07:53:18 +02:00
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <systemlib/err.h>
#include <drivers/drv_hrt.h>
2014-10-06 19:20:17 +02:00
#include <rc/st24.h>
2014-10-06 07:53:18 +02:00
#include "../../src/systemcmds/tests/tests.h"
2014-10-07 09:54:20 +02:00
int main(int argc, char *argv[])
{
2014-10-06 07:53:18 +02:00
warnx("ST24 test started");
2014-10-07 09:54:20 +02:00
if (argc < 2) {
2014-10-06 07:53:18 +02:00
errx(1, "Need a filename for the input file");
2014-10-07 09:54:20 +02:00
}
2014-10-06 07:53:18 +02:00
warnx("loading data from: %s", argv[1]);
FILE *fp;
2014-10-07 09:54:20 +02:00
fp = fopen(argv[1], "rt");
if (!fp) {
2014-10-06 07:53:18 +02:00
errx(1, "failed opening file");
2014-10-07 09:54:20 +02:00
}
2014-10-06 07:53:18 +02:00
float f;
unsigned x;
int ret;
// Trash the first 20 lines
for (unsigned i = 0; i < 20; i++) {
2014-10-06 19:20:17 +02:00
char buf[200];
(void)fgets(buf, sizeof(buf), fp);
2014-10-06 07:53:18 +02:00
}
float last_time = 0;
while (EOF != (ret = fscanf(fp, "%f,%x,,", &f, &x))) {
if (((f - last_time) * 1000 * 1000) > 3000) {
2014-10-07 09:54:20 +02:00
// warnx("FRAME RESET\n\n");
2014-10-06 07:53:18 +02:00
}
2014-10-06 19:20:17 +02:00
uint8_t b = static_cast<uint8_t>(x);
2014-10-06 07:53:18 +02:00
last_time = f;
// Pipe the data into the parser
hrt_abstime now = hrt_absolute_time();
2014-10-06 19:20:17 +02:00
uint8_t rssi;
uint8_t rx_count;
uint16_t channel_count;
2014-10-07 09:54:20 +02:00
uint16_t channels[20];
2014-10-06 19:20:17 +02:00
2014-10-07 09:54:20 +02:00
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);
2014-10-06 19:20:17 +02:00
for (unsigned i = 0; i < channel_count; i++) {
2014-10-07 07:14:28 +02:00
int16_t val = channels[i];
2014-10-07 09:54:20 +02:00
warnx("channel %u: %d 0x%03X", i, static_cast<int>(val), static_cast<int>(val));
2014-10-06 19:20:17 +02:00
}
}
2014-10-06 07:53:18 +02:00
}
if (ret == EOF) {
warnx("Test finished, reached end of file");
2014-10-07 09:54:20 +02:00
2014-10-06 07:53:18 +02:00
} else {
warnx("Test aborted, errno: %d", ret);
}
}