diff options
author | willem ferguson <willemferguson@zoology.up.ac.za> | 2014-11-22 15:13:13 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-24 12:14:03 -0800 |
commit | b493a9967e32b770d13c34e5c4dc2c7fc470d1b6 (patch) | |
tree | d598e2364a85bffba5391852082ff957165ac9c6 | |
parent | 42dbecae17c86c725d5fe657b4a6f0aed7a3a891 (diff) | |
download | subsurface-b493a9967e32b770d13c34e5c4dc2c7fc470d1b6.tar.gz |
CCR dive logs: git I/O
This patch privides for writing CCR dive log parameters to a git
repository and for reading the data back from a git repository.
This involves writing and reading the following members of the
structures of sample:
o2sensor[3]
o2cylinderpressure
and dc->no_o2sensors.
Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | load-git.c | 47 | ||||
-rw-r--r-- | save-git.c | 20 |
2 files changed, 55 insertions, 12 deletions
diff --git a/load-git.c b/load-git.c index 459d8d117..02fc98b68 100644 --- a/load-git.c +++ b/load-git.c @@ -141,6 +141,7 @@ static enum dive_comp_type get_dctype(const char *line) static int get_index(const char *line) { return atoi(line); } + static int get_hex(const char *line) { return strtoul(line, NULL, 16); } @@ -323,15 +324,15 @@ static int match_action(char *line, struct membuffer *str, void *data, char *p = line, c; unsigned low, high; - while ((c = *p) >= 'a' && c <= 'z') - p++; + while ((c = *p) >= 'a' && c <= 'z') // skip over 1st word + p++; // Extract the second word from the line: if (p == line) return -1; switch (c) { - case 0: + case 0: // if 2nd word is C-terminated break; - case ' ': - *p++ = 0; + case ' ': // =end of 2nd word? + *p++ = 0; // then C-terminate that word break; default: return -1; @@ -344,10 +345,10 @@ static int match_action(char *line, struct membuffer *str, void *data, unsigned mid = (low+high)/2; struct keyword_action *a = action + mid; int cmp = strcmp(line, a->keyword); - if (!cmp) { - a->fn(p, str, data); - return 0; - } + if (!cmp) { // attribute found: + a->fn(p, str, data); // Execute appropriate function, + return 0; // .. passing 2n word from above + } // (p) as a function argument. if (cmp < 0) high = mid; else @@ -395,6 +396,26 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va sample->setpoint.mbar = p.mbar; return; } + if (!strcmp(key, "sensor1")) { + pressure_t p = get_pressure(value); + sample->o2sensor[0].mbar = p.mbar; + return; + } + if (!strcmp(key, "sensor2")) { + pressure_t p = get_pressure(value); + sample->o2sensor[1].mbar = p.mbar; + return; + } + if (!strcmp(key, "sensor3")) { + pressure_t p = get_pressure(value); + sample->o2sensor[2].mbar = p.mbar; + return; + } + if (!strcmp(key, "o2pressure")) { + pressure_t p = get_pressure(value); + sample->o2cylinderpressure.mbar = p.mbar; + return; + } if (!strcmp(key, "heartbeat")) { sample->heartbeat = atoi(value); return; @@ -403,6 +424,7 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va sample->bearing.degrees = atoi(value); return; } + report_error("Unexpected sample key/value pair (%s/%s)", key, value); } @@ -517,6 +539,9 @@ static void parse_dc_meandepth(char *line, struct membuffer *str, void *_dc) static void parse_dc_model(char *line, struct membuffer *str, void *_dc) { struct divecomputer *dc = _dc; dc->model = get_utf8(str); } +static void parse_dc_numberofoxygensensors(char *line, struct membuffer *str, void *_dc) +{ struct divecomputer *dc = _dc; dc->no_o2sensors = get_index(line); } + static void parse_dc_surfacepressure(char *line, struct membuffer *str, void *_dc) { struct divecomputer *dc = _dc; dc->surface_pressure = get_pressure(line); } @@ -741,8 +766,8 @@ struct keyword_action dc_action[] = { #undef D #define D(x) { #x, parse_dc_ ## x } D(airtemp), D(date), D(dctype), D(deviceid), D(diveid), D(duration), - D(event), D(keyvalue), D(maxdepth), D(meandepth), D(model), D(salinity), - D(surfacepressure), D(surfacetime), D(time), D(watertemp), + D(event), D(keyvalue), D(maxdepth), D(meandepth), D(model), D(numberofoxygensensors), + D(salinity), D(surfacepressure), D(surfacetime), D(time), D(watertemp) }; /* Sample lines start with a space or a number */ diff --git a/save-git.c b/save-git.c index 8cde454f2..f9f5943b1 100644 --- a/save-git.c +++ b/save-git.c @@ -246,6 +246,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl put_milli(b, " ", sample->depth.mm, "m"); put_temperature(b, sample->temperature, " ", "°C"); put_pressure(b, sample->cylinderpressure, " ", "bar"); + put_pressure(b, sample->o2cylinderpressure," o2pressure=","bar"); /* * We only show sensor information for samples with pressure, and only if it @@ -284,6 +285,21 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl old->cns = sample->cns; } + if (sample->o2sensor[0].mbar != old->o2sensor[0].mbar) { + put_milli(b, " sensor1=", sample->o2sensor[0].mbar, "bar"); + old->o2sensor[0] = sample->o2sensor[0]; + } + + if ((sample->o2sensor[1].mbar) && (sample->o2sensor[1].mbar != old->o2sensor[1].mbar)) { + put_milli(b, " sensor2=", sample->o2sensor[1].mbar, "bar"); + old->o2sensor[1] = sample->o2sensor[1]; + } + + if ((sample->o2sensor[2].mbar) && (sample->o2sensor[2].mbar != old->o2sensor[2].mbar)) { + put_milli(b, " sensor3=", sample->o2sensor[2].mbar, "bar"); + old->o2sensor[2] = sample->o2sensor[2]; + } + if (sample->setpoint.mbar != old->setpoint.mbar) { put_milli(b, " po2=", sample->setpoint.mbar, "bar"); old->setpoint = sample->setpoint; @@ -339,8 +355,10 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, "duration ", "min\n"); - if (dc->dctype != OC) + if (dc->dctype != OC) { put_format(b, "dctype %s\n", dctype_text[dc->dctype]); + put_format(b, "numberofoxygensensors %d\n",dc->no_o2sensors); + } save_depths(b, dc); save_temperatures(b, dc); |