Integrate the context object in the library.

The public api is changed to require a context object for all
operations. Because other library objects store the context pointer
internally, only the constructor functions need an explicit context
object as a parameter.
This commit is contained in:
Jef Driesen 2012-07-01 09:47:51 +02:00
parent 3311960795
commit 53e9d72a40
98 changed files with 1008 additions and 613 deletions

View File

@ -19,6 +19,8 @@
* MA 02110-1301 USA
*/
#include <libdivecomputer/utils.h>
#include "common.h"
const char *
@ -51,3 +53,11 @@ errmsg (dc_status_t rc)
return "Unknown error";
}
}
void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
{
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
message ("%s: %s [in %s:%d (%s)]\n", loglevels[loglevel], msg, file, line, function);
}

View File

@ -22,7 +22,8 @@
#ifndef EXAMPLES_COMMON_H
#define EXAMPLES_COMMON_H
#include <libdivecomputer/device.h>
#include <libdivecomputer/common.h>
#include <libdivecomputer/context.h>
#ifdef __cplusplus
extern "C" {
@ -31,6 +32,9 @@ extern "C" {
const char *
errmsg (dc_status_t rc);
void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -29,12 +29,18 @@
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 ("cressi_edy_device_open\n");
dc_status_t rc = cressi_edy_device_open (&device, name);
dc_status_t rc = cressi_edy_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("hw_frog_device_open\n");
dc_status_t rc = hw_frog_device_open (&device, name);
dc_status_t rc = hw_frog_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -43,6 +49,7 @@ test_dump_memory (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -50,9 +57,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("hw_ostc_device_open\n");
dc_status_t rc = hw_ostc_device_open (&device, name);
dc_status_t rc = hw_ostc_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("mares_darwin_device_open\n");
dc_status_t rc = mares_darwin_device_open (&device, name, 0);
dc_status_t rc = mares_darwin_device_open (&device, context, name, 0);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("mares_iconhd_device_open\n");
dc_status_t rc = mares_iconhd_device_open (&device, name);
dc_status_t rc = mares_iconhd_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("mares_nemo_device_open\n");
dc_status_t rc = mares_nemo_device_open (&device, name);
dc_status_t rc = mares_nemo_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("mares_puck_device_open\n");
dc_status_t rc = mares_puck_device_open (&device, name);
dc_status_t rc = mares_puck_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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, name);
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;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -63,6 +70,7 @@ test_dump_memory (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -70,9 +78,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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_veo250_device_open\n");
dc_status_t rc = oceanic_veo250_device_open (&device, name);
dc_status_t rc = oceanic_veo250_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -63,6 +70,7 @@ test_dump_memory (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -70,9 +78,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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_vtpro_device_open\n");
dc_status_t rc = oceanic_vtpro_device_open (&device, name);
dc_status_t rc = oceanic_vtpro_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -30,12 +30,18 @@
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 ("reefnet_sensus_device_open\n");
dc_status_t rc = reefnet_sensus_device_open (&device, name);
dc_status_t rc = reefnet_sensus_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -52,6 +58,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -68,9 +75,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -30,12 +30,18 @@
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 ("reefnet_sensuspro_device_open\n");
dc_status_t rc = reefnet_sensuspro_device_open (&device, name);
dc_status_t rc = reefnet_sensuspro_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -52,6 +58,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -68,9 +75,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -30,12 +30,18 @@
dc_status_t
test_dump_memory_dives (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 ("reefnet_sensusultra_device_open\n");
dc_status_t rc = reefnet_sensusultra_device_open (&device, name);
dc_status_t rc = reefnet_sensusultra_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -49,6 +55,7 @@ test_dump_memory_dives (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -56,9 +63,12 @@ test_dump_memory_dives (const char* name, const char* filename)
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;
}
@ -66,12 +76,18 @@ test_dump_memory_dives (const char* name, const char* filename)
dc_status_t
test_dump_memory_data (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 ("reefnet_sensusultra_device_open\n");
dc_status_t rc = reefnet_sensusultra_device_open (&device, name);
dc_status_t rc = reefnet_sensusultra_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -88,6 +104,7 @@ test_dump_memory_data (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -104,9 +121,12 @@ test_dump_memory_data (const char* name, const char* filename)
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;
}
@ -114,13 +134,19 @@ test_dump_memory_data (const char* name, const char* filename)
dc_status_t
test_dump_memory_user (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
unsigned char data[REEFNET_SENSUSULTRA_MEMORY_USER_SIZE] = {0};
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("reefnet_sensusultra_device_open\n");
dc_status_t rc = reefnet_sensusultra_device_open (&device, name);
dc_status_t rc = reefnet_sensusultra_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -134,6 +160,7 @@ test_dump_memory_user (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -148,9 +175,12 @@ test_dump_memory_user (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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_d9_device_open\n");
dc_status_t rc = suunto_d9_device_open (&device, name, 0);
dc_status_t rc = suunto_d9_device_open (&device, context, name, 0);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -44,6 +50,7 @@ test_dump_sdm (const char* name)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot identify computer.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -52,6 +59,7 @@ test_dump_sdm (const char* name)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -59,9 +67,12 @@ test_dump_sdm (const char* name)
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;
}
@ -69,12 +80,18 @@ test_dump_sdm (const char* name)
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 ("suunto_d9_device_open\n");
dc_status_t rc = suunto_d9_device_open (&device, name, 0);
dc_status_t rc = suunto_d9_device_open (&device, context, name, 0);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -84,6 +101,7 @@ test_dump_memory (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot identify computer.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -95,6 +113,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -111,9 +130,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("suunto_eon_device_open\n");
dc_status_t rc = suunto_eon_device_open (&device, name);
dc_status_t rc = suunto_eon_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -8,12 +8,18 @@
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 ("suunto_solution_device_open\n");
int rc = suunto_solution_device_open (&device, name);
int rc = suunto_solution_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -25,6 +31,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -41,9 +48,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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_vyper2_device_open\n");
dc_status_t rc = suunto_vyper2_device_open (&device, name);
dc_status_t rc = suunto_vyper2_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -44,6 +50,7 @@ test_dump_sdm (const char* name)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot identify computer.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -52,6 +59,7 @@ test_dump_sdm (const char* name)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -59,9 +67,12 @@ test_dump_sdm (const char* name)
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;
}
@ -69,12 +80,18 @@ test_dump_sdm (const char* name)
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 ("suunto_vyper2_device_open\n");
dc_status_t rc = suunto_vyper2_device_open (&device, name);
dc_status_t rc = suunto_vyper2_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -84,6 +101,7 @@ test_dump_memory (const char* name, const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot identify computer.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -95,6 +113,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -111,9 +130,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -30,12 +30,18 @@
dc_status_t
test_dump_sdm (const char* name, unsigned int delay)
{
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, name);
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;
}
@ -46,6 +52,7 @@ test_dump_sdm (const char* name, unsigned int delay)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -53,9 +60,12 @@ test_dump_sdm (const char* name, unsigned int delay)
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;
}
@ -63,12 +73,18 @@ test_dump_sdm (const char* name, unsigned int delay)
dc_status_t
test_dump_memory (const char* name, unsigned int delay, 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 ("suunto_vyper_device_open\n");
dc_status_t rc = suunto_vyper_device_open (&device, name);
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;
}
@ -82,6 +98,7 @@ test_dump_memory (const char* name, unsigned int delay, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -98,9 +115,12 @@ test_dump_memory (const char* name, unsigned int delay, const char* filename)
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;
}

View File

@ -34,6 +34,7 @@
#define DC_TICKS_FORMAT "%lld"
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h>
#include <libdivecomputer/utils.h>
@ -579,7 +580,7 @@ search (dc_descriptor_t **out, const char *name, dc_family_t backend, unsigned i
static dc_status_t
dowork (dc_descriptor_t *descriptor, const char *devname, const char *rawfile, const char *xmlfile, int memory, int dives, dc_buffer_t *fingerprint)
dowork (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, const char *rawfile, const char *xmlfile, int memory, int dives, dc_buffer_t *fingerprint)
{
dc_status_t rc = DC_STATUS_SUCCESS;
@ -592,7 +593,7 @@ dowork (dc_descriptor_t *descriptor, const char *devname, const char *rawfile, c
dc_descriptor_get_product (descriptor),
devname ? devname : "null");
dc_device_t *device = NULL;
rc = dc_device_open (&device, descriptor, devname);
rc = dc_device_open (&device, context, descriptor, devname);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening device.");
return rc;
@ -772,9 +773,19 @@ main (int argc, char *argv[])
message_set_logfile (logfile);
dc_context_t *context = NULL;
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, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
/* Search for a matching device descriptor. */
dc_descriptor_t *descriptor = NULL;
dc_status_t rc = search (&descriptor, name, backend, model);
rc = search (&descriptor, name, backend, model);
if (rc != DC_STATUS_SUCCESS) {
message_set_logfile (NULL);
return EXIT_FAILURE;
@ -789,11 +800,12 @@ main (int argc, char *argv[])
}
dc_buffer_t *fp = fpconvert (fingerprint);
rc = dowork (descriptor, devname, rawfile, xmlfile, memory, dives, fp);
rc = dowork (context, descriptor, devname, rawfile, xmlfile, memory, dives, fp);
dc_buffer_free (fp);
message ("Result: %s\n", errmsg (rc));
dc_descriptor_free (descriptor);
dc_context_free (context);
message_set_logfile (NULL);

View File

@ -8,12 +8,18 @@
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 ("uwatec_aladin_device_open\n");
dc_status_t rc = uwatec_aladin_device_open (&device, name);
dc_status_t rc = uwatec_aladin_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -25,6 +31,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -41,9 +48,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("uwatec_memomouse_device_open\n");
dc_status_t rc = uwatec_memomouse_device_open (&device, name);
dc_status_t rc = uwatec_memomouse_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -31,12 +31,18 @@
dc_status_t
test_dump_memory (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 ("uwatec_smart_device_open\n");
dc_status_t rc = uwatec_smart_device_open (&device);
dc_status_t rc = uwatec_smart_device_open (&device, context);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot open device.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* filename)
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot identify computer.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -57,6 +64,7 @@ test_dump_memory (const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -73,9 +81,12 @@ test_dump_memory (const char* filename)
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;
}

View File

@ -29,12 +29,18 @@
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 ("zeagle_n2ition3_device_open\n");
dc_status_t rc = zeagle_n2ition3_device_open (&device, name);
dc_status_t rc = zeagle_n2ition3_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
@ -46,6 +52,7 @@ test_dump_memory (const char* name, const char* filename)
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
@ -62,9 +69,12 @@ test_dump_memory (const char* name, const char* filename)
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;
}

View File

@ -22,6 +22,7 @@
#ifndef ATOMICS_COBALT_H
#define ATOMICS_COBALT_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,13 +31,13 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
atomics_cobalt_device_open (dc_device_t **device);
atomics_cobalt_device_open (dc_device_t **device, dc_context_t *context);
dc_status_t
atomics_cobalt_device_set_simulation (dc_device_t *device, unsigned int simulation);
dc_status_t
atomics_cobalt_parser_create (dc_parser_t **parser);
atomics_cobalt_parser_create (dc_parser_t **parser, dc_context_t *context);
dc_status_t
atomics_cobalt_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);

View File

@ -22,6 +22,7 @@
#ifndef CRESSI_EDY_H
#define CRESSI_EDY_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -33,10 +34,10 @@ extern "C" {
#define CRESSI_EDY_PACKET_SIZE 128
dc_status_t
cressi_edy_device_open (dc_device_t **device, const char *name);
cressi_edy_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
cressi_edy_parser_create (dc_parser_t **parser, unsigned int model);
cressi_edy_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -23,6 +23,7 @@
#define DC_DEVICE_H
#include "common.h"
#include "context.h"
#include "descriptor.h"
#include "buffer.h"
#include "datetime.h"
@ -63,7 +64,7 @@ typedef void (*dc_event_callback_t) (dc_device_t *device, dc_event_type_t event,
typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata);
dc_status_t
dc_device_open (dc_device_t **out, dc_descriptor_t *descriptor, const char *name);
dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *name);
dc_family_t
dc_device_get_type (dc_device_t *device);

View File

@ -22,6 +22,7 @@
#ifndef HW_FROG_H
#define HW_FROG_H
#include "context.h"
#include "device.h"
#include "parser.h"
#include "buffer.h"
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
hw_frog_device_open (dc_device_t **device, const char *name);
hw_frog_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
hw_frog_device_clock (dc_device_t *device, const dc_datetime_t *datetime);

View File

@ -22,6 +22,7 @@
#ifndef HW_OSTC_H
#define HW_OSTC_H
#include "context.h"
#include "device.h"
#include "parser.h"
#include "buffer.h"
@ -37,7 +38,7 @@ typedef enum hw_ostc_format_t {
} hw_ostc_format_t;
dc_status_t
hw_ostc_device_open (dc_device_t **device, const char *name);
hw_ostc_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
hw_ostc_device_md2hash (dc_device_t *device, unsigned char data[], unsigned int size);
@ -61,7 +62,7 @@ dc_status_t
hw_ostc_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
hw_ostc_parser_create (dc_parser_t **parser, unsigned int frog);
hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int frog);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef MARES_DARWIN_H
#define MARES_DARWIN_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,13 +31,13 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
mares_darwin_device_open (dc_device_t **device, const char *name, unsigned int model);
mares_darwin_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model);
dc_status_t
mares_darwin_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
mares_darwin_parser_create (dc_parser_t **parser, unsigned int model);
mares_darwin_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef MARES_ICONHD_H
#define MARES_ICONHD_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -32,13 +33,13 @@ extern "C" {
#define MARES_ICONHD_MEMORY_SIZE 0x100000
dc_status_t
mares_iconhd_device_open (dc_device_t **device, const char *name);
mares_iconhd_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
mares_iconhd_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
mares_iconhd_parser_create (dc_parser_t **parser, unsigned int model);
mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef MARES_NEMO_H
#define MARES_NEMO_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,13 +31,13 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
mares_nemo_device_open (dc_device_t **device, const char *name);
mares_nemo_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
mares_nemo_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
mares_nemo_parser_create (dc_parser_t **parser, unsigned int model);
mares_nemo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef MARES_PUCK_H
#define MARES_PUCK_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,7 +31,7 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
mares_puck_device_open (dc_device_t **device, const char *name);
mares_puck_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
mares_puck_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);

View File

@ -22,6 +22,7 @@
#ifndef OCEANIC_ATOM2_H
#define OCEANIC_ATOM2_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,13 +31,13 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
oceanic_atom2_device_open (dc_device_t **device, const char *name);
oceanic_atom2_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
oceanic_atom2_device_keepalive (dc_device_t *device);
dc_status_t
oceanic_atom2_parser_create (dc_parser_t **parser, unsigned int model);
oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef OCEANIC_VEO250_H
#define OCEANIC_VEO250_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,13 +31,13 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
oceanic_veo250_device_open (dc_device_t **device, const char *name);
oceanic_veo250_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
oceanic_veo250_device_keepalive (dc_device_t *device);
dc_status_t
oceanic_veo250_parser_create (dc_parser_t **parser, unsigned int model);
oceanic_veo250_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef OCEANIC_VTPRO_H
#define OCEANIC_VTPRO_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,13 +31,13 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
oceanic_vtpro_device_open (dc_device_t **device, const char *name);
oceanic_vtpro_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
oceanic_vtpro_device_keepalive (dc_device_t *device);
dc_status_t
oceanic_vtpro_parser_create (dc_parser_t **parser);
oceanic_vtpro_parser_create (dc_parser_t **parser, dc_context_t *context);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef REEFNET_SENSUS_H
#define REEFNET_SENSUS_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -33,7 +34,7 @@ extern "C" {
#define REEFNET_SENSUS_HANDSHAKE_SIZE 10
dc_status_t
reefnet_sensus_device_open (dc_device_t **device, const char *name);
reefnet_sensus_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
reefnet_sensus_device_set_timestamp (dc_device_t *device, unsigned int timestamp);
@ -45,7 +46,7 @@ dc_status_t
reefnet_sensus_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
reefnet_sensus_parser_create (dc_parser_t **parser, unsigned int devtime, dc_ticks_t systime);
reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);
dc_status_t
reefnet_sensus_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);

View File

@ -22,6 +22,7 @@
#ifndef REEFNET_SENSUSPRO_H
#define REEFNET_SENSUSPRO_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -33,7 +34,7 @@ extern "C" {
#define REEFNET_SENSUSPRO_HANDSHAKE_SIZE 10
dc_status_t
reefnet_sensuspro_device_open (dc_device_t **device, const char *name);
reefnet_sensuspro_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
reefnet_sensuspro_device_set_timestamp (dc_device_t *device, unsigned int timestamp);
@ -48,7 +49,7 @@ dc_status_t
reefnet_sensuspro_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
reefnet_sensuspro_parser_create (dc_parser_t **parser, unsigned int devtime, dc_ticks_t systime);
reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);
dc_status_t
reefnet_sensuspro_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);

