void print_devices() { fprintf(stderr, "Supported devices:\n\n"); dc_iterator_t *iterator = NULL; dc_descriptor_t *descriptor = NULL; dc_descriptor_iterator (&iterator); while (dc_iterator_next (iterator, &descriptor) == DC_STATUS_SUCCESS) { fprintf (stderr, " %s %s\n", dc_descriptor_get_vendor (descriptor), dc_descriptor_get_product (descriptor)); dc_descriptor_free (descriptor); } dc_iterator_free (iterator); exit(EXIT_FAILURE); }
void DownloadFromDCWidget::fill_computer_list() { dc_iterator_t *iterator = NULL; dc_descriptor_t *descriptor = NULL; struct mydescriptor *mydescriptor; QStringList computer; dc_descriptor_iterator(&iterator); while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) { const char *vendor = dc_descriptor_get_vendor(descriptor); const char *product = dc_descriptor_get_product(descriptor); if (!vendorList.contains(vendor)) vendorList.append(vendor); if (!productList[vendor].contains(product)) productList[vendor].push_back(product); descriptorLookup[QString(vendor) + QString(product)] = descriptor; } dc_iterator_free(iterator); Q_FOREACH (QString vendor, vendorList) qSort(productList[vendor]); /* and add the Uemis Zurich which we are handling internally THIS IS A HACK as we magically have a data structure here that happens to match a data structure that is internal to libdivecomputer; this WILL BREAK if libdivecomputer changes the dc_descriptor struct... eventually the UEMIS code needs to move into libdivecomputer, I guess */ mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor)); mydescriptor->vendor = "Uemis"; mydescriptor->product = "Zurich"; mydescriptor->type = DC_FAMILY_NULL; mydescriptor->model = 0; if (!vendorList.contains("Uemis")) vendorList.append("Uemis"); if (!productList["Uemis"].contains("Zurich")) productList["Uemis"].push_back("Zurich"); descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor; qSort(vendorList); }
static dc_status_t download (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, const char *cachedir, dc_buffer_t *fingerprint, dctool_output_t *output) { dc_status_t rc = DC_STATUS_SUCCESS; dc_device_t *device = NULL; dc_buffer_t *ofingerprint = NULL; // Open the device. message ("Opening the device (%s %s, %s).\n", dc_descriptor_get_vendor (descriptor), dc_descriptor_get_product (descriptor), devname ? devname : "null"); rc = dc_device_open (&device, context, descriptor, devname); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error opening the device."); goto cleanup; } // Initialize the event data. event_data_t eventdata = {0}; if (fingerprint) { eventdata.cachedir = NULL; } else { eventdata.cachedir = cachedir; } // Register the event handler. message ("Registering the event handler.\n"); int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR; rc = dc_device_set_events (device, events, event_cb, &eventdata); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error registering the event handler."); goto cleanup; } // Register the cancellation handler. message ("Registering the cancellation handler.\n"); rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error registering the cancellation handler."); goto cleanup; } // Register the fingerprint data. if (fingerprint) { message ("Registering the fingerprint data.\n"); rc = dc_device_set_fingerprint (device, dc_buffer_get_data (fingerprint), dc_buffer_get_size (fingerprint)); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error registering the fingerprint data."); goto cleanup; } } // Initialize the dive data. dive_data_t divedata = {0}; divedata.device = device; divedata.fingerprint = &ofingerprint; divedata.number = 0; divedata.output = output; // Download the dives. message ("Downloading the dives.\n"); rc = dc_device_foreach (device, dive_cb, &divedata); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error downloading the dives."); goto cleanup; } // Store the fingerprint data. if (cachedir && ofingerprint) { char filename[1024] = {0}; dc_family_t family = DC_FAMILY_NULL; // Generate the fingerprint filename. family = dc_device_get_type (device); snprintf (filename, sizeof (filename), "%s/%s-%08X.bin", cachedir, dctool_family_name (family), eventdata.devinfo.serial); // Write the fingerprint file. dctool_file_write (filename, ofingerprint); } cleanup: dc_buffer_free (ofingerprint); dc_device_close (device); return rc; }
void fill_computer_list() { dc_iterator_t *iterator = NULL; dc_descriptor_t *descriptor = NULL; unsigned int transportMask = get_supported_transports(NULL); fill_supported_mobile_list(); dc_descriptor_iterator(&iterator); while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) { // mask out the transports that aren't supported unsigned int transports = dc_descriptor_get_transports(descriptor) & transportMask; if (transports == 0) // none of the transports are available, skip continue; const char *vendor = dc_descriptor_get_vendor(descriptor); const char *product = dc_descriptor_get_product(descriptor); #if defined(Q_OS_ANDROID) if ((transports & ~(DC_TRANSPORT_SERIAL | DC_TRANSPORT_USB | DC_TRANSPORT_USBHID)) == 0) // if the only available transports are serial/USB, then check against // the ones that we explicitly support on Android if (!mobileProductList.contains(vendor) || !mobileProductList[vendor].contains(product)) continue; #endif if (!vendorList.contains(vendor)) vendorList.append(vendor); if (!productList[vendor].contains(product)) productList[vendor].append(product); descriptorLookup[QString(vendor) + QString(product)] = descriptor; } dc_iterator_free(iterator); Q_FOREACH (QString vendor, vendorList) qSort(productList[vendor]); #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) /* currently suppress the Uemis Zurich on Q_OS_ANDROID and Q_OS_IOS, * as it is no BT device */ /* and add the Uemis Zurich which we are handling internally THIS IS A HACK as we magically have a data structure here that happens to match a data structure that is internal to libdivecomputer; this WILL BREAK if libdivecomputer changes the dc_descriptor struct... eventually the UEMIS code needs to move into libdivecomputer, I guess */ struct mydescriptor *mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor)); mydescriptor->vendor = "Uemis"; mydescriptor->product = "Zurich"; mydescriptor->type = DC_FAMILY_NULL; mydescriptor->model = 0; mydescriptor->transports = DC_TRANSPORT_USBSTORAGE; if (!vendorList.contains("Uemis")) vendorList.append("Uemis"); if (!productList["Uemis"].contains("Zurich")) productList["Uemis"].push_back("Zurich"); descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor; #endif qSort(vendorList); }
static dc_status_t search(dc_descriptor_t **out, const char *name, dc_family_t backend, unsigned int model) { dc_status_t rc = DC_STATUS_SUCCESS; dc_iterator_t *iterator = NULL; rc = dc_descriptor_iterator(&iterator); if (rc != DC_STATUS_SUCCESS) { WARNING("Error creating the device descriptor iterator."); return rc; } dc_descriptor_t *descriptor = NULL, *current = NULL; while ((rc = dc_iterator_next(iterator, &descriptor)) == DC_STATUS_SUCCESS) { if (name) { const char *vendor = dc_descriptor_get_vendor(descriptor); const char *product = dc_descriptor_get_product(descriptor); size_t n = strlen(vendor); if (strncasecmp(name, vendor, n) == 0 && name[n] == ' ' && strcasecmp(name + n + 1, product) == 0) { current = descriptor; break; } else if (strcasecmp(name, product) == 0) { current = descriptor; break; } } else { if (backend == dc_descriptor_get_type(descriptor)) { if (model == dc_descriptor_get_model(descriptor)) { /* Exact match found. Return immediately */ dc_descriptor_free(current); current = descriptor; break; } else { /* Possible match found. Keep searching for an exact match. * If no exact match is found, return the first match found. */ if (current == NULL) { current = descriptor; descriptor = NULL; } } } } dc_descriptor_free(descriptor); } if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_DONE) { dc_descriptor_free(current); dc_iterator_free(iterator); WARNING("Error iterating the device descriptor."); return rc; } dc_iterator_free(iterator); *out = current; return DC_STATUS_SUCCESS; }
static dc_status_t dowork(dc_context_t *context, dc_descriptor_t *descriptor, program_options_t *options, dc_buffer_t *fingerprint) { dc_status_t rc = DC_STATUS_SUCCESS; /* initialize the device data */ device_data_t devdata = {{0}}; /* open the device */ message("Opening the device (%s, %s, %s.\n", dc_descriptor_get_vendor(descriptor), dc_descriptor_get_product(descriptor), options->devname ? options->devname : "null"); dc_device_t *device = NULL; rc = dc_device_open(&device, context, descriptor, options->devname); if (rc != DC_STATUS_SUCCESS) { WARNING("Error opening device."); return rc; } /* register the event handler */ message("Registering the event handler.\n"); int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK; rc = dc_device_set_events(device, events, event_cb, &devdata); if (rc != DC_STATUS_SUCCESS) { WARNING("Error registering the event handler."); dc_device_close(device); return rc; } /* register the cancellation handler */ message("Registering the cancellation handler.\n"); rc = dc_device_set_cancel(device, cancel_cb, NULL); if (rc != DC_STATUS_SUCCESS) { WARNING("Error registering the cancellation handler."); dc_device_close(device); return rc; } /* register the fingerprint data */ if (fingerprint) { message("Registering the fingerprint data.\n"); rc = dc_device_set_fingerprint(device, dc_buffer_get_data(fingerprint), dc_buffer_get_size(fingerprint)); if (rc != DC_STATUS_SUCCESS) { WARNING("Error registerting the fingerprint data"); dc_device_close(device); return rc; } } /* dump the memory if requested */ if (options->dumpMemory) { WARNING("Memory dump not enabled."); } /* dump the dives if requested */ if (options->dumpDives) { /* initialize the dive data */ dive_data_t divedata = {0}; dif_dive_collection_t *dc = dif_dive_collection_alloc(); divedata.device = device; divedata.fingerprint = NULL; divedata.number = 0; divedata.dc = dc; /* download the dives */ message("Downloading the dives.\n"); rc = dc_device_foreach(device, dive_cb, &divedata); if (rc != DC_STATUS_SUCCESS) { WARNING("Error downloading the dives."); dc_buffer_free(divedata.fingerprint); dc_device_close (device); return rc; } xml_options_t *xmlOptions = dif_xml_options_alloc(); xmlOptions->filename = options->xmlfile; xmlOptions->useInvalidElements = options->useInvalidElements; if (options->truncateDives) { divedata.dc = dif_alg_dc_truncate_dives(divedata.dc); } if (options->initialPressureFix) { divedata.dc = dif_alg_dc_initial_pressure_fix(divedata.dc); } dif_save_dive_collection_uddf_options(divedata.dc, xmlOptions); /* free the fingerprint buffer */ dc_buffer_free(divedata.fingerprint); dif_dive_collection_free(divedata.dc); dif_xml_options_free(xmlOptions); } /* close the device */ message("Closing the device.\n"); rc = dc_device_close(device); if (rc != DC_STATUS_SUCCESS) { WARNING("Error closing the device."); return rc; } return DC_STATUS_SUCCESS; }