summaryrefslogtreecommitdiffstats
path: root/core/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Seppo Takalo <seppo.takalo@iki.fi>2017-09-13 17:46:21 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-09-13 07:57:45 -0700
commit83c9ad35a6c9266c17097d5e3f35837fc62833f6 (patch)
treeb5951fc7d2678d47693135ac40353170fc67fc72 /core/parse-xml.c
parent6509f2ed9f5fe59dc75b94c645fddeb3758f5242 (diff)
downloadsubsurface-83c9ad35a6c9266c17097d5e3f35837fc62833f6.tar.gz
Fix Shearwater cylinder detection logic
Fix the SQL query to find proper dive id instead of assuming log number to be the same as id. Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
Diffstat (limited to 'core/parse-xml.c')
-rw-r--r--core/parse-xml.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 50962aac2..3dd32c1c8 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -2653,11 +2653,17 @@ extern int shearwater_cylinders(void *handle, int columns, char **data, char **c
(void) columns;
(void) column;
+ int o2 = lrint(atof(data[0]) * 1000);
+ int he = lrint(atof(data[1]) * 1000);
+
+ /* Shearwater allows entering only 99%, not 100%
+ * so assume 99% to be pure oxygen */
+ if (o2 == 990 && he == 0)
+ o2 = 1000;
+
cylinder_start();
- if (data[0])
- cur_dive->cylinder[cur_cylinder_index].gasmix.o2.permille = lrint(atof(data[0]) * 1000);
- if (data[1])
- cur_dive->cylinder[cur_cylinder_index].gasmix.he.permille = lrint(atof(data[1]) * 1000);
+ cur_dive->cylinder[cur_cylinder_index].gasmix.o2.permille = o2;
+ cur_dive->cylinder[cur_cylinder_index].gasmix.he.permille = he;
cylinder_end();
return 0;
@@ -2781,8 +2787,8 @@ extern int shearwater_dive(void *param, int columns, char **data, char **column)
char *err = NULL;
char get_profile_template[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling from dive_log_records AS r join dive_logs as l on r.diveLogId=l.diveId where diveLogId = %d";
char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI from dive_log_records AS r join dive_logs as l on r.diveLogId=l.diveId where number = %d";
- char get_cylinder_template[] = "select fractionO2,fractionHe from dive_log_records where diveLogId = %d group by fractionO2,fractionHe";
- char get_changes_template[] = "select a.currentTime,a.fractionO2,a.fractionHe from dive_log_records as a,dive_log_records as b where a.diveLogId = %d and b.diveLogId = %d and (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) union select min(currentTime),fractionO2,fractionHe from dive_log_records";
+ char get_cylinder_template[] = "select fractionO2,fractionHe from dive_log_records as r join dive_logs as l on r.diveLogId=l.diveId where number = %d group by fractionO2,fractionHe";
+ char get_changes_template[] = "select a.currentTime,a.fractionO2,a.fractionHe from dive_log_records as a,dive_log_records as b where a.diveLogId = %d and b.diveLogId = %d and (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) union select min(currentTime),fractionO2,fractionHe from dive_log_records where diveLogId = %d";
char get_buffer[1024];
dive_start();
@@ -2855,7 +2861,7 @@ extern int shearwater_dive(void *param, int columns, char **data, char **column)
return 1;
}
- snprintf(get_buffer, sizeof(get_buffer) - 1, get_changes_template, cur_dive->number, cur_dive->number);
+ snprintf(get_buffer, sizeof(get_buffer) - 1, get_changes_template, cur_dive->number);
retval = sqlite3_exec(handle, get_buffer, &shearwater_changes, 0, &err);
if (retval != SQLITE_OK) {
fprintf(stderr, "%s", "Database query shearwater_changes failed.\n");