View File

@ -22,6 +22,7 @@
#ifndef REEFNET_SENSUSULTRA_H
#define REEFNET_SENSUSULTRA_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -44,7 +45,7 @@ typedef enum reefnet_sensusultra_parameter_t {
} reefnet_sensusultra_parameter_t;
dc_status_t
reefnet_sensusultra_device_open (dc_device_t **device, const char *name);
reefnet_sensusultra_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
reefnet_sensusultra_device_set_maxretries (dc_device_t *device, unsigned int maxretries);
@ -71,7 +72,7 @@ dc_status_t
reefnet_sensusultra_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
reefnet_sensusultra_parser_create (dc_parser_t **parser, unsigned int devtime, dc_ticks_t systime);
reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);
dc_status_t
reefnet_sensusultra_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);

View File

@ -22,6 +22,7 @@
#ifndef SUUNTO_D9_H
#define SUUNTO_D9_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -34,13 +35,13 @@ extern "C" {
#define SUUNTO_D9_VERSION_SIZE 0x04
dc_status_t
suunto_d9_device_open (dc_device_t **device, const char *name, unsigned int model);
suunto_d9_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model);
dc_status_t
suunto_d9_device_reset_maxdepth (dc_device_t *device);
dc_status_t
suunto_d9_parser_create (dc_parser_t **parser, unsigned int model);
suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef SUUNTO_EON_H
#define SUUNTO_EON_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -32,7 +33,7 @@ extern "C" {
#define SUUNTO_EON_MEMORY_SIZE 0x900
dc_status_t
suunto_eon_device_open (dc_device_t **device, const char *name);
suunto_eon_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
suunto_eon_device_write_name (dc_device_t *device, unsigned char data[], unsigned int size);
@ -44,7 +45,7 @@ dc_status_t
suunto_eon_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
suunto_eon_parser_create (dc_parser_t **parser, int spyder);
suunto_eon_parser_create (dc_parser_t **parser, dc_context_t *context, int spyder);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef SUUNTO_SOLUTION_H
#define SUUNTO_SOLUTION_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -32,13 +33,13 @@ extern "C" {
#define SUUNTO_SOLUTION_MEMORY_SIZE 256
dc_status_t
suunto_solution_device_open (dc_device_t **device, const char *name);
suunto_solution_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
suunto_solution_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
suunto_solution_parser_create (dc_parser_t **parser);
suunto_solution_parser_create (dc_parser_t **parser, dc_context_t *context);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef SUUNTO_VYPER_H
#define SUUNTO_VYPER_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -33,7 +34,7 @@ extern "C" {
#define SUUNTO_VYPER_PACKET_SIZE 32
dc_status_t
suunto_vyper_device_open (dc_device_t **device, const char *name);
suunto_vyper_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
suunto_vyper_device_set_delay (dc_device_t *device, unsigned int delay);
@ -45,7 +46,7 @@ dc_status_t
suunto_vyper_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
suunto_vyper_parser_create (dc_parser_t **parser);
suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context);
#ifdef __cplusplus
}

View File

@ -26,6 +26,7 @@
extern "C" {
#endif /* __cplusplus */
#include "context.h"
#include "device.h"
#define SUUNTO_VYPER2_MEMORY_SIZE 0x8000
@ -33,7 +34,7 @@ extern "C" {
#define SUUNTO_VYPER2_VERSION_SIZE 0x04
dc_status_t
suunto_vyper2_device_open (dc_device_t **device, const char *name);
suunto_vyper2_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
suunto_vyper2_device_reset_maxdepth (dc_device_t *device);

View File

@ -26,12 +26,13 @@
extern "C" {
#endif /* __cplusplus */
#include "context.h"
#include "device.h"
#define UWATEC_ALADIN_MEMORY_SIZE 2048
dc_status_t
uwatec_aladin_device_open (dc_device_t **device, const char *name);
uwatec_aladin_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
uwatec_aladin_device_set_timestamp (dc_device_t *device, unsigned int timestamp);

View File

@ -22,6 +22,7 @@
#ifndef UWATEC_MEMOMOUSE_H
#define UWATEC_MEMOMOUSE_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -30,7 +31,7 @@ extern "C" {
#endif /* __cplusplus */
dc_status_t
uwatec_memomouse_device_open (dc_device_t **device, const char *name);
uwatec_memomouse_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
uwatec_memomouse_device_set_timestamp (dc_device_t *device, unsigned int timestamp);
@ -39,7 +40,7 @@ dc_status_t
uwatec_memomouse_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
uwatec_memomouse_parser_create (dc_parser_t **parser, unsigned int devtime, dc_ticks_t systime);
uwatec_memomouse_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef UWATEC_SMART_H
#define UWATEC_SMART_H
#include "context.h"
#include "device.h"
#include "parser.h"
@ -32,7 +33,7 @@ extern "C" {
#define UWATEC_SMART_VERSION_SIZE 9
dc_status_t
uwatec_smart_device_open (dc_device_t **device);
uwatec_smart_device_open (dc_device_t **device, dc_context_t *context);
dc_status_t
uwatec_smart_device_set_timestamp (dc_device_t *device, unsigned int timestamp);
@ -41,7 +42,7 @@ dc_status_t
uwatec_smart_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t
uwatec_smart_parser_create (dc_parser_t **parser, unsigned int model, unsigned int devtime, dc_ticks_t systime);
uwatec_smart_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int devtime, dc_ticks_t systime);
#ifdef __cplusplus
}

View File

@ -22,6 +22,7 @@
#ifndef ZEAGLE_N2ITION3_H
#define ZEAGLE_N2ITION3_H
#include "context.h"
#include "device.h"
#ifdef __cplusplus
@ -32,7 +33,7 @@ extern "C" {
#define ZEAGLE_N2ITION3_PACKET_SIZE 64
dc_status_t
zeagle_n2ition3_device_open (dc_device_t **device, const char *name);
zeagle_n2ition3_device_open (dc_device_t **device, dc_context_t *context, const char *name);
#ifdef __cplusplus
}

View File

@ -31,8 +31,8 @@
#endif
#include <libdivecomputer/atomics_cobalt.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "checksum.h"
#include "array.h"
@ -86,7 +86,7 @@ device_is_atomics_cobalt (dc_device_t *abstract)
dc_status_t
atomics_cobalt_device_open (dc_device_t **out)
atomics_cobalt_device_open (dc_device_t **out, dc_context_t *context)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -95,7 +95,7 @@ atomics_cobalt_device_open (dc_device_t **out)
// Allocate memory.
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) malloc (sizeof (atomics_cobalt_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -110,14 +110,14 @@ atomics_cobalt_device_open (dc_device_t **out)
int rc = libusb_init (&device->context);
if (rc < 0) {
WARNING ("Failed to initialize usb support.");
ERROR (context, "Failed to initialize usb support.");
free (device);
return DC_STATUS_IO;
}
device->handle = libusb_open_device_with_vid_pid (device->context, VID, PID);
if (device->handle == NULL) {
WARNING ("Failed to open the usb device.");
ERROR (context, "Failed to open the usb device.");
libusb_exit (device->context);
free (device);
return DC_STATUS_IO;
@ -125,7 +125,7 @@ atomics_cobalt_device_open (dc_device_t **out)
rc = libusb_claim_interface (device->handle, 0);
if (rc < 0) {
WARNING ("Failed to claim the usb interface.");
ERROR (context, "Failed to claim the usb interface.");
libusb_close (device->handle);
libusb_exit (device->context);
free (device);
@ -134,7 +134,7 @@ atomics_cobalt_device_open (dc_device_t **out)
dc_status_t status = atomics_cobalt_device_version ((dc_device_t *) device, device->version, sizeof (device->version));
if (status != DC_STATUS_SUCCESS) {
WARNING ("Failed to identify the dive computer.");
ERROR (context, "Failed to identify the dive computer.");
libusb_close (device->handle);
libusb_exit (device->context);
free (device);
@ -220,7 +220,7 @@ atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsi
LIBUSB_RECIPIENT_DEVICE | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT,
bRequest, 0, 0, NULL, 0, TIMEOUT);
if (rc != LIBUSB_SUCCESS) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE(rc);
}
@ -230,7 +230,7 @@ atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsi
rc = libusb_bulk_transfer (device->handle, 0x82,
packet, sizeof (packet), &length, TIMEOUT);
if (rc != LIBUSB_SUCCESS || length != sizeof (packet)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE(rc);
}
@ -238,7 +238,7 @@ atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsi
unsigned short crc = array_uint16_le (packet + SZ_VERSION);
unsigned short ccrc = checksum_add_uint16 (packet, SZ_VERSION, 0x0);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -262,7 +262,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -276,7 +276,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
LIBUSB_RECIPIENT_DEVICE | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT,
bRequest, 0, 0, NULL, 0, TIMEOUT);
if (rc != LIBUSB_SUCCESS) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE(rc);
}
@ -288,7 +288,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
rc = libusb_bulk_transfer (device->handle, 0x82,
packet, sizeof (packet), &length, TIMEOUT);
if (rc != LIBUSB_SUCCESS) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE(rc);
}
@ -309,13 +309,13 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
// Check for a buffer error.
if (dc_buffer_get_size (buffer) != nbytes) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
// Check for the minimum length.
if (nbytes < 2) {
WARNING ("Data packet is too short.");
ERROR (abstract->context, "Data packet is too short.");
return DC_STATUS_PROTOCOL;
}
@ -330,7 +330,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
unsigned short crc = array_uint16_le (data + nbytes - 2);
unsigned short ccrc = checksum_add_uint16 (data, nbytes - 2, 0x0);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}

View File

