Merge pull request #2236 from TSC21/drivers_cleanup

drivers: added validity check
This commit is contained in:
Lorenz Meier
2015-06-26 07:39:09 +02:00
4 changed files with 18 additions and 4 deletions
+2
View File
@@ -329,6 +329,8 @@ test(const bool use_i2c, const int bus)
} }
warnx("periodic read %u", i); 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("measurement: %0.3f m", (double)report.current_distance);
warnx("time: %lld", report.timestamp); warnx("time: %lld", report.timestamp);
} }
+4
View File
@@ -832,6 +832,7 @@ test()
} }
warnx("single read"); warnx("single read");
warnx("measurement: %0.2f m", (double)report.current_distance);
warnx("time: %llu", report.timestamp); warnx("time: %llu", report.timestamp);
/* start the sensor polling at 2Hz */ /* start the sensor polling at 2Hz */
@@ -860,6 +861,9 @@ test()
} }
warnx("periodic read %u", i); 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); warnx("time: %llu", report.timestamp);
} }
+4 -2
View File
@@ -854,7 +854,7 @@ test()
} }
warnx("single read"); warnx("single read");
warnx("val: %0.2f m", (double)report.current_distance); warnx("measurement: %0.2f m", (double)report.current_distance);
warnx("time: %llu", report.timestamp); warnx("time: %llu", report.timestamp);
/* start the sensor polling at 2 Hz rate */ /* start the sensor polling at 2 Hz rate */
@@ -885,7 +885,9 @@ test()
} }
warnx("read #%u", i); warnx("read #%u", i);
warnx("val: %0.3f m", (double)report.current_distance); 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: %llu", report.timestamp); warnx("time: %llu", report.timestamp);
} }
+8 -2
View File
@@ -125,6 +125,7 @@ private:
work_s _work; work_s _work;
ringbuffer::RingBuffer *_reports; ringbuffer::RingBuffer *_reports;
bool _sensor_ok; bool _sensor_ok;
uint8_t _valid;
int _measure_ticks; int _measure_ticks;
bool _collect_phase; bool _collect_phase;
int _class_instance; int _class_instance;
@@ -211,7 +212,7 @@ static const uint8_t crc_table[] = {
0xfa, 0xfd, 0xf4, 0xf3 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 i;
uint16_t crc = 0x0; uint16_t crc = 0x0;
@@ -221,7 +222,7 @@ static const uint8_t crc_table[] = {
} }
return crc & 0xFF; return crc & 0xFF;
}*/ }
/* /*
* Driver 'main' command. * Driver 'main' command.
@@ -234,6 +235,7 @@ TRONE::TRONE(int bus, int address) :
_max_distance(TRONE_MAX_DISTANCE), _max_distance(TRONE_MAX_DISTANCE),
_reports(nullptr), _reports(nullptr),
_sensor_ok(false), _sensor_ok(false),
_valid(0),
_measure_ticks(0), _measure_ticks(0),
_collect_phase(false), _collect_phase(false),
_class_instance(-1), _class_instance(-1),
@@ -592,6 +594,10 @@ TRONE::collect()
/* TODO: set proper ID */ /* TODO: set proper ID */
report.id = 0; 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 */ /* publish it, if we are the primary */
if (_distance_sensor_topic != nullptr) { if (_distance_sensor_topic != nullptr) {
orb_publish(ORB_ID(distance_sensor), _distance_sensor_topic, &report); orb_publish(ORB_ID(distance_sensor), _distance_sensor_topic, &report);