示例#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
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
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
static const char *do_libdivecomputer_import(device_data_t *data)
{
	dc_status_t rc;
	const char *err;

	import_dive_number = 0;
	data->device = NULL;
	data->context = NULL;

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

	err = _("Unable to open %s %s (%s)");
	rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
	if (rc == DC_STATUS_SUCCESS) {
		err = do_device_import(data);
		dc_device_close(data->device);
	}
	dc_context_free(data->context);
	return err;
}
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;
}
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);
}
示例#9
0
int main(int argc, char ** argv)
{
	char*         cmd = NULL;
	dc_context_t* context = dc_context_new(receive_event, NULL, "CLI");
	int           stresstest_only = 0;

	dc_cmdline_skip_auth(context); /* disable the need to enter the command `auth <password>` for all mailboxes. */

	/* open database from the commandline (if omitted, it can be opened using the `open`-command) */
	if (argc == 2) {
		if (strcmp(argv[1], "--stress")==0) {
			stresstest_only = 1;
		}
		else if (!dc_open(context, argv[1], NULL)) {
			printf("ERROR: Cannot open %s.\n", argv[1]);
		}
	}
	else if (argc != 1) {
		printf("ERROR: Bad arguments\n");
	}

	s_do_log_info = 0;
	stress_functions(context);
	s_do_log_info = 1;


	if (stresstest_only) {
		return 0;
	}

	printf("Delta Chat Core is awaiting your commands.\n");

	/* wait for command */
	while (1)
	{
		/* read command */
		const char* cmdline = read_cmd();
		free(cmd);
		cmd = dc_strdup(cmdline);
		char* arg1 = strchr(cmd, ' ');
		if (arg1) { *arg1 = 0; arg1++; }

		if (strcmp(cmd, "connect")==0)
		{
			start_threads(context);
		}
		else if (strcmp(cmd, "disconnect")==0)
		{
			stop_threads(context);
		}
		else if (strcmp(cmd, "smtp-jobs")==0)
		{
			if (run_threads) {
				printf("smtp-jobs are already running in a thread.\n");
			}
			else {
				dc_perform_smtp_jobs(context);
			}
		}
		else if (strcmp(cmd, "imap-jobs")==0)
		{
			if (run_threads) {
				printf("imap-jobs are already running in a thread.\n");
			}
			else {
				dc_perform_imap_jobs(context);
			}
		}
		else if (strcmp(cmd, "configure")==0)
		{
			start_threads(context);
			dc_configure(context);
		}
		else if (strcmp(cmd, "oauth2")==0)
		{
			char* addr = dc_get_config(context, "addr");
			if (addr==NULL || addr[0]==0) {
				printf("oauth2: set addr first.\n");
			}
			else {
				char* oauth2_url = dc_get_oauth2_url(context, addr,
					"chat.delta:/com.b44t.messenger");
				if (oauth2_url==NULL) {
					printf("OAuth2 not available for %s.\n", addr);
				}
				else {
					printf("Open the following url, "
						"set mail_pw to the generated token "
						"and server_flags to 2:\n%s\n", oauth2_url);
				}
				free(oauth2_url);
			}
			free(addr);
		}
		else if (strcmp(cmd, "clear")==0)
		{
			printf("\n\n\n\n"); /* insert some blank lines to visualize the break in the buffer */
			printf("\e[1;1H\e[2J"); /* should work on ANSI terminals and on Windows 10. If not, well, then not. */
		}
		else if (strcmp(cmd, "getqr")==0 || strcmp(cmd, "getbadqr")==0)