Handle int and float temperatures

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
This commit is contained in:
Miika Turkia 2018-04-07 07:46:37 +03:00 committed by Dirk Hohndel
parent e04dadc378
commit 6cfbe10bc3

View file

@ -364,6 +364,7 @@ extern int dm5_dive(void *param, int columns, char **data, char **column)
(void) columns; (void) columns;
(void) column; (void) column;
int i; int i;
int tempformat = 0;
int interval, retval = 0, block_size; int interval, retval = 0, block_size;
sqlite3 *handle = (sqlite3 *)param; sqlite3 *handle = (sqlite3 *)param;
unsigned const char *sampleBlob; unsigned const char *sampleBlob;
@ -451,6 +452,8 @@ extern int dm5_dive(void *param, int columns, char **data, char **column)
block_size = 23; block_size = 23;
break; break;
case 4: case 4:
// Temperature is stored in float
tempformat = 1;
block_size = 26; block_size = 26;
break; break;
default: default:
@ -461,18 +464,22 @@ extern int dm5_dive(void *param, int columns, char **data, char **column)
for (i = 0; interval && sampleBlob && i * interval < cur_dive->duration.seconds; i++) { for (i = 0; interval && sampleBlob && i * interval < cur_dive->duration.seconds; i++) {
float *depth = (float *)&sampleBlob[i * block_size + 3]; float *depth = (float *)&sampleBlob[i * block_size + 3];
int32_t temp = (sampleBlob[i * block_size + 10] << 8) + sampleBlob[i * block_size + 11];
int32_t pressure = (sampleBlob[i * block_size + 9] << 16) + (sampleBlob[i * block_size + 8] << 8) + sampleBlob[i * block_size + 7]; int32_t pressure = (sampleBlob[i * block_size + 9] << 16) + (sampleBlob[i * block_size + 8] << 8) + sampleBlob[i * block_size + 7];
sample_start(); sample_start();
cur_sample->time.seconds = i * interval; cur_sample->time.seconds = i * interval;
cur_sample->depth.mm = lrintf(depth[0] * 1000.0f); cur_sample->depth.mm = lrintf(depth[0] * 1000.0f);
if (tempformat == 1) {
float *temp = (float *)&(sampleBlob[i * block_size + 11]);
cur_sample->temperature.mkelvin = C_to_mkelvin(*temp);
} else {
cur_sample->temperature.mkelvin = C_to_mkelvin(sampleBlob[i * block_size + 11]);
}
/* /*
* Limit temperatures and cylinder pressures to somewhat * Limit cylinder pressures to somewhat sensible values
* sensible values
*/ */
if (temp >= -10 && temp < 50)
cur_sample->temperature.mkelvin = C_to_mkelvin(temp);
if (pressure >= 0 && pressure < 350000) if (pressure >= 0 && pressure < 350000)
cur_sample->pressure[0].mbar = pressure; cur_sample->pressure[0].mbar = pressure;
sample_end(); sample_end();