Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 720:4f70155362d2
Bugfix set date (year):
In the previous version the year selection was clipped to a range between 16 and 22. To avoid clipping issues in future the clipping is now done based on the firmware release date as lower limit and release date +10 years as upper limit.
author | Ideenmodellierer |
---|---|
date | Tue, 03 Jan 2023 19:47:12 +0100 |
parents | 045ff7800501 |
children | fceae45b3a69 |
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 | |
662 | 29 #define CHUNK_SIZE (20u) /* the DMA will handle chunk size transfers */ |
30 #define CHUNKS_PER_BUFFER (3u) | |
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 | |
151 while(localRX != rxWriteIndex) | |
152 { | |
153 lastReceiveTick = HAL_GetTick(); | |
154 if(rxState == RX_Ready) /* identify data content */ | |
155 { | |
156 switch(rxBuffer[localRX]) | |
157 { | |
158 case 'l': | |
159 case 'D': | |
160 case 'Z': | |
161 dataType = rxBuffer[localRX]; | |
162 rxState = RX_Data0; | |
163 dataValue = 0; | |
164 break; | |
165 | |
166 default: /* unknown or corrupted => ignore */ | |
167 break; | |
168 } | |
169 } | |
170 else if((rxState >= RX_Data0) && (rxState <= RX_Data4)) | |
171 { | |
172 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) | |
173 { | |
174 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0'); | |
175 rxState++; | |
176 } | |
177 } | |
178 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */ | |
179 { | |
180 if(rxState == RX_DataComplete) | |
181 { | |
182 if(externalInterface_GetCO2State() == 0) | |
183 { | |
184 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); | |
185 } | |
186 switch(dataType) | |
187 { | |
188 case 'D': externalInterface_SetCO2SignalStrength(dataValue); | |
189 break; | |
190 case 'l': LED_ZeroOffset = dataValue; | |
191 break; | |
192 case 'Z': externalInterface_SetCO2Value(dataValue); | |
193 break; | |
194 default: break; | |
195 } | |
196 } | |
197 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ | |
198 { | |
199 rxState = RX_Ready; | |
200 } | |
201 } | |
202 | |
203 localRX++; | |
204 rxReadIndex++; | |
205 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
206 { | |
207 localRX = 0; | |
208 rxReadIndex = 0; | |
209 } | |
210 } | |
211 | |
212 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */ | |
213 { | |
214 externalInterface_SetCO2State(0); | |
215 } | |
216 | |
217 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
218 { | |
219 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
220 { | |
221 dmaActive = 1; | |
222 } | |
223 } | |
38 | 224 } |
690 | 225 #endif |
226 | |
227 #ifdef ENABLE_SENTINEL_MODE | |
228 void HandleUARTSentinelData(void) | |
229 { | |
230 uint8_t localRX = rxReadIndex; | |
231 static uint8_t dataType = 0; | |
232 static uint32_t dataValue[3]; | |
233 static uint8_t dataValueIdx = 0; | |
234 static receiveState_t rxState = RX_Ready; | |
235 static uint32_t lastReceiveTick = 0; | |
236 static uint8_t lastAlive = 0; | |
237 static uint8_t curAlive = 0; | |
238 static uint8_t checksum = 0; | |
239 char checksum_str[]="00"; | |
240 | |
241 while(localRX != rxWriteIndex) | |
242 { | |
243 lastReceiveTick = HAL_GetTick(); | |
244 | |
245 switch(rxState) | |
246 { | |
247 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z')) | |
248 { | |
249 rxState = RX_DetectStart; | |
250 curAlive = rxBuffer[localRX]; | |
251 checksum = 0; | |
252 } | |
253 break; | |
254 | |
255 case RX_DetectStart: checksum += rxBuffer[localRX]; | |
256 if(rxBuffer[localRX] == '1') | |
257 { | |
258 rxState = RX_SelectData; | |
259 dataType = 0xFF; | |
260 | |
261 } | |
262 else | |
263 { | |
264 rxState = RX_Ready; | |
265 } | |
266 break; | |
267 | |
268 case RX_SelectData: checksum += rxBuffer[localRX]; | |
269 switch(rxBuffer[localRX]) | |
270 { | |
271 case 'T': dataType = rxBuffer[localRX]; | |
272 break; | |
273 case '0': if(dataType != 0xff) | |
274 { | |
275 rxState = RX_Data0; | |
276 dataValueIdx = 0; | |
277 dataValue[0] = 0; | |
278 | |
279 } | |
280 else | |
281 { | |
282 rxState = RX_Ready; | |
283 } | |
284 break; | |
285 default: rxState = RX_Ready; | |
286 } | |
287 break; | |
288 | |
289 case RX_Data0: | |
290 case RX_Data1: | |
291 case RX_Data2: | |
292 case RX_Data4: | |
293 case RX_Data5: | |
294 case RX_Data6: | |
295 case RX_Data8: | |
296 case RX_Data9: | |
297 case RX_Data10: checksum += rxBuffer[localRX]; | |
298 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) | |
299 { | |
300 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0'); | |
301 rxState++; | |
302 } | |
303 else | |
304 { | |
305 rxState = RX_Ready; | |
306 } | |
307 break; | |
308 | |
309 case RX_Data3: | |
310 case RX_Data7: checksum += rxBuffer[localRX]; | |
311 if(rxBuffer[localRX] == '0') | |
312 { | |
313 rxState++; | |
314 dataValueIdx++; | |
315 dataValue[dataValueIdx] = 0; | |
316 } | |
317 else | |
318 { | |
319 rxState = RX_Ready; | |
320 } | |
321 break; | |
322 case RX_Data11: rxState = RX_DataComplete; | |
323 ConvertByteToHexString(checksum,checksum_str); | |
324 if(rxBuffer[localRX] == checksum_str[0]) | |
325 { | |
326 rxState = RX_DataComplete; | |
327 } | |
328 else | |
329 { | |
330 rxState = RX_Ready; | |
331 } | |
332 | |
333 break; | |
334 | |
335 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) | |
336 { | |
337 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); | |
338 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); | |
339 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); | |
340 } | |
341 rxState = RX_Ready; | |
342 break; | |
343 | |
344 | |
345 default: rxState = RX_Ready; | |
346 break; | |
347 | |
348 } | |
349 | |
350 localRX++; | |
351 rxReadIndex++; | |
352 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
353 { | |
354 localRX = 0; | |
355 rxReadIndex = 0; | |
356 } | |
357 } | |
358 | |
359 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ | |
360 { | |
361 if(curAlive == lastAlive) | |
362 { | |
363 setExternalInterfaceChannel(0,0.0); | |
364 setExternalInterfaceChannel(1,0.0); | |
365 setExternalInterfaceChannel(2,0.0); | |
366 } | |
367 lastAlive = curAlive; | |
368 } | |
369 | |
370 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
371 { | |
372 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
373 { | |
374 dmaActive = 1; | |
375 } | |
376 } | |
377 } | |
378 #endif | |
38 | 379 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
380 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
|
381 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
382 switch (O2State) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
383 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
384 case UART_O2_CHECK: *cmdLength = snprintf((char*)cmdString, 10, "#LOGO"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
385 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
386 case UART_O2_REQ_INFO: *cmdLength = snprintf((char*)cmdString, 10, "#VERS"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
387 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
388 case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
389 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
390 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY"); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
391 break; |
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 default: *cmdLength = 0; |
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 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
396 if(*cmdLength != 0) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
397 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
398 cmdString[*cmdLength] = 0x0D; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
399 *cmdLength = *cmdLength + 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
400 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
401 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
402 |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
403 void StringToInt(char *pstr, uint32_t *puInt32) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
404 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
405 uint8_t index = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
406 uint32_t result = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
407 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
408 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
409 result *=10; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
410 result += pstr[index] - '0'; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
411 index++; |
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 *puInt32 = result; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
414 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
415 |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
416 void StringToUInt64(char *pstr, uint64_t *puint64) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
417 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
418 uint8_t index = 0; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
419 uint64_t result = 0; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
420 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
421 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
422 result *=10; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
423 result += pstr[index] - '0'; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
424 index++; |
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 *puint64 = result; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
427 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
428 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
429 void HandleUARTDigitalO2(void) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
430 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
431 static uint32_t lastO2ReqTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
432 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
433 static uartO2RxState_t rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
434 static uint32_t lastReceiveTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
435 static uint8_t lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
436 static uint8_t curAlive = 0; |
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 static uint8_t cmdLength = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
439 static uint8_t cmdString[10]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
440 static uint8_t cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
441 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
442 uint32_t tmpO2 = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
443 uint32_t tmpData = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
444 uint8_t localRX = rxReadIndex; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
445 uint32_t tick = HAL_GetTick(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
446 |
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 if(Comstatus_O2 == UART_O2_INIT) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
449 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
450 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
451 memset((char*) &sensorDataDiveO2, 0, sizeof(sensorDataDiveO2)); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
452 externalInterface_SetSensorData(0,(uint8_t*)&sensorDataDiveO2); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
453 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
454 lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
455 curAlive = 0; |
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 Comstatus_O2 = UART_O2_CHECK; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
458 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
459 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
460 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
461 rxState = O2RX_CONFIRM; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
462 cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
463 lastO2ReqTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
464 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
465 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
|
466 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
467 dmaActive = 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
468 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
469 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
470 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
|
471 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
472 lastO2ReqTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
473 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ |
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 Comstatus_O2 = UART_O2_REQ_O2; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
476 rxState = O2RX_CONFIRM; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
477 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
478 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
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 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
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 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
483 while((rxBuffer[localRX]!=0)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
484 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
485 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
486 lastReceiveTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
487 switch(rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
488 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
489 case O2RX_CONFIRM: if(rxBuffer[localRX] == '#') |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
490 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
491 cmdReadIndex = 0; |
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 if(rxBuffer[localRX] == cmdString[cmdReadIndex]) |
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 cmdReadIndex++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
496 if(cmdReadIndex == cmdLength - 1) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
497 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
498 tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
499 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf)); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
500 switch (Comstatus_O2) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
501 { |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
502 case UART_O2_CHECK: Comstatus_O2 = UART_O2_REQ_ID; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
503 rxState = O2RX_CONFIRM; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
504 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
505 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
506 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
507 case UART_O2_REQ_ID: rxState = O2RX_GETNR; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
508 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
509 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
510 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
511 case UART_O2_REQ_O2: rxState = O2RX_GETO2; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
512 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
513 default: Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
514 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
515 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
516 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
517 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
518 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
519 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
520 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
521 case O2RX_GETSTATUS: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
522 case O2RX_GETTEMP: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
523 case O2RX_GETTYPE: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
524 case O2RX_GETVERSION: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
525 case O2RX_GETCHANNEL: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
526 case O2RX_GETSUBSENSORS: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
527 case O2RX_GETO2: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
528 case O2RX_GETNR: if(rxBuffer[localRX] != 0x0D) |
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 if(rxBuffer[localRX] != ' ') |
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 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
533 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
534 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
535 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
536 if(tmpRxIdx != 0) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
537 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
538 switch(rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
539 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
540 case O2RX_GETCHANNEL: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
541 rxState = O2RX_GETVERSION; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
542 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
543 case O2RX_GETVERSION: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
544 rxState = O2RX_GETSUBSENSORS; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
545 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
546 case O2RX_GETTYPE: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
547 rxState = O2RX_GETCHANNEL; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
548 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
549 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
550 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
551 setExternalInterfaceChannel(0,(float)(tmpO2 / 10000.0)); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
552 rxState = O2RX_GETTEMP; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
553 break; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
554 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
555 rxState = O2RX_GETSTATUS; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
556 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
557 default: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
558 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
559 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
560 memset((char*) tmpRxBuf, 0, tmpRxIdx); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
561 tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
562 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
563 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
564 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
565 else |
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 switch (rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
568 { |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
569 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
570 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
571 Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
572 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
573 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
574 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
575 Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
576 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
577 break; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
578 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
579 /* no break */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
580 default: Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
581 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
582 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
583 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
584 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
585 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
586 default: rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
587 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
588 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
589 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
590 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
591 localRX++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
592 rxReadIndex++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
593 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
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 localRX = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
596 rxReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
597 } |
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 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
600 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
|
601 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
602 if(curAlive == lastAlive) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
603 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
604 setExternalInterfaceChannel(0,0.0); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
605 setExternalInterfaceChannel(1,0.0); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
606 setExternalInterfaceChannel(2,0.0); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
607 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
608 lastAlive = curAlive; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
609 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
610 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
611 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
|
612 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
613 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
|
614 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
615 dmaActive = 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
616 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
617 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
618 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
619 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
620 |
662 | 621 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 622 { |
662 | 623 if(huart == &huart1) |
624 { | |
625 dmaActive = 0; | |
626 rxWriteIndex+=CHUNK_SIZE; | |
627 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
628 { | |
629 rxWriteIndex = 0; | |
630 } | |
631 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE)) /* start next transfer if we did not catch up with read index */ | |
632 { | |
633 if(externalInterface_isEnabledPower33()) | |
634 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
635 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
662 | 636 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
637 { | |
638 dmaActive = 1; | |
639 } | |
640 } | |
641 } | |
642 } | |
38 | 643 } |
644 | |
645 | |
662 | 646 |
647 | |
648 | |
649 | |
650 | |
651 | |
38 | 652 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |