Exemplo n.º 1
0
static dc_status_t
fwupdate (const char *name, const char *hexfile, int ostc3)
{
	dc_context_t *context = NULL;
	dc_device_t *device = NULL;
	dc_status_t rc = DC_STATUS_SUCCESS;

	dc_context_new (&context);
	dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
	dc_context_set_logfunc (context, logfunc, NULL);

	if (ostc3) {
		message ("hw_ostc3_device_open\n");
		rc = hw_ostc3_device_open (&device, context, name);
	} else {
		message ("hw_ostc_device_open\n");
		rc = hw_ostc_device_open (&device, context, name);
	}
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Error opening serial port.");
		dc_context_free (context);
		return rc;
	}

	message ("dc_device_set_events.\n");
	rc = dc_device_set_events (device, DC_EVENT_PROGRESS, event_cb, NULL);
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Error registering the event handler.");
		dc_device_close (device);
		dc_context_free (context);
		return rc;
	}

	if (ostc3) {
		message ("hw_ostc3_device_fwupdate\n");
		rc = hw_ostc3_device_fwupdate (device, hexfile);
	} else {
		message ("hw_ostc_device_fwupdate\n");
		rc = hw_ostc_device_fwupdate (device, hexfile);
	}
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Error flashing firmware.");
		dc_device_close (device);
		dc_context_free (context);
		return rc;
	}

	message ("dc_device_close\n");
	rc = dc_device_close (device);
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Cannot close device.");
		dc_context_free (context);
		return rc;
	}

	dc_context_free (context);

	return DC_STATUS_SUCCESS;
}
Exemplo n.º 2
0
static const char *do_device_import(device_data_t *data)
{
	dc_status_t rc;
	dc_device_t *device = data->device;

	// Register the event handler.
	int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK;
	rc = dc_device_set_events(device, events, event_cb, data);
	if (rc != DC_STATUS_SUCCESS)
		return _("Error registering the event handler.");

	// Register the cancellation handler.
	rc = dc_device_set_cancel(device, cancel_cb, data);
	if (rc != DC_STATUS_SUCCESS)
		return _("Error registering the cancellation handler.");

	rc = import_device_data(device, data);
	if (rc != DC_STATUS_SUCCESS)
		return _("Dive data import error");

	/* All good */
	return NULL;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
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;
}