From a0d7b76dd040b28d3a455d491c904ef53b8368f9 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sat, 29 Dec 2018 21:31:12 +0200 Subject: Shearwater import: dive id might be large than int I encountered this while implementing Shearwater Cloud import, but it makes sense to increase the size for dive id for Shearwater Desktop as well. Signed-off-by: Miika Turkia --- core/import-shearwater.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/import-shearwater.c b/core/import-shearwater.c index 629f4721f..e887d0296 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -202,11 +202,11 @@ static int shearwater_dive(void *param, int columns, char **data, char **column) struct parser_state *state = (struct parser_state *)param; sqlite3 *handle = state->sql_handle; char *err = NULL; - char get_profile_template[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%d"; - char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %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.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %d"; - char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %d"; + char get_profile_template[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; + char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; + char get_cylinder_template[] = "select fractionO2,fractionHe from dive_log_records where diveLogId = %ld 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.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %ld"; + char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %ld"; char get_buffer[1024]; dive_start(state); @@ -214,7 +214,7 @@ static int shearwater_dive(void *param, int columns, char **data, char **column) state->cur_dive->when = (time_t)(atol(data[1])); - int dive_id = atoi(data[11]); + long int dive_id = atol(data[11]); if (data[2]) add_dive_site(data[2], state->cur_dive, state); -- cgit v1.2.3-70-g09d2 From 2bc7aa5fc72203b25eb77948da44cf7f7b65bc17 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sat, 29 Dec 2018 21:32:55 +0200 Subject: Initial support for Shearwater Cloud This works to some extent to part of a sample log I received. However, still quite a bit more work is needed. Signed-off-by: Miika Turkia --- core/dive.h | 1 + core/file.c | 9 +++ core/import-shearwater.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) (limited to 'core') diff --git a/core/dive.h b/core/dive.h index 6bc0f6fae..0f6d72a81 100644 --- a/core/dive.h +++ b/core/dive.h @@ -479,6 +479,7 @@ extern void set_filename(const char *filename); extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); +extern int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table); diff --git a/core/file.c b/core/file.c index 6f2edcf8d..fe2b0878b 100644 --- a/core/file.c +++ b/core/file.c @@ -132,6 +132,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'"; char dm5_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%SampleBlob%'"; char shearwater_test[] = "select count(*) from sqlite_master where type='table' and name='system' and sql like '%dbVersion%'"; + char shearwater_cloud_test[] = "select count(*) from sqlite_master where type='table' and name='SyncV3MetadataDiveLog' and sql like '%CreatedDevice%'"; char cobalt_test[] = "select count(*) from sqlite_master where type='table' and name='TrackPoints' and sql like '%DepthPressure%'"; char divinglog_test[] = "select count(*) from sqlite_master where type='table' and name='DBInfo' and sql like '%PrgName%'"; int retval; @@ -167,6 +168,14 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div return retval; } + /* Testing if DB schema resembles Shearwater cloud database format */ + retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL); + if (!retval) { + retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table); + sqlite3_close(handle); + return retval; + } + /* Testing if DB schema resembles Atomic Cobalt database format */ retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL); if (!retval) { diff --git a/core/import-shearwater.c b/core/import-shearwater.c index e887d0296..ada0bd6e4 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -313,6 +313,126 @@ static int shearwater_dive(void *param, int columns, char **data, char **column) return SQLITE_OK; } +static int shearwater_cloud_dive(void *param, int columns, char **data, char **column) +{ + UNUSED(columns); + UNUSED(column); + + int retval = 0; + struct parser_state *state = (struct parser_state *)param; + sqlite3 *handle = state->sql_handle; + char *err = NULL; + char get_profile_template[] = "select currentTime/1000,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; + char get_profile_template_ai[] = "select currentTime/1000,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; + char get_cylinder_template[] = "select fractionO2 / 100,fractionHe / 100 from dive_log_records where diveLogId = %ld group by fractionO2,fractionHe"; + char get_changes_template[] = "select a.currentTime/1000,a.fractionO2 / 100,a.fractionHe /100 from dive_log_records as a,dive_log_records as b where (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %ld"; + char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %ld"; + char get_buffer[1024]; + + dive_start(state); + state->cur_dive->number = atoi(data[0]); + + state->cur_dive->when = (time_t)(atol(data[1])); + + long int dive_id = atol(data[11]); + + if (data[2]) + add_dive_site(data[2], state->cur_dive, state); + if (data[3]) + utf8_string(data[3], &state->cur_dive->buddy); + if (data[4]) + utf8_string(data[4], &state->cur_dive->notes); + + state->metric = atoi(data[5]) == 1 ? 0 : 1; + + /* TODO: verify that metric calculation is correct */ + if (data[6]) + state->cur_dive->dc.maxdepth.mm = state->metric ? lrint(strtod_flags(data[6], NULL, 0) * 1000) : feet_to_mm(strtod_flags(data[6], NULL, 0)); + + if (data[7]) + state->cur_dive->dc.duration.seconds = atoi(data[7]) * 60; + + if (data[8]) + state->cur_dive->dc.surface_pressure.mbar = atoi(data[8]); + /* + * TODO: the deviceid hash should be calculated here. + */ + settings_start(state); + dc_settings_start(state); + if (data[9]) + utf8_string(data[9], &state->cur_settings.dc.serial_nr); + if (data[10]) { + switch (atoi(data[10])) { + case 2: + state->cur_settings.dc.model = strdup("Shearwater Petrel/Perdix"); + break; + case 4: + state->cur_settings.dc.model = strdup("Shearwater Predator"); + break; + default: + state->cur_settings.dc.model = strdup("Shearwater import"); + break; + } + } + + state->cur_settings.dc.deviceid = atoi(data[9]); + + dc_settings_end(state); + settings_end(state); + + if (data[10]) { + switch (atoi(data[10])) { + case 2: + state->cur_dive->dc.model = strdup("Shearwater Petrel/Perdix"); + break; + case 4: + state->cur_dive->dc.model = strdup("Shearwater Predator"); + break; + default: + state->cur_dive->dc.model = strdup("Shearwater import"); + break; + } + } + + if (data[11]) { + snprintf(get_buffer, sizeof(get_buffer) - 1, get_mode_template, dive_id); + retval = sqlite3_exec(handle, get_buffer, &shearwater_mode, state, &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, dive_id); + retval = sqlite3_exec(handle, get_buffer, &shearwater_cylinders, state, &err); + if (retval != SQLITE_OK) { + fprintf(stderr, "%s", "Database query shearwater_cylinders failed.\n"); + return 1; + } + + snprintf(get_buffer, sizeof(get_buffer) - 1, get_changes_template, dive_id); + retval = sqlite3_exec(handle, get_buffer, &shearwater_changes, state, &err); + if (retval != SQLITE_OK) { + fprintf(stderr, "%s", "Database query shearwater_changes failed.\n"); + return 1; + } + + snprintf(get_buffer, sizeof(get_buffer) - 1, get_profile_template_ai, dive_id); + retval = sqlite3_exec(handle, get_buffer, &shearwater_ai_profile_sample, state, &err); + if (retval != SQLITE_OK) { + snprintf(get_buffer, sizeof(get_buffer) - 1, get_profile_template, dive_id); + retval = sqlite3_exec(handle, get_buffer, &shearwater_profile_sample, state, &err); + if (retval != SQLITE_OK) { + fprintf(stderr, "%s", "Database query shearwater_profile_sample failed.\n"); + return 1; + } + } + + dive_end(state); + + return SQLITE_OK; +} + int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, struct dive_table *table) { @@ -340,3 +460,29 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer return 0; } +int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, + struct dive_table *table) +{ + UNUSED(buffer); + UNUSED(size); + + int retval; + char *err = NULL; + struct parser_state state; + + init_parser_state(&state); + state.target_table = table; + state.sql_handle = handle; + + char get_dives[] = "select l.number,startTimestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; + + retval = sqlite3_exec(handle, get_dives, &shearwater_cloud_dive, &state, &err); + free_parser_state(&state); + + if (retval != SQLITE_OK) { + fprintf(stderr, "Database query failed '%s'.\n", url); + return 1; + } + + return 0; +} -- cgit v1.2.3-70-g09d2 From 5e0f105114dc9181d597c6190a35f467304a241d Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sat, 29 Dec 2018 22:31:52 +0200 Subject: Sample rate varies between dives Seems that Shearwater cloud stores sample rate into the database and it is not constant within the log. Signed-off-by: Miika Turkia --- core/import-shearwater.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/import-shearwater.c b/core/import-shearwater.c index ada0bd6e4..d8308f20f 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -13,6 +13,8 @@ #include "membuffer.h" #include "gettext.h" +static int sample_rate = 0; + static int shearwater_cylinders(void *param, int columns, char **data, char **column) { UNUSED(columns); @@ -73,7 +75,7 @@ static int shearwater_changes(void *param, int columns, char **data, char **colu i = state->cur_cylinder_index; } - add_gas_switch_event(state->cur_dive, get_dc(state), atoi(data[0]), i); + add_gas_switch_event(state->cur_dive, get_dc(state), sample_rate ? atoi(data[0]) / sample_rate * 10 : atoi(data[0]), i); return 0; } @@ -86,7 +88,7 @@ static int shearwater_profile_sample(void *param, int columns, char **data, char sample_start(state); if (data[0]) - state->cur_sample->time.seconds = atoi(data[0]); + state->cur_sample->time.seconds = sample_rate ? atoi(data[0]) / sample_rate * 10 : atoi(data[0]); if (data[1]) state->cur_sample->depth.mm = state->metric ? lrint(strtod_flags(data[1], NULL, 0) * 1000) : feet_to_mm(strtod_flags(data[1], NULL, 0)); if (data[2]) @@ -137,7 +139,7 @@ static int shearwater_ai_profile_sample(void *param, int columns, char **data, c sample_start(state); if (data[0]) - state->cur_sample->time.seconds = atoi(data[0]); + state->cur_sample->time.seconds = sample_rate ? atoi(data[0]) / sample_rate * 10 : atoi(data[0]); if (data[1]) state->cur_sample->depth.mm = state->metric ? lrint(strtod_flags(data[1], NULL, 0) * 1000) : feet_to_mm(strtod_flags(data[1], NULL, 0)); if (data[2]) @@ -322,10 +324,10 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c struct parser_state *state = (struct parser_state *)param; sqlite3 *handle = state->sql_handle; char *err = NULL; - char get_profile_template[] = "select currentTime/1000,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; - char get_profile_template_ai[] = "select currentTime/1000,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; + char get_profile_template[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; + char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; char get_cylinder_template[] = "select fractionO2 / 100,fractionHe / 100 from dive_log_records where diveLogId = %ld group by fractionO2,fractionHe"; - char get_changes_template[] = "select a.currentTime/1000,a.fractionO2 / 100,a.fractionHe /100 from dive_log_records as a,dive_log_records as b where (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %ld"; + char get_changes_template[] = "select a.currentTime,a.fractionO2 / 100,a.fractionHe /100 from dive_log_records as a,dive_log_records as b where (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %ld"; char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %ld"; char get_buffer[1024]; @@ -335,6 +337,10 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c state->cur_dive->when = (time_t)(atol(data[1])); long int dive_id = atol(data[11]); + if (data[12]) + sample_rate = atoi(data[12]); + else + sample_rate = 0; if (data[2]) add_dive_site(data[2], state->cur_dive, state); @@ -447,6 +453,9 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer state.target_table = table; state.sql_handle = handle; + // So far have not seen any sample rate in Shearwater Desktop + sample_rate = 0; + 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, &state, &err); @@ -474,7 +483,7 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char * state.target_table = table; state.sql_handle = handle; - char get_dives[] = "select l.number,startTimestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; + char get_dives[] = "select l.number,startTimestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; retval = sqlite3_exec(handle, get_dives, &shearwater_cloud_dive, &state, &err); free_parser_state(&state); -- cgit v1.2.3-70-g09d2 From 01365b8c4b2cd73039f41f5d3f433c5d922fcf34 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sun, 30 Dec 2018 16:31:51 +0200 Subject: Use different time field as it seems to be more correct The starTimestamp is 4 hours apart on 2 different DCs within the sample log. DiveDate on the dive_logs table seems to be correct, but must be converted from human readable format. Signed-off-by: Miika Turkia --- core/import-shearwater.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/import-shearwater.c b/core/import-shearwater.c index d8308f20f..1a96c3e64 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -483,7 +483,7 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char * state.target_table = table; state.sql_handle = handle; - char get_dives[] = "select l.number,startTimestamp,location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; + char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,maxTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; retval = sqlite3_exec(handle, get_dives, &shearwater_cloud_dive, &state, &err); free_parser_state(&state); -- cgit v1.2.3-70-g09d2 From 5930cb52de2331523c05be26f50cf576be9b2335 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Mon, 31 Dec 2018 06:21:53 +0200 Subject: Grab correct setpoint on Shearwater cloud import Signed-off-by: Miika Turkia --- core/import-shearwater.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/import-shearwater.c b/core/import-shearwater.c index 1a96c3e64..67078e875 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -324,8 +324,8 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c struct parser_state *state = (struct parser_state *)param; sqlite3 *handle = state->sql_handle; char *err = NULL; - char get_profile_template[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; - char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; + char get_profile_template[] = "select currentTime,currentDepth,waterTemp,currentPPO2SetPoint,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; + char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,currentPPO2SetPoint,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; char get_cylinder_template[] = "select fractionO2 / 100,fractionHe / 100 from dive_log_records where diveLogId = %ld group by fractionO2,fractionHe"; char get_changes_template[] = "select a.currentTime,a.fractionO2 / 100,a.fractionHe /100 from dive_log_records as a,dive_log_records as b where (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %ld"; char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %ld"; -- cgit v1.2.3-70-g09d2 From 9c4234549408d58918d9718fd9ed06b966e25b2e Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Tue, 1 Jan 2019 15:32:27 +0200 Subject: Use correct value for PO2 averagePPO2 appears to be correct value instead of currentPPO2SetPoint. Signed-off-by: Miika Turkia --- core/import-shearwater.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/import-shearwater.c b/core/import-shearwater.c index 67078e875..1a96c3e64 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -324,8 +324,8 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c struct parser_state *state = (struct parser_state *)param; sqlite3 *handle = state->sql_handle; char *err = NULL; - char get_profile_template[] = "select currentTime,currentDepth,waterTemp,currentPPO2SetPoint,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; - char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,currentPPO2SetPoint,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; + char get_profile_template[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,firstStopDepth,firstStopTime from dive_log_records where diveLogId=%ld"; + char get_profile_template_ai[] = "select currentTime,currentDepth,waterTemp,averagePPO2,currentNdl,CNSPercent,decoCeiling,aiSensor0_PressurePSI,aiSensor1_PressurePSI,firstStopDepth,firstStopTime from dive_log_records where diveLogId = %ld"; char get_cylinder_template[] = "select fractionO2 / 100,fractionHe / 100 from dive_log_records where diveLogId = %ld group by fractionO2,fractionHe"; char get_changes_template[] = "select a.currentTime,a.fractionO2 / 100,a.fractionHe /100 from dive_log_records as a,dive_log_records as b where (a.id - 1) = b.id and (a.fractionO2 != b.fractionO2 or a.fractionHe != b.fractionHe) and a.diveLogId=b.divelogId and a.diveLogId = %ld"; char get_mode_template[] = "select distinct currentCircuitSetting from dive_log_records where diveLogId = %ld"; -- cgit v1.2.3-70-g09d2 From fd5aad719208f35252bacc9a7a46c829fc631923 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Thu, 3 Jan 2019 06:56:48 +0200 Subject: Use state structure for sample rate info Signed-off-by: Miika Turkia --- core/import-shearwater.c | 14 ++++++-------- core/parse.c | 1 + core/parse.h | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'core') diff --git a/core/import-shearwater.c b/core/import-shearwater.c index 1a96c3e64..451b04fe5 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -13,8 +13,6 @@ #include "membuffer.h" #include "gettext.h" -static int sample_rate = 0; - static int shearwater_cylinders(void *param, int columns, char **data, char **column) { UNUSED(columns); @@ -75,7 +73,7 @@ static int shearwater_changes(void *param, int columns, char **data, char **colu i = state->cur_cylinder_index; } - add_gas_switch_event(state->cur_dive, get_dc(state), sample_rate ? atoi(data[0]) / sample_rate * 10 : atoi(data[0]), i); + add_gas_switch_event(state->cur_dive, get_dc(state), state->sample_rate ? atoi(data[0]) / state->sample_rate * 10 : atoi(data[0]), i); return 0; } @@ -88,7 +86,7 @@ static int shearwater_profile_sample(void *param, int columns, char **data, char sample_start(state); if (data[0]) - state->cur_sample->time.seconds = sample_rate ? atoi(data[0]) / sample_rate * 10 : atoi(data[0]); + state->cur_sample->time.seconds = state->sample_rate ? atoi(data[0]) / state->sample_rate * 10 : atoi(data[0]); if (data[1]) state->cur_sample->depth.mm = state->metric ? lrint(strtod_flags(data[1], NULL, 0) * 1000) : feet_to_mm(strtod_flags(data[1], NULL, 0)); if (data[2]) @@ -139,7 +137,7 @@ static int shearwater_ai_profile_sample(void *param, int columns, char **data, c sample_start(state); if (data[0]) - state->cur_sample->time.seconds = sample_rate ? atoi(data[0]) / sample_rate * 10 : atoi(data[0]); + state->cur_sample->time.seconds = state->sample_rate ? atoi(data[0]) / state->sample_rate * 10 : atoi(data[0]); if (data[1]) state->cur_sample->depth.mm = state->metric ? lrint(strtod_flags(data[1], NULL, 0) * 1000) : feet_to_mm(strtod_flags(data[1], NULL, 0)); if (data[2]) @@ -338,9 +336,9 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c long int dive_id = atol(data[11]); if (data[12]) - sample_rate = atoi(data[12]); + state->sample_rate = atoi(data[12]); else - sample_rate = 0; + state->sample_rate = 0; if (data[2]) add_dive_site(data[2], state->cur_dive, state); @@ -454,7 +452,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer state.sql_handle = handle; // So far have not seen any sample rate in Shearwater Desktop - sample_rate = 0; + state.sample_rate = 0; 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"; diff --git a/core/parse.c b/core/parse.c index 8683daed4..2a408b57c 100644 --- a/core/parse.c +++ b/core/parse.c @@ -21,6 +21,7 @@ void init_parser_state(struct parser_state *state) memset(state, 0, sizeof(*state)); state->metric = true; state->cur_event.deleted = 1; + state->sample_rate = 0; } void free_parser_state(struct parser_state *state) diff --git a/core/parse.h b/core/parse.h index d56609e79..31f549e20 100644 --- a/core/parse.h +++ b/core/parse.h @@ -55,6 +55,7 @@ struct parser_state { int cur_cylinder_index, cur_ws_index; int lastcylinderindex, next_o2_sensor; int o2pressure_sensor; + int sample_rate; struct extra_data cur_extra_data; struct units xml_parsing_units; struct dive_table *target_table; /* non-owning */ -- cgit v1.2.3-70-g09d2