From 79e084a154c3b4d945fb00d85fc2307667f9ae2f Mon Sep 17 00:00:00 2001 From: TSC21 Date: Tue, 26 May 2015 18:05:26 +0100 Subject: [PATCH] drivers: added validity check --- src/drivers/ll40ls/ll40ls.cpp | 2 ++ src/drivers/mb12xx/mb12xx.cpp | 4 ++++ src/drivers/trone/trone.cpp | 10 ++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/drivers/ll40ls/ll40ls.cpp b/src/drivers/ll40ls/ll40ls.cpp index 8984220625..d806638788 100644 --- a/src/drivers/ll40ls/ll40ls.cpp +++ b/src/drivers/ll40ls/ll40ls.cpp @@ -295,6 +295,8 @@ test(const bool use_i2c, const int bus) } warnx("periodic read %u", i); + warnx("valid %u", (float)report.current_distance > report.min_distance + && (float)report.current_distance < report.max_distance ? 1 : 0); warnx("measurement: %0.3f m", (double)report.current_distance); warnx("time: %lld", report.timestamp); } diff --git a/src/drivers/mb12xx/mb12xx.cpp b/src/drivers/mb12xx/mb12xx.cpp index afeb8e5545..ec07399f54 100644 --- a/src/drivers/mb12xx/mb12xx.cpp +++ b/src/drivers/mb12xx/mb12xx.cpp @@ -832,6 +832,7 @@ test() } warnx("single read"); + warnx("measurement: %0.2f m", (double)report.current_distance); warnx("time: %llu", report.timestamp); /* start the sensor polling at 2Hz */ @@ -860,6 +861,9 @@ test() } warnx("periodic read %u", i); + warnx("valid %u", (float)report.current_distance > report.min_distance + && (float)report.current_distance < report.max_distance ? 1 : 0); + warnx("measurement: %0.3f", (double)report.current_distance); warnx("time: %llu", report.timestamp); } diff --git a/src/drivers/trone/trone.cpp b/src/drivers/trone/trone.cpp index 23e52547a1..6150cc90e2 100644 --- a/src/drivers/trone/trone.cpp +++ b/src/drivers/trone/trone.cpp @@ -125,6 +125,7 @@ private: work_s _work; ringbuffer::RingBuffer *_reports; bool _sensor_ok; + uint8_t _valid; int _measure_ticks; bool _collect_phase; int _class_instance; @@ -211,7 +212,7 @@ static const uint8_t crc_table[] = { 0xfa, 0xfd, 0xf4, 0xf3 }; -/* static uint8_t crc8(uint8_t *p, uint8_t len) { + static uint8_t crc8(uint8_t *p, uint8_t len) { uint16_t i; uint16_t crc = 0x0; @@ -221,7 +222,7 @@ static const uint8_t crc_table[] = { } return crc & 0xFF; -}*/ +} /* * Driver 'main' command. @@ -234,6 +235,7 @@ TRONE::TRONE(int bus, int address) : _max_distance(TRONE_MAX_DISTANCE), _reports(nullptr), _sensor_ok(false), + _valid(0), _measure_ticks(0), _collect_phase(false), _class_instance(-1), @@ -586,6 +588,10 @@ TRONE::collect() /* TODO: set proper ID */ report.id = 0; + // This validation check can be used later + _valid = crc8(val, 2) == val[2] && (float)report.current_distance > report.min_distance + && (float)report.current_distance < report.max_distance ? 1 : 0; + /* publish it, if we are the primary */ if (_distance_sensor_topic >= 0) { orb_publish(ORB_ID(distance_sensor), _distance_sensor_topic, &report);