annotate Discovery/Src/data_exchange_main.c @ 137:9eda5a75c5fd FlipDisplay

Only copy data if data connection to RTE is valid Only abort DMA if resync is not already in progress
author Ideenmodellierer
date Tue, 19 Feb 2019 21:48:32 +0100
parents acc98f5bd8c4
children cc9c18075e00
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 on receiption the data is merged with the data in externLogbookFlash,
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>
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 #include <string.h> // for memcopy
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 #include "bonex_mini.h" // for voltage to battery percentage
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 /* Expoted variables --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 uint8_t wasPowerOn = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 confirmbit8_Type requestNecessary = { .uw = 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 uint8_t wasUpdateNotPowerOn = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 uint8_t scooterFoundThisPowerOnCylce = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 /* Private variables with external access ------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 uint8_t told_reset_logik_alles_ok = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 SDataReceiveFromMaster dataOut;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 SDataExchangeSlaveToMaster dataIn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 uint32_t systick_last;
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
93 uint32_t systick_last_spi;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 uint8_t data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 uint8_t data_old__lost_connection_to_slave_counter_retry = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 uint32_t data_old__lost_connection_to_slave_counter_total = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 typedef enum
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 CPU2_TRANSFER_STOP = 0x00, /*!< */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 CPU2_TRANSFER_TEST_REQUEST = 0x01, /*!< */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 CPU2_TRANSFER_TEST_RECEIVE = 0x02, /*!< */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 CPU2_TRANSFER_SEND_OK = 0x03, /*!< */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 CPU2_TRANSFER_SEND_FALSE = 0x04, /*!< */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 CPU2_TRANSFER_DATA = 0x05, /*!< */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 }CPU2_TRANSFER_StatusTypeDef;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 const uint8_t header_test_request[4] = {0xBB, 0x00, 0x00, 0xBB};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 const uint8_t header_test_receive[4] = {0xBB, 0x01, 0x01, 0xBB};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 const uint8_t header_false[4] = {0xBB, 0xFF, 0xFF, 0xBB};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 const uint8_t header_correct[4] = {0xBB, 0xCC, 0xCC, 0xBB};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 const uint8_t header_data[4] = {0xAA, 0x01, 0x01, 0xAA};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 uint8_t DataEX_check_header_and_footer_ok(void);
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
118 uint8_t DataEX_check_header_and_footer_shifted(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 uint8_t DataEX_check_header_and_footer_devicedata(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 void DataEX_check_DeviceData(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 void DataEX_set_update_RTE_not_power_on(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 wasUpdateNotPowerOn = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 uint8_t DataEX_was_power_on(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 return wasPowerOn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 uint8_t count_DataEX_Error_Handler = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 uint8_t last_error_DataEX_Error_Handler = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 void DataEX_Error_Handler(uint8_t answer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 count_DataEX_Error_Handler++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 last_error_DataEX_Error_Handler = answer;
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
141
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
142 /* A wrong footer indicates a communication interrupt. Statemachine is waiting for new data which is not received because no new transmission is triggered */
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
143 /* ==> Abort data exchange to enable a new RX / TX cycle */
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
144 if(answer == HAL_BUSY)
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
145 {
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
146 HAL_SPI_Abort_IT(&cpu2DmaSpi);
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
147 data_old__lost_connection_to_slave_counter_total += 1000; /* add significant error offset to indicate error causing an abort event */
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
148 }
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
149
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 uint32_t DataEX_lost_connection_count(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 return data_old__lost_connection_to_slave_counter_total;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 uint32_t DataEX_time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 if(ticksstart <= ticksnow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 return ticksnow - ticksstart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 return 0xFFFFFFFF - ticksstart + ticksnow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 SDataReceiveFromMaster * dataOutGetPointer(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 return &dataOut;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 void DataEX_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 SDiveState * pStateReal = stateRealGetPointerWrite();
99
6a2308b9a3d4 Config for debug data
Dmitry Romanov <kitt@bk.ru>
parents: 90
diff changeset
182 pStateReal->data_old__lost_connection_to_slave = 0; //initial value
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 data_old__lost_connection_to_slave_counter_total = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 // old 160307: for(int i=0;i<EXCHANGE_BUFFERSIZE;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 // *(uint8_t *)(((uint32_t)&dataOut) + i) = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 dataOut.header.checkCode[0] = 0xBB;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 dataOut.header.checkCode[1] = 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 dataOut.header.checkCode[2] = 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 dataOut.header.checkCode[3] = 0xBB;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 dataOut.footer.checkCode[0] = 0xF4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 dataOut.footer.checkCode[1] = 0xF3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 dataOut.footer.checkCode[2] = 0xF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 dataOut.footer.checkCode[3] = 0xF1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 pStateReal->lifeData.scooterType = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 pStateReal->lifeData.scooterWattstunden = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 pStateReal->lifeData.scooterRestkapazitaet = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 pStateReal->lifeData.scooterDrehzahl = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 pStateReal->lifeData.scooterSpannung = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 pStateReal->lifeData.scooterTemperature = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 pStateReal->lifeData.scooterAmpere = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 pStateReal->lifeData.scooterRestkapazitaetWhBased = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 pStateReal->lifeData.scooterRestkapazitaetVoltageBased = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 pStateReal->lifeData.scooterAgeInMilliSeconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 systick_last = HAL_GetTick() - 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 }
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 void DataEx_call_helper_requests(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 static uint8_t setDateWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 static uint8_t setTimeWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 static uint8_t calibrateCompassWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 static uint8_t setButtonSensitivityWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 static uint8_t clearDecoWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 static uint8_t getDeviceDataWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 static uint8_t setAccidentFlagWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 static uint8_t setEndDiveWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 if(getDeviceDataWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 dataOut.getDeviceDataNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 requestNecessary.ub.devicedata = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 getDeviceDataWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 if(dataOut.getDeviceDataNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 getDeviceDataWasSend = 1;
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(setEndDiveWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 dataOut.setEndDive = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 //requestNecessary.ub.XXX = 1; not implemented and no space here
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 setEndDiveWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 if(dataOut.setEndDive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 setEndDiveWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 if(setAccidentFlagWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 dataOut.setAccidentFlag = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 requestNecessary.ub.accident = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 setAccidentFlagWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 if(dataOut.setAccidentFlag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 setAccidentFlagWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 if(setDateWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 dataOut.setDateNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 requestNecessary.ub.date = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 setDateWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 if(dataOut.setDateNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 setDateWasSend = 1;
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 if(setTimeWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 dataOut.setTimeNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 requestNecessary.ub.time = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 setTimeWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 if(dataOut.setTimeNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 setTimeWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 if(calibrateCompassWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 dataOut.calibrateCompassNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 requestNecessary.ub.compass = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 calibrateCompassWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 if(dataOut.calibrateCompassNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 calibrateCompassWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 if(clearDecoWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 dataOut.clearDecoNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 requestNecessary.ub.clearDeco = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 if(dataOut.clearDecoNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 clearDecoWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 if(setButtonSensitivityWasSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 dataOut.setButtonSensitivityNow = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 requestNecessary.ub.button = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 setButtonSensitivityWasSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 if(dataOut.setButtonSensitivityNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 setButtonSensitivityWasSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 uint8_t DataEX_call(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 uint8_t SPI_DMA_answer = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
104
22a1094545f3 Tested and alive.
Dmitry Romanov <kitt@bk.ru>
parents: 99
diff changeset
321 delayMicros(20); //~exchange time(+20% reserve)
87
Dmitry Romanov <kitt@bk.ru>
parents: 82
diff changeset
322 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 /* one cycle with NotChipSelect true to clear slave spi buffer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 if(data_old__lost_connection_to_slave_counter_temp >= 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 data_old__lost_connection_to_slave_counter_temp = 0;
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
328 if(DataEX_check_header_and_footer_shifted())
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
329 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
330 HAL_SPI_Abort_IT(&cpu2DmaSpi);
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
331 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 data_old__lost_connection_to_slave_counter_retry++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 DataEx_call_helper_requests();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 systick_last = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
341
89
ff7775cc34c4 temp! full cyclic SPI
Dmitry Romanov <kitt@bk.ru>
parents: 88
diff changeset
342 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE);
87
Dmitry Romanov <kitt@bk.ru>
parents: 82
diff changeset
343 // HAL_Delay(3);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 if(SPI_DMA_answer != HAL_OK)
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
345 DataEX_Error_Handler(SPI_DMA_answer);
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
346
104
22a1094545f3 Tested and alive.
Dmitry Romanov <kitt@bk.ru>
parents: 99
diff changeset
347 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 //HAL_Delay(3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 //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
350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353
82
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
354
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
355 uint32_t SPI_CALLBACKS;
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
356 uint32_t get_num_SPI_CALLBACKS(void){
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
357 return SPI_CALLBACKS;
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
358 }
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 SDataExchangeSlaveToMaster* get_dataInPointer(void){
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
361 return &dataIn;
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
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
364
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
365 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
366 {
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 if(hspi == &cpu2DmaSpi)
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
370 {
133
acc98f5bd8c4 Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents: 115
diff changeset
371 systick_last_spi = HAL_GetTick();
82
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
372 SPI_CALLBACKS+=1;
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
373 }
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
374 }
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
375
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
376
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
377
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
378
a6f0881074a4 +i2c analog noise filtering
Dmitry Romanov <kitt@bk.ru>
parents: 51
diff changeset
379
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 void DateEx_copy_to_dataOut(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 const SDiveState * pStateReal = stateRealGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 if(get_globalState() == StStop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 dataOut.mode = MODE_SHUTDOWN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 dataOut.mode = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 dataOut.diveModeInfo = pStateReal->diveSettings.diveMode; // hw 170215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 memcpy(&dataOut.data.DeviceData, stateDeviceGetPointer(), sizeof(SDevice));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 dataOut.data.VPMconservatism = pStateReal->diveSettings.vpm_conservatism;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 dataOut.data.actualGas = pStateReal->lifeData.actualGas;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 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
397 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15))))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 dataOut.revisionHardware = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 dataOut.revisionCRCx0x7A = 0x7A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 if(hardwareDataGetPointer()->primarySerial < 0xFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 dataOut.revisionHardware = hardwareDataGetPointer()->revision8bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 dataOut.revisionCRCx0x7A = hardwareDataGetPointer()->revision8bit ^ 0x7A;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 dataOut.revisionHardware = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 dataOut.revisionCRCx0x7A = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 for(int i = 0; i< 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 dataOut.data.VPM_adjusted_critical_radius_he[i] = pStateReal->vpm.adjusted_critical_radius_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 dataOut.data.VPM_adjusted_critical_radius_n2[i] = pStateReal->vpm.adjusted_critical_radius_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 dataOut.data.VPM_adjusted_crushing_pressure_he[i] = pStateReal->vpm.adjusted_crushing_pressure_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 dataOut.data.VPM_adjusted_crushing_pressure_n2[i] = pStateReal->vpm.adjusted_crushing_pressure_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 dataOut.data.VPM_initial_allowable_gradient_he[i] = pStateReal->vpm.initial_allowable_gradient_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 dataOut.data.VPM_initial_allowable_gradient_n2[i] = pStateReal->vpm.initial_allowable_gradient_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 dataOut.data.VPM_max_actual_gradient[i] = pStateReal->vpm.max_actual_gradient[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 MX_tell_reset_logik_alles_ok();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 told_reset_logik_alles_ok = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 if(!wasUpdateNotPowerOn)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 wasPowerOn = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 RTC_DateTypeDef Sdate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 RTC_TimeTypeDef Stime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 translateDate(settings->backup_localtime_rtc_dr, &Sdate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 translateTime(settings->backup_localtime_rtc_tr, &Stime);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 dataOut.data.newTime = Stime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 dataOut.setTimeNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 dataOut.data.newDate = Sdate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 dataOut.setDateNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 setButtonResponsiveness(settings->ButtonResponsiveness);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 // hw 160720 new lastKnownBatteryPercentage
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 if(!wasUpdateNotPowerOn)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 // dataOut.data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 dataOut.data.newBatteryGaugePercentageFloat = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 dataOut.setBatteryGaugeNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 }
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 void DataEX_copy_to_deco(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 SDiveState * pStateUsed;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 if(decoLock == DECO_CALC_running)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 if(stateUsed == stateRealGetPointer())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 pStateUsed = stateRealGetPointerWrite();
90
83857eb3b12b +- stable
Dmitry Romanov <kitt@bk.ru>
parents: 89
diff changeset
476 else{
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 pStateUsed = stateSimGetPointerWrite();
90
83857eb3b12b +- stable
Dmitry Romanov <kitt@bk.ru>
parents: 89
diff changeset
478 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 if(decoLock == DECO_CALC_init_as_is_start_of_dive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 vpm_init(&pStateUsed->vpm, pStateUsed->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 buehlmann_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 timer_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 resetEvents();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 * ToDo by Peter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 * copy VPM stuff etc. pp.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 * was void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 if(decoLock == DECO_CALC_FINSHED_Buehlmann)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 switch(decoLock)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 //Deco_calculation finished
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 case DECO_CALC_FINSHED_vpm:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 memcpy(&pStateUsed->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 pStateUsed->decolistVPM.tickstamp = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 pStateUsed->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 for(int i = 0; i< 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 pStateUsed->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 pStateUsed->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 pStateUsed->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 pStateUsed->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 pStateUsed->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 pStateUsed->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 pStateUsed->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 case DECO_CALC_FINSHED_Buehlmann:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 memcpy(&pStateUsed->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 pStateUsed->decolistBuehlmann.tickstamp = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 pStateUsed->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;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 case DECO_CALC_FINSHED_FutureBuehlmann:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 memcpy(&pStateUsed->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 pStateUsed->decolistFutureBuehlmann.tickstamp = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 case DECO_CALC_FINSHED_Futurevpm:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 memcpy(&pStateUsed->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 pStateUsed->decolistFutureVPM.tickstamp = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 //Copy Inputdata from stateReal to stateDeco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 memcpy(&stateDeco.lifeData,&pStateUsed->lifeData,sizeof(SLifeData));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 memcpy(&stateDeco.diveSettings,&pStateUsed->diveSettings,sizeof(SDiveSettings));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 stateDeco.vpm.deco_zone_reached = pStateUsed->vpm.deco_zone_reached;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 for(int i = 0; i< 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 stateDeco.vpm.max_crushing_pressure_he[i] = pStateUsed->vpm.max_crushing_pressure_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 stateDeco.vpm.max_crushing_pressure_n2[i] = pStateUsed->vpm.max_crushing_pressure_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 stateDeco.vpm.adjusted_critical_radius_he[i] = pStateUsed->vpm.adjusted_critical_radius_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 stateDeco.vpm.adjusted_critical_radius_n2[i] = pStateUsed->vpm.adjusted_critical_radius_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 decoLock = DECO_CALC_ready;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 lineWrite->date_rtc_dr = lineRead->date_rtc_dr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 lineWrite->time_rtc_tr = lineRead->time_rtc_tr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 lineWrite->value_int32 = lineRead->value_int32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 inStimestructure.TimeFormat = RTC_HOURFORMAT_24;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 (((uint32_t)inStimestructure.TimeFormat) << 16U));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 ((uint32_t)inSdatestructure.WeekDay << 13U));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 RTC_DateTypeDef sdatestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 RTC_TimeTypeDef stimestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 stimestructure.Hours = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 stimestructure.Minutes = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 stimestructure.Seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 sdatestructure.Date = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 sdatestructure.Month = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 sdatestructure.Year = 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 setWeekday(&sdatestructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 RTC_DateTypeDef sdatestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 RTC_TimeTypeDef stimestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 // from lineWrite to structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 translateDate(lineWrite->date_rtc_dr, &sdatestructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 translateTime(lineWrite->time_rtc_tr, &stimestructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 if( (sdatestructure.Year >= 15)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 && (sdatestructure.Year <= 30)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 && (sdatestructure.Month <= 12))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 DataEX_helper_set_Unknown_Date_deviceData(lineWrite);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 if(lineWrite->value_int32 < from)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 lineWrite->value_int32 = from;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 lineWrite->value_int32 = to;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 DataEX_helper_set_Unknown_Date_deviceData(lineWrite);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 void DataEX_check_DeviceData(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 SDevice *DeviceData = stateDeviceGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 void DataEX_merge_DeviceData_and_store(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 uint16_t dataLengthRead;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 SDevice DeviceDataFlash;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 SDevice *DeviceData = stateDeviceGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 if(dataLengthRead == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 ext_flash_write_devicedata();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 SDeviceLine batteryChargeCycles;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 SDeviceLine batteryChargeCompleteCycles;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 SDeviceLine temperatureMinimum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 SDeviceLine temperatureMaximum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 SDeviceLine depthMaximum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 SDeviceLine diveCycles;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 SDeviceLine voltageMinimum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 /* max values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 /* min values */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 // Voltage minimum, keep limit to 2.0 Volt; hw 09.09.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 if(DeviceDataFlash.voltageMinimum.value_int32 > 2000) // do not copy back 2000 and below
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 if(DeviceData->voltageMinimum.value_int32 < 2000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 DeviceData->voltageMinimum.value_int32 = 2000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 DataEX_check_DeviceData ();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 ext_flash_write_devicedata();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 void DataEX_copy_to_DeviceData(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 SDevice * pDeviceState = stateDeviceGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 void DataEX_copy_to_VpmRepetitiveData(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 if(dataInDevice->boolVpmRepetitiveDataValid)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 pVpmState->is_data_from_RTE_CPU = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 void DataEX_control_connection_while_asking_for_sleep(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 if(!DataEX_check_header_and_footer_ok())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 if(DataEX_check_header_and_footer_devicedata())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 data_old__lost_connection_to_slave_counter_retry = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 data_old__lost_connection_to_slave_counter_temp += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 data_old__lost_connection_to_slave_counter_total += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 SDiveState * pStateReal = stateRealGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 static uint16_t getDeviceDataAfterStartOfMainCPU = 20;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 /* internal sensor: HUD data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 for(int i=0;i<3;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 // wireless - �ltere daten aufr�umen
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
783 for(int i=0;i<(2*NUM_GASES+1);i++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 if(pStateReal->lifeData.bottle_bar[i])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 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
788 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 pStateReal->lifeData.bottle_bar[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 /* Why? hw 8.6.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 if(DataEX_check_header_and_footer_ok() && dataIn.power_on_reset)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 if(!DataEX_check_header_and_footer_ok())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 if(DataEX_check_header_and_footer_devicedata())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 DataEX_copy_to_DeviceData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 DataEX_merge_DeviceData_and_store();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 DataEX_copy_to_VpmRepetitiveData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 data_old__lost_connection_to_slave_counter_retry = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 pStateReal->data_old__lost_connection_to_slave = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 pStateReal->data_old__lost_connection_to_slave = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 data_old__lost_connection_to_slave_counter_temp += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 data_old__lost_connection_to_slave_counter_total += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 if(getDeviceDataAfterStartOfMainCPU)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 getDeviceDataAfterStartOfMainCPU--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 if(getDeviceDataAfterStartOfMainCPU == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 dataOut.getDeviceDataNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 getDeviceDataAfterStartOfMainCPU = 10*60*10;// * 100ms
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 /* new 151207 hw */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 if(requestNecessary.uw != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 requestNecessary.ub.button = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 if(requestNecessary.ub.button == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 if((dataIn.confirmRequest.ub.clearDeco != 1) && (requestNecessary.ub.clearDeco == 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 clearDeco(); // is dataOut.clearDecoNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 requestNecessary.uw = 0; // clear all
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 float ambient, surface, density, meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 SSettings *pSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 /* uint8_t IAmStolenPleaseKillMe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 */
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
860 pSettings = settingsGetPointer();
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
861
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
862 if(pSettings->IAmStolenPleaseKillMe > 3)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 pSettings->salinity = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 dataIn.data[dataIn.boolPressureData].surface_mbar = 999;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 dataIn.mode = MODE_DIVE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
870 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
871 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
872 ambient = dataIn.data[dataIn.boolPressureData].pressure_mbar / 1000.0f;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
873 surface = dataIn.data[dataIn.boolPressureData].surface_mbar / 1000.0f;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
875 density = ((float)( 100 + pSettings->salinity)) / 100.0f;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
876 meter = (ambient - surface);
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
877 meter /= (0.09807f * density);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
880 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
881 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
882 pStateReal->pressure_uTick_local_new = HAL_GetTick();
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
883
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
884 if(ambient < (surface + 0.04f))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
886 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
887 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
888 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 dataOut.setAccidentFlag = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 //Start of diveMode?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 if(modeChangeFlag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 *modeChangeFlag = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 if(stateUsed == stateSimGetPointer())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 // new 170508
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 settingsGetPointer()->bluetoothActive = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 MX_Bluetooth_PowerOff();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 //Init dive Mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 decoLock = DECO_CALC_init_as_is_start_of_dive;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 pStateReal->lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 pStateReal->lifeData.boolResetStopwatch = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 //End of diveMode?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 if(modeChangeFlag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 *modeChangeFlag = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 createDiveSettings();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 if(pStateReal->warnings.cnsHigh)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 if(pStateReal->lifeData.cns >= 130)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 else if(pStateReal->lifeData.cns >= 100)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 dataOut.setAccidentFlag += ACCIDENT_CNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 if(pStateReal->warnings.decoMissed)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 pStateReal->mode = dataIn.mode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 pStateReal->chargeStatus = dataIn.chargeStatus;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 pStateReal->lifeData.pressure_ambient_bar = ambient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 pStateReal->lifeData.pressure_surface_bar = surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 pStateReal->lifeData.depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 pStateReal->lifeData.depth_meter = meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 }
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
939
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
940 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
941 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
942 pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
943 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
944 if(pStateReal->mode != MODE_DIVE)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
945 pStateReal->lifeData.max_depth_meter = 0;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
946 else
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
947 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
948 if(meter > pStateReal->lifeData.max_depth_meter)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
949 pStateReal->lifeData.max_depth_meter = meter;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
950 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
952 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
953 pStateReal->decoMissed_at_the_end_of_dive = 1;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
954 if(dataIn.accidentFlags & ACCIDENT_CNS)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
955 pStateReal->cnsHigh_at_the_end_of_dive = 1;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
956
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
957 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
958 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
959 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
960 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961
109
65a6e352ce08 Consider computer heading in case of a flipped display
Ideenmodellierer
parents: 51
diff changeset
962
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
963 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
964 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
965 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
966 pStateReal->lifeData.compass_heading -= 180.0;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
967 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
968 }
109
65a6e352ce08 Consider computer heading in case of a flipped display
Ideenmodellierer
parents: 51
diff changeset
969
65a6e352ce08 Consider computer heading in case of a flipped display
Ideenmodellierer
parents: 51
diff changeset
970
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
971 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
972 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
974 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
975 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
976 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
978 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
979 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
980 pStateReal->compass_uTick_local_new = HAL_GetTick();
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
981
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
982 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
983 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
984 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
985 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
987 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
988 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
989
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
990 if(pStateReal->mode == MODE_DIVE)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 {
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
992 for(int i= 0; i <16; i++)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
993 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
994 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
995 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
996 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
997 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
998 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1001 /* battery and ambient light sensors
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1002 */
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1003 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
1004 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
1005 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1006 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 /* now in ext_flash_write_settings() // hw 161027
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 * if((pStateReal->lifeData.battery_charge > 1) && !DataEX_was_power_on() && ((uint8_t)(pStateReal->lifeData.battery_charge) != 0x10)) // get rid of 16% (0x10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 * pSettings->lastKnownBatteryPercentage = (uint8_t)(pStateReal->lifeData.battery_charge);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 /* OC and CCR but no sensors -> moved to updateSetpointStateUsed();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 float oxygen = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 if(pStateReal->diveSettings.diveMode == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 oxygen = 1.00f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 oxygen -= ((float)pStateReal->lifeData.actualGas.nitrogen_percentage)/100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 oxygen -= ((float)pStateReal->lifeData.actualGas.helium_percentage)/100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 pStateReal->lifeData.ppO2 = pStateReal->lifeData.pressure_ambient_bar * oxygen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 else if(pStateReal->diveSettings.diveMode == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 pStateReal->lifeData.ppO2 = ((float)pStateReal->lifeData.actualGas.setPoint_cbar) /100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 /* apnea specials
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 if(pStateReal->mode != MODE_DIVE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 pStateReal->lifeData.apnea_total_max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 pStateReal->lifeData.apnea_last_dive_time_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 pStateReal->lifeData.apnea_last_max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 if(pStateReal->lifeData.dive_time_seconds > 15)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 if(pStateReal->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 if(pStateReal->lifeData.max_depth_meter > 1.5f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 // eset max_depth_meter, average_depth_meter and internal values
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 pStateReal->lifeData.max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 pStateReal->lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 pStateReal->lifeData.boolResetStopwatch = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 /* average depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 float DepthNow = pStateReal->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 uint32_t AvgSecondsSinceLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 if(pStateReal->lifeData.boolResetAverageDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 *AvgDepthValue = DepthNow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 *AvgDepthCount = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 *AvgDepthTimer = DiveTime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 pStateReal->lifeData.boolResetAverageDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 else if (DiveTime > *AvgDepthTimer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 for(int i=0;i<AvgSecondsSinceLast;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 *AvgDepthCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 *AvgDepthTimer = DiveTime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 if(*AvgDepthCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 *AvgDepthValue = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 /* stop watch
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 if(pStateReal->lifeData.boolResetStopwatch)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds = pStateReal->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 pStateReal->lifeData.boolResetStopwatch = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 pStateReal->lifeData.stopwatch_seconds = pStateReal->lifeData.dive_time_seconds - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 /* wireless data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 uint16_t wirelessData[4][3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 pStateReal->lifeData.wireless_data[i].ageInMilliSeconds = dataIn.data[dataIn.boolWirelessData].wireless_data[i].ageInMilliSeconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 pStateReal->lifeData.wireless_data[i].status = dataIn.data[dataIn.boolWirelessData].wireless_data[i].status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 pStateReal->lifeData.wireless_data[i].numberOfBytes = dataIn.data[dataIn.boolWirelessData].wireless_data[i].numberOfBytes;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 for(int j=0;j<12;j++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 pStateReal->lifeData.wireless_data[i].data[j] = dataIn.data[dataIn.boolWirelessData].wireless_data[i].data[j];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 /* old stuff
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 // crc - is done in RTE 160325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 // size at the moment 4 bytes + one empty + crc -> minimum 5 bytes (+ crc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 // kopieren: Id, Wert, Alter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 uint8_t numberOfBytes = pStateReal->lifeData.wireless_data[i].numberOfBytes - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 if((numberOfBytes < 5) || (numberOfBytes > 7))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 wirelessData[i][0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 wirelessData[i][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 wirelessData[i][2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 if((crc32c_checksum(pStateReal->lifeData.wireless_data[i].data, numberOfBytes, 0, 0) & 0xFF)!= pStateReal->lifeData.wireless_data[i].data[numberOfBytes])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 // no crc is send at the moment
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 // wirelessData[i][0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 // wirelessData[i][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 // wirelessData[i][2] = 0;
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 // neu 160412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] >> 4) & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 wirelessData[i][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 wirelessData[i][0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 wirelessData[i][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 wirelessData[i][2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 // aussortieren doppelte ids, j�ngster datensatz ist relevant
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 for(int i=0;i<3;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 if(wirelessData[i][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 for(int j=i+1; j<4; j++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 if(wirelessData[i][0] == wirelessData[j][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 if(wirelessData[i][2] > wirelessData[j][2])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 wirelessData[i][0] = wirelessData[j][0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 wirelessData[i][1] = wirelessData[j][1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 wirelessData[i][2] = wirelessData[j][2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 wirelessData[j][0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 wirelessData[j][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 wirelessData[j][2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 // neu 160325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 wirelessData[i][0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 wirelessData[i][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 wirelessData[i][2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 // aussortieren doppelte ids, j�ngster datensatz ist relevant
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 for(int i=0;i<3;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 if(wirelessData[i][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 for(int j=i+1; j<4; j++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 if(wirelessData[i][0] == wirelessData[j][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 if(wirelessData[i][2] > wirelessData[j][2])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 wirelessData[i][0] = wirelessData[j][0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 wirelessData[i][1] = wirelessData[j][1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 wirelessData[i][2] = wirelessData[j][2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 wirelessData[j][0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 wirelessData[j][1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 wirelessData[j][2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 /* old
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 // copy to lifeData
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 if((wirelessData[i][0]) && (wirelessData[i][2]) && (wirelessData[i][2] < 60000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 for(int j=1;j<=(2*NUM_GASES+1);j++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 if(pStateReal->diveSettings.gas[j].bottle_wireless_id == wirelessData[i][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 pStateReal->lifeData.bottle_bar[j] = wirelessData[i][1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 pStateReal->lifeData.bottle_bar_age_MilliSeconds[j] = wirelessData[i][2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 // new: Bonex
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 float scooterSpeedFloat;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 int32_t scooterRemainingBattCapacity;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 if((wirelessData[i][0]))// && (wirelessData[i][2]) && (wirelessData[i][2] < 60000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 pStateReal->lifeData.scooterType = (pStateReal->lifeData.wireless_data[i].data[0] >> 4) & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 pStateReal->lifeData.scooterWattstunden = ((uint16_t)((((uint16_t)(pStateReal->lifeData.wireless_data[i].data[0] & 0x0F) << 8) | (pStateReal->lifeData.wireless_data[i].data[1]))));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 // pStateReal->lifeData.scooterWattstunden = pStateReal->lifeData.wireless_data[i].data[0] & 0x0F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 // pStateReal->lifeData.scooterWattstunden *= 256;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 // pStateReal->lifeData.scooterWattstunden += pStateReal->lifeData.wireless_data[i].data[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 pStateReal->lifeData.scooterRestkapazitaet = pStateReal->lifeData.wireless_data[i].data[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 pStateReal->lifeData.scooterDrehzahl = ((uint16_t)( (int16_t)((pStateReal->lifeData.wireless_data[i].data[4] << 8) | (pStateReal->lifeData.wireless_data[i].data[3]))));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 pStateReal->lifeData.scooterSpannung = ((float)(pStateReal->lifeData.wireless_data[i].data[5])) / 5.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 pStateReal->lifeData.scooterTemperature = ((uint16_t)( (int16_t)((pStateReal->lifeData.wireless_data[i].data[7] << 8) | (pStateReal->lifeData.wireless_data[i].data[6]))));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 pStateReal->lifeData.scooterAmpere = pStateReal->lifeData.wireless_data[i].data[9] >> 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 pStateReal->lifeData.scooterAgeInMilliSeconds = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 if(pStateReal->lifeData.scooterWattstunden > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 scooterRemainingBattCapacity = settingsGetPointer()->scooterBattSize / pStateReal->lifeData.scooterWattstunden;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 scooterRemainingBattCapacity = 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 if(scooterRemainingBattCapacity < 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 scooterRemainingBattCapacity = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 if(scooterRemainingBattCapacity > 100)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 scooterRemainingBattCapacity = 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 pStateReal->lifeData.scooterRestkapazitaetWhBased = scooterRemainingBattCapacity;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 // BONEX_calc_new_ResidualCapacity(&pStateReal->lifeData.scooterRestkapazitaetVoltageBased, (uint32_t)(1000 * pStateReal->lifeData.scooterSpannung),1000,1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 pStateReal->lifeData.scooterRestkapazitaetVoltageBased = BONEX_mini_ResidualCapacityVoltageBased(pStateReal->lifeData.scooterSpannung, pStateReal->lifeData.scooterAgeInMilliSeconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 scooterSpeedFloat = (float)pStateReal->lifeData.scooterDrehzahl;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 scooterSpeedFloat /= (37.0f / 1.1f); // 3700 rpm = 110 m/min
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 switch(settingsGetPointer()->scooterDrag)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 case 1:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 scooterSpeedFloat *= 0.95f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 case 2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 scooterSpeedFloat *= 0.85f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 case 3:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 scooterSpeedFloat *= 0.75f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 switch(settingsGetPointer()->scooterLoad)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 case 1:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 scooterSpeedFloat *= 0.90f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 case 2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 scooterSpeedFloat *= 0.80f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 case 3:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 scooterSpeedFloat *= 0.70f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 case 4:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 scooterSpeedFloat *= 0.60f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 if(scooterSpeedFloat < 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 pStateReal->lifeData.scooterSpeed = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 if(scooterSpeedFloat > 255)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 pStateReal->lifeData.scooterSpeed = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 pStateReal->lifeData.scooterSpeed = (uint16_t)scooterSpeedFloat;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 if(!scooterFoundThisPowerOnCylce && (pStateReal->lifeData.scooterAgeInMilliSeconds > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 scooterFoundThisPowerOnCylce = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 /* PIC data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 for(int i=0;i<4;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 /* sensorErrors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 pStateReal->sensorErrorsRTE = dataIn.sensorErrors;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 /* end
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 data_old__lost_connection_to_slave_counter_temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 data_old__lost_connection_to_slave_counter_retry = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 pStateReal->data_old__lost_connection_to_slave = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 uint8_t DataEX_check_RTE_version__needs_update(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 if(data_old__lost_connection_to_slave_counter_retry > 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 uint8_t DataEX_scooterDataFound(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 return scooterFoundThisPowerOnCylce;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 uint8_t DataEX_scooterFoundAndValidLicence(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 if(getLicence() != LICENCEBONEX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 return scooterFoundThisPowerOnCylce;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 //return 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 //return LICENCEBONEX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389
137
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1390 /* Check if there is an empty frame providec by RTE (all 0) or even no data provided by RTE (all 0xFF)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1391 * 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
1392 */
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1393 uint8_t DataEX_check_header_and_footer_shifted()
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1394 {
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1395 uint8_t ret = 1;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1396 if((dataIn.footer.checkCode[0] != 0x00)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1397 && (dataIn.footer.checkCode[1] != 0x00)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1398 && (dataIn.footer.checkCode[2] != 0x00)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1399 && (dataIn.footer.checkCode[3] != 0x00)) { ret = 0; }
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1400
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1401 if((dataIn.footer.checkCode[0] != 0xff)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1402 && (dataIn.footer.checkCode[1] != 0xff)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1403 && (dataIn.footer.checkCode[2] != 0xff)
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1404 && (dataIn.footer.checkCode[3] != 0xff)) { ret = 0; }
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1405
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1406 return ret;
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1407 }
9eda5a75c5fd Only copy data if data connection to RTE is valid
Ideenmodellierer
parents: 133
diff changeset
1408
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409 uint8_t DataEX_check_header_and_footer_ok(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 if(dataIn.header.checkCode[0] != 0xA1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 if(dataIn.header.checkCode[1] != 0xA2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 if(dataIn.header.checkCode[2] != 0xA3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 if(dataIn.header.checkCode[3] != 0xA4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 if(dataIn.footer.checkCode[0] != 0xE1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 if(dataIn.footer.checkCode[1] != 0xE2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 if(dataIn.footer.checkCode[2] != 0xE3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 if(dataIn.footer.checkCode[3] != 0xE4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 uint8_t DataEX_check_header_and_footer_devicedata(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 if(dataIn.header.checkCode[0] != 0xDF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 if(dataIn.header.checkCode[1] != 0xDE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 if(dataIn.header.checkCode[2] != 0xDD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439 if(dataIn.header.checkCode[3] != 0xDC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 if(dataIn.footer.checkCode[0] != 0xE1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 if(dataIn.footer.checkCode[1] != 0xE2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 if(dataIn.footer.checkCode[2] != 0xE3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 if(dataIn.footer.checkCode[3] != 0xE4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454