Beispiel #1
0
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);
}
Beispiel #3
0
static dc_descriptor_t *ostc_get_data_descriptor(int data_model, dc_family_t data_fam)
{
	dc_descriptor_t *descriptor = NULL, *current = NULL;;
	dc_iterator_t *iterator = NULL;
	dc_status_t rc;

	rc = dc_descriptor_iterator(&iterator);
	if (rc != DC_STATUS_SUCCESS) {
		fprintf(stderr,"Error creating the device descriptor iterator.\n");
		return current;
	}
	while ((dc_iterator_next(iterator, &descriptor)) == DC_STATUS_SUCCESS) {
		int desc_model = dc_descriptor_get_model(descriptor);
		dc_family_t desc_fam = dc_descriptor_get_type(descriptor);
		if (data_model == desc_model && data_fam == desc_fam) {
			current = descriptor;
			break;
		}
		dc_descriptor_free(descriptor);
	}
	dc_iterator_free(iterator);
	return current;
}
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);
}
Beispiel #5
0
int libdc_driver_open(dev_handle_t abstract, const char * devpath, const char * args)
{
	libdc_device_t dev = (libdc_device_t)(abstract);
	if (dev == NULL)
	{
		errno = EINVAL;
		return -1;
	}

	// Parse the Argument List
	arglist_t arglist;
	int rc = arglist_parse(& arglist, args);
	if (rc != 0)
	{
		dev->errcode = DRIVER_ERR_INVALID;
		dev->errmsg = "Invalid Argument String";
		return -1;
	}

	// Load a Device Descriptor based on the Model argument
	rc = arglist_read_uint(arglist, "model", & dev->modelid);
	if (rc != 0)
	{
		dev->errcode = DRIVER_ERR_INVALID;
		dev->errmsg = "Missing 'model' Argument";
		return -1;
	}

	int i, found = 0;
	for (i = 0; g_libdc_plugin_devtable[i].id != -1; ++i)
	{
		if (g_libdc_plugin_devtable[i].id == dev->modelid)
		{
			found = 1;
			dev->family = g_libdc_plugin_devtable[i].family;
			dev->model = g_libdc_plugin_devtable[i].model;
		}
	}

	if (! found)
	{
		dev->errcode = DRIVER_ERR_UNSUPPORTED;
		dev->errmsg = "Unsupported 'model' Argument";
		return -1;
	}

	dc_iterator_t * iterator = NULL;
	dc_descriptor_t * descriptor = NULL;
	dc_descriptor_iterator(& iterator);

	while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS)
	{
		if ((dc_descriptor_get_type(descriptor) == dev->family) &&
			(dc_descriptor_get_model(descriptor) == dev->model))
		{
			dev->descriptor = descriptor;
		}
	}

	dc_iterator_free(iterator);

	if (dev->descriptor == NULL)
	{
		dev->errcode = DRIVER_ERR_UNSUPPORTED;
		dev->errmsg = "Could not load descriptor for model";
		return -1;
	}

	// Open the Device
	dc_status_t ret = dc_device_open(& dev->device, dev->context, dev->descriptor, devpath);
	if (ret != DC_STATUS_SUCCESS)
	{
		dev->errcode = DRIVER_ERR_NO_DEVICE;
		dev->errmsg = "Failed to connect to device";
		return -1;
	}

	// Register the Event and Cancel Handlers
	int events = DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK;

	dc_device_set_events (dev->device, events, libdc_event_cb, dev);
	dc_device_set_cancel (dev->device, libdc_cancel_cb, dev);

	return DRIVER_ERR_SUCCESS;
}
Beispiel #6
0
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;
}