# HG changeset patch # User Ideenmodellierer # Date 1676839404 -3600 # Node ID e23fe82cbf8c0110a0f8fdf7068ef6bc5c525d41 # Parent 6a35e2e97bfb8901898745dde298ab9b1752290e 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. diff -r 6a35e2e97bfb -r e23fe82cbf8c Small_CPU/Inc/externalInterface.h --- a/Small_CPU/Inc/externalInterface.h Thu Feb 02 17:35:54 2023 +0100 +++ b/Small_CPU/Inc/externalInterface.h Sun Feb 19 21:43:24 2023 +0100 @@ -28,6 +28,8 @@ #endif /* Includes ------------------------------------------------------------------*/ +#include "configuration.h" + #define MAX_ADC_CHANNEL (3u) /* number of channels to be read */ #define EXTERNAL_ADC_NO_DATA 0xFF @@ -45,7 +47,13 @@ DETECTION_ANALOG1, /* check ADC channels for connected sensors */ DETECTION_ANALOG2, DETECTION_DIGO2, /* check UART channel for connected DigO2 sensor */ +#ifdef ENABLE_CO2_SUPPORT DETECTION_CO2, /* check UART channel for connected CO2 sensor */ +#endif +#ifdef ENABLE_SENTINEL_MODE + DETECTION_SENTINEL, /* check UART channel for connected Sentinel */ + DETECTION_SENTINEL2, +#endif DETECTION_DONE } externalInterfaceAutoDetect_t; diff -r 6a35e2e97bfb -r e23fe82cbf8c Small_CPU/Inc/uart.h --- a/Small_CPU/Inc/uart.h Thu Feb 02 17:35:54 2023 +0100 +++ b/Small_CPU/Inc/uart.h Sun Feb 19 21:43:24 2023 +0100 @@ -84,6 +84,7 @@ void MX_USART1_UART_DeInit(void); void MX_USART1_DMA_Init(void); uint8_t UART_ButtonAdjust(uint8_t *array); +void UART_StartDMA_Receiption(void); #ifdef ENABLE_CO2_SUPPORT void UART_HandleCO2Data(void); #endif @@ -91,9 +92,9 @@ void UART_HandleSentinelData(void); #endif void UART_HandleDigitalO2(void); - uint8_t UART_isDigO2Connected(); uint8_t UART_isCO2Connected(); +uint8_t UART_isSentinelConnected(); void UART_setTargetChannel(uint8_t channel); diff -r 6a35e2e97bfb -r e23fe82cbf8c Small_CPU/Src/externalInterface.c --- a/Small_CPU/Src/externalInterface.c Thu Feb 02 17:35:54 2023 +0100 +++ b/Small_CPU/Src/externalInterface.c Sun Feb 19 21:43:24 2023 +0100 @@ -313,8 +313,10 @@ case 0: case (EXT_INTERFACE_UART_CO2 >> 8): case (EXT_INTERFACE_UART_O2 >> 8): + case (EXT_INTERFACE_UART_SENTINEL >> 8): if((externalAutoDetect <= DETECTION_START) || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) - || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2))) + || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2)) + || ((protocol == EXT_INTERFACE_UART_SENTINEL >> 8) && (externalAutoDetect == DETECTION_SENTINEL))) { sensorDataId = 0; externalUART_Protocol = protocol; @@ -486,7 +488,8 @@ UART_setTargetChannel(index); /* tmpSensorMap[sensorIndex++] = SENSOR_DIGO2; */ } - externalAutoDetect = DETECTION_CO2; + externalAutoDetect++; +#ifdef ENABLE_CO2_SUPPORT externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8); break; case DETECTION_CO2: if(UART_isCO2Connected()) @@ -508,7 +511,25 @@ } } - externalAutoDetect = DETECTION_DONE; + externalAutoDetect++; +#endif +#ifdef ENABLE_SENTINEL_MODE + externalInterface_SwitchUART(EXT_INTERFACE_UART_SENTINEL >> 8); + UART_StartDMA_Receiption(); + break; + + case DETECTION_SENTINEL: + case DETECTION_SENTINEL2: + if(UART_isSentinelConnected()) + { + for(index = 0; index < 3; index++) /* Sentinel is occupiing all sensor slots */ + { + tmpSensorMap[index] = SENSOR_SENTINEL; + } + sensorIndex = 3; + } + externalAutoDetect++; +#endif break; case DETECTION_DONE: for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) { @@ -550,6 +571,10 @@ switch(Cmd & 0x00FF) /* lower byte is reserved for commands */ { case EXT_INTERFACE_AUTODETECT: externalAutoDetect = DETECTION_INIT; + for(index = 0; index < 3; index++) + { + SensorMap[index] = SENSOR_SEARCH; + } break; case EXT_INTERFACE_CO2_CALIB: cmdLength = snprintf(cmdString, 10, "G\r\n"); break; diff -r 6a35e2e97bfb -r e23fe82cbf8c Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Thu Feb 02 17:35:54 2023 +0100 +++ b/Small_CPU/Src/scheduler.c Sun Feb 19 21:43:24 2023 +0100 @@ -517,18 +517,18 @@ ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); #ifdef ENABLE_CO2_SUPPORT - if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_CO2) + if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_CO2 >> 8)) { UART_HandleCO2Data(); } #endif #ifdef ENABLE_SENTINEL_MODE - if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) + if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_SENTINEL >> 8)) { UART_HandleSentinelData(); } #endif - if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_O2) + if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_O2 >> 8)) { UART_HandleDigitalO2(); } @@ -845,7 +845,7 @@ } #endif #ifdef ENABLE_SENTINEL_MODE - if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) + if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_SENTINEL >> 8)) { UART_HandleSentinelData(); } diff -r 6a35e2e97bfb -r e23fe82cbf8c Small_CPU/Src/uart.c --- a/Small_CPU/Src/uart.c Thu Feb 02 17:35:54 2023 +0100 +++ b/Small_CPU/Src/uart.c Sun Feb 19 21:43:24 2023 +0100 @@ -39,6 +39,7 @@ static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */ static uint8_t digO2Connected = 0; /* Binary indicator if a sensor is connected or not */ static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */ +static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */ static uint8_t ppO2TargetChannel = 0; /* The OSTC4 supports three slots for visualization of the ppo2. This one is reserved for the digital sensor */ static SSensorDataDiveO2 sensorDataDiveO2; /* intermediate storage for additional sensor data */ @@ -86,6 +87,7 @@ dmaActive = 0; digO2Connected = 0; CO2Connected = 0; + SentinelConnected = 0; Comstatus_O2 = UART_O2_INIT; } @@ -194,6 +196,13 @@ } } +void UART_StartDMA_Receiption() +{ + if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) + { + dmaActive = 1; + } +} #ifdef ENABLE_CO2_SUPPORT void UART_HandleCO2Data(void) @@ -265,7 +274,7 @@ rxState = RX_Ready; } } - + rxBuffer[localRX] = 0; localRX++; rxReadIndex++; if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) @@ -283,10 +292,7 @@ if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ { - if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) - { - dmaActive = 1; - } + UART_StartDMA_Receiption(); } } #endif @@ -303,9 +309,9 @@ static uint8_t lastAlive = 0; static uint8_t curAlive = 0; static uint8_t checksum = 0; - char checksum_str[]="00"; + static char checksum_str[]="00"; - while(localRX != rxWriteIndex) + while((rxBuffer[localRX]!=0)) { lastReceiveTick = HAL_GetTick(); @@ -404,6 +410,7 @@ setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); + SentinelConnected = 1; } rxState = RX_Ready; break; @@ -413,7 +420,6 @@ break; } - localRX++; rxReadIndex++; if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) @@ -430,16 +436,14 @@ setExternalInterfaceChannel(0,0.0); setExternalInterfaceChannel(1,0.0); setExternalInterfaceChannel(2,0.0); + SentinelConnected = 0; } lastAlive = curAlive; } if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ { - if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) - { - dmaActive = 1; - } + UART_StartDMA_Receiption(); } } #endif @@ -482,10 +486,7 @@ cmdReadIndex = 0; lastO2ReqTick = tick; - if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) - { - dmaActive = 1; - } + UART_StartDMA_Receiption(); } if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */ { @@ -654,13 +655,9 @@ } lastAlive = curAlive; } - if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ { - if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) - { - dmaActive = 1; - } + UART_StartDMA_Receiption(); } } @@ -672,7 +669,10 @@ { return CO2Connected; } - +uint8_t UART_isSentinelConnected() +{ + return SentinelConnected; +} void UART_setTargetChannel(uint8_t channel) { @@ -694,10 +694,7 @@ if(externalInterface_isEnabledPower33()) { memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); - if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) - { - dmaActive = 1; - } + UART_StartDMA_Receiption(); } } }