summaryrefslogtreecommitdiffstats
path: root/core/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2018-09-12 06:41:15 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-12 05:31:29 -0700
commit3bd574ea89bc486b958232a9c7064f63d8686bf1 (patch)
treec46126af9d8f5bc4c8062a3f64e911c610b5bca6 /core/parse-xml.c
parent37e417c28a172b8c489feb789432aecdb42f2d56 (diff)
downloadsubsurface-3bd574ea89bc486b958232a9c7064f63d8686bf1.tar.gz
DLF import: record starting battery level
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Diffstat (limited to 'core/parse-xml.c')
-rw-r--r--core/parse-xml.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 227ce7f54..409619ab0 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1679,6 +1679,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
uint16_t volt2;
uint8_t percent2;
};
+ struct battery_status battery_start = {0, 0, 0, 0};
struct battery_status battery_end = {0, 0, 0, 0};
target_table = table;
@@ -1978,6 +1979,14 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
/* measure record */
switch (ptr[2] >> 5) {
case 1:
+ /* Record starting battery level */
+ if (!battery_start.volt1 && !battery_start.volt2) {
+ battery_start.volt1 = (ptr[5] << 8) + ptr[4];
+ battery_start.percent1 = ptr[6];
+ battery_start.volt2 = (ptr[9] << 8) + ptr[8];
+ battery_start.percent2 = ptr[10];
+ }
+
/* Measure Battery, recording the last reading only */
battery_end.volt1 = (ptr[5] << 8) + ptr[4];
battery_end.percent1 = ptr[6];
@@ -2014,6 +2023,26 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
}
}
+ /* Recording the starting battery status to extra data */
+ if (battery_start.volt1) {
+ size_t size = snprintf(NULL, 0, "%dmV (%d%%)", battery_start.volt1, battery_start.percent1) + 1;
+ char *ptr = malloc(size);
+
+ if (ptr) {
+ snprintf(ptr, size, "%dmV (%d%%)", battery_start.volt1, battery_start.percent1);
+ add_extra_data(cur_dc, "Battery 1 (start)", ptr);
+ free(ptr);
+ }
+
+ size = snprintf(NULL, 0, "%dmV (%d%%)", battery_start.volt2, battery_start.percent2) + 1;
+ ptr = malloc(size);
+ if (ptr) {
+ snprintf(ptr, size, "%dmV (%d%%)", battery_start.volt2, battery_start.percent2);
+ add_extra_data(cur_dc, "Battery 2 (start)", ptr);
+ free(ptr);
+ }
+ }
+
/* Recording the ending battery status to extra data */
if (battery_end.volt1) {
size_t size = snprintf(NULL, 0, "%dmV (%d%%)", battery_end.volt1, battery_end.percent1) + 1;