device_status_t
test_dump_memory_dives (const char* name, const char* filename)
{
	device_t *device = NULL;

	message ("reefnet_sensusultra_device_open\n");
	device_status_t rc = reefnet_sensusultra_device_open (&device, name);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Error opening serial port.");
		return rc;
	}

	time_t now = time (NULL);
	char datetime[21] = {0};
	strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now));
	message ("time=%lu (%s)\n", (unsigned long)now, datetime);

	message ("device_foreach\n");
	rc = device_foreach (device, NULL, NULL);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Cannot read dives.");
		device_close (device);
		return rc;
	}

	message ("device_close\n");
	rc = device_close (device);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Cannot close device.");
		return rc;
	}

	return DEVICE_STATUS_SUCCESS;
}
device_status_t
test_dump_memory_data (const char* name, const char* filename)
{
	device_t *device = NULL;

	message ("reefnet_sensusultra_device_open\n");
	device_status_t rc = reefnet_sensusultra_device_open (&device, name);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Error opening serial port.");
		return rc;
	}

	time_t now = time (NULL);
	char datetime[21] = {0};
	strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now));
	message ("time=%lu (%s)\n", (unsigned long)now, datetime);

	dc_buffer_t *buffer = dc_buffer_new (0);

	message ("device_dump\n");
	rc = device_dump (device, buffer);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Cannot read memory.");
		dc_buffer_free (buffer);
		device_close (device);
		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 ("device_close\n");
	rc = device_close (device);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Cannot close device.");
		return rc;
	}

	return DEVICE_STATUS_SUCCESS;
}
device_status_t
test_dump_memory_user (const char* name, const char* filename)
{
	device_t *device = NULL;
	unsigned char data[REEFNET_SENSUSULTRA_MEMORY_USER_SIZE] = {0};

	message ("reefnet_sensusultra_device_open\n");
	device_status_t rc = reefnet_sensusultra_device_open (&device, name);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Error opening serial port.");
		return rc;
	}

	time_t now = time (NULL);
	char datetime[21] = {0};
	strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now));
	message ("time=%lu (%s)\n", (unsigned long)now, datetime);

	message ("reefnet_sensusultra_device_read_user\n");
	rc = reefnet_sensusultra_device_read_user (device, data, sizeof (data));
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Cannot read memory.");
		device_close (device);
		return rc;
	}

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

	message ("device_close\n");
	rc = device_close (device);
	if (rc != DEVICE_STATUS_SUCCESS) {
		WARNING ("Cannot close device.");
		return rc;
	}

	return DEVICE_STATUS_SUCCESS;
}
Exemplo n.º 4
0
static device_status_t device_open(const char *devname,
	device_type_t type,
	device_t **device)
{
	switch (type) {
	case DEVICE_TYPE_SUUNTO_SOLUTION:
		return suunto_solution_device_open(device, devname);

	case DEVICE_TYPE_SUUNTO_EON:
		return suunto_eon_device_open(device, devname);

	case DEVICE_TYPE_SUUNTO_VYPER:
		return suunto_vyper_device_open(device, devname);

	case DEVICE_TYPE_SUUNTO_VYPER2:
		return suunto_vyper2_device_open(device, devname);

	case DEVICE_TYPE_SUUNTO_D9:
		return suunto_d9_device_open(device, devname);

	case DEVICE_TYPE_UWATEC_ALADIN:
		return uwatec_aladin_device_open(device, devname);

	case DEVICE_TYPE_UWATEC_MEMOMOUSE:
		return uwatec_memomouse_device_open(device, devname);

	case DEVICE_TYPE_UWATEC_SMART:
		return uwatec_smart_device_open(device);

	case DEVICE_TYPE_REEFNET_SENSUS:
		return reefnet_sensus_device_open(device, devname);

	case DEVICE_TYPE_REEFNET_SENSUSPRO:
		return reefnet_sensuspro_device_open(device, devname);

	case DEVICE_TYPE_REEFNET_SENSUSULTRA:
		return reefnet_sensusultra_device_open(device, devname);

	case DEVICE_TYPE_OCEANIC_VTPRO:
		return oceanic_vtpro_device_open(device, devname);

	case DEVICE_TYPE_OCEANIC_VEO250:
		return oceanic_veo250_device_open(device, devname);

	case DEVICE_TYPE_OCEANIC_ATOM2:
		return oceanic_atom2_device_open(device, devname);

	case DEVICE_TYPE_MARES_NEMO:
		return mares_nemo_device_open(device, devname);

	case DEVICE_TYPE_MARES_PUCK:
		return mares_puck_device_open(device, devname);

	case DEVICE_TYPE_MARES_ICONHD:
		return mares_iconhd_device_open(device, devname);

	case DEVICE_TYPE_HW_OSTC:
		return hw_ostc_device_open(device, devname);

	case DEVICE_TYPE_CRESSI_EDY:
		return cressi_edy_device_open(device, devname);

	case DEVICE_TYPE_ZEAGLE_N2ITION3:
		return zeagle_n2ition3_device_open(device, devname);

	case DEVICE_TYPE_ATOMICS_COBALT:
		return atomics_cobalt_device_open(device);

	default:
		return DEVICE_STATUS_ERROR;
	}
}
Exemplo n.º 5
0
dc_status_t
dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *name)
{
	dc_status_t rc = DC_STATUS_SUCCESS;
	dc_device_t *device = NULL;

	if (out == NULL || descriptor == NULL)
		return DC_STATUS_INVALIDARGS;

	switch (dc_descriptor_get_type (descriptor)) {
	case DC_FAMILY_SUUNTO_SOLUTION:
		rc = suunto_solution_device_open (&device, context, name);
		break;
	case DC_FAMILY_SUUNTO_EON:
		rc = suunto_eon_device_open (&device, context, name);
		break;
	case DC_FAMILY_SUUNTO_VYPER:
		rc = suunto_vyper_device_open (&device, context, name);
		break;
	case DC_FAMILY_SUUNTO_VYPER2:
		rc = suunto_vyper2_device_open (&device, context, name);
		break;
	case DC_FAMILY_SUUNTO_D9:
		rc = suunto_d9_device_open (&device, context, name, dc_descriptor_get_model (descriptor));
		break;
	case DC_FAMILY_UWATEC_ALADIN:
		rc = uwatec_aladin_device_open (&device, context, name);
		break;
	case DC_FAMILY_UWATEC_MEMOMOUSE:
		rc = uwatec_memomouse_device_open (&device, context, name);
		break;
	case DC_FAMILY_UWATEC_SMART:
		rc = uwatec_smart_device_open (&device, context);
		break;
	case DC_FAMILY_REEFNET_SENSUS:
		rc = reefnet_sensus_device_open (&device, context, name);
		break;
	case DC_FAMILY_REEFNET_SENSUSPRO:
		rc = reefnet_sensuspro_device_open (&device, context, name);
		break;
	case DC_FAMILY_REEFNET_SENSUSULTRA:
		rc = reefnet_sensusultra_device_open (&device, context, name);
		break;
	case DC_FAMILY_OCEANIC_VTPRO:
		rc = oceanic_vtpro_device_open (&device, context, name);
		break;
	case DC_FAMILY_OCEANIC_VEO250:
		rc = oceanic_veo250_device_open (&device, context, name);
		break;
	case DC_FAMILY_OCEANIC_ATOM2:
		rc = oceanic_atom2_device_open (&device, context, name);
		break;
	case DC_FAMILY_MARES_NEMO:
		rc = mares_nemo_device_open (&device, context, name);
		break;
	case DC_FAMILY_MARES_PUCK:
		rc = mares_puck_device_open (&device, context, name);
		break;
	case DC_FAMILY_MARES_DARWIN:
		rc = mares_darwin_device_open (&device, context, name, dc_descriptor_get_model (descriptor));
		break;
	case DC_FAMILY_MARES_ICONHD:
		rc = mares_iconhd_device_open (&device, context, name, dc_descriptor_get_model (descriptor));
		break;
	case DC_FAMILY_HW_OSTC:
		rc = hw_ostc_device_open (&device, context, name);
		break;
	case DC_FAMILY_HW_FROG:
		rc = hw_frog_device_open (&device, context, name);
		break;
	case DC_FAMILY_HW_OSTC3:
		rc = hw_ostc3_device_open (&device, context, name);
		break;
	case DC_FAMILY_CRESSI_EDY:
		rc = cressi_edy_device_open (&device, context, name);
		break;
	case DC_FAMILY_CRESSI_LEONARDO:
		rc = cressi_leonardo_device_open (&device, context, name);
		break;
	case DC_FAMILY_ZEAGLE_N2ITION3:
		rc = zeagle_n2ition3_device_open (&device, context, name);
		break;
	case DC_FAMILY_ATOMICS_COBALT:
		rc = atomics_cobalt_device_open (&device, context);
		break;
	case DC_FAMILY_SHEARWATER_PREDATOR:
		rc = shearwater_predator_device_open (&device, context, name);
		break;
	case DC_FAMILY_SHEARWATER_PETREL:
		rc = shearwater_petrel_device_open (&device, context, name);
		break;
	default:
		return DC_STATUS_INVALIDARGS;
	}

	*out = device;

	return rc;
}