annotate Discovery/Src/data_exchange_main.c @ 692:b052e812277c Betatest

Added compile switch for Sentinel rebreather option
author Ideenmodellierer
date Fri, 05 Aug 2022 15:27:01 +0200
parents 52d68cf9994c
children 6d7c812fc173
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 * @file data_exchange_main.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @date 13-Oct-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @version V0.0.3
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @since 17-Feb-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief Communication with the second CPU == RTE system
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ##### Version Changes #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 160217 V0.0.3 pStateUsed->decolistXXXXX.tickstamp = HAL_GetTick(); added
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 150627 V0.0.2
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 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 ##### Button, Set Time, Clear Deco etc Request #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 was updated (151207) for buttons and clear deco at the moment only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 using requestNecessary and checking in DataEX_copy_to_LifeData()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 Hence if there is no confirm from the smallCPU on the data after the request
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 the request will be send again.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 ##### Device Data #####
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 main CPU always sends the device data info that it has at the moment
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 on start it is INT32_MIN, INT32_MAX and 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 as initialized in data_central.c variable declaration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 second small CPU gets request to send its device data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
41 on reception the data is merged with the data in externLogbookFlash,
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 stored on the externLogbookFlash and from now on send to small CPU
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 ##### Magnet Reset #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 /* Includes ------------------------------------------------------------------*/
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
58 #include <stdlib.h>
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
59 #include <string.h> // for memcpy
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 #include "stdio.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 #include "ostc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 #include "settings.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 #include "data_central.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 #include "data_exchange_main.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 #include "base.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 #include "decom.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 #include "calc_crush.h" /* for vpm_init */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 #include "simulation.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #include "tCCR.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 #include "timer.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 #include "buehlmann.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 #include "externLogbookFlash.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
75 /* #define TESTBENCH */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
77 /* Exported variables --------------------------------------------------------*/
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
78 static uint8_t wasPowerOn = 0;
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
79 static confirmbit8_Type requestNecessary = { .uw = 0 };
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
80 static uint8_t wasUpdateNotPowerOn = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 /* Private variables with external access ------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 /* Private variables ---------------------------------------------------------*/
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
85 static uint8_t told_reset_logik_alles_ok = 0;
559
84a4e1200726 Check if HW evaluation was performed:
Ideenmodellierer
parents: 556
diff changeset
86 static hw_Info_t hw_Info;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
88 static SDataReceiveFromMaster dataOut;
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
89 static SDataExchangeSlaveToMaster dataIn;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
91 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0;
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
92 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0;
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
93 static uint32_t data_old__lost_connection_to_slave_counter_total = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
95 static uint8_t DeviceDataUpdated = 0;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
96
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
97 static uint16_t externalInterface_Cmd = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
98
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 /* Private types -------------------------------------------------------------*/
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
100 #define UNKNOWN_TIME_HOURS 1
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
101 #define UNKNOWN_TIME_MINUTES 0
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
102 #define UNKNOWN_TIME_SECOND 0
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
103 #define UNKNOWN_DATE_DAY 1
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
104 #define UNKNOWN_DATE_MONTH 1
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
105 #define UNKNOWN_DATE_YEAR 16
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106
577
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
107
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 /* Private function prototypes -----------------------------------------------*/
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
109 static uint8_t DataEX_check_header_and_footer_ok(void);
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
110 static uint8_t DataEX_check_header_and_footer_shifted(void);
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
111 static uint8_t DataEX_check_header_and_footer_devicedata(void);
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
112 static void DataEX_check_DeviceData(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 uint8_t DataEX_was_power_on(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 return wasPowerOn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
120 static uint8_t count_DataEX_Error_Handler = 0;
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
121 static uint8_t last_error_DataEX_Error_Handler = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
123 static void DataEX_Error_Handler(uint8_t answer)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 count_DataEX_Error_Handler++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 last_error_DataEX_Error_Handler = answer;
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
127
156
1fbdb45db701 Removed special indicator for DMA transfer error
Ideenmodellierer
parents: 154
diff changeset
128 /* A wrong footer indicates a communication interrupt. State machine is waiting for new data which is not received because no new transmission is triggered */
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
129 /* ==> Abort data exchange to enable a new RX / TX cycle */
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
130 if(answer == HAL_BUSY)
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
131 {
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
132 HAL_SPI_Abort_IT(&cpu2DmaSpi);
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
133 }
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
134
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 uint32_t DataEX_lost_connection_count(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 return data_old__lost_connection_to_slave_counter_total;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
145 SDataReceiveFromMaster *dataOutGetPointer(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 return &dataOut;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 void DataEX_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 SDiveState * pStateReal = stateRealGetPointerWrite();
99
6a2308b9a3d4 Config for debug data
Dmitry Romanov <kitt@bk.ru>
parents: 90
diff changeset
153 pStateReal->data_old__lost_connection_to_slave = 0; //initial value
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 data_old__lost_connection_to_slave_counter_total = 0;
407
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
156 DeviceDataUpdated = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 dataOut.header.checkCode[0] = 0xBB;
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
161 dataOut.header.checkCode[1] = SPI_RX_STATE_OK;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
162 dataOut.header.checkCode[2] = SPI_RX_STATE_OK;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 dataOut.header.checkCode[3] = 0xBB;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 dataOut.footer.checkCode[0] = 0xF4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 dataOut.footer.checkCode[1] = 0xF3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 dataOut.footer.checkCode[2] = 0xF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 dataOut.footer.checkCode[3] = 0xF1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
172 static void DataEx_call_helper_requests(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 static uint8_t setDateWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 static uint8_t setTimeWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 static uint8_t calibrateCompassWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 static uint8_t setButtonSensitivityWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 static uint8_t clearDecoWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 static uint8_t getDeviceDataWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 static uint8_t setAccidentFlagWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 static uint8_t setEndDiveWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 if(getDeviceDataWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 dataOut.getDeviceDataNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 getDeviceDataWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 if(dataOut.getDeviceDataNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 getDeviceDataWasSend = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
191 requestNecessary.ub.devicedata = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 if(setEndDiveWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 dataOut.setEndDive = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 //requestNecessary.ub.XXX = 1; not implemented and no space here
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 setEndDiveWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 if(dataOut.setEndDive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 setEndDiveWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 if(setAccidentFlagWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 dataOut.setAccidentFlag = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 setAccidentFlagWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 if(dataOut.setAccidentFlag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 setAccidentFlagWasSend = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
213 requestNecessary.ub.accident = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 if(setDateWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 dataOut.setDateNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 setDateWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 if(dataOut.setDateNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 setDateWasSend = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
224 requestNecessary.ub.date = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 if(setTimeWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 dataOut.setTimeNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 setTimeWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 if(dataOut.setTimeNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 setTimeWasSend = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
235 requestNecessary.ub.time = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 if(calibrateCompassWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 dataOut.calibrateCompassNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 calibrateCompassWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 if(dataOut.calibrateCompassNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 calibrateCompassWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 if(clearDecoWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 dataOut.clearDecoNow = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
251 requestNecessary.ub.compass = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 if(dataOut.clearDecoNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 clearDecoWasSend = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
256 requestNecessary.ub.clearDeco = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 if(setButtonSensitivityWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 dataOut.setButtonSensitivityNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 setButtonSensitivityWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 if(dataOut.setButtonSensitivityNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 setButtonSensitivityWasSend = 1;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
267 requestNecessary.ub.button = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 uint8_t DataEX_call(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 {
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
274 static uint32_t RTEOfflineCnt = 0;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
275 static uint8_t SusppressCom = 0;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
276
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 uint8_t SPI_DMA_answer = 0;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
278
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
279 if(SusppressCom)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 {
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
281 SusppressCom--;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 }
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 141
diff changeset
283 else
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 141
diff changeset
284 {
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
285 if(data_old__lost_connection_to_slave_counter_temp >= 2) /* error reaction is triggered whenever communication could not be reestablishen within two cycles */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
286 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
287 data_old__lost_connection_to_slave_counter_temp = 0;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
288 if(DataEX_check_header_and_footer_shifted())
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
289 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
290 if(RTEOfflineCnt > 1) /* RTE restarted communication after a longer silent time => restart error handling to recover */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
291 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
292 data_old__lost_connection_to_slave_counter_retry = 0;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
293 RTEOfflineCnt = 0;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
294 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
296 /* We received shifted data. Step one. Reset DMA to see if the problem is located at main */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
297 if (data_old__lost_connection_to_slave_counter_retry == 0)
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
298 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
299 HAL_SPI_Abort_IT(&cpu2DmaSpi);
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
300 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
301 /* reset of own DMA does not work ==> request reset of slave dma by indicating shifted receiption */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
302 if (data_old__lost_connection_to_slave_counter_retry == 1)
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
303 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
304 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_SHIFTED;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
305 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
306
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
307 /* stop communication with RTE to trigger RTE timeout reaction */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
308 if (data_old__lost_connection_to_slave_counter_retry == 2)
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
309 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
310 SusppressCom = 3;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
311 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
313 data_old__lost_connection_to_slave_counter_retry++;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
314 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
315 else
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
316 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
317 RTEOfflineCnt++; /* based on footer status the RTE does not seem to provide data in time */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
318 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OFFLINE;
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
319 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
320 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
321 #if USE_OLD_SYNC_METHOD
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
322 /* one cycle with NotChipSelect true to clear slave spi buffer */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
323 else
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
324 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
325 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
326 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
327 #endif
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
328
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
329 DataEx_call_helper_requests();
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
330
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
331 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
332
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
333 if(SusppressCom == 0)
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
334 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
335 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
336
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
337 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE);
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
338 if(SPI_DMA_answer != HAL_OK)
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
339 {
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
340 DataEX_Error_Handler(SPI_DMA_answer);
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
341 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
342 }
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
343 }
104
22a1094545f3 Tested and alive.
Dmitry Romanov <kitt@bk.ru>
parents: 99
diff changeset
344 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 //HAL_Delay(3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350
82
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
351
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
352 static uint32_t SPI_CALLBACKS;
82
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
353 uint32_t get_num_SPI_CALLBACKS(void){
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
354 return SPI_CALLBACKS;
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
355 }
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
356
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
357 SDataExchangeSlaveToMaster* get_dataInPointer(void){
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
358 return &dataIn;
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
359 }
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
360
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
361 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
362 {
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
363 if(hspi == &cpu2DmaSpi)
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
364 {
154
1ac5033f7c7a Keep NSS low during SPI transfer only
Ideenmodellierer
parents: 149
diff changeset
365 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
82
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
366 SPI_CALLBACKS+=1;
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
367 }
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
368 }
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
369
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
370
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 void DateEx_copy_to_dataOut(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 const SDiveState * pStateReal = stateRealGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 if(get_globalState() == StStop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 dataOut.mode = MODE_SHUTDOWN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 dataOut.mode = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 dataOut.diveModeInfo = pStateReal->diveSettings.diveMode; // hw 170215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 memcpy(&dataOut.data.DeviceData, stateDeviceGetPointer(), sizeof(SDevice));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 dataOut.data.VPMconservatism = pStateReal->diveSettings.vpm_conservatism;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 dataOut.data.actualGas = pStateReal->lifeData.actualGas;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 dataOut.data.ambient_pressure_mbar_ceiling = (pStateReal->decolistBuehlmann.output_ceiling_meter * 100) + (pStateReal->lifeData.pressure_surface_bar * 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
394
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
395
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
396 if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG)
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
397 {
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
398 externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
399 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
400
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
401 #ifdef ENABLE_SENTINEL_MODE
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
402 if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_SENTINEL)
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
403 {
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
404 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_SENTINEL;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
405 externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON);
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
406 }
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
407 #endif
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
408
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
409 if(settings->ext_uart_protocol)
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
410 {
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
411 externalInterface_Cmd |= (settings->ext_uart_protocol << 8);
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
412 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
413 if(settings->co2_sensor_active)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
414 {
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
415 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
416 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
417 dataOut.data.externalInterface_Cmd = externalInterface_Cmd;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
418 externalInterface_Cmd = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
419
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15))))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 dataOut.revisionHardware = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 dataOut.revisionCRCx0x7A = 0x7A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 if(hardwareDataGetPointer()->primarySerial < 0xFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 dataOut.revisionHardware = hardwareDataGetPointer()->revision8bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 dataOut.revisionCRCx0x7A = hardwareDataGetPointer()->revision8bit ^ 0x7A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 dataOut.revisionHardware = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 dataOut.revisionCRCx0x7A = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 MX_tell_reset_logik_alles_ok();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 told_reset_logik_alles_ok = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 if(!wasUpdateNotPowerOn)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 wasPowerOn = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 setButtonResponsiveness(settings->ButtonResponsiveness);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 void DataEX_copy_to_deco(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 if(decoLock == DECO_CALC_running)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 if(decoLock == DECO_CALC_init_as_is_start_of_dive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 {
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
461 vpm_init(&stateUsedWrite->vpm, stateUsedWrite->diveSettings.vpm_conservatism, 0, 0);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 buehlmann_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 timer_init();
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
464 resetEvents(stateUsedWrite);
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
465 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 if(decoLock == DECO_CALC_FINSHED_Buehlmann)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 switch(decoLock)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 //Deco_calculation finished
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 case DECO_CALC_FINSHED_vpm:
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
477 memcpy(&stateUsedWrite->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo));
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
478 stateUsedWrite->decolistVPM.tickstamp = HAL_GetTick();
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
479 stateUsedWrite->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 for(int i = 0; i< 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 {
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
482 stateUsedWrite->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
483 stateUsedWrite->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
484 stateUsedWrite->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
485 stateUsedWrite->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
486 stateUsedWrite->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
487 stateUsedWrite->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
488 stateUsedWrite->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i];
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 case DECO_CALC_FINSHED_Buehlmann:
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
492 memcpy(&stateUsedWrite->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo));
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
493 stateUsedWrite->decolistBuehlmann.tickstamp = HAL_GetTick();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
495 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 case DECO_CALC_FINSHED_FutureBuehlmann:
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
498 memcpy(&stateUsedWrite->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo));
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
499 stateUsedWrite->decolistFutureBuehlmann.tickstamp = HAL_GetTick();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 case DECO_CALC_FINSHED_Futurevpm:
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
502 memcpy(&stateUsedWrite->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo));
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
503 stateUsedWrite->decolistFutureVPM.tickstamp = HAL_GetTick();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 //Copy Inputdata from stateReal to stateDeco
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
508 memcpy(&stateDeco.lifeData,&stateUsedWrite->lifeData,sizeof(SLifeData));
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
509 memcpy(&stateDeco.diveSettings,&stateUsedWrite->diveSettings,sizeof(SDiveSettings));
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
511 stateDeco.vpm.deco_zone_reached = stateUsedWrite->vpm.deco_zone_reached;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 for(int i = 0; i< 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 {
288
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
515 stateDeco.vpm.max_crushing_pressure_he[i] = stateUsedWrite->vpm.max_crushing_pressure_he[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
516 stateDeco.vpm.max_crushing_pressure_n2[i] = stateUsedWrite->vpm.max_crushing_pressure_n2[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
517 stateDeco.vpm.adjusted_critical_radius_he[i] = stateUsedWrite->vpm.adjusted_critical_radius_he[i];
ba229a012ac7 cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents: 278
diff changeset
518 stateDeco.vpm.adjusted_critical_radius_n2[i] = stateUsedWrite->vpm.adjusted_critical_radius_n2[i];
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 decoLock = DECO_CALC_ready;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
524 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 lineWrite->date_rtc_dr = lineRead->date_rtc_dr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 lineWrite->time_rtc_tr = lineRead->time_rtc_tr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 lineWrite->value_int32 = lineRead->value_int32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
531 static void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 inStimestructure.TimeFormat = RTC_HOURFORMAT_24;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 (((uint32_t)inStimestructure.TimeFormat) << 16U));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
542 static void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 ((uint32_t)inSdatestructure.WeekDay << 13U));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
551 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 RTC_DateTypeDef sdatestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 RTC_TimeTypeDef stimestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
556 stimestructure.Hours = UNKNOWN_TIME_HOURS;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
557 stimestructure.Minutes = UNKNOWN_TIME_MINUTES;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
558 stimestructure.Seconds = UNKNOWN_TIME_SECOND;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
560 sdatestructure.Date = UNKNOWN_DATE_DAY;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
561 sdatestructure.Month = UNKNOWN_DATE_MONTH;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
562 sdatestructure.Year = UNKNOWN_DATE_YEAR;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 setWeekday(&sdatestructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
570 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 {
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
572 uint8_t retval = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 RTC_DateTypeDef sdatestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 RTC_TimeTypeDef stimestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 // from lineWrite to structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 translateDate(lineWrite->date_rtc_dr, &sdatestructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 translateTime(lineWrite->time_rtc_tr, &stimestructure);
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
579
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
580 /* Check if date is out of range */
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
581 if(!( (sdatestructure.Year >= 15)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 && (sdatestructure.Year <= 30)
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
583 && (sdatestructure.Month <= 12)))
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
584 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
585 DataEX_helper_set_Unknown_Date_deviceData(lineWrite);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
586 retval = 1;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
587 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
588 return retval;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
592 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to, uint8_t defaulttofrom)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 {
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
594 uint8_t retval = 0;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
595 RTC_DateTypeDef sdatestructure;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
596
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
597 /* Is value out of valid range? */
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
598 if(!(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to))
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
599 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
600 if(defaulttofrom)
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
601 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
602 lineWrite->value_int32 = from;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
603 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
604 else
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
605 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
606 lineWrite->value_int32 = to;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
607 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
608 DataEX_helper_set_Unknown_Date_deviceData(lineWrite);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
609 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
611 /* This is just a repair function to restore metric if a corruption occurred in an older fw version */
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
612 if(((lineWrite->value_int32 == to) && defaulttofrom )
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
613 || ((lineWrite->value_int32 == from) && !defaulttofrom ))
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
614 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
615 translateDate(lineWrite->date_rtc_dr, &sdatestructure);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
616 if(sdatestructure.Year == UNKNOWN_DATE_YEAR)
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
617 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
618 if(defaulttofrom)
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
619 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
620 lineWrite->value_int32 = from;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
621 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
622 else
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
623 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
624 lineWrite->value_int32 = to;
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
625 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
626 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
627 }
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
628 return retval;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
632 static void DataEX_check_DeviceData(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 SDevice *DeviceData = stateDeviceGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
645 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000,1);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
646 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000,1);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
647 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000,1);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
648 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000,1);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
649 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000,1);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
650 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100,1);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
651 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100,0);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
652 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, 2*1000, 6*1000,0);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
656 static void DataEX_merge_DeviceData_and_store(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 uint16_t dataLengthRead;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 SDevice DeviceDataFlash;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 SDevice *DeviceData = stateDeviceGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 if(dataLengthRead == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 {
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 407
diff changeset
666 ext_flash_write_devicedata(false);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 /* max values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 }
406
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
691 if(DeviceData->hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32)
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
692 {
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
693 DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation);
439874690f85 Bugfix Min max values for device data checks:
ideenmodellierer
parents: 342
diff changeset
694 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695
407
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
696
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 /* min values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 DataEX_check_DeviceData ();
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 407
diff changeset
708 ext_flash_write_devicedata(false);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
712 static void DataEX_copy_to_DeviceData(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 SDevice * pDeviceState = stateDeviceGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice));
559
84a4e1200726 Check if HW evaluation was performed:
Ideenmodellierer
parents: 556
diff changeset
718 memcpy(&hw_Info, &dataInDevice->hw_Info, sizeof(dataInDevice->hw_Info));
84a4e1200726 Check if HW evaluation was performed:
Ideenmodellierer
parents: 556
diff changeset
719
407
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
720 DeviceDataUpdated = 1; /* indicate new data to be written to flash by background task (at last op hour count will be updated) */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
724 static void DataEX_copy_to_VpmRepetitiveData(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 if(dataInDevice->boolVpmRepetitiveDataValid)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 pVpmState->is_data_from_RTE_CPU = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 void DataEX_control_connection_while_asking_for_sleep(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 if(!DataEX_check_header_and_footer_ok())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 if(DataEX_check_header_and_footer_devicedata())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 data_old__lost_connection_to_slave_counter_retry = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0;
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
746 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 data_old__lost_connection_to_slave_counter_temp += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 data_old__lost_connection_to_slave_counter_total += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
757 static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds)
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
758 {
342
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
759 float ambient = 0;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
760 float surface = 0;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
761 float depth = 0;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
762 float density = 0;
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
763
342
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
764 ambient = d->data[d->boolPressureData].pressure_mbar / 1000.0f;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
765 surface = d->data[d->boolPressureData].surface_mbar / 1000.0f;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
766 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
767
497
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
768 #ifdef TESTBENCH
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
769 /* do plausibility check (typically only needed at debug hardware) */
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
770 if(ambient < 0)
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
771 {
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
772 ambient = 1.0;
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
773 }
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
774 if(surface < 0)
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
775 {
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
776 surface = 1.0;
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
777 }
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
778 #endif
342
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
779 ds->lifeData.pressure_ambient_bar = ambient;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
780 ds->lifeData.pressure_surface_bar = surface;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
781 depth = (ambient - surface) / (0.09807f * density);
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
782 ds->lifeData.bool_temp1 = d->data[d->boolPressureData].SPARE1;
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
783
342
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
784 return depth;
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
785 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786
189
8b8074080d7b Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents: 173
diff changeset
787 static float getTemperature(SDataExchangeSlaveToMaster *d)
8b8074080d7b Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents: 173
diff changeset
788 {
342
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
789 float temp = 0;
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
790 temp = d->data[d->boolPressureData].temperature;
189
8b8074080d7b Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents: 173
diff changeset
791
497
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
792 #ifdef TESTBENCH
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
793 /* do plausibility check (typically only needed at debug hardware */
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
794 if(temp < -40.0)
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
795 {
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
796 temp = 20.0;
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
797 }
5757edda56b7 Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents: 451
diff changeset
798 #endif
342
ea3fda8eb93e Removed averaging of pressure and temperatur values
ideenmodellierer
parents: 309
diff changeset
799 return temp;
189
8b8074080d7b Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents: 173
diff changeset
800 }
8b8074080d7b Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents: 173
diff changeset
801
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
804 static uint16_t getDeviceDataAfterStartOfMainCPU = 20;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
805
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
806 SDiveState *pStateReal = stateRealGetPointerWrite();
577
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
807 uint8_t idx;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
808 float meter = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
809 SSettings *pSettings;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
810
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
811
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 // wireless - �ltere daten aufr�umen
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 436
diff changeset
814 #if 0
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
815 for(int i=0;i<(2*NUM_GASES+1);i++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 if(pStateReal->lifeData.bottle_bar[i])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 if((pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] == 0) || (pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] > 60000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 pStateReal->lifeData.bottle_bar[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 }
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 436
diff changeset
828 #else
451
c2e02b87774f Allocate received bar value to active gas (was static allocated to gas[1])
ideenmodellierer
parents: 446
diff changeset
829 if(stateRealGetPointer()->lifeData.bottle_bar_age_MilliSeconds[stateRealGetPointer()->lifeData.actualGas.GasIdInSettings] < 6000) /* max age after ten minutes */
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 436
diff changeset
830 {
451
c2e02b87774f Allocate received bar value to active gas (was static allocated to gas[1])
ideenmodellierer
parents: 446
diff changeset
831 stateRealGetPointerWrite()->lifeData.bottle_bar_age_MilliSeconds[stateRealGetPointer()->lifeData.actualGas.GasIdInSettings]++;
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 436
diff changeset
832 }
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 436
diff changeset
833 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 if(!DataEX_check_header_and_footer_ok())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 if(DataEX_check_header_and_footer_devicedata())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 DataEX_copy_to_DeviceData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 DataEX_copy_to_VpmRepetitiveData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 data_old__lost_connection_to_slave_counter_retry = 0;
275
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
842 /* Do not yet reset state. Wait till common data has been received in next cycle. Otherwise invalid data may be forwarded for processing */
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
843 /* pStateReal->data_old__lost_connection_to_slave = 0; */
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
844 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 pStateReal->data_old__lost_connection_to_slave = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 data_old__lost_connection_to_slave_counter_temp += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 data_old__lost_connection_to_slave_counter_total += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 }
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
854 else /* RX data OK */
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
855 {
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
856 data_old__lost_connection_to_slave_counter_temp = 0;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
857 data_old__lost_connection_to_slave_counter_retry = 0;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
858 pStateReal->data_old__lost_connection_to_slave = 0;
208
9fc06e1e0f66 Update SPI error display and handling
ideenmodellierer
parents: 198
diff changeset
859 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
860 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 if(getDeviceDataAfterStartOfMainCPU)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 getDeviceDataAfterStartOfMainCPU--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 if(getDeviceDataAfterStartOfMainCPU == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 dataOut.getDeviceDataNow = 1;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
868 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
872 if((requestNecessary.uw != 0) && (dataIn.confirmRequest.uw != 0))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 requestNecessary.ub.button = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
878 if(((dataIn.confirmRequest.uw) & CRCLEARDECO) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
879 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
880 requestNecessary.ub.clearDeco = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
881 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
882 if(((dataIn.confirmRequest.uw) & CRDATE) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
883 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
884 requestNecessary.ub.date = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
885 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
886 if(((dataIn.confirmRequest.uw) & CRTIME) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
887 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
888 requestNecessary.ub.time = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
889 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
890 if(((dataIn.confirmRequest.uw) & CRCOMPASS) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
891 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
892 requestNecessary.ub.compass = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
893 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
894 if(((dataIn.confirmRequest.uw) & CRDEVICEDATA) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
895 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
896 requestNecessary.ub.devicedata = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
897 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
898 if(((dataIn.confirmRequest.uw) & CRBATTERY) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
899 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
900 requestNecessary.ub.batterygauge = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
901 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
902 if(((dataIn.confirmRequest.uw) & CRACCIDENT) != 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
903 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
904 requestNecessary.ub.accident = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
905 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
907 if(requestNecessary.ub.button == 1) /* send button values to RTE */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 }
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 141
diff changeset
912
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 /* uint8_t IAmStolenPleaseKillMe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 */
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
915 pSettings = settingsGetPointer();
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
916
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
917 if(pSettings->IAmStolenPleaseKillMe > 3)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 pSettings->salinity = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 dataIn.data[dataIn.boolPressureData].surface_mbar = 999;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 dataIn.mode = MODE_DIVE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924
556
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
925
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
926 /* internal sensor: HUD data */
559
84a4e1200726 Check if HW evaluation was performed:
Ideenmodellierer
parents: 556
diff changeset
927 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
556
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
928 {
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
929 for(int i=0;i<3;i++)
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
930 {
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
931 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i);
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
932 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i);
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
933 }
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
934 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V();
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
935 }
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
936 else /* use data from external ADC */
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
937 {
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
938 if(pStateReal->data_old__lost_connection_to_slave == 0)
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
939 {
577
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
940 for(idx = 0; idx < 3; idx++)
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
941 {
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
942 pStateReal->lifeData.sensorVoltage_mV[idx] = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].extADC_voltage[idx];
577
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
943 if(pStateReal->lifeData.sensorVoltage_mV[idx] < IGNORE_O2_VOLTAGE_LEVEL_MV)
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
944 {
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
945 pStateReal->lifeData.sensorVoltage_mV[idx] = 0.0;
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
946 pStateReal->lifeData.ppO2Sensor_bar[idx] = 0;
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
947 }
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
948 else
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
949 {
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
950 pStateReal->lifeData.ppO2Sensor_bar[idx] = pStateReal->lifeData.sensorVoltage_mV[idx] * pSettings->ppo2sensors_calibCoeff[idx];
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
951 }
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
952
9bb9a52d6ae5 Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents: 559
diff changeset
953 }
556
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
954 }
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
955 }
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
956
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
957 if(pStateReal->data_old__lost_connection_to_slave == 0)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
958 {
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
959 meter = getSampleDepth(&dataIn, pStateReal);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
961 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
962 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
963 pStateReal->pressure_uTick_local_new = HAL_GetTick();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
965 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
966 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
967 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
969 if(pStateReal->data_old__lost_connection_to_slave == 0)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 {
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
971 //Start of diveMode?
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
972 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
973 {
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
974 if(modeChangeFlag)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
975 {
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
976 *modeChangeFlag = 1;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
977 }
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
978 if(stateUsed == stateSimGetPointer())
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 }
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
982 // new 170508
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 settingsGetPointer()->bluetoothActive = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 MX_Bluetooth_PowerOff();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 //Init dive Mode
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
986 decoLock = DECO_CALC_init_as_is_start_of_dive;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
987 pStateReal->lifeData.boolResetAverageDepth = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 }
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
989
197
c853f5d23bb7 cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents: 189
diff changeset
990 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns;
c853f5d23bb7 cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents: 189
diff changeset
991 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu;
c853f5d23bb7 cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents: 189
diff changeset
992 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes;
c853f5d23bb7 cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents: 189
diff changeset
993 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes;
c853f5d23bb7 cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents: 189
diff changeset
994
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
995 //End of diveMode?
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
996 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
997 {
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
998 if(modeChangeFlag)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
999 {
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1000 *modeChangeFlag = 1;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1001 }
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1002 createDiveSettings();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1004 if(pStateReal->warnings.cnsHigh)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1005 {
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1006 if(pStateReal->lifeData.cns >= 130)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1007 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1008 else if(pStateReal->lifeData.cns >= 100)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1009 dataOut.setAccidentFlag += ACCIDENT_CNS;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1010 }
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1011 if(pStateReal->warnings.decoMissed)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1012 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1013 }
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1014 pStateReal->mode = dataIn.mode;
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1015 pStateReal->chargeStatus = dataIn.chargeStatus;
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1016
306
2f43419102c8 bugfix, cleanup: do not clip depth to 0
Jan Mulder <jlmulder@xs4all.nl>
parents: 288
diff changeset
1017 pStateReal->lifeData.depth_meter = meter;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1018
189
8b8074080d7b Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents: 173
diff changeset
1019 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn);
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1020 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1021 if(pStateReal->mode != MODE_DIVE)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1022 pStateReal->lifeData.max_depth_meter = 0;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1023 else
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1024 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1025 if(meter > pStateReal->lifeData.max_depth_meter)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1026 pStateReal->lifeData.max_depth_meter = meter;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1027 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1029 if(requestNecessary.ub.clearDeco == 0) /* No "reset deco" is send to RTE ? */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1030 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1031 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1032 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1033 pStateReal->decoMissed_at_the_end_of_dive = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1034 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1035 else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1036 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1037 pStateReal->decoMissed_at_the_end_of_dive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1038 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1039 if(dataIn.accidentFlags & ACCIDENT_CNS)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1040 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1041 pStateReal->cnsHigh_at_the_end_of_dive = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1042 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1043 else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1044 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1045 pStateReal->cnsHigh_at_the_end_of_dive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1046 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1047 }
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1048 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1049 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1050 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1051 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1053 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1054 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1055 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1056 pStateReal->lifeData.compass_heading -= 180.0;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1057 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1058 }
109
65a6e352ce08 Consider computer heading in case of a flipped display
Ideenmodellierer
parents: 51
diff changeset
1059
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1060 pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1061 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1063 pStateReal->lifeData.compass_DX_f = dataIn.data[dataIn.boolCompassData].compass_DX_f;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1064 pStateReal->lifeData.compass_DY_f = dataIn.data[dataIn.boolCompassData].compass_DY_f;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1065 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1067 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1068 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1069 pStateReal->compass_uTick_local_new = HAL_GetTick();
539
d784f281833a Added inertia simulation for compass heading:
Ideenmodellierer
parents: 497
diff changeset
1070 compass_Inertia(pStateReal->lifeData.compass_heading);
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1071
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1072 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar));
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1073 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar));
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1074
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1075 if(pStateReal->mode == MODE_DIVE)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 {
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1077 for(int i= 0; i <16; i++)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1078 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1079 pStateReal->vpm.max_crushing_pressure_he[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_he[i];
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1080 pStateReal->vpm.max_crushing_pressure_n2[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_n2[i];
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1081 pStateReal->vpm.adjusted_critical_radius_he[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_he[i];
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1082 pStateReal->vpm.adjusted_critical_radius_n2[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_n2[i];
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1083 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1086 /* battery and ambient light sensors
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1087 */
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1088 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1089 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1090 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage;
275
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1091
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1092 /* PIC data
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1093 */
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1094 for(int i=0;i<4;i++)
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1095 {
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1096 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i];
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1097 }
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1098
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1099 /* sensorErrors
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1100 */
189387bf23a8 Do not mark data as valid if devicedata is received.
ideenmodellierer
parents: 232
diff changeset
1101 pStateReal->sensorErrorsRTE = dataIn.sensorErrors;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1102
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1103 /* data from CO2 sensor */
691
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
1104 pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm;
52d68cf9994c Improvment external interface usage:
Ideenmodellierer
parents: 662
diff changeset
1105 pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength;
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1106 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 /* apnea specials
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 if(pStateReal->mode != MODE_DIVE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 pStateReal->lifeData.apnea_total_max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 pStateReal->lifeData.apnea_last_dive_time_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 pStateReal->lifeData.apnea_last_max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 if(pStateReal->lifeData.dive_time_seconds > 15)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 if(pStateReal->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 if(pStateReal->lifeData.max_depth_meter > 1.5f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 }
173
05c770dc2911 Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents: 156
diff changeset
1135 // reset max_depth_meter, average_depth_meter and internal values
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 pStateReal->lifeData.max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 pStateReal->lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140
308
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
1141 setAvgDepth(pStateReal);
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
1142 }
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
1143
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
1144 void setAvgDepth(SDiveState *pStateReal) {
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
1145
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 float DepthNow = pStateReal->lifeData.depth_meter;
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1148 static uint32_t AvgDepthCount = 0;
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1149 static uint32_t AvgDepthTimer = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 uint32_t AvgSecondsSinceLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time;
308
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
1152
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 if(pStateReal->lifeData.boolResetAverageDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 *AvgDepthValue = DepthNow;
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1156 AvgDepthCount = 0;
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1157 AvgDepthTimer = DiveTime;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 pStateReal->lifeData.boolResetAverageDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 }
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1160 else if (DiveTime > AvgDepthTimer)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 {
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1162 AvgSecondsSinceLast = DiveTime - AvgDepthTimer;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 for(int i=0;i<AvgSecondsSinceLast;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 {
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1165 *AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1);
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1166 AvgDepthCount += 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 }
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1168 AvgDepthTimer = DiveTime;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 }
309
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1170 if(AvgDepthCount == 0)
b0045281cb2d cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents: 308
diff changeset
1171 *AvgDepthValue = DepthNow;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 uint8_t DataEX_check_RTE_version__needs_update(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 if(data_old__lost_connection_to_slave_counter_retry > 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
1201 /* Check if there is an empty frame provided by RTE (all 0) or even no data provided by RTE (all 0xFF)
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1202 * If that is not the case the DMA is somehow not in sync
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1203 */
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
1204 static uint8_t DataEX_check_header_and_footer_shifted()
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1205 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1206 uint8_t ret = 1;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1207 if((dataIn.footer.checkCode[0] == 0x00)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1208 && (dataIn.footer.checkCode[1] == 0x00)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1209 && (dataIn.footer.checkCode[2] == 0x00)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1210 && (dataIn.footer.checkCode[3] == 0x00)) { ret = 0; }
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1211
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1212 if((dataIn.footer.checkCode[0] == 0xff)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1213 && (dataIn.footer.checkCode[1] == 0xff)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1214 && (dataIn.footer.checkCode[2] == 0xff)
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1215 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; }
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1216
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1217 return ret;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1218 }
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1219
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
1220 static uint8_t DataEX_check_header_and_footer_ok(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 if(dataIn.header.checkCode[0] != 0xA1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 return 0;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1224 #if USE_OLD_HEADER_FORMAT
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 if(dataIn.header.checkCode[1] != 0xA2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 if(dataIn.header.checkCode[2] != 0xA3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 return 0;
141
30d855ea60d8 Only use data if data frame is valid
Ideenmodellierer
parents: 138
diff changeset
1229 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 if(dataIn.header.checkCode[3] != 0xA4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 if(dataIn.footer.checkCode[0] != 0xE1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 if(dataIn.footer.checkCode[1] != 0xE2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 if(dataIn.footer.checkCode[2] != 0xE3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 if(dataIn.footer.checkCode[3] != 0xE4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243
198
878dc9e0dbc5 cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents: 197
diff changeset
1244 static uint8_t DataEX_check_header_and_footer_devicedata(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 if(dataIn.header.checkCode[0] != 0xDF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 if(dataIn.header.checkCode[1] != 0xDE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 if(dataIn.header.checkCode[2] != 0xDD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 if(dataIn.header.checkCode[3] != 0xDC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 if(dataIn.footer.checkCode[0] != 0xE1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 if(dataIn.footer.checkCode[1] != 0xE2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 if(dataIn.footer.checkCode[2] != 0xE3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 if(dataIn.footer.checkCode[3] != 0xE4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 }
407
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1265
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1266 void DataEX_merge_devicedata(void)
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1267 {
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1268 if(DeviceDataUpdated)
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1269 {
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1270 DeviceDataUpdated = 0;
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1271 DataEX_merge_DeviceData_and_store();
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1272 }
b11e50415982 Bugfix parallel call of external flash functions:
ideenmodellierer
parents: 406
diff changeset
1273 }
556
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
1274 uint8_t DataEX_external_ADC_Present(void)
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
1275 {
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
1276 uint8_t retval;
559
84a4e1200726 Check if HW evaluation was performed:
Ideenmodellierer
parents: 556
diff changeset
1277 retval = hw_Info.extADC;
556
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
1278
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
1279 return retval;
eb2060caca7d Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents: 539
diff changeset
1280 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1281
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1282 void DataEX_setExtInterface_Cmd(uint16_t Cmd)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1283 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1284 externalInterface_Cmd = Cmd;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1285 return;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1286 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 584
diff changeset
1287