summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-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;