@ -23,8 +23,8 @@
#include <libdivecomputer/atomics_cobalt.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -69,7 +69,7 @@ parser_is_atomics_cobalt (dc_parser_t *abstract)
dc_status_t
atomics_cobalt_parser_create (dc_parser_t **out)
atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -77,7 +77,7 @@ atomics_cobalt_parser_create (dc_parser_t **out)
// Allocate memory.
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t *) malloc (sizeof (atomics_cobalt_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/cressi_edy.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -85,38 +85,40 @@ device_is_cressi_edy (dc_device_t *abstract)
static dc_status_t
cressi_edy_transfer (cressi_edy_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, int trailer)
{
dc_device_t *abstract = (dc_device_t *) device;
assert (asize >= csize);
// Flush the serial input buffer.
int rc = serial_flush (device->port, SERIAL_QUEUE_INPUT);
if (rc == -1) {
WARNING ("Failed to flush the serial input buffer.");
ERROR (abstract->context, "Failed to flush the serial input buffer.");
return DC_STATUS_IO;
}
// Send the command to the device.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
// Receive the answer of the device.
n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the echo.
if (memcmp (answer, command, csize) != 0) {
WARNING ("Unexpected echo.");
ERROR (abstract->context, "Unexpected echo.");
return DC_STATUS_PROTOCOL;
}
// Verify the trailer of the packet.
if (trailer && answer[asize - 1] != 0x45) {
WARNING ("Unexpected answer trailer byte.");
ERROR (abstract->context, "Unexpected answer trailer byte.");
return DC_STATUS_PROTOCOL;
}
@ -171,7 +173,7 @@ cressi_edy_quit (cressi_edy_device_t *device)
dc_status_t
cressi_edy_device_open (dc_device_t **out, const char *name)
cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -179,7 +181,7 @@ cressi_edy_device_open (dc_device_t **out, const char *name)
// Allocate memory.
cressi_edy_device_t *device = (cressi_edy_device_t *) malloc (sizeof (cressi_edy_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -193,7 +195,7 @@ cressi_edy_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -201,7 +203,7 @@ cressi_edy_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (1200 8N1).
rc = serial_configure (device->port, 1200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -209,7 +211,7 @@ cressi_edy_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -218,7 +220,7 @@ cressi_edy_device_open (dc_device_t **out, const char *name)
// Set the DTR and clear the RTS line.
if (serial_set_dtr (device->port, 1) == -1 ||
serial_set_rts (device->port, 0) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -232,7 +234,7 @@ cressi_edy_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (4800 8N1).
rc = serial_configure (device->port, 4800, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -332,7 +334,7 @@ cressi_edy_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, CRESSI_EDY_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -363,7 +365,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v
unsigned char config[CRESSI_EDY_PACKET_SIZE] = {0};
dc_status_t rc = cressi_edy_device_read (abstract, 0x7F80, config, sizeof (config));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the configuration data.");
ERROR (abstract->context, "Failed to read the configuration data.");
return rc;
}
@ -378,7 +380,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v
last < RB_LOGBOOK_BEGIN || last >= RB_LOGBOOK_END) {
if (last == 0xFF)
return DC_STATUS_SUCCESS;
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -388,7 +390,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v
// Get the profile pointer.
unsigned int eop = array_uint16_le (config + 0x7E) * PAGESIZE + BASE;
if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) {
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -406,7 +408,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v
// Get the pointer to the profile data.
unsigned int current = array_uint16_le (config + 2 * idx) * PAGESIZE + BASE;
if (current < RB_PROFILE_BEGIN || current >= RB_PROFILE_END) {
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -428,7 +430,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v
// Read the memory page.
rc = cressi_edy_device_read (abstract, address, buffer + offset, CRESSI_EDY_PACKET_SIZE);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the memory page.");
ERROR (abstract->context, "Failed to read the memory page.");
return rc;
}

View File

@ -22,8 +22,8 @@
#include <stdlib.h>
#include <libdivecomputer/cressi_edy.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -61,7 +61,7 @@ parser_is_cressi_edy (dc_parser_t *abstract)
dc_status_t
cressi_edy_parser_create (dc_parser_t **out, unsigned int model)
cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -69,7 +69,7 @@ cressi_edy_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
cressi_edy_parser_t *parser = (cressi_edy_parser_t *) malloc (sizeof (cressi_edy_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -39,6 +39,8 @@ typedef struct device_backend_t device_backend_t;
struct dc_device_t {
const device_backend_t *backend;
// Library context.
dc_context_t *context;
// Event notifications.
unsigned int event_mask;
dc_event_callback_t event_callback;

View File

@ -34,6 +34,7 @@
#include <libdivecomputer/atomics.h>
#include "device-private.h"
#include "context-private.h"
void
@ -41,6 +42,8 @@ device_init (dc_device_t *device, const device_backend_t *backend)
{
device->backend = backend;
device->context = NULL;
device->event_mask = 0;
device->event_callback = NULL;
device->event_userdata = NULL;
@ -53,7 +56,7 @@ device_init (dc_device_t *device, const device_backend_t *backend)
}
dc_status_t
dc_device_open (dc_device_t **out, dc_descriptor_t *descriptor, const char *name)
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;
@ -63,73 +66,73 @@ dc_device_open (dc_device_t **out, dc_descriptor_t *descriptor, const char *name
switch (dc_descriptor_get_type (descriptor)) {
case DC_FAMILY_SUUNTO_SOLUTION:
rc = suunto_solution_device_open (&device, name);
rc = suunto_solution_device_open (&device, context, name);
break;
case DC_FAMILY_SUUNTO_EON:
rc = suunto_eon_device_open (&device, name);
rc = suunto_eon_device_open (&device, context, name);
break;
case DC_FAMILY_SUUNTO_VYPER:
rc = suunto_vyper_device_open (&device, name);
rc = suunto_vyper_device_open (&device, context, name);
break;
case DC_FAMILY_SUUNTO_VYPER2:
rc = suunto_vyper2_device_open (&device, name);
rc = suunto_vyper2_device_open (&device, context, name);
break;
case DC_FAMILY_SUUNTO_D9:
rc = suunto_d9_device_open (&device, name, dc_descriptor_get_model (descriptor));
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, name);
rc = uwatec_aladin_device_open (&device, context, name);
break;
case DC_FAMILY_UWATEC_MEMOMOUSE:
rc = uwatec_memomouse_device_open (&device, name);
rc = uwatec_memomouse_device_open (&device, context, name);
break;
case DC_FAMILY_UWATEC_SMART:
rc = uwatec_smart_device_open (&device);
rc = uwatec_smart_device_open (&device, context);
break;
case DC_FAMILY_REEFNET_SENSUS:
rc = reefnet_sensus_device_open (&device, name);
rc = reefnet_sensus_device_open (&device, context, name);
break;
case DC_FAMILY_REEFNET_SENSUSPRO:
rc = reefnet_sensuspro_device_open (&device, name);
rc = reefnet_sensuspro_device_open (&device, context, name);
break;
case DC_FAMILY_REEFNET_SENSUSULTRA:
rc = reefnet_sensusultra_device_open (&device, name);
rc = reefnet_sensusultra_device_open (&device, context, name);
break;
case DC_FAMILY_OCEANIC_VTPRO:
rc = oceanic_vtpro_device_open (&device, name);
rc = oceanic_vtpro_device_open (&device, context, name);
break;
case DC_FAMILY_OCEANIC_VEO250:
rc = oceanic_veo250_device_open (&device, name);
rc = oceanic_veo250_device_open (&device, context, name);
break;
case DC_FAMILY_OCEANIC_ATOM2:
rc = oceanic_atom2_device_open (&device, name);
rc = oceanic_atom2_device_open (&device, context, name);
break;
case DC_FAMILY_MARES_NEMO:
rc = mares_nemo_device_open (&device, name);
rc = mares_nemo_device_open (&device, context, name);
break;
case DC_FAMILY_MARES_PUCK:
rc = mares_puck_device_open (&device, name);
rc = mares_puck_device_open (&device, context, name);
break;
case DC_FAMILY_MARES_DARWIN:
rc = mares_darwin_device_open (&device, name, dc_descriptor_get_model (descriptor));
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, name);
rc = mares_iconhd_device_open (&device, context, name);
break;
case DC_FAMILY_HW_OSTC:
rc = hw_ostc_device_open (&device, name);
rc = hw_ostc_device_open (&device, context, name);
break;
case DC_FAMILY_HW_FROG:
rc = hw_frog_device_open (&device, name);
rc = hw_frog_device_open (&device, context, name);
break;
case DC_FAMILY_CRESSI_EDY:
rc = cressi_edy_device_open (&device, name);
rc = cressi_edy_device_open (&device, context, name);
break;
case DC_FAMILY_ZEAGLE_N2ITION3:
rc = zeagle_n2ition3_device_open (&device, name);
rc = zeagle_n2ition3_device_open (&device, context, name);
break;
case DC_FAMILY_ATOMICS_COBALT:
rc = atomics_cobalt_device_open (&device);
rc = atomics_cobalt_device_open (&device, context);
break;
default:
return DC_STATUS_INVALIDARGS;

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/hw_frog.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -99,11 +99,13 @@ hw_frog_transfer (hw_frog_device_t *device,
unsigned char output[],
unsigned int osize)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command.
unsigned char command[1] = {cmd};
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -112,13 +114,13 @@ hw_frog_transfer (hw_frog_device_t *device,
unsigned char answer[1] = {0};
n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the echo.");
ERROR (abstract->context, "Failed to receive the echo.");
return EXITCODE (n);
}
// Verify the echo.
if (memcmp (answer, command, sizeof (command)) != 0) {
WARNING ("Unexpected echo.");
ERROR (abstract->context, "Unexpected echo.");
return DC_STATUS_PROTOCOL;
}
}
@ -127,7 +129,7 @@ hw_frog_transfer (hw_frog_device_t *device,
// Send the input data packet.
n = serial_write (device->port, input, isize);
if (n != isize) {
WARNING ("Failed to send the data.");
ERROR (abstract->context, "Failed to send the data packet.");
return EXITCODE (n);
}
}
@ -150,7 +152,7 @@ hw_frog_transfer (hw_frog_device_t *device,
// Read the packet.
n = serial_read (device->port, output + nbytes, len);
if (n != len) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -169,13 +171,13 @@ hw_frog_transfer (hw_frog_device_t *device,
unsigned char answer[1] = {0};
n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the ready byte.");
ERROR (abstract->context, "Failed to receive the ready byte.");
return EXITCODE (n);
}
// Verify the ready byte.
if (answer[0] != READY) {
WARNING ("Unexpected ready byte.");
ERROR (abstract->context, "Unexpected ready byte.");
return DC_STATUS_PROTOCOL;
}
}
@ -185,7 +187,7 @@ hw_frog_transfer (hw_frog_device_t *device,
dc_status_t
hw_frog_device_open (dc_device_t **out, const char *name)
hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -193,7 +195,7 @@ hw_frog_device_open (dc_device_t **out, const char *name)
// Allocate memory.
hw_frog_device_t *device = (hw_frog_device_t *) malloc (sizeof (hw_frog_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -207,7 +209,7 @@ hw_frog_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -215,7 +217,7 @@ hw_frog_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (115200 8N1).
rc = serial_configure (device->port, 115200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -223,7 +225,7 @@ hw_frog_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -236,7 +238,7 @@ hw_frog_device_open (dc_device_t **out, const char *name)
// Send the init command.
dc_status_t status = hw_frog_transfer (device, NULL, INIT, NULL, 0, NULL, 0);
if (status != DC_STATUS_SUCCESS) {
WARNING ("Failed to send the init command.");
ERROR (context, "Failed to send the command.");
serial_close (device->port);
free (device);
return status;
@ -256,7 +258,7 @@ hw_frog_device_close (dc_device_t *abstract)
// Send the exit command.
dc_status_t status = hw_frog_transfer (device, NULL, EXIT, NULL, 0, NULL, 0);
if (status != DC_STATUS_SUCCESS) {
WARNING ("Failed to send the exit command.");
ERROR (abstract->context, "Failed to send the command.");
serial_close (device->port);
free (device);
return status;
@ -327,7 +329,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
unsigned char id[SZ_VERSION] = {0};
dc_status_t rc = hw_frog_device_version (abstract, id, sizeof (id));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the version.");
ERROR (abstract->context, "Failed to read the version.");
return rc;
}
@ -341,7 +343,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
// Allocate memory.
unsigned char *header = malloc (RB_LOGBOOK_SIZE * RB_LOGBOOK_COUNT);
if (header == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (abstract->context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -349,7 +351,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
rc = hw_frog_transfer (device, &progress, HEADER,
NULL, 0, header, RB_LOGBOOK_SIZE * RB_LOGBOOK_COUNT);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the header.");
ERROR (abstract->context, "Failed to read the header.");
free (header);
return rc;
}
@ -394,7 +396,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
end < RB_PROFILE_BEGIN ||
end >= RB_PROFILE_END)
{
WARNING("Invalid ringbuffer pointer detected!");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
free (header);
return DC_STATUS_DATAFORMAT;
}
@ -419,7 +421,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
// Allocate enough memory for the largest dive.
unsigned char *profile = malloc (maxsize);
if (profile == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (abstract->context, "Failed to allocate memory.");
free (header);
return DC_STATUS_NOMEMORY;
}
@ -441,7 +443,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
rc = hw_frog_transfer (device, &progress, DIVE,
number, sizeof (number), profile, length);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the dive.");
ERROR (abstract->context, "Failed to read the dive.");
free (profile);
free (header);
return rc;
@ -467,7 +469,7 @@ hw_frog_device_clock (dc_device_t *abstract, const dc_datetime_t *datetime)
return DC_STATUS_INVALIDARGS;
if (datetime == NULL) {
WARNING ("Invalid parameter specified.");
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
@ -494,7 +496,7 @@ hw_frog_device_display (dc_device_t *abstract, const char *text)
// Check the maximum length.
size_t length = (text ? strlen (text) : 0);
if (length > SZ_DISPLAY) {
WARNING ("Invalid parameter specified.");
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
@ -524,7 +526,7 @@ hw_frog_device_customtext (dc_device_t *abstract, const char *text)
// Check the maximum length.
size_t length = (text ? strlen (text) : 0);
if (length > SZ_CUSTOMTEXT) {
WARNING ("Invalid parameter specified.");
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/hw_ostc.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -84,11 +84,13 @@ device_is_hw_ostc (dc_device_t *abstract)
static dc_status_t
hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command.
unsigned char command[1] = {cmd};
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -97,13 +99,13 @@ hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
unsigned char answer[1] = {0};
n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the echo.");
ERROR (abstract->context, "Failed to receive the echo.");
return EXITCODE (n);
}
// Verify the echo.
if (memcmp (answer, command, sizeof (command)) != 0) {
WARNING ("Unexpected echo.");
ERROR (abstract->context, "Unexpected echo.");
return DC_STATUS_PROTOCOL;
}
}
@ -113,7 +115,7 @@ hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
dc_status_t
hw_ostc_device_open (dc_device_t **out, const char *name)
hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -121,7 +123,7 @@ hw_ostc_device_open (dc_device_t **out, const char *name)
// Allocate memory.
hw_ostc_device_t *device = (hw_ostc_device_t *) malloc (sizeof (hw_ostc_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -135,7 +137,7 @@ hw_ostc_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -143,7 +145,7 @@ hw_ostc_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (115200 8N1).
rc = serial_configure (device->port, 115200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -151,7 +153,7 @@ hw_ostc_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data.
if (serial_set_timeout (device->port, 4000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -215,7 +217,7 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -228,7 +230,7 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char command[1] = {'a'};
int rc = serial_write (device->port, command, sizeof (command));
if (rc != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (rc);
}
@ -236,14 +238,14 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char header[SZ_HEADER] = {0};
int n = serial_read (device->port, header, sizeof (header));
if (n != sizeof (header)) {
WARNING ("Failed to receive the header.");
ERROR (abstract->context, "Failed to receive the header.");
return EXITCODE (n);
}
// Verify the header.
unsigned char preamble[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x55};
if (memcmp (header, preamble, sizeof (preamble)) != 0) {
WARNING ("Unexpected answer header.");
ERROR (abstract->context, "Unexpected answer header.");
return DC_STATUS_DATAFORMAT;
}
@ -264,7 +266,7 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Allocate the required amount of memory.
if (!dc_buffer_resize (buffer, size)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -290,7 +292,7 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Read the packet.
int n = serial_read (device->port, data + nbytes, len);
if (n != len) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -344,7 +346,7 @@ hw_ostc_device_md2hash (dc_device_t *abstract, unsigned char data[], unsigned in
return DC_STATUS_INVALIDARGS;
if (size < SZ_MD2HASH) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -356,7 +358,7 @@ hw_ostc_device_md2hash (dc_device_t *abstract, unsigned char data[], unsigned in
// Read the answer.
int n = serial_read (device->port, data, SZ_MD2HASH);
if (n != SZ_MD2HASH) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -373,7 +375,7 @@ hw_ostc_device_clock (dc_device_t *abstract, const dc_datetime_t *datetime)
return DC_STATUS_INVALIDARGS;
if (datetime == NULL) {
WARNING ("Invalid parameter specified.");
ERROR (abstract->context, "Invalid parameter specified.");
return DC_STATUS_INVALIDARGS;
}
@ -388,7 +390,7 @@ hw_ostc_device_clock (dc_device_t *abstract, const dc_datetime_t *datetime)
datetime->month, datetime->day, datetime->year - 2000};
int n = serial_write (device->port, packet, sizeof (packet));
if (n != sizeof (packet)) {
WARNING ("Failed to send the data packet.");
ERROR (abstract->context, "Failed to send the data packet.");
return EXITCODE (n);
}
@ -405,12 +407,12 @@ hw_ostc_device_eeprom_read (dc_device_t *abstract, unsigned int bank, unsigned c
return DC_STATUS_INVALIDARGS;
if (bank > 2) {
WARNING ("Invalid eeprom bank specified.");
ERROR (abstract->context, "Invalid eeprom bank specified.");
return DC_STATUS_INVALIDARGS;
}
if (size < SZ_EEPROM) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -423,7 +425,7 @@ hw_ostc_device_eeprom_read (dc_device_t *abstract, unsigned int bank, unsigned c
// Read the answer.
int n = serial_read (device->port, data, SZ_EEPROM);
if (n != SZ_EEPROM) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -440,12 +442,12 @@ hw_ostc_device_eeprom_write (dc_device_t *abstract, unsigned int bank, const uns
return DC_STATUS_INVALIDARGS;
if (bank > 2) {
WARNING ("Invalid eeprom bank specified.");
ERROR (abstract->context, "Invalid eeprom bank specified.");
return DC_STATUS_INVALIDARGS;
}
if (size != SZ_EEPROM) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -493,7 +495,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -505,7 +507,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
// content. Usually the total size is around 4K, which is used as an
// initial guess and expanded when necessary.
if (!dc_buffer_reserve (buffer, 4096)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
} else {
@ -514,7 +516,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
// allocated immediately.
bpp = (format == HW_OSTC_FORMAT_RGB16) ? 2 : 3;
if (!dc_buffer_resize (buffer, WIDTH * HEIGHT * bpp)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
}
@ -543,7 +545,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
unsigned char raw[3] = {0};
int n = serial_read (device->port, raw, 1);
if (n != 1) {
WARNING ("Failed to receive the packet.");
ERROR (abstract->context, "Failed to receive the packet.");
return EXITCODE (n);
}
@ -561,7 +563,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
// Color pixel.
n = serial_read (device->port, raw + 1, 2);
if (n != 2) {
WARNING ("Failed to receive the packet.");
ERROR (abstract->context, "Failed to receive the packet.");
return EXITCODE (n);
}
@ -572,7 +574,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
// Check for buffer overflows.
if (npixels + count > WIDTH * HEIGHT) {
WARNING ("Unexpected number of pixels received.");
ERROR (abstract->context, "Unexpected number of pixels received.");
return DC_STATUS_DATAFORMAT;
}

View File

@ -22,8 +22,8 @@
#include <stdlib.h>
#include <libdivecomputer/hw_ostc.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -68,7 +68,7 @@ parser_is_hw_ostc (dc_parser_t *abstract)
dc_status_t
hw_ostc_parser_create (dc_parser_t **out, unsigned int frog)
hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int frog)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -76,7 +76,7 @@ hw_ostc_parser_create (dc_parser_t **out, unsigned int frog)
// Allocate memory.
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) malloc (sizeof (hw_ostc_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,7 @@
#include <string.h> // memcpy, memcmp
#include <assert.h> // assert
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "mares_common.h"
#include "checksum.h"
#include "array.h"
@ -141,7 +140,7 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[
// Send the command to the device.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -150,26 +149,26 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[
unsigned char echo[PACKETSIZE] = {0};
n = serial_read (device->port, echo, csize);
if (n != csize) {
WARNING ("Failed to receive the echo.");
ERROR (abstract->context, "Failed to receive the echo.");
return EXITCODE (n);
}
// Verify the echo.
if (memcmp (echo, command, csize) != 0) {
WARNING ("Unexpected echo.");
WARNING (abstract->context, "Unexpected echo.");
}
}
// Receive the answer of the device.
n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the header and trailer of the packet.
if (answer[0] != '<' || answer[asize - 1] != '>') {
WARNING ("Unexpected answer header/trailer byte.");
ERROR (abstract->context, "Unexpected answer header/trailer byte.");
return DC_STATUS_PROTOCOL;
}
@ -178,7 +177,7 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[
unsigned char ccrc = checksum_add_uint8 (answer + 1, asize - 4, 0x00);
mares_common_convert_ascii_to_binary (answer + asize - 3, 2, &crc, 1);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -253,7 +252,7 @@ mares_common_device_read (dc_device_t *abstract, unsigned int address, unsigned
dc_status_t
mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned char fingerprint[], const unsigned char data[], dc_dive_callback_t callback, void *userdata)
mares_common_extract_dives (dc_context_t *context, const mares_common_layout_t *layout, const unsigned char fingerprint[], const unsigned char data[], dc_dive_callback_t callback, void *userdata)
{
assert (layout != NULL);
@ -266,7 +265,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
// Get the end of the profile ring buffer.
unsigned int eop = array_uint16_le (data + 0x6B);
if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) {
WARNING ("Ringbuffer pointer out of range.");
ERROR (context, "Ringbuffer pointer out of range.");
return DC_STATUS_DATAFORMAT;
}
@ -277,7 +276,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
layout->rb_profile_end - layout->rb_profile_begin +
layout->rb_freedives_end - layout->rb_freedives_begin);
if (buffer == NULL) {
WARNING ("Out of memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -353,7 +352,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
// something is wrong and an error is returned.
unsigned int length = array_uint16_le (buffer + offset);
if (length != nbytes) {
WARNING ("Calculated and stored size are not equal.");
ERROR (context, "Calculated and stored size are not equal.");
free (buffer);
return DC_STATUS_DATAFORMAT;
}
@ -381,7 +380,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
// equals the number of freedives in the profile data. If
// both values are different, the profile data is incomplete.
if (count != nsamples) {
WARNING ("Unexpected number of freedive sessions.");
ERROR (context, "Unexpected number of freedive sessions.");
free (buffer);
return DC_STATUS_DATAFORMAT;
}

View File

@ -53,7 +53,7 @@ dc_status_t
mares_common_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
dc_status_t
mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned char fingerprint[], const unsigned char data[], dc_dive_callback_t callback, void *userdata);
mares_common_extract_dives (dc_context_t *context, const mares_common_layout_t *layout, const unsigned char fingerprint[], const unsigned char data[], dc_dive_callback_t callback, void *userdata);
#ifdef __cplusplus
}

View File

@ -25,8 +25,8 @@
#include <libdivecomputer/mares_darwin.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "mares_common.h"
#include "array.h"
@ -101,7 +101,7 @@ device_is_mares_darwin (dc_device_t *abstract)
}
dc_status_t
mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int model)
mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -109,7 +109,7 @@ mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int mode
// Allocate memory.
mares_darwin_device_t *device = (mares_darwin_device_t *) malloc (sizeof (mares_darwin_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -127,7 +127,7 @@ mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int mode
// Open the device.
int rc = serial_open (&device->base.port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -135,7 +135,7 @@ mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int mode
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->base.port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->base.port);
free (device);
return DC_STATUS_IO;
@ -143,7 +143,7 @@ mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int mode
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->base.port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->base.port);
free (device);
return DC_STATUS_IO;
@ -152,7 +152,7 @@ mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int mode
// Set the DTR/RTS lines.
if (serial_set_dtr (device->base.port, 1) == -1 ||
serial_set_rts (device->base.port, 1) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->base.port);
free (device);
return DC_STATUS_IO;
@ -216,7 +216,7 @@ mares_darwin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -274,21 +274,21 @@ mares_darwin_extract_dives (dc_device_t *abstract, const unsigned char data[], u
// Get the profile pointer.
unsigned int eop = array_uint16_be (data + 0x8A);
if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) {
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
// Get the logbook index.
unsigned int last = data[0x8C];
if (last >= layout->rb_logbook_count) {
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
// Allocate memory for the largest possible dive.
unsigned char *buffer = malloc (layout->rb_logbook_size + layout->rb_profile_end - layout->rb_profile_begin);
if (buffer == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (abstract->context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -24,8 +24,8 @@
#include <libdivecomputer/mares_darwin.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -67,7 +67,7 @@ parser_is_mares_darwin (dc_parser_t *abstract)
dc_status_t
mares_darwin_parser_create (dc_parser_t **out, unsigned int model)
mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -75,7 +75,7 @@ mares_darwin_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
mares_darwin_parser_t *parser = (mares_darwin_parser_t *) malloc (sizeof (mares_darwin_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/mares_iconhd.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "array.h"
@ -86,9 +86,11 @@ device_is_mares_iconhd (dc_device_t *abstract)
static unsigned int
mares_iconhd_get_model (mares_iconhd_device_t *device, unsigned int model)
{
dc_context_t *context = (device ? ((dc_device_t *) device)->context : NULL);
// Try to correct an invalid model code using the version packet.
if (model == 0xFF) {
WARNING("Invalid model code detected!");
WARNING (context, "Invalid model code detected!");
const unsigned char iconhdnet[] = "Icon AIR";
if (device && memcmp (device->version + 0x46, iconhdnet, sizeof (iconhdnet) - 1) == 0)
model = ICONHDNET;
@ -115,7 +117,7 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -123,13 +125,13 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
unsigned char header[1] = {0};
n = serial_read (device->port, header, sizeof (header));
if (n != sizeof (header)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the header byte.
if (header[0] != ACK) {
WARNING ("Unexpected answer byte.");
ERROR (abstract->context, "Unexpected answer byte.");
return DC_STATUS_PROTOCOL;
}
@ -150,7 +152,7 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
// Read the packet.
n = serial_read (device->port, answer + nbytes, len);
if (n != len) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -167,13 +169,13 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
unsigned char trailer[1] = {0};
n = serial_read (device->port, trailer, sizeof (trailer));
if (n != sizeof (trailer)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the trailer byte.
if (trailer[0] != EOF) {
WARNING ("Unexpected answer byte.");
ERROR (abstract->context, "Unexpected answer byte.");
return DC_STATUS_PROTOCOL;
}
@ -206,7 +208,7 @@ mares_iconhd_read (mares_iconhd_device_t *device, unsigned int address, unsigned
dc_status_t
mares_iconhd_device_open (dc_device_t **out, const char *name)
mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -214,7 +216,7 @@ mares_iconhd_device_open (dc_device_t **out, const char *name)
// Allocate memory.
mares_iconhd_device_t *device = (mares_iconhd_device_t *) malloc (sizeof (mares_iconhd_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -229,7 +231,7 @@ mares_iconhd_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -237,7 +239,7 @@ mares_iconhd_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (256000 8N1).
rc = serial_configure (device->port, BAUDRATE, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -245,7 +247,7 @@ mares_iconhd_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -255,7 +257,7 @@ mares_iconhd_device_open (dc_device_t **out, const char *name)
if (serial_set_dtr (device->port, 0) == -1 ||
serial_set_rts (device->port, 0) == -1)
{
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -333,7 +335,7 @@ mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, MARES_ICONHD_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -378,6 +380,7 @@ dc_status_t
mares_iconhd_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
dc_context_t *context = (abstract ? abstract->context : NULL);
if (abstract && !device_is_mares_iconhd (abstract))
return DC_STATUS_INVALIDARGS;
@ -402,14 +405,14 @@ mares_iconhd_extract_dives (dc_device_t *abstract, const unsigned char data[], u
break;
}
if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) {
WARNING ("Ringbuffer pointer out of range.");
ERROR (context, "Ringbuffer pointer out of range.");
return DC_STATUS_DATAFORMAT;
}
// Make the ringbuffer linear, to avoid having to deal with the wrap point.
unsigned char *buffer = (unsigned char *) malloc (RB_PROFILE_END - RB_PROFILE_BEGIN);
if (buffer == NULL) {
WARNING ("Out of memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -445,7 +448,7 @@ mares_iconhd_extract_dives (dc_device_t *abstract, const unsigned char data[], u
if (length == 0 || length == 0xFFFFFFFF)
break;
if (length != nbytes) {
WARNING ("Calculated and stored size are not equal.");
ERROR (context, "Calculated and stored size are not equal.");
free (buffer);
return DC_STATUS_DATAFORMAT;
}

View File

@ -22,8 +22,8 @@
#include <stdlib.h>
#include <libdivecomputer/mares_iconhd.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -64,7 +64,7 @@ parser_is_mares_iconhd (dc_parser_t *abstract)
dc_status_t
mares_iconhd_parser_create (dc_parser_t **out, unsigned int model)
mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -72,7 +72,7 @@ mares_iconhd_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) malloc (sizeof (mares_iconhd_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/mares_nemo.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "mares_common.h"
#include "serial.h"
@ -96,7 +96,7 @@ device_is_mares_nemo (dc_device_t *abstract)
dc_status_t
mares_nemo_device_open (dc_device_t **out, const char *name)
mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -104,7 +104,7 @@ mares_nemo_device_open (dc_device_t **out, const char *name)
// Allocate memory.
mares_nemo_device_t *device = (mares_nemo_device_t *) malloc (sizeof (mares_nemo_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -118,7 +118,7 @@ mares_nemo_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -126,7 +126,7 @@ mares_nemo_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -134,7 +134,7 @@ mares_nemo_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -143,7 +143,7 @@ mares_nemo_device_open (dc_device_t **out, const char *name)
// Set the DTR/RTS lines.
if (serial_set_dtr (device->port, 1) == -1 ||
serial_set_rts (device->port, 1) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -204,7 +204,7 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, MEMORYSIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -227,7 +227,7 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
for (unsigned int i = 0; i < 20;) {
int n = serial_read (device->port, &header, 1);
if (n != 1) {
WARNING ("Failed to receive the header.");
ERROR (abstract->context, "Failed to receive the header.");
return EXITCODE (n);
}
if (header == 0xEE) {
@ -247,7 +247,7 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char packet[(PACKETSIZE + 1) * 2] = {0};
int n = serial_read (device->port, packet, sizeof (packet));
if (n != sizeof (packet)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -259,20 +259,20 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
if (crc1 == ccrc1 && crc2 == ccrc2) {
// Both packets have a correct checksum.
if (memcmp (packet, packet + PACKETSIZE + 1, PACKETSIZE) != 0) {
WARNING ("Both packets are not equal.");
ERROR (abstract->context, "Both packets are not equal.");
return DC_STATUS_PROTOCOL;
}
dc_buffer_append (buffer, packet, PACKETSIZE);
} else if (crc1 == ccrc1) {
// Only the first packet has a correct checksum.
WARNING ("Only the first packet has a correct checksum.");
WARNING (abstract->context, "Only the first packet has a correct checksum.");
dc_buffer_append (buffer, packet, PACKETSIZE);
} else if (crc2 == ccrc2) {
// Only the second packet has a correct checksum.
WARNING ("Only the second packet has a correct checksum.");
WARNING (abstract->context, "Only the second packet has a correct checksum.");
dc_buffer_append (buffer, packet + PACKETSIZE + 1, PACKETSIZE);
} else {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -327,6 +327,7 @@ mares_nemo_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
if (size < PACKETSIZE)
return DC_STATUS_DATAFORMAT;
dc_context_t *context = (abstract ? abstract->context : NULL);
unsigned char *fingerprint = (device ? device->fingerprint : NULL);
const mares_common_layout_t *layout = NULL;
@ -346,5 +347,5 @@ mares_nemo_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
if (size < layout->memsize)
return DC_STATUS_DATAFORMAT;
return mares_common_extract_dives (layout, fingerprint, data, callback, userdata);
return mares_common_extract_dives (context, layout, fingerprint, data, callback, userdata);
}

View File

@ -24,8 +24,8 @@
#include <libdivecomputer/mares_nemo.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -79,7 +79,7 @@ parser_is_mares_nemo (dc_parser_t *abstract)
dc_status_t
mares_nemo_parser_create (dc_parser_t **out, unsigned int model)
mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -87,7 +87,7 @@ mares_nemo_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) malloc (sizeof (mares_nemo_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -433,7 +433,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c
// in the summary entry). If both values are different, the
// the profile data is probably incorrect.
if (count != n) {
WARNING ("Unexpected number of samples.");
ERROR (abstract->context, "Unexpected number of samples.");
return DC_STATUS_DATAFORMAT;
}
} else {

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/mares_puck.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "mares_common.h"
#include "serial.h"
@ -94,7 +94,7 @@ device_is_mares_puck (dc_device_t *abstract)
dc_status_t
mares_puck_device_open (dc_device_t **out, const char *name)
mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -102,7 +102,7 @@ mares_puck_device_open (dc_device_t **out, const char *name)
// Allocate memory.
mares_puck_device_t *device = (mares_puck_device_t *) malloc (sizeof (mares_puck_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -116,7 +116,7 @@ mares_puck_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->base.port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -124,7 +124,7 @@ mares_puck_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (38400 8N1).
rc = serial_configure (device->base.port, 38400, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->base.port);
free (device);
return DC_STATUS_IO;
@ -132,7 +132,7 @@ mares_puck_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->base.port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->base.port);
free (device);
return DC_STATUS_IO;
@ -141,7 +141,7 @@ mares_puck_device_open (dc_device_t **out, const char *name)
// Clear the DTR/RTS lines.
if (serial_set_dtr (device->base.port, 0) == -1 ||
serial_set_rts (device->base.port, 0) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->base.port);
free (device);
return DC_STATUS_IO;
@ -227,7 +227,7 @@ mares_puck_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -261,7 +261,7 @@ mares_puck_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v
devinfo.serial = array_uint16_be (data + 8);
device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo);
rc = mares_common_extract_dives (device->layout, device->fingerprint, data, callback, userdata);
rc = mares_common_extract_dives (abstract->context, device->layout, device->fingerprint, data, callback, userdata);
dc_buffer_free (buffer);
@ -280,6 +280,7 @@ mares_puck_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
if (size < PACKETSIZE)
return DC_STATUS_DATAFORMAT;
dc_context_t *context = (abstract ? abstract->context : NULL);
unsigned char *fingerprint = (device ? device->fingerprint : NULL);
const mares_common_layout_t *layout = NULL;
@ -302,5 +303,5 @@ mares_puck_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
if (size < layout->memsize)
return DC_STATUS_DATAFORMAT;
return mares_common_extract_dives (layout, fingerprint, data, callback, userdata);
return mares_common_extract_dives (context, layout, fingerprint, data, callback, userdata);
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/oceanic_atom2.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "oceanic_common.h"
#include "serial.h"
@ -226,7 +226,7 @@ oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -234,13 +234,13 @@ oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[
unsigned char response = 0;
n = serial_read (device->port, &response, 1);
if (n != 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the response of the dive computer.
if (response != ack) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -251,6 +251,8 @@ oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[
static dc_status_t
oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the device. If the device responds with an
// ACK byte, the command was received successfully and the answer
// (if any) follows after the ACK byte. If the device responds with
@ -276,7 +278,7 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm
// Receive the answer of the dive computer.
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -284,7 +286,7 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm
unsigned char crc = answer[asize - 1];
unsigned char ccrc = checksum_add_uint8 (answer, asize - 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
}
@ -307,7 +309,7 @@ oceanic_atom2_quit (oceanic_atom2_device_t *device)
dc_status_t
oceanic_atom2_device_open (dc_device_t **out, const char *name)
oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -315,7 +317,7 @@ oceanic_atom2_device_open (dc_device_t **out, const char *name)
// Allocate memory.
oceanic_atom2_device_t *device = (oceanic_atom2_device_t *) malloc (sizeof (oceanic_atom2_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -329,7 +331,7 @@ oceanic_atom2_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -337,7 +339,7 @@ oceanic_atom2_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (38400 8N1).
rc = serial_configure (device->port, 38400, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -345,7 +347,7 @@ oceanic_atom2_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000 ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;

View File

@ -23,9 +23,9 @@
#include <libdivecomputer/oceanic_atom2.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "oceanic_common.h"
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -88,7 +88,7 @@ parser_is_oceanic_atom2 (dc_parser_t *abstract)
dc_status_t
oceanic_atom2_parser_create (dc_parser_t **out, unsigned int model)
oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -96,7 +96,7 @@ oceanic_atom2_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) malloc (sizeof (oceanic_atom2_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,9 +23,8 @@
#include <stdlib.h> // malloc, free
#include <assert.h> // assert
#include <libdivecomputer/utils.h>
#include "oceanic_common.h"
#include "context-private.h"
#include "device-private.h"
#include "ringbuffer.h"
#include "array.h"
@ -154,7 +153,7 @@ oceanic_common_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -185,7 +184,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned char id[PAGESIZE] = {0};
dc_status_t rc = dc_device_read (abstract, layout->cf_devinfo, id, sizeof (id));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read device id.");
ERROR (abstract->context, "Failed to read the memory page.");
return rc;
}
@ -207,7 +206,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned char pointers[PAGESIZE] = {0};
rc = dc_device_read (abstract, layout->cf_pointers, pointers, sizeof (pointers));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read pointers.");
ERROR (abstract->context, "Failed to read the memory page.");
return rc;
}
@ -377,7 +376,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
// This appears to happen on some devices, and we attempt to
// fix this here.
if (array_isequal (logbooks + current, layout->rb_logbook_entry_size, 0xFF)) {
WARNING("Uninitialized logbook entries detected!");
WARNING (abstract->context, "Uninitialized logbook entries detected!");
begin = current + layout->rb_logbook_entry_size;
abort = 1;
break;
@ -395,7 +394,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
rb_entry_last < layout->rb_profile_begin ||
rb_entry_last >= layout->rb_profile_end)
{
WARNING("Invalid ringbuffer pointer detected!");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
status = DC_STATUS_DATAFORMAT;
begin = current + layout->rb_logbook_entry_size;
abort = 1;
@ -409,13 +408,13 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
// Skip gaps between the profiles.
unsigned int gap = 0;
if (previous && rb_entry_end != previous) {
WARNING ("Profiles are not continuous.");
WARNING (abstract->context, "Profiles are not continuous.");
gap = RB_PROFILE_DISTANCE (rb_entry_end, previous, layout);
}
// Make sure the profile size is valid.
if (rb_entry_size + gap > remaining) {
WARNING ("Unexpected profile size.");
WARNING (abstract->context, "Unexpected profile size.");
begin = current + layout->rb_logbook_entry_size;
abort = 1;
break;
@ -490,7 +489,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
// Skip gaps between the profiles.
unsigned int gap = 0;
if (rb_entry_end != previous) {
WARNING ("Profiles are not continuous.");
WARNING (abstract->context, "Profiles are not continuous.");
gap = RB_PROFILE_DISTANCE (rb_entry_end, previous, layout);
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/oceanic_veo250.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "oceanic_common.h"
#include "serial.h"
@ -102,7 +102,7 @@ oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char comman
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -110,13 +110,13 @@ oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char comman
unsigned char response = NAK;
n = serial_read (device->port, &response, 1);
if (n != 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the response of the dive computer.
if (response != ACK) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -127,6 +127,8 @@ oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char comman
static dc_status_t
oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the device. If the device responds with an
// ACK byte, the command was received successfully and the answer
// (if any) follows after the ACK byte. If the device responds with
@ -150,13 +152,13 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co
// Receive the answer of the dive computer.
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the last byte of the answer.
if (answer[asize - 1] != NAK) {
WARNING ("Unexpected answer byte.");
ERROR (abstract->context, "Unexpected answer byte.");
return DC_STATUS_PROTOCOL;
}
@ -167,11 +169,13 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co
static dc_status_t
oceanic_veo250_init (oceanic_veo250_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the dive computer.
unsigned char command[2] = {0x55, 0x00};
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -179,7 +183,7 @@ oceanic_veo250_init (oceanic_veo250_device_t *device)
unsigned char answer[13] = {0};
n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
if (n == 0)
return DC_STATUS_SUCCESS;
return EXITCODE (n);
@ -190,7 +194,7 @@ oceanic_veo250_init (oceanic_veo250_device_t *device)
0x50, 0x50, 0x53, 0x2D, 0x2D, 0x4F, 0x4B,
0x5F, 0x56, 0x32, 0x2E, 0x30, 0x30};
if (memcmp (answer, response, sizeof (response)) != 0) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -201,11 +205,13 @@ oceanic_veo250_init (oceanic_veo250_device_t *device)
static dc_status_t
oceanic_veo250_quit (oceanic_veo250_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the dive computer.
unsigned char command[2] = {0x98, 0x00};
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -214,7 +220,7 @@ oceanic_veo250_quit (oceanic_veo250_device_t *device)
dc_status_t
oceanic_veo250_device_open (dc_device_t **out, const char *name)
oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -222,7 +228,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name)
// Allocate memory.
oceanic_veo250_device_t *device = (oceanic_veo250_device_t *) malloc (sizeof (oceanic_veo250_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -241,7 +247,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -249,7 +255,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -257,7 +263,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000 ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -266,7 +272,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name)
// Set the DTR and RTS lines.
if (serial_set_dtr (device->port, 1) == -1 ||
serial_set_rts (device->port, 1) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -348,7 +354,7 @@ oceanic_veo250_device_keepalive (dc_device_t *abstract)
// Verify the answer.
if (answer[0] != NAK) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -377,7 +383,7 @@ oceanic_veo250_device_version (dc_device_t *abstract, unsigned char data[], unsi
unsigned char crc = answer[PAGESIZE];
unsigned char ccrc = checksum_add_uint8 (answer, PAGESIZE, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -431,7 +437,7 @@ oceanic_veo250_device_read (dc_device_t *abstract, unsigned int address, unsigne
unsigned char crc = answer[offset + PAGESIZE];
unsigned char ccrc = checksum_add_uint8 (answer + offset, PAGESIZE, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}

View File

@ -23,9 +23,9 @@
#include <libdivecomputer/oceanic_veo250.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "oceanic_common.h"
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -67,7 +67,7 @@ parser_is_oceanic_veo250 (dc_parser_t *abstract)
dc_status_t
oceanic_veo250_parser_create (dc_parser_t **out, unsigned int model)
oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -75,7 +75,7 @@ oceanic_veo250_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) malloc (sizeof (oceanic_veo250_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/oceanic_vtpro.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "oceanic_common.h"
#include "serial.h"
@ -114,7 +114,7 @@ oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -122,13 +122,13 @@ oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[
unsigned char response = NAK;
n = serial_read (device->port, &response, 1);
if (n != 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the response of the dive computer.
if (response != ACK) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -139,6 +139,8 @@ oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[
static dc_status_t
oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the device. If the device responds with an
// ACK byte, the command was received successfully and the answer
// (if any) follows after the ACK byte. If the device responds with
@ -159,7 +161,7 @@ oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char comm
// Receive the answer of the dive computer.
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -170,11 +172,13 @@ oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char comm
static dc_status_t
oceanic_vtpro_init (oceanic_vtpro_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the dive computer.
unsigned char command[2] = {0xAA, 0x00};
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -182,7 +186,7 @@ oceanic_vtpro_init (oceanic_vtpro_device_t *device)
unsigned char answer[13] = {0};
n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -191,7 +195,7 @@ oceanic_vtpro_init (oceanic_vtpro_device_t *device)
0x4D, 0x4F, 0x44, 0x2D, 0x2D, 0x4F, 0x4B,
0x5F, 0x56, 0x32, 0x2E, 0x30, 0x30};
if (memcmp (answer, response, sizeof (response)) != 0) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -202,6 +206,8 @@ oceanic_vtpro_init (oceanic_vtpro_device_t *device)
static dc_status_t
oceanic_vtpro_quit (oceanic_vtpro_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the dive computer.
unsigned char answer[1] = {0};
unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00};
@ -211,7 +217,7 @@ oceanic_vtpro_quit (oceanic_vtpro_device_t *device)
// Verify the last byte of the answer.
if (answer[0] != END) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -222,6 +228,8 @@ oceanic_vtpro_quit (oceanic_vtpro_device_t *device)
static dc_status_t
oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the dive computer.
// The timeout is temporary increased, because the
// device needs approximately 6 seconds to respond.
@ -235,7 +243,7 @@ oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
// Verify the last byte of the answer.
if (answer[1] != 0x00) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -244,7 +252,7 @@ oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
dc_status_t
oceanic_vtpro_device_open (dc_device_t **out, const char *name)
oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -252,7 +260,7 @@ oceanic_vtpro_device_open (dc_device_t **out, const char *name)
// Allocate memory.
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t *) malloc (sizeof (oceanic_vtpro_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -269,7 +277,7 @@ oceanic_vtpro_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -277,7 +285,7 @@ oceanic_vtpro_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -285,7 +293,7 @@ oceanic_vtpro_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000 ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -294,7 +302,7 @@ oceanic_vtpro_device_open (dc_device_t **out, const char *name)
// Set the DTR and RTS lines.
if (serial_set_dtr (device->port, 1) == -1 ||
serial_set_rts (device->port, 1) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -387,7 +395,7 @@ oceanic_vtpro_device_keepalive (dc_device_t *abstract)
// Verify the last byte of the answer.
if (answer[0] != END) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -420,7 +428,7 @@ oceanic_vtpro_device_version (dc_device_t *abstract, unsigned char data[], unsig
unsigned char crc = ans[PAGESIZE / 2];
unsigned char ccrc = checksum_add_uint4 (ans, PAGESIZE / 2, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -438,13 +446,13 @@ oceanic_vtpro_device_version (dc_device_t *abstract, unsigned char data[], unsig
unsigned char crc = answer[PAGESIZE / 2];
unsigned char ccrc = checksum_add_uint4 (answer, PAGESIZE / 2, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
// Verify the last byte of the answer.
if (answer[PAGESIZE / 2 + 1] != END) {
WARNING ("Unexpected answer byte.");
ERROR (abstract->context, "Unexpected answer byte.");
return DC_STATUS_PROTOCOL;
}
@ -498,7 +506,7 @@ oceanic_vtpro_device_read (dc_device_t *abstract, unsigned int address, unsigned
unsigned char crc = answer[offset + PAGESIZE];
unsigned char ccrc = checksum_add_uint8 (answer + offset, PAGESIZE, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}

View File

@ -23,9 +23,9 @@
#include <libdivecomputer/oceanic_vtpro.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "oceanic_common.h"
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -66,7 +66,7 @@ parser_is_oceanic_vtpro (dc_parser_t *abstract)
dc_status_t
oceanic_vtpro_parser_create (dc_parser_t **out)
oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -74,7 +74,7 @@ oceanic_vtpro_parser_create (dc_parser_t **out)
// Allocate memory.
oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) malloc (sizeof (oceanic_vtpro_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -256,7 +256,7 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
// Get the current timestamp.
unsigned int current = bcd2dec (data[offset + 1] & 0x0F) * 60 + bcd2dec (data[offset + 0]);
if (current < timestamp) {
WARNING ("Timestamp moved backwards.");
ERROR (abstract->context, "Timestamp moved backwards.");
return DC_STATUS_DATAFORMAT;
}
@ -294,11 +294,11 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
if (interval) {
if (current > timestamp + 1) {
WARNING ("Unexpected timestamp jump.");
ERROR (abstract->context, "Unexpected timestamp jump.");
return DC_STATUS_DATAFORMAT;
}
if (i >= count) {
WARNING ("Unexpected number of samples with the same timestamp.");
ERROR (abstract->context, "Unexpected number of samples with the same timestamp.");
return DC_STATUS_DATAFORMAT;
}
}

View File

@ -22,6 +22,7 @@
#ifndef PARSER_PRIVATE_H
#define PARSER_PRIVATE_H
#include <libdivecomputer/context.h>
#include <libdivecomputer/parser.h>
#ifdef __cplusplus
@ -35,6 +36,7 @@ typedef struct parser_backend_t parser_backend_t;
struct dc_parser_t {
const parser_backend_t *backend;
dc_context_t *context;
const unsigned char *data;
unsigned int size;
};

View File

@ -43,70 +43,72 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device)
if (out == NULL || device == NULL)
return DC_STATUS_INVALIDARGS;
dc_context_t *context = device->context;
switch (dc_device_get_type (device)) {
case DC_FAMILY_SUUNTO_SOLUTION:
rc = suunto_solution_parser_create (&parser);
rc = suunto_solution_parser_create (&parser, context);
break;
case DC_FAMILY_SUUNTO_EON:
rc = suunto_eon_parser_create (&parser, 0);
rc = suunto_eon_parser_create (&parser, context, 0);
break;
case DC_FAMILY_SUUNTO_VYPER:
if (device->devinfo.model == 0x01)
rc = suunto_eon_parser_create (&parser, 1);
rc = suunto_eon_parser_create (&parser, context, 1);
else
rc = suunto_vyper_parser_create (&parser);
rc = suunto_vyper_parser_create (&parser, context);
break;
case DC_FAMILY_SUUNTO_VYPER2:
case DC_FAMILY_SUUNTO_D9:
rc = suunto_d9_parser_create (&parser, device->devinfo.model);
rc = suunto_d9_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_UWATEC_ALADIN:
case DC_FAMILY_UWATEC_MEMOMOUSE:
rc = uwatec_memomouse_parser_create (&parser, device->clock.devtime, device->clock.systime);
rc = uwatec_memomouse_parser_create (&parser, context, device->clock.devtime, device->clock.systime);
break;
case DC_FAMILY_UWATEC_SMART:
rc = uwatec_smart_parser_create (&parser, device->devinfo.model, device->clock.devtime, device->clock.systime);
rc = uwatec_smart_parser_create (&parser, context, device->devinfo.model, device->clock.devtime, device->clock.systime);
break;
case DC_FAMILY_REEFNET_SENSUS:
rc = reefnet_sensus_parser_create (&parser, device->clock.devtime, device->clock.systime);
rc = reefnet_sensus_parser_create (&parser, context, device->clock.devtime, device->clock.systime);
break;
case DC_FAMILY_REEFNET_SENSUSPRO:
rc = reefnet_sensuspro_parser_create (&parser, device->clock.devtime, device->clock.systime);
rc = reefnet_sensuspro_parser_create (&parser, context, device->clock.devtime, device->clock.systime);
break;
case DC_FAMILY_REEFNET_SENSUSULTRA:
rc = reefnet_sensusultra_parser_create (&parser, device->clock.devtime, device->clock.systime);
rc = reefnet_sensusultra_parser_create (&parser, context, device->clock.devtime, device->clock.systime);
break;
case DC_FAMILY_OCEANIC_VTPRO:
rc = oceanic_vtpro_parser_create (&parser);
rc = oceanic_vtpro_parser_create (&parser, context);
break;
case DC_FAMILY_OCEANIC_VEO250:
rc = oceanic_veo250_parser_create (&parser, device->devinfo.model);
rc = oceanic_veo250_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_OCEANIC_ATOM2:
rc = oceanic_atom2_parser_create (&parser, device->devinfo.model);
rc = oceanic_atom2_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_MARES_NEMO:
case DC_FAMILY_MARES_PUCK:
rc = mares_nemo_parser_create (&parser, device->devinfo.model);
rc = mares_nemo_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_MARES_DARWIN:
rc = mares_darwin_parser_create (&parser, device->devinfo.model);
rc = mares_darwin_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_MARES_ICONHD:
rc = mares_iconhd_parser_create (&parser, device->devinfo.model);
rc = mares_iconhd_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_HW_OSTC:
rc = hw_ostc_parser_create (&parser, 0);
rc = hw_ostc_parser_create (&parser, context, 0);
break;
case DC_FAMILY_HW_FROG:
rc = hw_ostc_parser_create (&parser, 1);
rc = hw_ostc_parser_create (&parser, context, 1);
break;
case DC_FAMILY_CRESSI_EDY:
case DC_FAMILY_ZEAGLE_N2ITION3:
rc = cressi_edy_parser_create (&parser, device->devinfo.model);
rc = cressi_edy_parser_create (&parser, context, device->devinfo.model);
break;
case DC_FAMILY_ATOMICS_COBALT:
rc = atomics_cobalt_parser_create (&parser);
rc = atomics_cobalt_parser_create (&parser, context);
break;
default:
return DC_STATUS_INVALIDARGS;
@ -122,6 +124,7 @@ void
parser_init (dc_parser_t *parser, const parser_backend_t *backend)
{
parser->backend = backend;
parser->context = NULL;
parser->data = NULL;
parser->size = 0;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/reefnet_sensus.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -74,11 +74,13 @@ device_is_reefnet_sensus (dc_device_t *abstract)
static dc_status_t
reefnet_sensus_cancel (reefnet_sensus_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the device.
unsigned char command = 0x00;
int n = serial_write (device->port, &command, 1);
if (n != 1) {
WARNING ("Failed to send the cancel command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -90,7 +92,7 @@ reefnet_sensus_cancel (reefnet_sensus_device_t *device)
dc_status_t
reefnet_sensus_device_open (dc_device_t **out, const char *name)
reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -98,7 +100,7 @@ reefnet_sensus_device_open (dc_device_t **out, const char *name)
// Allocate memory.
reefnet_sensus_device_t *device = (reefnet_sensus_device_t *) malloc (sizeof (reefnet_sensus_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -116,7 +118,7 @@ reefnet_sensus_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -124,7 +126,7 @@ reefnet_sensus_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (19200 8N1).
rc = serial_configure (device->port, 19200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -132,7 +134,7 @@ reefnet_sensus_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000 ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -182,7 +184,7 @@ reefnet_sensus_device_get_handshake (dc_device_t *abstract, unsigned char data[]
return DC_STATUS_INVALIDARGS;
if (size < REEFNET_SENSUS_HANDSHAKE_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -229,11 +231,13 @@ reefnet_sensus_device_set_fingerprint (dc_device_t *abstract, const unsigned cha
static dc_status_t
reefnet_sensus_handshake (reefnet_sensus_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Send the command to the device.
unsigned char command = 0x0A;
int n = serial_write (device->port, &command, 1);
if (n != 1) {
WARNING ("Failed to send the handshake command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -241,13 +245,13 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device)
unsigned char handshake[REEFNET_SENSUS_HANDSHAKE_SIZE + 2] = {0};
n = serial_read (device->port, handshake, sizeof (handshake));
if (n != sizeof (handshake)) {
WARNING ("Failed to receive the handshake.");
ERROR (abstract->context, "Failed to receive the handshake.");
return EXITCODE (n);
}
// Verify the header of the packet.
if (handshake[0] != 'O' || handshake[1] != 'K') {
WARNING ("Unexpected answer header.");
ERROR (abstract->context, "Unexpected answer header.");
return DC_STATUS_PROTOCOL;
}
@ -294,7 +298,7 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUS_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -312,7 +316,7 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char command = 0x40;
int n = serial_write (device->port, &command, 1);
if (n != 1) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -329,7 +333,7 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
n = serial_read (device->port, answer + nbytes, len);
if (n != len) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -343,7 +347,7 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Verify the headers of the package.
if (memcmp (answer, "DATA", 4) != 0 ||
memcmp (answer + sizeof (answer) - 3, "END", 3) != 0) {
WARNING ("Unexpected answer start or end byte(s).");
ERROR (abstract->context, "Unexpected answer start or end byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -351,7 +355,7 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned short crc = array_uint16_le (answer + 4 + REEFNET_SENSUS_MEMORY_SIZE);
unsigned short ccrc = checksum_add_uint16 (answer + 4, REEFNET_SENSUS_MEMORY_SIZE, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -390,6 +394,7 @@ dc_status_t
reefnet_sensus_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
dc_context_t *context = (abstract ? abstract->context : NULL);
if (abstract && !device_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
@ -435,7 +440,7 @@ reefnet_sensus_extract_dives (dc_device_t *abstract, const unsigned char data[],
// Report an error if no end of dive was found.
if (!found) {
WARNING ("No end of dive found.");
ERROR (context, "No end of dive found.");
return DC_STATUS_DATAFORMAT;
}

View File

@ -23,8 +23,8 @@
#include <libdivecomputer/reefnet_sensus.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -73,7 +73,7 @@ parser_is_reefnet_sensus (dc_parser_t *abstract)
dc_status_t
reefnet_sensus_parser_create (dc_parser_t **out, unsigned int devtime, dc_ticks_t systime)
reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -81,7 +81,7 @@ reefnet_sensus_parser_create (dc_parser_t **out, unsigned int devtime, dc_ticks_
// Allocate memory.
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t *) malloc (sizeof (reefnet_sensus_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/reefnet_sensuspro.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -71,7 +71,7 @@ device_is_reefnet_sensuspro (dc_device_t *abstract)
dc_status_t
reefnet_sensuspro_device_open (dc_device_t **out, const char *name)
reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -79,7 +79,7 @@ reefnet_sensuspro_device_open (dc_device_t **out, const char *name)
// Allocate memory.
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t *) malloc (sizeof (reefnet_sensuspro_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -96,7 +96,7 @@ reefnet_sensuspro_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -104,7 +104,7 @@ reefnet_sensuspro_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (19200 8N1).
rc = serial_configure (device->port, 19200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -112,7 +112,7 @@ reefnet_sensuspro_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -157,7 +157,7 @@ reefnet_sensuspro_device_get_handshake (dc_device_t *abstract, unsigned char dat
return DC_STATUS_INVALIDARGS;
if (size < REEFNET_SENSUSPRO_HANDSHAKE_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -204,6 +204,8 @@ reefnet_sensuspro_device_set_fingerprint (dc_device_t *abstract, const unsigned
static dc_status_t
reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Assert a break condition.
serial_set_break (device->port, 1);
@ -211,7 +213,7 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
unsigned char handshake[REEFNET_SENSUSPRO_HANDSHAKE_SIZE + 2] = {0};
int rc = serial_read (device->port, handshake, sizeof (handshake));
if (rc != sizeof (handshake)) {
WARNING ("Failed to receive the handshake.");
ERROR (abstract->context, "Failed to receive the handshake.");
return EXITCODE (rc);
}
@ -222,7 +224,7 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
unsigned short crc = array_uint16_le (handshake + REEFNET_SENSUSPRO_HANDSHAKE_SIZE);
unsigned short ccrc = checksum_crc_ccitt_uint16 (handshake, REEFNET_SENSUSPRO_HANDSHAKE_SIZE);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -255,6 +257,8 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
static dc_status_t
reefnet_sensuspro_send (reefnet_sensuspro_device_t *device, unsigned char command)
{
dc_device_t *abstract = (dc_device_t *) device;
// Wake-up the device.
dc_status_t rc = reefnet_sensuspro_handshake (device);
if (rc != DC_STATUS_SUCCESS)
@ -263,7 +267,7 @@ reefnet_sensuspro_send (reefnet_sensuspro_device_t *device, unsigned char comman
// Send the instruction code to the device.
int n = serial_write (device->port, &command, 1);
if (n != 1) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -282,7 +286,7 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUSPRO_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -305,7 +309,7 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
int n = serial_read (device->port, answer + nbytes, len);
if (n != len) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -319,7 +323,7 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned short crc = array_uint16_le (answer + REEFNET_SENSUSPRO_MEMORY_SIZE);
unsigned short ccrc = checksum_crc_ccitt_uint16 (answer, REEFNET_SENSUSPRO_MEMORY_SIZE);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -374,7 +378,7 @@ reefnet_sensuspro_device_write_interval (dc_device_t *abstract, unsigned char in
int n = serial_write (device->port, &interval, 1);
if (n != 1) {
WARNING ("Failed to send the new value.");
ERROR (abstract->context, "Failed to send the data packet.");
return EXITCODE (n);
}

View File

@ -24,8 +24,8 @@
#include <libdivecomputer/reefnet_sensuspro.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -72,7 +72,7 @@ parser_is_reefnet_sensuspro (dc_parser_t *abstract)
dc_status_t
reefnet_sensuspro_parser_create (dc_parser_t **out, unsigned int devtime, dc_ticks_t systime)
reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -80,7 +80,7 @@ reefnet_sensuspro_parser_create (dc_parser_t **out, unsigned int devtime, dc_tic
// Allocate memory.
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t *) malloc (sizeof (reefnet_sensuspro_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/reefnet_sensusultra.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -77,7 +77,7 @@ device_is_reefnet_sensusultra (dc_device_t *abstract)
dc_status_t
reefnet_sensusultra_device_open (dc_device_t **out, const char *name)
reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -85,7 +85,7 @@ reefnet_sensusultra_device_open (dc_device_t **out, const char *name)
// Allocate memory.
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t *) malloc (sizeof (reefnet_sensusultra_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -103,7 +103,7 @@ reefnet_sensusultra_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -111,7 +111,7 @@ reefnet_sensusultra_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (115200 8N1).
rc = serial_configure (device->port, 115200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -119,7 +119,7 @@ reefnet_sensusultra_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -164,7 +164,7 @@ reefnet_sensusultra_device_get_handshake (dc_device_t *abstract, unsigned char d
return DC_STATUS_INVALIDARGS;
if (size < REEFNET_SENSUSULTRA_HANDSHAKE_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -225,24 +225,26 @@ reefnet_sensusultra_device_set_fingerprint (dc_device_t *abstract, const unsigne
static dc_status_t
reefnet_sensusultra_send_uchar (reefnet_sensusultra_device_t *device, unsigned char value)
{
dc_device_t *abstract = (dc_device_t *) device;
// Wait for the prompt byte.
unsigned char prompt = 0;
int rc = serial_read (device->port, &prompt, 1);
if (rc != 1) {
WARNING ("Failed to receive the prompt byte");
ERROR (abstract->context, "Failed to receive the prompt byte");
return EXITCODE (rc);
}
// Verify the prompt byte.
if (prompt != PROMPT) {
WARNING ("Unexpected answer data.");
ERROR (abstract->context, "Unexpected answer data.");
return DC_STATUS_PROTOCOL;
}
// Send the value to the device.
rc = serial_write (device->port, &value, 1);
if (rc != 1) {
WARNING ("Failed to send the value.");
ERROR (abstract->context, "Failed to send the value.");
return EXITCODE (rc);
}
@ -282,7 +284,7 @@ reefnet_sensusultra_packet (reefnet_sensusultra_device_t *device, unsigned char
// Receive the data packet.
int rc = serial_read (device->port, data, size);
if (rc != size) {
WARNING ("Failed to receive the packet.");
ERROR (abstract->context, "Failed to receive the packet.");
return EXITCODE (rc);
}
@ -290,7 +292,7 @@ reefnet_sensusultra_packet (reefnet_sensusultra_device_t *device, unsigned char
unsigned short crc = array_uint16_le (data + size - 2);
unsigned short ccrc = checksum_crc_ccitt_uint16 (data + header, size - header - 2);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -339,6 +341,8 @@ reefnet_sensusultra_handshake (reefnet_sensusultra_device_t *device, unsigned sh
static dc_status_t
reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *data, unsigned int size, unsigned int pagenum)
{
dc_device_t *abstract = (dc_device_t *) device;
assert (size >= REEFNET_SENSUSULTRA_PACKET_SIZE + 4);
unsigned int nretries = 0;
@ -362,7 +366,7 @@ reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *d
// Verify the page number.
unsigned int page = array_uint16_le (data);
if (page != pagenum) {
WARNING ("Unexpected page number.");
ERROR (abstract->context, "Unexpected page number.");
return DC_STATUS_PROTOCOL;
}
@ -413,7 +417,7 @@ reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -442,7 +446,7 @@ reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Prepend the packet to the buffer.
if (!dc_buffer_prepend (buffer, packet + 2, REEFNET_SENSUSULTRA_PACKET_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -468,7 +472,7 @@ reefnet_sensusultra_device_read_user (dc_device_t *abstract, unsigned char *data
return DC_STATUS_INVALIDARGS;
if (size < REEFNET_SENSUSULTRA_MEMORY_USER_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -511,7 +515,7 @@ reefnet_sensusultra_device_write_user (dc_device_t *abstract, const unsigned cha
return DC_STATUS_INVALIDARGS;
if (size < REEFNET_SENSUSULTRA_MEMORY_USER_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -608,7 +612,7 @@ reefnet_sensusultra_device_sense (dc_device_t *abstract, unsigned char *data, un
return DC_STATUS_INVALIDARGS;
if (size < REEFNET_SENSUSULTRA_SENSE_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -709,7 +713,7 @@ reefnet_sensusultra_device_foreach (dc_device_t *abstract, dc_dive_callback_t ca
dc_buffer_t *buffer = dc_buffer_new (REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE);
if (buffer == NULL) {
WARNING ("Memory allocation error.");
ERROR (abstract->context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -750,7 +754,7 @@ reefnet_sensusultra_device_foreach (dc_device_t *abstract, dc_dive_callback_t ca
// Prepend the packet to the buffer.
if (!dc_buffer_prepend (buffer, packet + 2, REEFNET_SENSUSULTRA_PACKET_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}

View File

@ -24,8 +24,8 @@
#include <libdivecomputer/reefnet_sensusultra.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -72,7 +72,7 @@ parser_is_reefnet_sensusultra (dc_parser_t *abstract)
dc_status_t
reefnet_sensusultra_parser_create (dc_parser_t **out, unsigned int devtime, dc_ticks_t systime)
reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -80,7 +80,7 @@ reefnet_sensusultra_parser_create (dc_parser_t **out, unsigned int devtime, dc_t
// Allocate memory.
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t *) malloc (sizeof (reefnet_sensusultra_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,7 @@
#include <string.h> // memcmp, memcpy
#include <assert.h> // assert
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "suunto_common2.h"
#include "ringbuffer.h"
#include "checksum.h"
@ -107,7 +106,7 @@ dc_status_t
suunto_common2_device_version (dc_device_t *abstract, unsigned char data[], unsigned int size)
{
if (size < SZ_VERSION) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_INVALIDARGS;
}
@ -218,7 +217,7 @@ suunto_common2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -250,7 +249,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned char version[SZ_VERSION] = {0};
dc_status_t rc = suunto_common2_device_version (abstract, version, sizeof (version));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory header.");
ERROR (abstract->context, "Failed to read the memory header.");
return rc;
}
@ -262,7 +261,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned char serial[SZ_MINIMUM > 4 ? SZ_MINIMUM : 4] = {0};
rc = suunto_common2_device_read (abstract, layout->serial, serial, sizeof (serial));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory header.");
ERROR (abstract->context, "Failed to read the memory header.");
return rc;
}
@ -281,7 +280,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned char header[8] = {0};
rc = suunto_common2_device_read (abstract, 0x0190, header, sizeof (header));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory header.");
ERROR (abstract->context, "Failed to read the memory header.");
return rc;
}
@ -297,7 +296,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
begin < layout->rb_profile_begin ||
begin >= layout->rb_profile_end)
{
WARNING("Invalid ringbuffer pointer detected!");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -305,7 +304,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned char *data = (unsigned char *) malloc (layout->rb_profile_end - layout->rb_profile_begin + SZ_MINIMUM);
if (data == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (abstract->context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -339,7 +338,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
unsigned int size = RB_PROFILE_DISTANCE (layout, current, previous, 1);
if (size < 4 || size > remaining) {
WARNING ("Unexpected profile size.");
ERROR (abstract->context, "Unexpected profile size.");
free (data);
return DC_STATUS_DATAFORMAT;
}
@ -376,7 +375,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
// Read the package.
rc = suunto_common2_device_read (abstract, address - extra, data + offset - extra, len + extra);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
ERROR (abstract->context, "Failed to read the memory.");
free (data);
return rc;
}
@ -404,12 +403,12 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
next < layout->rb_profile_begin ||
next >= layout->rb_profile_end)
{
WARNING("Invalid ringbuffer pointer detected!");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
free (data);
return DC_STATUS_DATAFORMAT;
}
if (next != previous && next != current) {
WARNING ("Profiles are not continuous.");
ERROR (abstract->context, "Profiles are not continuous.");
free (data);
return DC_STATUS_DATAFORMAT;
}
@ -429,7 +428,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
return DC_STATUS_SUCCESS;
}
} else {
WARNING ("Skipping incomplete dive.");
ERROR (abstract->context, "Skipping incomplete dive.");
status = DC_STATUS_DATAFORMAT;
}

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/suunto_d9.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "suunto_common2.h"
#include "serial.h"
#include "checksum.h"
@ -93,6 +93,7 @@ static dc_status_t
suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_device_t *abstract = (dc_device_t *) device;
// The list with possible baudrates.
const int baudrates[] = {9600, 115200};
@ -109,7 +110,7 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
// Adjust the baudrate.
int rc = serial_configure (device->port, baudrates[idx], 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (abstract->context, "Failed to set the terminal attributes.");
return DC_STATUS_IO;
}
@ -124,7 +125,7 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
dc_status_t
suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -132,7 +133,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
// Allocate memory.
suunto_d9_device_t *device = (suunto_d9_device_t *) malloc (sizeof (suunto_d9_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -146,7 +147,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -154,7 +155,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -162,7 +163,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
// Set the timeout for receiving data (3000 ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -170,7 +171,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
// Set the DTR line (power supply for the interface).
if (serial_set_dtr (device->port, 1) == -1) {
WARNING ("Failed to set the DTR line.");
ERROR (context, "Failed to set the DTR line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -185,7 +186,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model)
// Try to autodetect the protocol variant.
dc_status_t status = suunto_d9_device_autodetect (device, model);
if (status != DC_STATUS_SUCCESS) {
WARNING ("Failed to identify the protocol variant.");
ERROR (context, "Failed to identify the protocol variant.");
serial_close (device->port);
free (device);
return status;
@ -239,7 +240,7 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -248,13 +249,13 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
assert (sizeof (echo) >= csize);
n = serial_read (device->port, echo, csize);
if (n != csize) {
WARNING ("Failed to receive the echo.");
ERROR (abstract->context, "Failed to receive the echo.");
return EXITCODE (n);
}
// Verify the echo.
if (memcmp (command, echo, csize) != 0) {
WARNING ("Unexpected echo.");
ERROR (abstract->context, "Unexpected echo.");
return DC_STATUS_PROTOCOL;
}
@ -264,25 +265,25 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
// Receive the answer of the dive computer.
n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the header of the package.
if (answer[0] != command[0]) {
WARNING ("Unexpected answer header.");
ERROR (abstract->context, "Unexpected answer header.");
return DC_STATUS_PROTOCOL;
}
// Verify the size of the package.
if (array_uint16_be (answer + 1) + 4 != asize) {
WARNING ("Unexpected answer size.");
ERROR (abstract->context, "Unexpected answer size.");
return DC_STATUS_PROTOCOL;
}
// Verify the parameters of the package.
if (memcmp (command + 3, answer + 3, asize - size - 4) != 0) {
WARNING ("Unexpected answer parameters.");
ERROR (abstract->context, "Unexpected answer parameters.");
return DC_STATUS_PROTOCOL;
}
@ -290,7 +291,7 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
unsigned char crc = answer[asize - 1];
unsigned char ccrc = checksum_xor_uint8 (answer, asize - 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}

View File

@ -23,8 +23,8 @@
#include <string.h> // memcmp
#include <libdivecomputer/suunto_d9.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -84,7 +84,7 @@ parser_is_suunto_d9 (dc_parser_t *abstract)
dc_status_t
suunto_d9_parser_create (dc_parser_t **out, unsigned int model)
suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -92,7 +92,7 @@ suunto_d9_parser_create (dc_parser_t **out, unsigned int model)
// Allocate memory.
suunto_d9_parser_t *parser = (suunto_d9_parser_t *) malloc (sizeof (suunto_d9_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -459,7 +459,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca
sample.event.type = SAMPLE_EVENT_SAFETYSTOP_MANDATORY;
break;
default: // Unknown
WARNING ("Unknown event");
WARNING (abstract->context, "Unknown event");
break;
}
if (type & 0x80)
@ -512,7 +512,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca
offset += 4;
break;
default:
WARNING ("Unknown event");
WARNING (abstract->context, "Unknown event");
break;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/suunto_eon.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "suunto_common.h"
#include "serial.h"
@ -76,7 +76,7 @@ device_is_suunto_eon (dc_device_t *abstract)
dc_status_t
suunto_eon_device_open (dc_device_t **out, const char *name)
suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -84,7 +84,7 @@ suunto_eon_device_open (dc_device_t **out, const char *name)
// Allocate memory.
suunto_eon_device_t *device = (suunto_eon_device_t *) malloc (sizeof (suunto_eon_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -97,7 +97,7 @@ suunto_eon_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -105,7 +105,7 @@ suunto_eon_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (1200 8N2).
rc = serial_configure (device->port, 1200, 8, SERIAL_PARITY_NONE, 2, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -113,7 +113,7 @@ suunto_eon_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000ms).
if (serial_set_timeout (device->port, -1) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -121,7 +121,7 @@ suunto_eon_device_open (dc_device_t **out, const char *name)
// Clear the RTS line.
if (serial_set_rts (device->port, 0)) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -165,7 +165,7 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SUUNTO_EON_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -178,7 +178,7 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char command[1] = {'P'};
int rc = serial_write (device->port, command, sizeof (command));
if (rc != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (rc);
}
@ -186,7 +186,7 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char answer[SUUNTO_EON_MEMORY_SIZE + 1] = {0};
rc = serial_read (device->port, answer, sizeof (answer));
if (rc != sizeof (answer)) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (rc);
}
@ -198,7 +198,7 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned char crc = answer[sizeof (answer) - 1];
unsigned char ccrc = checksum_add_uint8 (answer, sizeof (answer) - 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -254,7 +254,7 @@ suunto_eon_device_write_name (dc_device_t *abstract, unsigned char data[], unsig
memcpy (command + 1, data, size);
int rc = serial_write (device->port, command, sizeof (command));
if (rc != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (rc);
}
@ -274,7 +274,7 @@ suunto_eon_device_write_interval (dc_device_t *abstract, unsigned char interval)
unsigned char command[2] = {'T', interval};
int rc = serial_write (device->port, command, sizeof (command));
if (rc != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (rc);
}

View File

@ -23,8 +23,8 @@
#include <libdivecomputer/suunto_eon.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -66,7 +66,7 @@ parser_is_suunto_eon (dc_parser_t *abstract)
dc_status_t
suunto_eon_parser_create (dc_parser_t **out, int spyder)
suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -74,7 +74,7 @@ suunto_eon_parser_create (dc_parser_t **out, int spyder)
// Allocate memory.
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) malloc (sizeof (suunto_eon_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -326,7 +326,7 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c
sample.event.type = SAMPLE_EVENT_ASCENT;
break;
default: // Unknown
WARNING ("Unknown event");
WARNING (abstract->context, "Unknown event");
break;
}

View File

@ -23,8 +23,8 @@
#include <libdivecomputer/suunto_solution.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "ringbuffer.h"
#include "serial.h"
@ -69,7 +69,7 @@ device_is_suunto_solution (dc_device_t *abstract)
dc_status_t
suunto_solution_device_open (dc_device_t **out, const char *name)
suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -77,7 +77,7 @@ suunto_solution_device_open (dc_device_t **out, const char *name)
// Allocate memory.
suunto_solution_device_t *device = (suunto_solution_device_t *) malloc (sizeof (suunto_solution_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -90,7 +90,7 @@ suunto_solution_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -98,7 +98,7 @@ suunto_solution_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (1200 8N2).
rc = serial_configure (device->port, 1200, 8, SERIAL_PARITY_NONE, 2, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -106,7 +106,7 @@ suunto_solution_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -114,7 +114,7 @@ suunto_solution_device_open (dc_device_t **out, const char *name)
// Clear the RTS line.
if (serial_set_rts (device->port, 0)) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -158,7 +158,7 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SUUNTO_SOLUTION_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -183,7 +183,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive: 0x3F
n = serial_read (device->port, answer, 1);
if (n != 1) return EXITCODE (n);
if (answer[0] != 0x3F) WARNING ("Unexpected answer byte.");
if (answer[0] != 0x3F)
WARNING (abstract->context, "Unexpected answer byte.");
// Send: 0x4D, 0x01, 0x01
command[0] = 0x4D;
@ -200,7 +201,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive: 0x01, i, data[i]
n = serial_read (device->port, answer, 3);
if (n != 3) return EXITCODE (n);
if (answer[0] != 0x01 || answer[1] != i) WARNING ("Unexpected answer byte.");
if (answer[0] != 0x01 || answer[1] != i)
WARNING (abstract->context, "Unexpected answer byte.");
// Send: i
command[0] = i;
@ -209,7 +211,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive: data[i]
n = serial_read (device->port, data + i, 1);
if (n != 1) return EXITCODE (n);
if (data[i] != answer[2]) WARNING ("Unexpected answer byte.");
if (data[i] != answer[2])
WARNING (abstract->context, "Unexpected answer byte.");
// Send: 0x0D
command[0] = 0x0D;
@ -223,7 +226,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive: 0x02, 0x00, 0x80
n = serial_read (device->port, answer, 3);
if (n != 3) return EXITCODE (n);
if (answer[0] != 0x02 || answer[1] != 0x00 || answer[2] != 0x80) WARNING ("Unexpected answer byte.");
if (answer[0] != 0x02 || answer[1] != 0x00 || answer[2] != 0x80)
WARNING (abstract->context, "Unexpected answer byte.");
// Send: 0x80
command[0] = 0x80;
@ -232,7 +236,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive: 0x80
n = serial_read (device->port, answer, 1);
if (n != 1) return EXITCODE (n);
if (answer[0] != 0x80) WARNING ("Unexpected answer byte.");
if (answer[0] != 0x80)
WARNING (abstract->context, "Unexpected answer byte.");
// Send: 0x20
command[0] = 0x20;
@ -241,7 +246,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive: 0x3F
n = serial_read (device->port, answer, 1);
if (n != 1) return EXITCODE (n);
if (answer[0] != 0x3F) WARNING ("Unexpected answer byte.");
if (answer[0] != 0x3F)
WARNING (abstract->context, "Unexpected answer byte.");
// Update and emit a progress event.
progress.current += 1;

View File

@ -23,8 +23,8 @@
#include <libdivecomputer/suunto_solution.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
typedef struct suunto_solution_parser_t suunto_solution_parser_t;
@ -63,7 +63,7 @@ parser_is_suunto_solution (dc_parser_t *abstract)
dc_status_t
suunto_solution_parser_create (dc_parser_t **out)
suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -71,7 +71,7 @@ suunto_solution_parser_create (dc_parser_t **out)
// Allocate memory.
suunto_solution_parser_t *parser = (suunto_solution_parser_t *) malloc (sizeof (suunto_solution_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -237,7 +237,7 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac
sample.event.type = SAMPLE_EVENT_ASCENT;
break;
default: // Unknown
WARNING ("Unknown event");
WARNING (abstract->context, "Unknown event");
break;
}

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/suunto_vyper.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "suunto_common.h"
#include "serial.h"
@ -96,7 +96,7 @@ device_is_suunto_vyper (dc_device_t *abstract)
dc_status_t
suunto_vyper_device_open (dc_device_t **out, const char *name)
suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -104,7 +104,7 @@ suunto_vyper_device_open (dc_device_t **out, const char *name)
// Allocate memory.
suunto_vyper_device_t *device = (suunto_vyper_device_t *) malloc (sizeof (suunto_vyper_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -118,7 +118,7 @@ suunto_vyper_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -126,7 +126,7 @@ suunto_vyper_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (2400 8O1).
rc = serial_configure (device->port, 2400, 8, SERIAL_PARITY_ODD, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -134,7 +134,7 @@ suunto_vyper_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -142,7 +142,7 @@ suunto_vyper_device_open (dc_device_t **out, const char *name)
// Set the DTR line (power supply for the interface).
if (serial_set_dtr (device->port, 1) == -1) {
WARNING ("Failed to set the DTR line.");
ERROR (context, "Failed to set the DTR line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -198,6 +198,8 @@ suunto_vyper_device_set_delay (dc_device_t *abstract, unsigned int delay)
static dc_status_t
suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize)
{
dc_device_t *abstract = (dc_device_t *) device;
serial_sleep (device->port, device->delay);
// Set RTS to send the command.
@ -206,7 +208,7 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[],
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -244,20 +246,20 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman
// Send the command to the dive computer.
dc_status_t rc = suunto_vyper_send (device, command, csize);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return rc;
}
// Receive the answer of the dive computer.
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the header of the package.
if (memcmp (command, answer, asize - size - 1) != 0) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -265,7 +267,7 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman
unsigned char crc = answer[asize - 1];
unsigned char ccrc = checksum_xor_uint8 (answer, asize - 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -367,7 +369,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -376,7 +378,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
command[2] = checksum_xor_uint8 (command, 2, 0x00);
dc_status_t rc = suunto_vyper_send (device, command, 3);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return rc;
}
@ -399,14 +401,14 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
// an error, because the DC always sends at least one package.
if (n == 0 && npackages != 0)
break;
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the header of the package.
if (answer[0] != command[0] ||
answer[1] > SUUNTO_VYPER_PACKET_SIZE) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -414,7 +416,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
unsigned char len = answer[1];
n = serial_read (device->port, answer + 2, len + 1);
if (n != len + 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -422,7 +424,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
unsigned char crc = answer[len + 2];
unsigned char ccrc = checksum_xor_uint8 (answer, len + 2, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -462,7 +464,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
// Check for a buffer error.
if (dc_buffer_get_size (buffer) != nbytes) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -495,7 +497,7 @@ suunto_vyper_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SUUNTO_VYPER_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,8 @@
#include <stdlib.h> // malloc, free
#include <libdivecomputer/suunto_vyper2.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "suunto_common2.h"
#include "serial.h"
#include "checksum.h"
@ -75,7 +75,7 @@ device_is_suunto_vyper2 (dc_device_t *abstract)
dc_status_t
suunto_vyper2_device_open (dc_device_t **out, const char *name)
suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -83,7 +83,7 @@ suunto_vyper2_device_open (dc_device_t **out, const char *name)
// Allocate memory.
suunto_vyper2_device_t *device = (suunto_vyper2_device_t *) malloc (sizeof (suunto_vyper2_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -96,7 +96,7 @@ suunto_vyper2_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -104,7 +104,7 @@ suunto_vyper2_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -112,7 +112,7 @@ suunto_vyper2_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (3000 ms).
if (serial_set_timeout (device->port, 3000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -120,7 +120,7 @@ suunto_vyper2_device_open (dc_device_t **out, const char *name)
// Set the DTR line (power supply for the interface).
if (serial_set_dtr (device->port, 1) == -1) {
WARNING ("Failed to set the DTR line.");
ERROR (context, "Failed to set the DTR line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -181,7 +181,7 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
// Send the command to the dive computer.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
@ -191,25 +191,25 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
// Receive the answer of the dive computer.
n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the header of the package.
if (answer[0] != command[0]) {
WARNING ("Unexpected answer header.");
ERROR (abstract->context, "Unexpected answer header.");
return DC_STATUS_PROTOCOL;
}
// Verify the size of the package.
if (array_uint16_be (answer + 1) + 4 != asize) {
WARNING ("Unexpected answer size.");
ERROR (abstract->context, "Unexpected answer size.");
return DC_STATUS_PROTOCOL;
}
// Verify the parameters of the package.
if (memcmp (command + 3, answer + 3, asize - size - 4) != 0) {
WARNING ("Unexpected answer parameters.");
ERROR (abstract->context, "Unexpected answer parameters.");
return DC_STATUS_PROTOCOL;
}
@ -217,7 +217,7 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
unsigned char crc = answer[asize - 1];
unsigned char ccrc = checksum_xor_uint8 (answer, asize - 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}

View File

@ -23,8 +23,8 @@
#include <libdivecomputer/suunto_vyper.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
typedef struct suunto_vyper_parser_t suunto_vyper_parser_t;
@ -64,7 +64,7 @@ parser_is_suunto_vyper (dc_parser_t *abstract)
dc_status_t
suunto_vyper_parser_create (dc_parser_t **out)
suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -72,7 +72,7 @@ suunto_vyper_parser_create (dc_parser_t **out)
// Allocate memory.
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) malloc (sizeof (suunto_vyper_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -320,7 +320,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t
sample.event.value = data[offset++];
break;
default: // Unknown
WARNING ("Unknown event");
WARNING (abstract->context, "Unknown event");
break;
}

View File

@ -23,8 +23,8 @@
#include <memory.h> // memcpy
#include <libdivecomputer/uwatec_aladin.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "ringbuffer.h"
@ -78,7 +78,7 @@ device_is_uwatec_aladin (dc_device_t *abstract)
dc_status_t
uwatec_aladin_device_open (dc_device_t **out, const char *name)
uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -86,7 +86,7 @@ uwatec_aladin_device_open (dc_device_t **out, const char *name)
// Allocate memory.
uwatec_aladin_device_t *device = (uwatec_aladin_device_t *) malloc (sizeof (uwatec_aladin_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -102,7 +102,7 @@ uwatec_aladin_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -110,7 +110,7 @@ uwatec_aladin_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (19200 8N1).
rc = serial_configure (device->port, 19200, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -118,7 +118,7 @@ uwatec_aladin_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (INFINITE).
if (serial_set_timeout (device->port, -1) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -127,7 +127,7 @@ uwatec_aladin_device_open (dc_device_t **out, const char *name)
// Clear the RTS line and set the DTR line.
if (serial_set_dtr (device->port, 1) == -1 ||
serial_set_rts (device->port, 0) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -205,7 +205,7 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, UWATEC_ALADIN_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -223,7 +223,7 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
int rc = serial_read (device->port, answer + i, 1);
if (rc != 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (rc);
}
if (answer[i] == (i < 3 ? 0x55 : 0x00)) {
@ -244,7 +244,7 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Receive the remaining part of the package.
int rc = serial_read (device->port, answer + 4, sizeof (answer) - 4);
if (rc != sizeof (answer) - 4) {
WARNING ("Unexpected EOF in answer.");
ERROR (abstract->context, "Unexpected EOF in answer.");
return EXITCODE (rc);
}
@ -259,7 +259,7 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
unsigned short crc = array_uint16_le (answer + UWATEC_ALADIN_MEMORY_SIZE);
unsigned short ccrc = checksum_add_uint16 (answer, UWATEC_ALADIN_MEMORY_SIZE, 0x0000);
if (ccrc != crc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/uwatec_memomouse.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -76,7 +76,7 @@ device_is_uwatec_memomouse (dc_device_t *abstract)
dc_status_t
uwatec_memomouse_device_open (dc_device_t **out, const char *name)
uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -84,7 +84,7 @@ uwatec_memomouse_device_open (dc_device_t **out, const char *name)
// Allocate memory.
uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t *) malloc (sizeof (uwatec_memomouse_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -100,7 +100,7 @@ uwatec_memomouse_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -108,7 +108,7 @@ uwatec_memomouse_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (9600 8N1).
rc = serial_configure (device->port, 9600, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -116,7 +116,7 @@ uwatec_memomouse_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -125,7 +125,7 @@ uwatec_memomouse_device_open (dc_device_t **out, const char *name)
// Clear the RTS and DTR lines.
if (serial_set_rts (device->port, 0) == -1 ||
serial_set_dtr (device->port, 0) == -1) {
WARNING ("Failed to set the DTR/RTS line.");
ERROR (context, "Failed to set the DTR/RTS line.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -198,12 +198,14 @@ uwatec_memomouse_device_set_fingerprint (dc_device_t *abstract, const unsigned c
static dc_status_t
uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size, unsigned int *result)
{
dc_device_t *abstract = (dc_device_t *) device;
assert (result != NULL);
// Receive the header of the package.
int rc = serial_read (device->port, data, 1);
if (rc != 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (rc);
}
@ -213,14 +215,14 @@ uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char d
// Verify the header of the package.
unsigned int len = data[0];
if (len + 2 > size) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
// Receive the remaining part of the package.
rc = serial_read (device->port, data + 1, len + 1);
if (rc != len + 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (rc);
}
@ -231,7 +233,7 @@ uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char d
unsigned char crc = data[len + 1];
unsigned char ccrc = checksum_xor_uint8 (data, len + 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -244,6 +246,8 @@ uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char d
static dc_status_t
uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size, unsigned int *result)
{
dc_device_t *abstract = (dc_device_t *) device;
dc_status_t rc = DC_STATUS_SUCCESS;
while ((rc = uwatec_memomouse_read_packet (device, data, size, result)) != DC_STATUS_SUCCESS) {
// Automatically discard a corrupted packet,
@ -258,7 +262,7 @@ uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned
unsigned char value = NAK;
int n = serial_write (device->port, &value, 1);
if (n != 1) {
WARNING ("Failed to reject the packet.");
ERROR (abstract->context, "Failed to reject the packet.");
return EXITCODE (n);
}
}
@ -270,9 +274,11 @@ uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned
static dc_status_t
uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer_t *buffer, dc_event_progress_t *progress)
{
dc_device_t *abstract = (dc_device_t *) device;
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -294,7 +300,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer
unsigned char value = ACK;
int n = serial_write (device->port, &value, 1);
if (n != 1) {
WARNING ("Failed to accept the packet.");
ERROR (abstract->context, "Failed to accept the packet.");
return EXITCODE (n);
}
@ -302,7 +308,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer
// The first packet should contain at least
// the total size of the inner packet.
if (length < 2) {
WARNING ("First package is too small.");
ERROR (abstract->context, "Data packet is too short.");
return DC_STATUS_PROTOCOL;
}
@ -311,7 +317,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer
// Pre-allocate the required amount of memory.
if (!dc_buffer_reserve (buffer, total)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
}
@ -336,7 +342,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer
unsigned char crc = data[total - 1];
unsigned char ccrc = checksum_xor_uint8 (data, total - 1, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -368,7 +374,7 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
unsigned char value = NAK;
int n = serial_write (device->port, &value, 1);
if (n != 1) {
WARNING ("Failed to reject the packet.");
ERROR (abstract->context, "Failed to reject the packet.");
return EXITCODE (n);
}
@ -407,21 +413,21 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
// Send the command to the device.
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
// Wait for the answer (ACK).
n = serial_read (device->port, &answer, 1);
if (n != 1) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
}
// Verify the answer.
if (answer != ACK) {
WARNING ("Unexpected answer start byte(s).");
ERROR (abstract->context, "Unexpected answer start byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -466,7 +472,7 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -476,7 +482,7 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Set the DTR line.
if (serial_set_dtr (device->port, 1) == -1) {
WARNING ("Failed to set the RTS line.");
ERROR (abstract->context, "Failed to set the RTS line.");
return DC_STATUS_IO;
}
@ -485,7 +491,7 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Clear the DTR line again.
if (serial_set_dtr (device->port, 0) == -1) {
WARNING ("Failed to set the RTS line.");
ERROR (abstract->context, "Failed to set the RTS line.");
return DC_STATUS_IO;
}

View File

@ -22,8 +22,8 @@
#include <stdlib.h>
#include <libdivecomputer/uwatec_memomouse.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -62,7 +62,7 @@ parser_is_uwatec_memomouse (dc_parser_t *abstract)
dc_status_t
uwatec_memomouse_parser_create (dc_parser_t **out, unsigned int devtime, dc_ticks_t systime)
uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -70,7 +70,7 @@ uwatec_memomouse_parser_create (dc_parser_t **out, unsigned int devtime, dc_tick
// Allocate memory.
uwatec_memomouse_parser_t *parser = (uwatec_memomouse_parser_t *) malloc (sizeof (uwatec_memomouse_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}

View File

@ -23,8 +23,8 @@
#include <string.h> // strncmp, strstr
#include <libdivecomputer/uwatec_smart.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "irda.h"
#include "array.h"
@ -96,15 +96,17 @@ uwatec_smart_discovery (unsigned int address, const char *name, unsigned int cha
static dc_status_t
uwatec_smart_transfer (uwatec_smart_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
{
dc_device_t *abstract = (dc_device_t *) device;
int n = irda_socket_write (device->socket, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
n = irda_socket_read (device->socket, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
@ -115,6 +117,8 @@ uwatec_smart_transfer (uwatec_smart_device_t *device, const unsigned char comman
static dc_status_t
uwatec_smart_handshake (uwatec_smart_device_t *device)
{
dc_device_t *abstract = (dc_device_t *) device;
// Command template.
unsigned char answer[1] = {0};
unsigned char command[5] = {0x00, 0x10, 0x27, 0, 0};
@ -127,7 +131,7 @@ uwatec_smart_handshake (uwatec_smart_device_t *device)
// Verify the answer.
if (answer[0] != 0x01) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -139,7 +143,7 @@ uwatec_smart_handshake (uwatec_smart_device_t *device)
// Verify the answer.
if (answer[0] != 0x01) {
WARNING ("Unexpected answer byte(s).");
ERROR (abstract->context, "Unexpected answer byte(s).");
return DC_STATUS_PROTOCOL;
}
@ -148,7 +152,7 @@ uwatec_smart_handshake (uwatec_smart_device_t *device)
dc_status_t
uwatec_smart_device_open (dc_device_t **out)
uwatec_smart_device_open (dc_device_t **out, dc_context_t *context)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -156,7 +160,7 @@ uwatec_smart_device_open (dc_device_t **out)
// Allocate memory.
uwatec_smart_device_t *device = (uwatec_smart_device_t *) malloc (sizeof (uwatec_smart_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -173,7 +177,7 @@ uwatec_smart_device_open (dc_device_t **out)
// Open the irda socket.
int rc = irda_socket_open (&device->socket);
if (rc == -1) {
WARNING ("Failed to open the irda socket.");
ERROR (context, "Failed to open the irda socket.");
free (device);
return DC_STATUS_IO;
}
@ -181,14 +185,14 @@ uwatec_smart_device_open (dc_device_t **out)
// Discover the device.
rc = irda_socket_discover (device->socket, uwatec_smart_discovery, device);
if (rc == -1) {
WARNING ("Failed to discover the device.");
ERROR (context, "Failed to discover the device.");
irda_socket_close (device->socket);
free (device);
return DC_STATUS_IO;
}
if (device->address == 0) {
WARNING ("No dive computer found.");
ERROR (context, "No dive computer found.");
irda_socket_close (device->socket);
free (device);
return DC_STATUS_IO;
@ -197,7 +201,7 @@ uwatec_smart_device_open (dc_device_t **out)
// Connect the device.
rc = irda_socket_connect_lsap (device->socket, device->address, 1);
if (rc == -1) {
WARNING ("Failed to connect the device.");
ERROR (context, "Failed to connect the device.");
irda_socket_close (device->socket);
free (device);
return DC_STATUS_IO;
@ -273,7 +277,7 @@ uwatec_smart_device_version (dc_device_t *abstract, unsigned char data[], unsign
uwatec_smart_device_t *device = (uwatec_smart_device_t *) abstract;
if (size < UWATEC_SMART_VERSION_SIZE) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -311,7 +315,7 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -376,7 +380,7 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Allocate the required amount of memory.
if (!dc_buffer_resize (buffer, length)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -395,7 +399,7 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress);
if (total != length + 4) {
WARNING ("Received an unexpected size.");
ERROR (abstract->context, "Received an unexpected size.");
return DC_STATUS_PROTOCOL;
}
@ -415,7 +419,7 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
int n = irda_socket_read (device->socket, data + nbytes, len);
if (n != len) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}

View File

@ -24,8 +24,8 @@
#include <libdivecomputer/uwatec_smart.h>
#include <libdivecomputer/units.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "parser-private.h"
#include "array.h"
@ -76,7 +76,7 @@ parser_is_uwatec_smart (dc_parser_t *abstract)
dc_status_t
uwatec_smart_parser_create (dc_parser_t **out, unsigned int model, unsigned int devtime, dc_ticks_t systime)
uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int devtime, dc_ticks_t systime)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -84,7 +84,7 @@ uwatec_smart_parser_create (dc_parser_t **out, unsigned int model, unsigned int
// Allocate memory.
uwatec_smart_parser_t *parser = (uwatec_smart_parser_t *) malloc (sizeof (uwatec_smart_parser_t));
if (parser == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -524,7 +524,7 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t
id = uwatec_smart_identify (data + offset, size - offset);
}
if (id >= entries) {
WARNING ("Invalid type bits.");
ERROR (abstract->context, "Invalid type bits.");
return DC_STATUS_DATAFORMAT;
}
@ -549,7 +549,7 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t
// Check for buffer overflows.
if (offset + table[id].extrabytes > size) {
WARNING ("Incomplete sample data.");
ERROR (abstract->context, "Incomplete sample data.");
return DC_STATUS_DATAFORMAT;
}
@ -629,7 +629,7 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t
complete = value;
break;
default:
WARNING ("Unknown sample type.");
WARNING (abstract->context, "Unknown sample type.");
break;
}

View File

@ -24,8 +24,8 @@
#include <assert.h> // assert
#include <libdivecomputer/zeagle_n2ition3.h>
#include <libdivecomputer/utils.h>
#include "context-private.h"
#include "device-private.h"
#include "serial.h"
#include "checksum.h"
@ -80,37 +80,39 @@ device_is_zeagle_n2ition3 (dc_device_t *abstract)
static dc_status_t
zeagle_n2ition3_packet (zeagle_n2ition3_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
{
dc_device_t *abstract = (dc_device_t *) device;
assert (asize >= csize + 5);
// Send the command to the device.
int n = serial_write (device->port, command, csize);
if (n != csize) {
WARNING ("Failed to send the command.");
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE (n);
}
// Receive the answer of the device.
n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE (n);
}
// Verify the echo.
if (memcmp (answer, command, csize) != 0) {
WARNING ("Unexpected echo.");
ERROR (abstract->context, "Unexpected echo.");
return DC_STATUS_PROTOCOL;
}
// Verify the header and trailer of the packet.
if (answer[csize] != 0x02 && answer[asize - 1] != 0x03) {
WARNING ("Unexpected answer header/trailer byte.");
ERROR (abstract->context, "Unexpected answer header/trailer byte.");
return DC_STATUS_PROTOCOL;
}
// Verify the size of the packet.
if (array_uint16_le (answer + csize + 1) + csize + 5 != asize) {
WARNING ("Unexpected answer size.");
ERROR (abstract->context, "Unexpected answer size.");
return DC_STATUS_PROTOCOL;
}
@ -118,7 +120,7 @@ zeagle_n2ition3_packet (zeagle_n2ition3_device_t *device, const unsigned char co
unsigned char crc = answer[asize - 2];
unsigned char ccrc = ~checksum_add_uint8 (answer + csize + 3, asize - csize - 5, 0x00) + 1;
if (crc != ccrc) {
WARNING ("Unexpected answer checksum.");
ERROR (abstract->context, "Unexpected answer checksum.");
return DC_STATUS_PROTOCOL;
}
@ -135,7 +137,7 @@ zeagle_n2ition3_init (zeagle_n2ition3_device_t *device)
}
dc_status_t
zeagle_n2ition3_device_open (dc_device_t **out, const char *name)
zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
if (out == NULL)
return DC_STATUS_INVALIDARGS;
@ -143,7 +145,7 @@ zeagle_n2ition3_device_open (dc_device_t **out, const char *name)
// Allocate memory.
zeagle_n2ition3_device_t *device = (zeagle_n2ition3_device_t *) malloc (sizeof (zeagle_n2ition3_device_t));
if (device == NULL) {
WARNING ("Failed to allocate memory.");
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
@ -156,7 +158,7 @@ zeagle_n2ition3_device_open (dc_device_t **out, const char *name)
// Open the device.
int rc = serial_open (&device->port, name);
if (rc == -1) {
WARNING ("Failed to open the serial port.");
ERROR (context, "Failed to open the serial port.");
free (device);
return DC_STATUS_IO;
}
@ -164,7 +166,7 @@ zeagle_n2ition3_device_open (dc_device_t **out, const char *name)
// Set the serial communication protocol (4800 8N1).
rc = serial_configure (device->port, 4800, 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
if (rc == -1) {
WARNING ("Failed to set the terminal attributes.");
ERROR (context, "Failed to set the terminal attributes.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -172,7 +174,7 @@ zeagle_n2ition3_device_open (dc_device_t **out, const char *name)
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
ERROR (context, "Failed to set the timeout.");
serial_close (device->port);
free (device);
return DC_STATUS_IO;
@ -278,7 +280,7 @@ zeagle_n2ition3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, ZEAGLE_N2ITION3_MEMORY_SIZE)) {
WARNING ("Insufficient buffer space available.");
ERROR (abstract->context, "Insufficient buffer space available.");
return DC_STATUS_NOMEMORY;
}
@ -302,7 +304,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba
unsigned char config[(RB_LOGBOOK_END - RB_LOGBOOK_BEGIN) * 2 + 8] = {0};
dc_status_t rc = zeagle_n2ition3_device_read (abstract, RB_LOGBOOK_OFFSET, config, sizeof (config));
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the configuration data.");
ERROR (abstract->context, "Failed to read the configuration data.");
return rc;
}
@ -313,7 +315,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba
last < RB_LOGBOOK_BEGIN || last >= RB_LOGBOOK_END) {
if (last == 0xFF)
return DC_STATUS_SUCCESS;
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -323,7 +325,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba
// Get the profile pointer.
unsigned int eop = array_uint16_le (config + 0x7E);
if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) {
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -338,7 +340,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba
// Get the pointer to the profile data.
unsigned int current = array_uint16_le (config + 2 * idx);
if (current < RB_PROFILE_BEGIN || current >= RB_PROFILE_END) {
WARNING ("Invalid ringbuffer pointer detected.");
ERROR (abstract->context, "Invalid ringbuffer pointer detected.");
return DC_STATUS_DATAFORMAT;
}
@ -399,7 +401,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba
// Read the memory page.
rc = zeagle_n2ition3_device_read (abstract, address, buffer + offset, len);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Failed to read the memory page.");
ERROR (abstract->context, "Failed to read the memory page.");
return rc;
}