diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2017-09-13 18:54:41 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-09-13 14:04:31 -0700 |
commit | 5afa5ed9f15455c8cbf8806c228e119d41199e78 (patch) | |
tree | 8d9a59d5310a2ca52ffa29f851ba17af95c682a4 /core/parse-xml.c | |
parent | 19db825240bd249ce51d8081411e696f2b0cce55 (diff) | |
download | subsurface-5afa5ed9f15455c8cbf8806c228e119d41199e78.tar.gz |
Detect dive mode on Shearwater DB import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Diffstat (limited to 'core/parse-xml.c')
-rw-r--r-- | core/parse-xml.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c index b2a06bb21..eac0880a4 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -2799,6 +2799,18 @@ extern int shearwater_ai_profile_sample(void *handle, int columns, char **data, return 0; } +extern int shearwater_mode(void *handle, int columns, char **data, char **column) +{ + (void) handle; + (void) columns; + (void) column; + + if (data[0]) + cur_dive->dc.divemode = atoi(data[0]) == 0 ? CCR : OC; + + return 0; +} + extern int shearwater_dive(void *param, int columns, char **data, char **column) { (void) columns; @@ -2811,6 +2823,7 @@ extern int shearwater_dive(void *param, int columns, char **data, char **column) 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 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 join dive_logs as l on a.diveLogId=l.diveId,dive_log_records as b where l.number = %d and (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId"; + char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %d"; char get_buffer[1024]; dive_start(); @@ -2876,6 +2889,15 @@ extern int shearwater_dive(void *param, int columns, char **data, char **column) } } + if (data[11]) { + snprintf(get_buffer, sizeof(get_buffer) - 1, get_mode_template, atoi(data[11])); + retval = sqlite3_exec(handle, get_buffer, &shearwater_mode, 0, &err); + if (retval != SQLITE_OK) { + fprintf(stderr, "%s", "Database query shearwater_mode failed.\n"); + return 1; + } + } + snprintf(get_buffer, sizeof(get_buffer) - 1, get_cylinder_template, cur_dive->number); retval = sqlite3_exec(handle, get_buffer, &shearwater_cylinders, 0, &err); if (retval != SQLITE_OK) { @@ -3099,7 +3121,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer char *err = NULL; target_table = table; - char get_dives[] = "select l.number,timestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel FROM dive_info AS i JOIN dive_logs AS l ON i.diveId=l.diveId"; + char get_dives[] = "select l.number,timestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,i.diveId FROM dive_info AS i JOIN dive_logs AS l ON i.diveId=l.diveId"; retval = sqlite3_exec(handle, get_dives, &shearwater_dive, handle, &err); |