From ee308be071a95987d034aca32f165d97bf8ea452 Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk@hohndel.org>
Date: Tue, 30 Sep 2014 12:35:04 -0700
Subject: [PATCH 2/4] Aeris A300CS: add support for NDL / deco data

Encoded in every sample. The depth is in multiples of 10 feet which gives
somewhat odd metric stop depth - but rounding to full meters would take
care of that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
---
 src/oceanic_atom2_parser.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c
index a4832a1..2fc87e6 100644
--- a/src/oceanic_atom2_parser.c
+++ b/src/oceanic_atom2_parser.c
@@ -633,6 +633,22 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
 			sample.depth = depth / 16.0 * FEET;
 			if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata);
 
+			// NDL / Deco
+			// bits 6..4 of byte 15 encode deco state & depth
+			// bytes 6 & 7 encode minutes of NDL / deco
+			if (parser->model == A300CS) {
+				unsigned int deco = (data[offset + 15] & 0x70) >> 4;
+				if (deco) {
+					sample.deco.type = DC_DECO_DECOSTOP;
+					sample.deco.depth = deco * 10 * FEET;
+				} else {
+					sample.deco.type = DC_DECO_NDL;
+					sample.deco.depth = 0.0;
+				}
+				sample.deco.time = array_uint16_le(data + offset + 6) & 0x03FF;
+				if (callback) callback (DC_SAMPLE_DECO, sample, userdata);
+			}
+
 			complete = 1;
 		}
 
-- 
1.9.1

