hp-3457a: Implement workaround for double-precision data

Certain output modules do not understand double-precision data.
Although we need double precision to represent the full resolution
of 7.5 digit readings, temporarily convert data to single precision
so that the output modules understand it. While the reasing might be
off by a few counts, we ensure the output modules do not display
completely bogus data.

For details, see bug #779.
This commit is contained in:
Alexandru Gagniuc 2016-03-29 19:21:55 -07:00 committed by Uwe Hermann
parent db23af7fc2
commit 625430bf88
1 changed files with 11 additions and 2 deletions

View File

@ -216,9 +216,17 @@ static int calculate_num_zero_digits(double measurement, double range)
return zero_digits; return zero_digits;
} }
/*
* Until the output modules understand double precision data, we need to send
* the measurement as floats instead of doubles, hence, the dance with
* measurement_workaround double to float conversion.
* See bug #779 for details.
* The workaround should be removed once the output modules are fixed.
*/
static void acq_send_measurement(struct sr_dev_inst *sdi) static void acq_send_measurement(struct sr_dev_inst *sdi)
{ {
double hires_measurement; double hires_measurement;
float measurement_workaround;
int zero_digits, num_digits; int zero_digits, num_digits;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog; struct sr_datafeed_analog analog;
@ -241,12 +249,13 @@ static void acq_send_measurement(struct sr_dev_inst *sdi)
packet.payload = &analog; packet.payload = &analog;
sr_analog_init(&analog, &encoding, &meaning, &spec, num_digits); sr_analog_init(&analog, &encoding, &meaning, &spec, num_digits);
encoding.unitsize = sizeof(double); encoding.unitsize = sizeof(float);
meaning.channels = sdi->channels; meaning.channels = sdi->channels;
measurement_workaround = hires_measurement;
analog.num_samples = 1; analog.num_samples = 1;
analog.data = &hires_measurement; analog.data = &measurement_workaround;
meaning.mq = devc->measurement_mq; meaning.mq = devc->measurement_mq;
meaning.unit = devc->measurement_unit; meaning.unit = devc->measurement_unit;