On 2015-04-02 18:29, Dirk Hohndel wrote:
On Sun, Mar 29, 2015 at 08:46:29PM +0200, Salvador Cuñat wrote:
+
+/*
+ * 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.
+ */
+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.
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?

The dc_parser_new() function requires a valid device handle. In this offline parsing scenario, you don't have that. That's a shortcoming which is already on my todo list:

The dive callback of the dc_device_foreach() function will be changed to no longer return the binary data, but immediately return a parser object. The consequence is that you'll no longer need the dc_parser_new() function, except for the offline parsing scenario. For this purpose, it will be changed to take a device descriptor instead of a device handle. The raw data will also need to be passed directly to this new dc_parser_new, such that we can get rid of the silly dc_parser_set_data() function.

Jef
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to