Mercurial > public > ostc4
view Discovery/Inc/crcmodel.h @ 471:73da921869d9 fix-bat-2
bugfix: implement battery charge percentage in dive header
This commit is (much) less trivial than the related 919e5cb51c92.
First, rename the CCRmode attribute (corresponding to byte Ox59) of
the SLogbookHeaderOSTC3. This byte (according to the hwOS interface
document) does not contain any CCR related value, but it contains
"battery information". Already since 2017, this byte is used from
libdivecomputer to interface the charge percentage. So, its
renamed from CCRmode to batteryCharge, to reflect its true purpose.
Now, simply add a batteryCharge attribute to the SLogbookHeader
(and see below why that is possible, without breaking things).
The remaining changes are trivial to implement battery charge
percentage in dive header.
Caveat: do not get confused by the exact role of the individual
logbook header types. SLogbookHeaderOSTC3 is the formal type of
the logbook format that the OSTC4 produces. This format is
supposed to identical to the format, as is used in hwOS for the
series of small OSTCs. Only some values of attributes are different.
For example, the OSTC4 supports VPM, so byte 0x79 (deco model used
for this dive) also has a value for VPM. But the SLogbookHeader
type, despite its name and structure, is *not* a true logbook
header, as it includes attributes that are not available in the
SLogbookHeaderOSTC3 formal header type.
Signed-off-by: Jan Mulder <jan@jlmulder.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 22 Apr 2020 13:08:57 +0200 |
parents | 5f11787b4f42 |
children | 45b8f3c2acce |
line wrap: on
line source
/////////////////////////////////////////////////////////////////////////////// /// -*- coding: UTF-8 -*- /// /// \file Discovery/Inc/crcmodel.h /// \brief Rocksoft CRC Model Algorithm /// \author Ross Williams (ross@guest.adelaide.edu.au.) and Heinrichs Weikamp /// \date 3 June 1993 /// /// \details /// /// This is the header (.h) file for the reference /// implementation of the Rocksoft^tm Model CRC Algorithm. For more /// information on the Rocksoft^tm Model CRC Algorithm, see the document /// titled "A Painless Guide to CRC Error Detection Algorithms" by Ross /// Williams (ross@guest.adelaide.edu.au.). This document is likely to be in /// "ftp.adelaide.edu.au/pub/rocksoft". /// /// Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia. /// /// $Id$ /////////////////////////////////////////////////////////////////////////////// /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh /// /// This program is free software: you can redistribute it and/or modify /// it under the terms of the GNU General Public License as published by /// the Free Software Foundation, either version 3 of the License, or /// (at your option) any later version. /// /// This program is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with this program. If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////// /******************************************************************************/ /* Start of crcmodel.h */ /******************************************************************************/ /* */ /* Author : Ross Williams (ross@guest.adelaide.edu.au.). */ /* Date : 3 June 1993. */ /* Status : Public domain. */ /* */ /* Description : This is the header (.h) file for the reference */ /* implementation of the Rocksoft^tm Model CRC Algorithm. For more */ /* information on the Rocksoft^tm Model CRC Algorithm, see the document */ /* titled "A Painless Guide to CRC Error Detection Algorithms" by Ross */ /* Williams (ross@guest.adelaide.edu.au.). This document is likely to be in */ /* "ftp.adelaide.edu.au/pub/rocksoft". */ /* */ /* Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia. */ /* */ /******************************************************************************/ /* */ /* How to Use This Package */ /* ----------------------- */ /* Step 1: Declare a variable of type cm_t. Declare another variable */ /* (p_cm say) of type p_cm_t and initialize it to point to the first */ /* variable (e.g. p_cm_t p_cm = &cm_t). */ /* */ /* Step 2: Assign values to the parameter fields of the structure. */ /* If you don't know what to assign, see the document cited earlier. */ /* For example: */ /* p_cm->cm_width = 16; */ /* p_cm->cm_poly = 0x8005L; */ /* p_cm->cm_init = 0L; */ /* p_cm->cm_refin = TRUE; */ /* p_cm->cm_refot = TRUE; */ /* p_cm->cm_xorot = 0L; */ /* Note: Poly is specified without its top bit (18005 becomes 8005). */ /* Note: Width is one bit less than the raw poly width. */ /* */ /* Step 3: Initialize the instance with a call cm_ini(p_cm); */ /* */ /* Step 4: Process zero or more message bytes by placing zero or more */ /* successive calls to cm_nxt. Example: cm_nxt(p_cm,ch); */ /* */ /* Step 5: Extract the CRC value at any time by calling crc = cm_crc(p_cm); */ /* If the CRC is a 16-bit value, it will be in the bottom 16 bits. */ /* */ /******************************************************************************/ /* */ /* Design Notes */ /* ------------ */ /* PORTABILITY: This package has been coded very conservatively so that */ /* it will run on as many machines as possible. For example, all external */ /* identifiers have been restricted to 6 characters and all internal ones to */ /* 8 characters. The prefix cm (for Crc Model) is used as an attempt to avoid */ /* namespace collisions. This package is endian independent. */ /* */ /* EFFICIENCY: This package (and its interface) is not designed for */ /* speed. The purpose of this package is to act as a well-defined reference */ /* model for the specification of CRC algorithms. If you want speed, cook up */ /* a specific table-driven implementation as described in the document cited */ /* above. This package is designed for validation only; if you have found or */ /* implemented a CRC algorithm and wish to describe it as a set of parameters */ /* to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm implementation */ /* should behave identically to this package under those parameters. */ /* */ /******************************************************************************/ #ifndef CRC_MODEL_H #define CRC_MODEL_H /******************************************************************************/ /* The following definitions are extracted from my style header file which */ /* would be cumbersome to distribute with this package. The DONE_STYLE is the */ /* idempotence symbol used in my style header file. */ #ifndef DONE_STYLE typedef unsigned long ulong; typedef unsigned bool; typedef unsigned char * p_ubyte_; #ifndef TRUE #define FALSE 0 #define TRUE 1 #endif /* Change to the second definition if you don't have prototypes. */ #define P_(A) A /* #define P_(A) () */ /* Uncomment this definition if you don't have void. */ /* typedef int void; */ #endif /******************************************************************************/ /* CRC Model Abstract Type */ /* ----------------------- */ /* The following type stores the context of an executing instance of the */ /* model algorithm. Most of the fields are model parameters which must be */ /* set before the first initializing call to cm_ini. */ typedef struct { int cm_width; /* Parameter: Width in bits [8,32]. */ ulong cm_poly; /* Parameter: The algorithm's polynomial. */ ulong cm_init; /* Parameter: Initial register value. */ bool cm_refin; /* Parameter: Reflect input bytes? */ bool cm_refot; /* Parameter: Reflect output CRC? */ ulong cm_xorot; /* Parameter: XOR this to output CRC. */ ulong cm_reg; /* Context: Context during execution. */ } cm_t; typedef cm_t *p_cm_t; /******************************************************************************/ /* Functions That Implement The Model */ /* ---------------------------------- */ /* The following functions animate the cm_t abstraction. */ void cm_ini P_((p_cm_t p_cm)); /* Initializes the argument CRC model instance. */ /* All parameter fields must be set before calling this. */ void cm_nxt P_((p_cm_t p_cm,int ch)); /* Processes a single message byte [0,255]. */ void cm_blk P_((p_cm_t p_cm,p_ubyte_ blk_adr,ulong blk_len)); /* Processes a block of message bytes. */ ulong cm_crc P_((p_cm_t p_cm)); /* Returns the CRC value for the message bytes processed so far. */ /******************************************************************************/ /* Functions For Table Calculation */ /* ------------------------------- */ /* The following function can be used to calculate a CRC lookup table. */ /* It can also be used at run-time to create or check static tables. */ ulong cm_tab P_((p_cm_t p_cm,int index)); /* Returns the i'th entry for the lookup table for the specified algorithm. */ /* The function examines the fields cm_width, cm_poly, cm_refin, and the */ /* argument table index in the range [0,255] and returns the table entry in */ /* the bottom cm_width bytes of the return value. */ /******************************************************************************/ #endif // CRC_MODEL_H