From 4cc0bc25ae818c4128355aedf73b48e0a50412b9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 4 Mar 2024 21:38:07 +0100 Subject: [PATCH] Support reading the logbook in forward direction To prepare the code to support reading the logbook ringbuffer in the forward direction, a new field is added to the layout data structure to indicate the direction of the ringbuffer, the workaround for handling an invalid pointer is extended to support both directions, and finally the correct parameters are passed to the rbstream reader. --- src/oceanic_atom2.c | 21 +++++++++++++++++++++ src/oceanic_common.c | 16 ++++++++++++++-- src/oceanic_common.h | 1 + src/oceanic_veo250.c | 1 + src/oceanic_vtpro.c | 3 +++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index d520e0e..69ab7d5 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -100,6 +100,7 @@ static const oceanic_common_layout_t aeris_f10_layout = { 0x0100, /* rb_logbook_begin */ 0x0D80, /* rb_logbook_end */ 32, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0D80, /* rb_profile_begin */ 0x10000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -115,6 +116,7 @@ static const oceanic_common_layout_t aeris_f11_layout = { 0x0100, /* rb_logbook_begin */ 0x0D80, /* rb_logbook_end */ 32, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0D80, /* rb_profile_begin */ 0x20000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -130,6 +132,7 @@ static const oceanic_common_layout_t oceanic_default_layout = { 0x0240, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0x10000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -145,6 +148,7 @@ static const oceanic_common_layout_t oceanic_atom1_layout = { 0x0240, /* rb_logbook_begin */ 0x0440, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0440, /* rb_profile_begin */ 0x8000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -160,6 +164,7 @@ static const oceanic_common_layout_t oceanic_atom2a_layout = { 0x0240, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0xFE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -175,6 +180,7 @@ static const oceanic_common_layout_t oceanic_atom2b_layout = { 0x0240, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0xFE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -190,6 +196,7 @@ static const oceanic_common_layout_t oceanic_atom2c_layout = { 0x0240, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0xFFF0, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -205,6 +212,7 @@ static const oceanic_common_layout_t sherwood_wisdom_layout = { 0x03D0, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0xFE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -220,6 +228,7 @@ static const oceanic_common_layout_t oceanic_proplus3_layout = { 0x03E0, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0xFE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -235,6 +244,7 @@ static const oceanic_common_layout_t tusa_zenair_layout = { 0x0240, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0xFE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -250,6 +260,7 @@ static const oceanic_common_layout_t oceanic_oc1_layout = { 0x0240, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0x1FE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -265,6 +276,7 @@ static const oceanic_common_layout_t oceanic_oci_layout = { 0x10C0, /* rb_logbook_begin */ 0x1400, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x1400, /* rb_profile_begin */ 0x1FE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -280,6 +292,7 @@ static const oceanic_common_layout_t oceanic_atom3_layout = { 0x0400, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0x1FE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -295,6 +308,7 @@ static const oceanic_common_layout_t oceanic_vt4_layout = { 0x0420, /* rb_logbook_begin */ 0x0A40, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0A40, /* rb_profile_begin */ 0x1FE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -310,6 +324,7 @@ static const oceanic_common_layout_t hollis_tx1_layout = { 0x0780, /* rb_logbook_begin */ 0x1000, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x1000, /* rb_profile_begin */ 0x40000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -325,6 +340,7 @@ static const oceanic_common_layout_t oceanic_veo1_layout = { 0x0400, /* rb_logbook_begin */ 0x0400, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0400, /* rb_profile_begin */ 0x0400, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -340,6 +356,7 @@ static const oceanic_common_layout_t oceanic_reactpro_layout = { 0x0400, /* rb_logbook_begin */ 0x0600, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0600, /* rb_profile_begin */ 0xFE00, /* rb_profile_end */ 1, /* pt_mode_global */ @@ -355,6 +372,7 @@ static const oceanic_common_layout_t oceanic_proplusx_layout = { 0x1000, /* rb_logbook_begin */ 0x10000, /* rb_logbook_end */ 16, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x40000, /* rb_profile_begin */ 0x440000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -370,6 +388,7 @@ static const oceanic_common_layout_t aqualung_i770r_layout = { 0x2000, /* rb_logbook_begin */ 0x10000, /* rb_logbook_end */ 16, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x40000, /* rb_profile_begin */ 0x640000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -385,6 +404,7 @@ static const oceanic_common_layout_t aeris_a300cs_layout = { 0x0900, /* rb_logbook_begin */ 0x1000, /* rb_logbook_end */ 16, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x1000, /* rb_profile_begin */ 0x3FE00, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -400,6 +420,7 @@ static const oceanic_common_layout_t aqualung_i450t_layout = { 0x10C0, /* rb_logbook_begin */ 0x1400, /* rb_logbook_end */ 16, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x1400, /* rb_profile_begin */ 0x3FE00, /* rb_profile_end */ 0, /* pt_mode_global */ diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 44e0781..2d54fb7 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -329,6 +329,9 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr rb_logbook_begin > layout->rb_logbook_end) { ERROR (abstract->context, "Invalid logbook begin pointer detected (0x%04x).", rb_logbook_begin); + if (layout->rb_logbook_direction == 0) { + return DC_STATUS_DATAFORMAT; + } // Fall back to downloading the entire logbook ringbuffer as // workaround for an invalid logbook begin pointer! rb_logbook_begin = rb_logbook_end; @@ -337,7 +340,12 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr rb_logbook_end > layout->rb_logbook_end) { ERROR (abstract->context, "Invalid logbook end pointer detected (0x%04x).", rb_logbook_end); - return DC_STATUS_DATAFORMAT; + if (layout->rb_logbook_direction != 0) { + return DC_STATUS_DATAFORMAT; + } + // Fall back to downloading the entire logbook ringbuffer as + // workaround for an invalid logbook end pointer! + rb_logbook_end = rb_logbook_begin; } // Calculate the number of bytes. @@ -366,7 +374,11 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr // Create the ringbuffer stream. dc_rbstream_t *rbstream = NULL; - rc = dc_rbstream_new (&rbstream, abstract, PAGESIZE, PAGESIZE * device->multipage, layout->rb_logbook_begin, layout->rb_logbook_end, rb_logbook_end, DC_RBSTREAM_BACKWARD); + rc = dc_rbstream_new (&rbstream, abstract, + PAGESIZE, PAGESIZE * device->multipage, + layout->rb_logbook_begin, layout->rb_logbook_end, + layout->rb_logbook_direction ? rb_logbook_end : rb_logbook_begin, + layout->rb_logbook_direction ? DC_RBSTREAM_BACKWARD : DC_RBSTREAM_FORWARD); if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to create the ringbuffer stream."); return rc; diff --git a/src/oceanic_common.h b/src/oceanic_common.h index b4291f7..b468b07 100644 --- a/src/oceanic_common.h +++ b/src/oceanic_common.h @@ -144,6 +144,7 @@ typedef struct oceanic_common_layout_t { unsigned int rb_logbook_begin; unsigned int rb_logbook_end; unsigned int rb_logbook_entry_size; + unsigned int rb_logbook_direction; // Profile ringbuffer unsigned int rb_profile_begin; unsigned int rb_profile_end; diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index 82f73c7..f39b1cd 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -72,6 +72,7 @@ static const oceanic_common_layout_t oceanic_veo250_layout = { 0x0400, /* rb_logbook_begin */ 0x0600, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0600, /* rb_profile_begin */ 0x8000, /* rb_profile_end */ 1, /* pt_mode_global */ diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index cba7fcc..b63c0fb 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -82,6 +82,7 @@ static const oceanic_common_layout_t oceanic_vtpro_layout = { 0x0240, /* rb_logbook_begin */ 0x0440, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x0440, /* rb_profile_begin */ 0x8000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -97,6 +98,7 @@ static const oceanic_common_layout_t oceanic_wisdom_layout = { 0x03D0, /* rb_logbook_begin */ 0x05D0, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x05D0, /* rb_profile_begin */ 0x8000, /* rb_profile_end */ 0, /* pt_mode_global */ @@ -112,6 +114,7 @@ static const oceanic_common_layout_t aeris_500ai_layout = { 0x0200, /* rb_logbook_begin */ 0x0200, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ + 1, /* rb_logbook_direction */ 0x00200, /* rb_profile_begin */ 0x20000, /* rb_profile_end */ 0, /* pt_mode_global */