From 0d0c654b278a2cc05ce33bcd0373698f0828834c Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 9 Jan 2011 21:33:29 +0100 Subject: [PATCH] Use the new field api in the example application. --- examples/universal.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/examples/universal.c b/examples/universal.c index 9f32c36..cb70fc2 100644 --- a/examples/universal.c +++ b/examples/universal.c @@ -372,6 +372,62 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second); + // Parse the divetime. + message ("Parsing the divetime.\n"); + unsigned int divetime = 0; + rc = parser_get_field (parser, FIELD_TYPE_DIVETIME, 0, &divetime); + if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) { + WARNING ("Error parsing the divetime."); + parser_destroy (parser); + return rc; + } + + fprintf (fp, "%02u:%02u\n", + divetime / 60, divetime % 60); + + // Parse the maxdepth. + message ("Parsing the maxdepth.\n"); + double maxdepth = 0.0; + rc = parser_get_field (parser, FIELD_TYPE_MAXDEPTH, 0, &maxdepth); + if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) { + WARNING ("Error parsing the maxdepth."); + parser_destroy (parser); + return rc; + } + + fprintf (fp, "%.2f\n", + maxdepth); + + // Parse the gas mixes. + message ("Parsing the gas mixes.\n"); + unsigned int ngases = 0; + rc = parser_get_field (parser, FIELD_TYPE_GASMIX_COUNT, 0, &ngases); + if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) { + WARNING ("Error parsing the gas mix count."); + parser_destroy (parser); + return rc; + } + + for (unsigned int i = 0; i < ngases; ++i) { + gasmix_t gasmix = {0}; + rc = parser_get_field (parser, FIELD_TYPE_GASMIX, i, &gasmix); + if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) { + WARNING ("Error parsing the gas mix."); + parser_destroy (parser); + return rc; + } + + fprintf (fp, + "\n" + " %.1f\n" + " %.1f\n" + " %.1f\n" + "\n", + gasmix.helium * 100.0, + gasmix.oxygen * 100.0, + gasmix.nitrogen * 100.0); + } + // Initialize the sample data. sample_data_t sampledata = {0}; sampledata.nsamples = 0;