diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2018-09-09 21:11:34 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-09 12:26:45 -0700 |
commit | aae2403ddd6dd8ff07c9acd1ef6639390fefb7d7 (patch) | |
tree | f9f949a9f77527a8bd37c210002444348e631a83 /core/parse-xml.c | |
parent | a93ecf3912bcd78930487b0e05f41ebd5c6e7ed4 (diff) | |
download | subsurface-aae2403ddd6dd8ff07c9acd1ef6639390fefb7d7.tar.gz |
DLF import: Record battery status
This will record the ending battery status to extra data. Would need
info from CCR divers whether this suffices or if we should record also
the starting volatage or even every single reading.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Diffstat (limited to 'core/parse-xml.c')
-rw-r--r-- | core/parse-xml.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c index 9cc5270e7..df05f5535 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1682,6 +1682,12 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl unsigned int time = 0; int i; char serial[6]; + struct { + uint16_t volt1; + uint8_t percent1; + uint16_t volt2; + uint8_t percent2; + } battery = {0, 0, 0, 0}; target_table = table; @@ -1980,8 +1986,12 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl /* measure record */ switch (ptr[2] >> 5) { case 1: - /* Measure Battery */ - //printf("B1: %dmV %d% B2: %dmV %d%\n", (ptr[5] << 8) + ptr[4], (ptr[7] << 8) + ptr[6], (ptr[9] << 8) + ptr[8], (ptr[11] << 8) + ptr[10]); + /* Measure Battery, recording the last reading only */ + battery.volt1 = (ptr[5] << 8) + ptr[4]; + battery.percent1 = ptr[6]; + battery.volt2 = (ptr[9] << 8) + ptr[8]; + battery.percent2 = ptr[10]; + break; case 3: /* Measure Oxygen */ //printf("o2 cells(0.01 mV): %d %d %d %d\n", (ptr[5] << 8) + ptr[4], (ptr[7] << 8) + ptr[6], (ptr[9] << 8) + ptr[8], (ptr[11] << 8) + ptr[10]); @@ -2004,6 +2014,27 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl break; } } + + /* Recording the ending battery status to extra data */ + if (battery.volt1) { + size_t size = snprintf(NULL, 0, "%dmV (%d%%)", battery.volt1, battery.percent1) + 1; + char *ptr = malloc(size); + + if (ptr) { + snprintf(ptr, size, "%dmV (%d%%)", battery.volt1, battery.percent1); + add_extra_data(cur_dc, "Battery 1", ptr); + free(ptr); + } + + size = snprintf(NULL, 0, "%dmV (%d%%)", battery.volt2, battery.percent2) + 1; + ptr = malloc(size); + if (ptr) { + snprintf(ptr, size, "%dmV (%d%%)", battery.volt2, battery.percent2); + add_extra_data(cur_dc, "Battery 2", ptr); + free(ptr); + } + } + divecomputer_end(); dive_end(); return 0; |