annotate Discovery/Src/logbook_miniLive.c @ 319:d8e86af78474 fix-version

bugfix: correct packed main version number in dive header This fixes a rather mysterious bug. Users report that up to 1.3.5 beta, a correct version number is shown in libdivecomputer based applications (like in Subsurface, in the extra data tab). Careful examining the code in both libdivecomputer and the firmware shows a subtle error in the bit mask and shift operation to pack a full X.Y.Z.beta version number in 2 bytes (as is available in the dive header) in the firmware end (as the libdivecomputer code looks sane, assuming this is the right way to pack things). Likely, this bug crept in in the conversion from the closed source Keil period into the open source GCC setup of the code base. So its impossible to document the exact history of this problem here. Further notice that the main version number is only 1 of 3 version numbers, denoting the full version of the firmware (besides Font and RTE). Finally notice that this way of packing is limited to 2^5 bits (decimal 32), so we could easily build a 1.4.21, but not a 1.4.55. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Wed, 19 Jun 2019 14:31:50 +0200
parents 5ca177d2df5d
children 0a3836643173
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @copyright heinrichs weikamp
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @file logbook_miniLive.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 13-March-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @since 13-March-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief little logbook for during the dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * @bug
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * @warning
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 #include "logbook_miniLive.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 #include "data_exchange.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 * @brief t7_updateMiniLiveLogbook. / Create depth samples for view during dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 * @date 13-March-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #define MLLsize (296)
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
35 static uint16_t MLLdataDepth[MLLsize];
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
36 static uint16_t MLLpointer = 0;
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
37 static uint8_t MLLtickIntervallSeconds = 2;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 uint16_t *getMiniLiveLogbookPointerToData(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 return MLLdataDepth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 uint16_t getMiniLiveLogbookActualDataLength(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 return MLLpointer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 void updateMiniLiveLogbook( _Bool checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 static uint8_t bDiveMode = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 static uint32_t last_second = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 static uint8_t secondsCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 if(checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 uint32_t now = current_second();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 if( last_second == now)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 last_second = now;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 secondsCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 if(!bDiveMode)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 secondsCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 MLLtickIntervallSeconds = 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 bDiveMode = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 MLLpointer = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 for(int i=0;i<MLLsize;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 MLLdataDepth[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 else if(stateUsed->mode == MODE_DIVE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 bDiveMode = 3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 if(secondsCount >= MLLtickIntervallSeconds)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 secondsCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 if((MLLpointer >= MLLsize) && (MLLtickIntervallSeconds < 127))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 MLLpointer = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 MLLtickIntervallSeconds *= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 for(int i=0;i<MLLsize/2;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 MLLdataDepth[i] = MLLdataDepth[MLLpointer++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 MLLdataDepth[i] += MLLdataDepth[MLLpointer++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 MLLdataDepth[i] /= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 MLLpointer = MLLsize/2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 for(int i=MLLsize/2;i<MLLsize;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 MLLdataDepth[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 if(MLLpointer < MLLsize)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 else if(bDiveMode == 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 //End of Dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 for(int i=0;i<MLLsize;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 MLLdataDepth[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 bDiveMode = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/