Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 726:8f3a8c85a6c4
Bugfix data synchronization after RTE start:
In previous version invalid data may be transferred in case the communication is corrupted directly after RTE startup. Root cause was that the data was evaluated without caring if a communication error was reported. In the new version the startup condition and evaluation of data is only done if valid data has been received by the RTE => SPI communication is up and runnig.
author | Ideenmodellierer |
---|---|
date | Sat, 14 Jan 2023 20:35:40 +0100 |
parents | 621265ec3d23 |
children | d646a0f724a7 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file uart.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @version V0.0.1 | |
6 * @date 27-March-2014 | |
7 * @brief button control | |
8 * | |
9 @verbatim | |
10 ============================================================================== | |
11 ##### How to use ##### | |
12 ============================================================================== | |
13 @endverbatim | |
14 ****************************************************************************** | |
15 * @attention | |
16 * | |
17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
18 * | |
19 ****************************************************************************** | |
20 */ | |
21 /* Includes ------------------------------------------------------------------*/ | |
22 #include "uart.h" | |
662 | 23 #include "externalInterface.h" |
24 #include "data_exchange.h" | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
25 #include <string.h> /* memset */ |
38 | 26 |
27 /* Private variables ---------------------------------------------------------*/ | |
28 | |
721 | 29 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */ |
30 #define CHUNKS_PER_BUFFER (5u) | |
662 | 31 UART_HandleTypeDef huart1; |
32 | |
33 DMA_HandleTypeDef hdma_usart1_rx; | |
38 | 34 |
662 | 35 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ |
36 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */ | |
37 static uint8_t rxReadIndex; /* Index at which new data is stared */ | |
38 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */ | |
39 static uint8_t dmaActive; /* Indicator if DMA receiption needs to be started */ | |
38 | 40 |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
41 static SSensorDataDiveO2 sensorDataDiveO2; /* intermediate storage for additional sensor data */ |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
42 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
43 char tmpRxBuf[30]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
44 uint8_t tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
45 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
46 static uartO2Status_t Comstatus_O2 = UART_O2_INIT; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
47 |
662 | 48 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */ |
49 float LED_ZeroOffset = 0.0; | |
50 float pCO2 = 0.0; | |
38 | 51 /* Exported functions --------------------------------------------------------*/ |
52 | |
662 | 53 void MX_USART1_UART_Init(void) |
38 | 54 { |
662 | 55 /* regular init */ |
56 | |
57 huart1.Instance = USART1; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
58 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
59 if(externalInterface_GetUARTProtocol() == 0x04) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
60 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
61 huart1.Init.BaudRate = 19200; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
62 Comstatus_O2 = UART_O2_INIT; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
63 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
64 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
65 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
66 huart1.Init.BaudRate = 9600; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
67 } |
662 | 68 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
69 huart1.Init.StopBits = UART_STOPBITS_1; | |
70 huart1.Init.Parity = UART_PARITY_NONE; | |
71 huart1.Init.Mode = UART_MODE_TX_RX; | |
72 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
73 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
74 | |
75 HAL_UART_Init(&huart1); | |
76 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
77 MX_USART1_DMA_Init(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
78 |
662 | 79 rxReadIndex = 0; |
80 lastCmdIndex = 0; | |
81 rxWriteIndex = 0; | |
82 dmaActive = 0; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
83 Comstatus_O2 = UART_O2_INIT; |
662 | 84 } |
38 | 85 |
662 | 86 void MX_USART1_UART_DeInit(void) |
87 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
88 HAL_DMA_Abort(&hdma_usart1_rx); |
662 | 89 HAL_DMA_DeInit(&hdma_usart1_rx); |
90 HAL_UART_DeInit(&huart1); | |
91 } | |
92 | |
93 void MX_USART1_DMA_Init() | |
94 { | |
95 /* DMA controller clock enable */ | |
96 __DMA2_CLK_ENABLE(); | |
97 | |
98 /* Peripheral DMA init*/ | |
99 hdma_usart1_rx.Instance = DMA2_Stream5; | |
100 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
101 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
102 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
103 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
104 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
105 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
106 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
107 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
108 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
109 HAL_DMA_Init(&hdma_usart1_rx); | |
110 | |
111 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
112 | |
113 /* DMA interrupt init */ | |
114 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0); | |
115 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); | |
38 | 116 } |
117 | |
690 | 118 void ConvertByteToHexString(uint8_t byte, char* str) |
119 { | |
120 uint8_t worker = 0; | |
121 uint8_t digit = 0; | |
122 uint8_t digitCnt = 1; | |
38 | 123 |
690 | 124 worker = byte; |
125 while((worker!=0) && (digitCnt != 255)) | |
126 { | |
127 digit = worker % 16; | |
128 if( digit < 10) | |
129 { | |
130 digit += '0'; | |
131 } | |
132 else | |
133 { | |
134 digit += 'A' - 10; | |
135 } | |
136 str[digitCnt--]= digit; | |
137 worker = worker / 16; | |
138 } | |
139 } | |
662 | 140 |
690 | 141 |
142 #ifdef ENABLE_CO2_SUPPORT | |
143 void HandleUARTCO2Data(void) | |
38 | 144 { |
662 | 145 uint8_t localRX = rxReadIndex; |
146 uint8_t dataType = 0; | |
690 | 147 uint32_t dataValue = 0; |
662 | 148 static receiveState_t rxState = RX_Ready; |
149 static uint32_t lastReceiveTick = 0; | |
150 | |
725 | 151 |
152 while((rxBuffer[localRX]!=0)) | |
662 | 153 { |
154 lastReceiveTick = HAL_GetTick(); | |
155 if(rxState == RX_Ready) /* identify data content */ | |
156 { | |
157 switch(rxBuffer[localRX]) | |
158 { | |
159 case 'l': | |
160 case 'D': | |
161 case 'Z': | |
162 dataType = rxBuffer[localRX]; | |
163 rxState = RX_Data0; | |
164 dataValue = 0; | |
165 break; | |
166 | |
167 default: /* unknown or corrupted => ignore */ | |
168 break; | |
169 } | |
170 } | |
725 | 171 else if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) |
662 | 172 { |
725 | 173 if((rxState >= RX_Data0) && (rxState <= RX_Data4)) |
662 | 174 { |
175 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0'); | |
176 rxState++; | |
725 | 177 if(rxState == RX_Data5) |
178 { | |
179 rxState = RX_DataComplete; | |
180 } | |
181 } | |
182 else /* protocol error data has max 5 digits */ | |
183 { | |
184 rxState = RX_Ready; | |
662 | 185 } |
186 } | |
187 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */ | |
188 { | |
189 if(rxState == RX_DataComplete) | |
190 { | |
191 if(externalInterface_GetCO2State() == 0) | |
192 { | |
193 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); | |
194 } | |
195 switch(dataType) | |
196 { | |
197 case 'D': externalInterface_SetCO2SignalStrength(dataValue); | |
198 break; | |
199 case 'l': LED_ZeroOffset = dataValue; | |
200 break; | |
201 case 'Z': externalInterface_SetCO2Value(dataValue); | |
202 break; | |
203 default: break; | |
204 } | |
205 } | |
206 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ | |
207 { | |
208 rxState = RX_Ready; | |
209 } | |
210 } | |
211 | |
212 localRX++; | |
213 rxReadIndex++; | |
214 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
215 { | |
216 localRX = 0; | |
217 rxReadIndex = 0; | |
218 } | |
219 } | |
220 | |
221 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */ | |
222 { | |
223 externalInterface_SetCO2State(0); | |
224 } | |
225 | |
226 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
227 { | |
228 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
229 { | |
230 dmaActive = 1; | |
231 } | |
232 } | |
38 | 233 } |
690 | 234 #endif |
235 | |
236 #ifdef ENABLE_SENTINEL_MODE | |
237 void HandleUARTSentinelData(void) | |
238 { | |
239 uint8_t localRX = rxReadIndex; | |
240 static uint8_t dataType = 0; | |
241 static uint32_t dataValue[3]; | |
242 static uint8_t dataValueIdx = 0; | |
243 static receiveState_t rxState = RX_Ready; | |
244 static uint32_t lastReceiveTick = 0; | |
245 static uint8_t lastAlive = 0; | |
246 static uint8_t curAlive = 0; | |
247 static uint8_t checksum = 0; | |
248 char checksum_str[]="00"; | |
249 | |
250 while(localRX != rxWriteIndex) | |
251 { | |
252 lastReceiveTick = HAL_GetTick(); | |
253 | |
254 switch(rxState) | |
255 { | |
256 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z')) | |
257 { | |
258 rxState = RX_DetectStart; | |
259 curAlive = rxBuffer[localRX]; | |
260 checksum = 0; | |
261 } | |
262 break; | |
263 | |
264 case RX_DetectStart: checksum += rxBuffer[localRX]; | |
265 if(rxBuffer[localRX] == '1') | |
266 { | |
267 rxState = RX_SelectData; | |
268 dataType = 0xFF; | |
269 | |
270 } | |
271 else | |
272 { | |
273 rxState = RX_Ready; | |
274 } | |
275 break; | |
276 | |
277 case RX_SelectData: checksum += rxBuffer[localRX]; | |
278 switch(rxBuffer[localRX]) | |
279 { | |
280 case 'T': dataType = rxBuffer[localRX]; | |
281 break; | |
282 case '0': if(dataType != 0xff) | |
283 { | |
284 rxState = RX_Data0; | |
285 dataValueIdx = 0; | |
286 dataValue[0] = 0; | |
287 | |
288 } | |
289 else | |
290 { | |
291 rxState = RX_Ready; | |
292 } | |
293 break; | |
294 default: rxState = RX_Ready; | |
295 } | |
296 break; | |
297 | |
298 case RX_Data0: | |
299 case RX_Data1: | |
300 case RX_Data2: | |
301 case RX_Data4: | |
302 case RX_Data5: | |
303 case RX_Data6: | |
304 case RX_Data8: | |
305 case RX_Data9: | |
306 case RX_Data10: checksum += rxBuffer[localRX]; | |
307 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) | |
308 { | |
309 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0'); | |
310 rxState++; | |
311 } | |
312 else | |
313 { | |
314 rxState = RX_Ready; | |
315 } | |
316 break; | |
317 | |
318 case RX_Data3: | |
319 case RX_Data7: checksum += rxBuffer[localRX]; | |
320 if(rxBuffer[localRX] == '0') | |
321 { | |
322 rxState++; | |
323 dataValueIdx++; | |
324 dataValue[dataValueIdx] = 0; | |
325 } | |
326 else | |
327 { | |
328 rxState = RX_Ready; | |
329 } | |
330 break; | |
331 case RX_Data11: rxState = RX_DataComplete; | |
332 ConvertByteToHexString(checksum,checksum_str); | |
333 if(rxBuffer[localRX] == checksum_str[0]) | |
334 { | |
335 rxState = RX_DataComplete; | |
336 } | |
337 else | |
338 { | |
339 rxState = RX_Ready; | |
340 } | |
341 | |
342 break; | |
343 | |
344 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) | |
345 { | |
346 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); | |
347 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); | |
348 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); | |
349 } | |
350 rxState = RX_Ready; | |
351 break; | |
352 | |
353 | |
354 default: rxState = RX_Ready; | |
355 break; | |
356 | |
357 } | |
358 | |
359 localRX++; | |
360 rxReadIndex++; | |
361 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
362 { | |
363 localRX = 0; | |
364 rxReadIndex = 0; | |
365 } | |
366 } | |
367 | |
368 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ | |
369 { | |
370 if(curAlive == lastAlive) | |
371 { | |
372 setExternalInterfaceChannel(0,0.0); | |
373 setExternalInterfaceChannel(1,0.0); | |
374 setExternalInterfaceChannel(2,0.0); | |
375 } | |
376 lastAlive = curAlive; | |
377 } | |
378 | |
379 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
380 { | |
381 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
382 { | |
383 dmaActive = 1; | |
384 } | |
385 } | |
386 } | |
387 #endif | |
38 | 388 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
389 void DigitalO2_SetupCmd(uint8_t O2State, uint8_t *cmdString, uint8_t *cmdLength) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
390 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
391 switch (O2State) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
392 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
393 case UART_O2_CHECK: *cmdLength = snprintf((char*)cmdString, 10, "#LOGO"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
394 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
395 case UART_O2_REQ_INFO: *cmdLength = snprintf((char*)cmdString, 10, "#VERS"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
396 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
397 case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
398 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
399 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
400 break; |
721 | 401 case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#DRAW"); |
402 break; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
403 default: *cmdLength = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
404 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
405 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
406 if(*cmdLength != 0) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
407 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
408 cmdString[*cmdLength] = 0x0D; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
409 *cmdLength = *cmdLength + 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
410 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
411 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
412 |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
413 void StringToInt(char *pstr, uint32_t *puInt32) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
414 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
415 uint8_t index = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
416 uint32_t result = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
417 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
418 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
419 result *=10; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
420 result += pstr[index] - '0'; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
421 index++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
422 } |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
423 *puInt32 = result; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
424 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
425 |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
426 void StringToUInt64(char *pstr, uint64_t *puint64) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
427 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
428 uint8_t index = 0; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
429 uint64_t result = 0; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
430 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
431 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
432 result *=10; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
433 result += pstr[index] - '0'; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
434 index++; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
435 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
436 *puint64 = result; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
437 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
438 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
439 void HandleUARTDigitalO2(void) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
440 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
441 static uint32_t lastO2ReqTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
442 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
443 static uartO2RxState_t rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
444 static uint32_t lastReceiveTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
445 static uint8_t lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
446 static uint8_t curAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
447 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
448 static uint8_t cmdLength = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
449 static uint8_t cmdString[10]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
450 static uint8_t cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
451 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
452 uint32_t tmpO2 = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
453 uint32_t tmpData = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
454 uint8_t localRX = rxReadIndex; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
455 uint32_t tick = HAL_GetTick(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
456 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
457 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
458 if(Comstatus_O2 == UART_O2_INIT) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
459 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
460 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
461 memset((char*) &sensorDataDiveO2, 0, sizeof(sensorDataDiveO2)); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
462 externalInterface_SetSensorData(0,(uint8_t*)&sensorDataDiveO2); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
463 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
464 lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
465 curAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
466 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
467 Comstatus_O2 = UART_O2_CHECK; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
468 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
469 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
470 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
471 rxState = O2RX_CONFIRM; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
472 cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
473 lastO2ReqTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
474 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
475 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
476 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
477 dmaActive = 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
478 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
479 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
480 if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
481 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
482 lastO2ReqTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
483 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
484 { |
721 | 485 Comstatus_O2 = UART_O2_REQ_RAW; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
486 rxState = O2RX_CONFIRM; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
487 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
488 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
489 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
490 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
491 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
492 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
493 while((rxBuffer[localRX]!=0)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
494 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
495 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
496 lastReceiveTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
497 switch(rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
498 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
499 case O2RX_CONFIRM: if(rxBuffer[localRX] == '#') |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
500 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
501 cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
502 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
503 if(rxBuffer[localRX] == cmdString[cmdReadIndex]) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
504 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
505 cmdReadIndex++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
506 if(cmdReadIndex == cmdLength - 1) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
507 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
508 tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
509 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf)); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
510 switch (Comstatus_O2) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
511 { |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
512 case UART_O2_CHECK: Comstatus_O2 = UART_O2_REQ_ID; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
513 rxState = O2RX_CONFIRM; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
514 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
515 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
516 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
517 case UART_O2_REQ_ID: rxState = O2RX_GETNR; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
518 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
519 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
520 break; |
721 | 521 case UART_O2_REQ_RAW: |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
522 case UART_O2_REQ_O2: rxState = O2RX_GETO2; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
523 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
524 default: Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
525 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
526 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
527 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
528 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
529 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
530 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
531 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
532 case O2RX_GETSTATUS: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
533 case O2RX_GETTEMP: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
534 case O2RX_GETTYPE: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
535 case O2RX_GETVERSION: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
536 case O2RX_GETCHANNEL: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
537 case O2RX_GETSUBSENSORS: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
538 case O2RX_GETO2: |
721 | 539 case O2RX_GETNR: |
540 case O2RX_GETDPHI: | |
541 case O2RX_INTENSITY: | |
542 case O2RX_AMBIENTLIGHT: | |
543 case O2RX_PRESSURE: | |
544 case O2RX_HUMIDITY: | |
545 if(rxBuffer[localRX] != 0x0D) | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
546 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
547 if(rxBuffer[localRX] != ' ') |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
548 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
549 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
550 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
551 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
552 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
553 if(tmpRxIdx != 0) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
554 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
555 switch(rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
556 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
557 case O2RX_GETCHANNEL: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
558 rxState = O2RX_GETVERSION; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
559 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
560 case O2RX_GETVERSION: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
561 rxState = O2RX_GETSUBSENSORS; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
562 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
563 case O2RX_GETTYPE: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
564 rxState = O2RX_GETCHANNEL; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
565 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
566 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
567 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
568 setExternalInterfaceChannel(0,(float)(tmpO2 / 10000.0)); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
569 rxState = O2RX_GETTEMP; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
570 break; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
571 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
572 rxState = O2RX_GETSTATUS; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
573 break; |
721 | 574 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status); /* raw data cycle */ |
575 rxState = O2RX_GETDPHI; | |
576 break; | |
577 case O2RX_GETDPHI: /* ignored to save memory and most likly irrelevant for diver */ | |
578 rxState = O2RX_INTENSITY; | |
579 break; | |
580 case O2RX_INTENSITY: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.intensity); /* raw data cycle */ | |
581 rxState = O2RX_AMBIENTLIGHT; | |
582 break; | |
583 case O2RX_AMBIENTLIGHT: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.ambient); /* raw data cycle */ | |
584 rxState = O2RX_PRESSURE; | |
585 break; | |
586 case O2RX_PRESSURE: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.pressure); /* raw data cycle */ | |
587 rxState = O2RX_HUMIDITY; | |
588 break; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
589 default: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
590 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
591 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
592 memset((char*) tmpRxBuf, 0, tmpRxIdx); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
593 tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
594 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
595 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
596 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
597 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
598 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
599 switch (rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
600 { |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
601 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
602 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
603 Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
604 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
605 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
606 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
607 Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
608 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
609 break; |
721 | 610 case O2RX_HUMIDITY: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.humidity); /* raw data cycle */ |
611 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2); | |
612 Comstatus_O2 = UART_O2_IDLE; | |
613 rxState = O2RX_IDLE; | |
614 break; | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
615 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
616 /* no break */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
617 default: Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
618 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
619 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
620 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
621 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
622 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
623 default: rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
624 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
625 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
626 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
627 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
628 localRX++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
629 rxReadIndex++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
630 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
631 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
632 localRX = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
633 rxReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
634 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
635 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
636 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
637 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
638 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
639 if(curAlive == lastAlive) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
640 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
641 setExternalInterfaceChannel(0,0.0); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
642 setExternalInterfaceChannel(1,0.0); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
643 setExternalInterfaceChannel(2,0.0); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
644 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
645 lastAlive = curAlive; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
646 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
647 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
648 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
649 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
650 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
651 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
652 dmaActive = 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
653 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
654 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
655 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
656 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
657 |
662 | 658 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 659 { |
662 | 660 if(huart == &huart1) |
661 { | |
662 dmaActive = 0; | |
663 rxWriteIndex+=CHUNK_SIZE; | |
664 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
665 { | |
666 rxWriteIndex = 0; | |
667 } | |
668 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE)) /* start next transfer if we did not catch up with read index */ | |
669 { | |
670 if(externalInterface_isEnabledPower33()) | |
671 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
672 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
662 | 673 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
674 { | |
675 dmaActive = 1; | |
676 } | |
677 } | |
678 } | |
679 } | |
38 | 680 } |
681 | |
682 | |
662 | 683 |
684 | |
685 | |
686 | |
687 | |
688 | |
38 | 689 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |