OSTCTools import support

Salvador Cuñat salvador.cunat at gmail.com
Fri Apr 3 00:18:48 PDT 2015


Good morning, again,  ;-)

2015-04-02 18:29 GMT+02:00 Dirk Hohndel <dirk at hohndel.org>:

>
> I think that we'll end up using something like this when doing the BT
> device communication in Subsurface. So this should be done in a generic
> way that allows us to take a buffer and hand it off to the correct parser.
>
>
 It is, basically,  what this function aims to do.

> +     case DC_STATUS_CANCELLED:
> > +             return "Cancelled";
> > +     default:
> > +             return "Unknown error";
> > +     }
> > +}
> > +
>
> Yeah, this should be its own commit.
>
> No problem. It was a matter of an issue  with git commit and my own
laziness.


>
> > + * Parse data buffers instead of dc devices downloaded data.
> > + * Intended to be used to parse profile data from binary files during
> import tasks.
> > + * Actually included Uwatec families because of smartrak import and H&W
> families
> > + * for future use in "OSTC TOOLS" .dive files import.
> > + * For others, simply include them in the switch  (check parameters).
> > + * Note that dc_descriptor_t in data  *must* have been filled using
> dc_descriptor_iterator()
> > + * calls.
> > + */
>

Hmmm. Forgot to update this comments.


> > +dc_status_t libdc_buffer_parser(struct dive *dive, device_data_t *data,
> unsigned char *buffer, int size)
> > +{
> > +     dc_status_t rc;
> > +     dc_parser_t *parser = NULL;
> > +
> > +     switch (data->descriptor->type) {
> > +     case DC_FAMILY_UWATEC_ALADIN:
> > +     case DC_FAMILY_UWATEC_MEMOMOUSE:
> > +             rc = uwatec_memomouse_parser_create(&parser,
> data->context, 0, 0);
> > +             break;
> > +     case DC_FAMILY_UWATEC_SMART:
> > +     case DC_FAMILY_UWATEC_MERIDIAN:
> > +             rc = uwatec_smart_parser_create (&parser, data->context,
> data->descriptor->model, 0, 0);
> > +             break;
> > +     case DC_FAMILY_HW_OSTC:
> > +             rc = hw_ostc_parser_create (&parser, data->context,
> data->deviceid, 0);
> > +             break;
> > +     case DC_FAMILY_HW_FROG:
> > +     case DC_FAMILY_HW_OSTC3:
> > +             rc = hw_ostc_parser_create (&parser, data->context,
> data->deviceid, 1);
> > +             break;
> > +     }
> > +     if  (rc != DC_STATUS_SUCCESS) {
> > +             fprintf(stderr, "Error creating parser.\n");
> > +             dc_parser_destroy (parser);
> > +             return rc;
> > +     }
> > +     rc = dc_parser_set_data(parser, buffer, size);
> > +     if (rc != DC_STATUS_SUCCESS) {
> > +             fprintf(stderr, "Error registering the data.\n");
> > +             dc_parser_destroy (parser);
> > +             return rc;
> > +     }
> > +     // Do not parse Aladin/Memomouse headers as they are fakes
> > +     // Do not return on error, we can still parse the samples
> > +     if (data->descriptor->type != DC_FAMILY_UWATEC_ALADIN &&
> data->descriptor->type != DC_FAMILY_UWATEC_MEMOMOUSE) {
> > +             rc = libdc_header_parser (parser, data, dive);
> > +             if (rc != DC_STATUS_SUCCESS) {
> > +                     fprintf(stderr, "Error parsing the dive header
> data. Dive # %d\n", dive->number);
> > +             }
> > +     }
> > +     rc = dc_parser_samples_foreach (parser, sample_cb, &dive->dc);
> > +     if (rc != DC_STATUS_SUCCESS) {
> > +             fprintf(stderr, "Error parsing the sample data. Dive #
> %d\nStatus = %s\n", dive->number, errmsg(rc));
> > +             dc_parser_destroy (parser);
> > +             return rc;
> > +     }
> > +     dc_parser_destroy(parser);
> > +     return(DC_STATUS_SUCCESS);
> > +}
>
> So the caller assembles a device_data_t buffer and then hands this to this
> function... but that functionality already exists inside libdivecomputer.
>

Yes, a device_data_t structure and a buffer with the dive data, plus the
dive structure to be filled.


> I'm sure I'm missing something obvious, but why are we replicating this
> here? Is it because of the "fake headers" in the Aladin/Memomouse case?
> Why wouldn't you just call dc_parser_new() to get the correct parser?
>

Here I've followed the recommendation in libdivecomputer's web page.  BTW
dc_parser_new() needs a dc_device_t structure, which is set via
dc_device_open(), which should fail because we don't have a real device to
open  (if I have really undestood libdivecomputer, which I'm absolutely
unsure).

Regards.

Salva.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20150403/5a7d1b97/attachment-0001.html>


More information about the subsurface mailing list