Mercurial > public > ostc4
comparison Small_CPU/Src/uart.c @ 742:e23fe82cbf8c
Update Sentinel protocol:
The Sentinel protocol is now supported by autodetection.
Added Autodetection indicator:
In the previous version no indicator showed that an auto detection is running. A new pseudo sensor type has been introduced which now causes the auto detection string to be displayed while the detection is running in the background.
author | Ideenmodellierer |
---|---|
date | Sun, 19 Feb 2023 21:43:24 +0100 |
parents | 2a801cfe23ab |
children | df0d43da1614 |
comparison
equal
deleted
inserted
replaced
741:6a35e2e97bfb | 742:e23fe82cbf8c |
---|---|
37 static uint8_t rxReadIndex; /* Index at which new data is stared */ | 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 */ | 38 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */ |
39 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */ | 39 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */ |
40 static uint8_t digO2Connected = 0; /* Binary indicator if a sensor is connected or not */ | 40 static uint8_t digO2Connected = 0; /* Binary indicator if a sensor is connected or not */ |
41 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */ | 41 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */ |
42 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */ | |
42 static uint8_t ppO2TargetChannel = 0; /* The OSTC4 supports three slots for visualization of the ppo2. This one is reserved for the digital sensor */ | 43 static uint8_t ppO2TargetChannel = 0; /* The OSTC4 supports three slots for visualization of the ppo2. This one is reserved for the digital sensor */ |
43 | 44 |
44 static SSensorDataDiveO2 sensorDataDiveO2; /* intermediate storage for additional sensor data */ | 45 static SSensorDataDiveO2 sensorDataDiveO2; /* intermediate storage for additional sensor data */ |
45 | 46 |
46 char tmpRxBuf[30]; | 47 char tmpRxBuf[30]; |
84 lastCmdIndex = 0; | 85 lastCmdIndex = 0; |
85 rxWriteIndex = 0; | 86 rxWriteIndex = 0; |
86 dmaActive = 0; | 87 dmaActive = 0; |
87 digO2Connected = 0; | 88 digO2Connected = 0; |
88 CO2Connected = 0; | 89 CO2Connected = 0; |
90 SentinelConnected = 0; | |
89 Comstatus_O2 = UART_O2_INIT; | 91 Comstatus_O2 = UART_O2_INIT; |
90 } | 92 } |
91 | 93 |
92 void MX_USART1_UART_DeInit(void) | 94 void MX_USART1_UART_DeInit(void) |
93 { | 95 { |
192 str[digitCnt--]= digit; | 194 str[digitCnt--]= digit; |
193 worker = worker / 16; | 195 worker = worker / 16; |
194 } | 196 } |
195 } | 197 } |
196 | 198 |
199 void UART_StartDMA_Receiption() | |
200 { | |
201 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
202 { | |
203 dmaActive = 1; | |
204 } | |
205 } | |
197 | 206 |
198 #ifdef ENABLE_CO2_SUPPORT | 207 #ifdef ENABLE_CO2_SUPPORT |
199 void UART_HandleCO2Data(void) | 208 void UART_HandleCO2Data(void) |
200 { | 209 { |
201 uint8_t localRX = rxReadIndex; | 210 uint8_t localRX = rxReadIndex; |
263 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ | 272 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ |
264 { | 273 { |
265 rxState = RX_Ready; | 274 rxState = RX_Ready; |
266 } | 275 } |
267 } | 276 } |
268 | 277 rxBuffer[localRX] = 0; |
269 localRX++; | 278 localRX++; |
270 rxReadIndex++; | 279 rxReadIndex++; |
271 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | 280 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
272 { | 281 { |
273 localRX = 0; | 282 localRX = 0; |
281 CO2Connected = 0; | 290 CO2Connected = 0; |
282 } | 291 } |
283 | 292 |
284 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | 293 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ |
285 { | 294 { |
286 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | 295 UART_StartDMA_Receiption(); |
287 { | |
288 dmaActive = 1; | |
289 } | |
290 } | 296 } |
291 } | 297 } |
292 #endif | 298 #endif |
293 | 299 |
294 #ifdef ENABLE_SENTINEL_MODE | 300 #ifdef ENABLE_SENTINEL_MODE |
301 static receiveState_t rxState = RX_Ready; | 307 static receiveState_t rxState = RX_Ready; |
302 static uint32_t lastReceiveTick = 0; | 308 static uint32_t lastReceiveTick = 0; |
303 static uint8_t lastAlive = 0; | 309 static uint8_t lastAlive = 0; |
304 static uint8_t curAlive = 0; | 310 static uint8_t curAlive = 0; |
305 static uint8_t checksum = 0; | 311 static uint8_t checksum = 0; |
306 char checksum_str[]="00"; | 312 static char checksum_str[]="00"; |
307 | 313 |
308 while(localRX != rxWriteIndex) | 314 while((rxBuffer[localRX]!=0)) |
309 { | 315 { |
310 lastReceiveTick = HAL_GetTick(); | 316 lastReceiveTick = HAL_GetTick(); |
311 | 317 |
312 switch(rxState) | 318 switch(rxState) |
313 { | 319 { |
402 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) | 408 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) |
403 { | 409 { |
404 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); | 410 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); |
405 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); | 411 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); |
406 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); | 412 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); |
413 SentinelConnected = 1; | |
407 } | 414 } |
408 rxState = RX_Ready; | 415 rxState = RX_Ready; |
409 break; | 416 break; |
410 | 417 |
411 | 418 |
412 default: rxState = RX_Ready; | 419 default: rxState = RX_Ready; |
413 break; | 420 break; |
414 | 421 |
415 } | 422 } |
416 | |
417 localRX++; | 423 localRX++; |
418 rxReadIndex++; | 424 rxReadIndex++; |
419 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | 425 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
420 { | 426 { |
421 localRX = 0; | 427 localRX = 0; |
428 if(curAlive == lastAlive) | 434 if(curAlive == lastAlive) |
429 { | 435 { |
430 setExternalInterfaceChannel(0,0.0); | 436 setExternalInterfaceChannel(0,0.0); |
431 setExternalInterfaceChannel(1,0.0); | 437 setExternalInterfaceChannel(1,0.0); |
432 setExternalInterfaceChannel(2,0.0); | 438 setExternalInterfaceChannel(2,0.0); |
439 SentinelConnected = 0; | |
433 } | 440 } |
434 lastAlive = curAlive; | 441 lastAlive = curAlive; |
435 } | 442 } |
436 | 443 |
437 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | 444 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ |
438 { | 445 { |
439 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | 446 UART_StartDMA_Receiption(); |
440 { | |
441 dmaActive = 1; | |
442 } | |
443 } | 447 } |
444 } | 448 } |
445 #endif | 449 #endif |
446 | 450 |
447 | 451 |
480 | 484 |
481 rxState = O2RX_CONFIRM; | 485 rxState = O2RX_CONFIRM; |
482 cmdReadIndex = 0; | 486 cmdReadIndex = 0; |
483 lastO2ReqTick = tick; | 487 lastO2ReqTick = tick; |
484 | 488 |
485 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | 489 UART_StartDMA_Receiption(); |
486 { | |
487 dmaActive = 1; | |
488 } | |
489 } | 490 } |
490 if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */ | 491 if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */ |
491 { | 492 { |
492 lastO2ReqTick = tick; | 493 lastO2ReqTick = tick; |
493 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ | 494 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ |
652 { | 653 { |
653 setExternalInterfaceChannel(ppO2TargetChannel,0.0); | 654 setExternalInterfaceChannel(ppO2TargetChannel,0.0); |
654 } | 655 } |
655 lastAlive = curAlive; | 656 lastAlive = curAlive; |
656 } | 657 } |
657 | |
658 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | 658 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ |
659 { | 659 { |
660 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | 660 UART_StartDMA_Receiption(); |
661 { | |
662 dmaActive = 1; | |
663 } | |
664 } | 661 } |
665 } | 662 } |
666 | 663 |
667 uint8_t UART_isDigO2Connected() | 664 uint8_t UART_isDigO2Connected() |
668 { | 665 { |
670 } | 667 } |
671 uint8_t UART_isCO2Connected() | 668 uint8_t UART_isCO2Connected() |
672 { | 669 { |
673 return CO2Connected; | 670 return CO2Connected; |
674 } | 671 } |
675 | 672 uint8_t UART_isSentinelConnected() |
673 { | |
674 return SentinelConnected; | |
675 } | |
676 | 676 |
677 void UART_setTargetChannel(uint8_t channel) | 677 void UART_setTargetChannel(uint8_t channel) |
678 { | 678 { |
679 ppO2TargetChannel = channel; | 679 ppO2TargetChannel = channel; |
680 } | 680 } |
692 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE)) /* start next transfer if we did not catch up with read index */ | 692 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE)) /* start next transfer if we did not catch up with read index */ |
693 { | 693 { |
694 if(externalInterface_isEnabledPower33()) | 694 if(externalInterface_isEnabledPower33()) |
695 { | 695 { |
696 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); | 696 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
697 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | 697 UART_StartDMA_Receiption(); |
698 { | |
699 dmaActive = 1; | |
700 } | |
701 } | 698 } |
702 } | 699 } |
703 } | 700 } |
704 } | 701 } |
705 | 702 |