コード例 #1
0
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
	dc_context_t *context = NULL;
	dc_device_t *device = NULL;

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

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

	dc_buffer_t *buffer = dc_buffer_new (0);

	message ("dc_device_dump\n");
	rc = dc_device_dump (device, buffer);
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Cannot read memory.");
		dc_buffer_free (buffer);
		dc_device_close (device);
		dc_context_free (context);
		return rc;
	}

	message ("Dumping data\n");
	FILE* fp = fopen (filename, "wb");
	if (fp != NULL) {
		fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
		fclose (fp);
	}

	dc_buffer_free (buffer);

	message ("dc_device_foreach\n");
	rc = dc_device_foreach (device, NULL, NULL);
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Cannot read dives.");
		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;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: dc2uddf.c プロジェクト: pridkett/dc2uddf
int dump_dives(program_options_t *options) {
    dc_family_t backend = DC_FAMILY_NULL;
    dc_loglevel_t loglevel = DC_LOGLEVEL_WARNING;
    const char *logfile = "output.log";
    const char *name = NULL;
    const char *fingerprint = NULL;
    unsigned int model = 0;

    if (options->backend != NULL) {
        backend = lookup_type(options->backend);
    }
    signal (SIGINT, sighandler);

    message_set_logfile(logfile);

    dc_context_t *context = NULL;

    /* create a new context */
    dc_status_t rc = dc_context_new(&context);
    if (rc != DC_STATUS_SUCCESS) {
        message_set_logfile(NULL);
        return EXIT_FAILURE;
    }

    dc_context_set_loglevel(context, loglevel);
    dc_context_set_logfunc(context, logfunc, NULL);

    dc_descriptor_t *descriptor = NULL;
    rc = search(&descriptor, name, backend, model);
    if (rc != DC_STATUS_SUCCESS) {
        message_set_logfile(NULL);
        return EXIT_FAILURE;
    }

    /* fail if no device descriptor found */
    if (descriptor == NULL) {
        WARNING("No matching device found");
        /* FIXME: bail out to usage information */
        message_set_logfile(NULL);
        return EXIT_FAILURE;
    }

    dc_buffer_t *fp = fpconvert(fingerprint);
    rc = dowork(context, descriptor, options, fp);
    dc_buffer_free(fp);
    /* FIXME: why aren't calls to errmsg working? */
    // message("Result: %s\n", errmsg(rc));

    dc_descriptor_free(descriptor);
    dc_context_free(context);

    message_set_logfile(NULL);

    return rc != DC_STATUS_SUCCESS ? EXIT_FAILURE : EXIT_SUCCESS;
}
コード例 #4
0
ファイル: libdc_driver.c プロジェクト: asymworks/benthos-dc
int libdc_driver_create(dev_handle_t * abstract)
{
	libdc_device_t * dev = (libdc_device_t *)(abstract);
	if (dev == NULL)
	{
		errno = EINVAL;
		return -1;
	}

	dc_context_t * ctx = NULL;
	dc_status_t rc = dc_context_new(& ctx);
	if (rc != DC_STATUS_SUCCESS)
	{
		errno = EINVAL;
		return -1;
	}

	libdc_device_t d = (libdc_device_t)malloc(sizeof(struct libdc_device_));
	if (d == NULL)
		return -1;

	d->modelid = 0;
	d->context = ctx;
	d->family = 0;
	d->model = 0;
	d->descriptor = NULL;
	d->device = NULL;
	d->devtime = 0;
	d->systime = 0;
	d->errcode = 0;
	d->errmsg = NULL;
	d->dcb = NULL;
	d->pcb = NULL;
	d->cb_data = NULL;
	d->cancel = 0;
	d->dives = NULL;

	dc_context_set_loglevel(d->context, DC_LOGLEVEL_NONE);
	dc_context_set_logfunc(d->context, NULL, 0);

	* dev = d;
	return 0;
}
コード例 #5
0
dc_status_t
test_dump_sdm (const char* name)
{
	dc_context_t *context = NULL;
	dc_device_t *device = NULL;

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

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

	message ("dc_device_foreach\n");
	rc = dc_device_foreach (device, NULL, NULL);
	if (rc != DC_STATUS_SUCCESS) {
		WARNING ("Cannot read dives.");
		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;
}
コード例 #6
0
QString ConfigureDiveComputer::dc_open(device_data_t *data)
{
	FILE *fp = NULL;
	dc_status_t rc;

	if (data->libdc_log)
		fp = subsurface_fopen(logfile_name, "w");

	data->libdc_logfile = fp;

	rc = dc_context_new(&data->context);
	if (rc != DC_STATUS_SUCCESS) {
		return tr("Unable to create libdivecomputer context");
	}

	if (fp) {
		dc_context_set_loglevel(data->context, DC_LOGLEVEL_ALL);
		dc_context_set_logfunc(data->context, logfunc, fp);
		fprintf(data->libdc_logfile, "Subsurface: v%s, ", subsurface_git_version());
		fprintf(data->libdc_logfile, "built with libdivecomputer v%s\n", dc_version(NULL));
	}

	rc = divecomputer_device_open(data);

	if (rc != DC_STATUS_SUCCESS) {
		report_error(errmsg(rc));
	} else {
		rc = dc_device_open(&data->device, data->context, data->descriptor, data->iostream);
	}

	if (rc != DC_STATUS_SUCCESS) {
		return tr("Could not a establish connection to the dive computer.");
	}

	setState(OPEN);

	return NULL;
}
コード例 #7
0
QString ConfigureDiveComputer::dc_open(device_data_t *data)
{
	FILE *fp = NULL;
	dc_status_t rc;

	if (data->libdc_log)
		fp = subsurface_fopen(logfile_name, "w");

	data->libdc_logfile = fp;

	rc = dc_context_new(&data->context);
	if (rc != DC_STATUS_SUCCESS) {
		return tr("Unable to create libdivecomputer context");
	}

	if (fp) {
		dc_context_set_loglevel(data->context, DC_LOGLEVEL_ALL);
		dc_context_set_logfunc(data->context, logfunc, fp);
	}

#if defined(SSRF_CUSTOM_SERIAL)
	if (data->bluetooth_mode) {
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
		rc = dc_context_set_custom_serial(data->context, get_qt_serial_ops());
#endif
#ifdef SERIAL_FTDI
	} else if (!strcmp(data->devname, "ftdi")) {
		rc = dc_context_set_custom_serial(data->context, &serial_ftdi_ops);
#endif
	}

	if (rc != DC_STATUS_SUCCESS) {
		report_error(errmsg(rc));
	} else {
#else
	{
#endif
		rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
	}

	if (rc != DC_STATUS_SUCCESS) {
		return tr("Could not a establish connection to the dive computer.");
	}

	setState(OPEN);

	return NULL;
}

void ConfigureDiveComputer::dc_close(device_data_t *data)
{
	if (data->device)
		dc_device_close(data->device);
	data->device = NULL;
	if (data->context)
		dc_context_free(data->context);
	data->context = NULL;

	if (data->libdc_logfile)
		fclose(data->libdc_logfile);

	setState(INITIAL);
}