<div dir="ltr">Good morning, again,  ;-)<br><div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-02 18:29 GMT+02:00 Dirk Hohndel <span dir="ltr"><<a href="mailto:dirk@hohndel.org" target="_blank">dirk@hohndel.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
I think that we'll end up using something like this when doing the BT<br>
device communication in Subsurface. So this should be done in a generic<br>
way that allows us to take a buffer and hand it off to the correct parser.<br>
<br></blockquote><div> </div><div> <span lang="en"><span>It</span> <span>is, basically, </span> <span>what</span> <span>this function</span> <span>aims to do.</span></span><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     case DC_STATUS_CANCELLED:<br>
> +             return "Cancelled";<br>
> +     default:<br>
> +             return "Unknown error";<br>
> +     }<br>
> +}<br>
> +<br>
<br>
Yeah, this should be its own commit.<br>
<br>
</blockquote><div>No problem. It was a matter of an issue  with git commit and my own laziness.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
> + * Parse data buffers instead of dc devices downloaded data.<br>
> + * Intended to be used to parse profile data from binary files during import tasks.<br>
> + * Actually included Uwatec families because of smartrak import and H&W families<br>
> + * for future use in "OSTC TOOLS" .dive files import.<br>
> + * For others, simply include them in the switch  (check parameters).<br>
> + * Note that dc_descriptor_t in data  *must* have been filled using dc_descriptor_iterator()<br>
> + * calls.<br>
> + */<br></blockquote><div><br></div><div>Hmmm. Forgot to update this comments.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +dc_status_t libdc_buffer_parser(struct dive *dive, device_data_t *data, unsigned char *buffer, int size)<br>
> +{<br>
> +     dc_status_t rc;<br>
> +     dc_parser_t *parser = NULL;<br>
> +<br>
> +     switch (data->descriptor->type) {<br>
> +     case DC_FAMILY_UWATEC_ALADIN:<br>
> +     case DC_FAMILY_UWATEC_MEMOMOUSE:<br>
> +             rc = uwatec_memomouse_parser_create(&parser, data->context, 0, 0);<br>
> +             break;<br>
> +     case DC_FAMILY_UWATEC_SMART:<br>
> +     case DC_FAMILY_UWATEC_MERIDIAN:<br>
> +             rc = uwatec_smart_parser_create (&parser, data->context, data->descriptor->model, 0, 0);<br>
> +             break;<br>
> +     case DC_FAMILY_HW_OSTC:<br>
> +             rc = hw_ostc_parser_create (&parser, data->context, data->deviceid, 0);<br>
> +             break;<br>
> +     case DC_FAMILY_HW_FROG:<br>
> +     case DC_FAMILY_HW_OSTC3:<br>
> +             rc = hw_ostc_parser_create (&parser, data->context, data->deviceid, 1);<br>
> +             break;<br>
> +     }<br>
<span>> +     if  (rc != DC_STATUS_SUCCESS) {<br>
</span>> +             fprintf(stderr, "Error creating parser.\n");<br>
> +             dc_parser_destroy (parser);<br>
> +             return rc;<br>
> +     }<br>
> +     rc = dc_parser_set_data(parser, buffer, size);<br>
<span>> +     if (rc != DC_STATUS_SUCCESS) {<br>
</span>> +             fprintf(stderr, "Error registering the data.\n");<br>
> +             dc_parser_destroy (parser);<br>
> +             return rc;<br>
> +     }<br>
> +     // Do not parse Aladin/Memomouse headers as they are fakes<br>
> +     // Do not return on error, we can still parse the samples<br>
> +     if (data->descriptor->type != DC_FAMILY_UWATEC_ALADIN && data->descriptor->type != DC_FAMILY_UWATEC_MEMOMOUSE) {<br>
> +             rc = libdc_header_parser (parser, data, dive);<br>
<span>> +             if (rc != DC_STATUS_SUCCESS) {<br>
</span>> +                     fprintf(stderr, "Error parsing the dive header data. Dive # %d\n", dive->number);<br>
> +             }<br>
> +     }<br>
> +     rc = dc_parser_samples_foreach (parser, sample_cb, &dive->dc);<br>
<span>> +     if (rc != DC_STATUS_SUCCESS) {<br>
</span>> +             fprintf(stderr, "Error parsing the sample data. Dive # %d\nStatus = %s\n", dive->number, errmsg(rc));<br>
> +             dc_parser_destroy (parser);<br>
> +             return rc;<br>
> +     }<br>
> +     dc_parser_destroy(parser);<br>
> +     return(DC_STATUS_SUCCESS);<br>
> +}<br>
<br>
So the caller assembles a device_data_t buffer and then hands this to this<br>
function... but that functionality already exists inside libdivecomputer.<br></blockquote><div><br></div><div>Yes, a device_data_t structure and a buffer with the dive data, plus the dive structure to be filled.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I'm sure I'm missing something obvious, but why are we replicating this<br>
here? Is it because of the "fake headers" in the Aladin/Memomouse case?<br>
Why wouldn't you just call dc_parser_new() to get the correct parser?<br></blockquote><div><br></div><div>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). <br></div></div><br></div><div class="gmail_extra">Regards.<br><br></div><div class="gmail_extra">Salva.<br></div></div></div>