From 74bbea85f557b37463cb0193a8656af3da324757 Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk@hohndel.org>
Date: Thu, 2 Oct 2014 10:47:57 -0700
Subject: [PATCH 4/4] Aeris A300CS: detect the number of cylinders used

The A300CS actually tells us how many of the cylinders it considers "in
use".

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

diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c
index 988b485..63416c7 100644
--- a/src/oceanic_atom2_parser.c
+++ b/src/oceanic_atom2_parser.c
@@ -352,15 +352,26 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
 				*((double *) value) = array_uint16_le (data + footer + 4) / 16.0 * FEET;
 			break;
 		case DC_FIELD_GASMIX_COUNT:
-			if (parser->model == DATAMASK || parser->model == COMPUMASK)
+			if (parser->model == DATAMASK || parser->model == COMPUMASK) {
 				*((unsigned int *) value) = 1;
-			else if (parser->model == VT4 || parser->model == VT41 ||
-				parser->model == OCI || parser->model == A300CS)
+			} else if (parser->model == VT4 || parser->model == VT41 ||
+				parser->model == OCI) {
 				*((unsigned int *) value) = 4;
-			else if (parser->model == TX1)
+			} else if (parser->model == TX1) {
 				*((unsigned int *) value) = 6;
-			else
+			} else if (parser->model == A300CS) {
+				if (data[0x39] & 0x04) {
+					*((unsigned int *) value) = 1;
+				} else if (data[0x39] & 0x08) {
+					*((unsigned int *) value) = 2;
+				} else if (data[0x39] & 0x10) {
+					*((unsigned int *) value) = 3;
+				} else {
+					*((unsigned int *) value) = 4;
+				}
+			} else {
 				*((unsigned int *) value) = 3;
+			}
 			break;
 		case DC_FIELD_GASMIX:
 			if (parser->model == DATAMASK || parser->model == COMPUMASK) {
-- 
1.9.1

