Mercurial > public > ostc4
changeset 784:95af969fe0ae
Bugfixloop UART multiplexer integration:
Fixed problems showing up in cases like no Mux detected, only one sensor connected to mux and mixed analog / digital sensor operation
author | Ideenmodellierer |
---|---|
date | Tue, 30 May 2023 18:44:20 +0200 |
parents | c31237d20491 |
children | 3c0b16473af4 |
files | Small_CPU/Src/externalInterface.c Small_CPU/Src/uart.c |
diffstat | 2 files changed, 76 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Src/externalInterface.c Mon May 29 20:26:38 2023 +0200 +++ b/Small_CPU/Src/externalInterface.c Tue May 30 18:44:20 2023 +0200 @@ -469,7 +469,6 @@ static uint8_t sensorIndex = 0; static uint8_t uartMuxChannel = 0; uint8_t index = 0; - uint8_t index2 = 0; if(externalAutoDetect != DETECTION_OFF) { @@ -488,7 +487,7 @@ UART_MapDigO2_Channel(index,index); /* request all addresses */ tmpMuxMapping[index] = 0xff; } - UART_MapDigO2_Channel(3,4); + UART_MapDigO2_Channel(2,3); if(externalInterfacePresent) { @@ -559,6 +558,10 @@ { tmpSensorMap[index] = SENSOR_DIGO2; tmpMuxMapping[externalAutoDetect - DETECTION_DIGO2_0] = index; + if(externalAutoDetect == DETECTION_DIGO2_2 ) /* special handling needed because channel is used twice during mux detection */ + { + UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0); + } } } else @@ -569,7 +572,10 @@ { externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); UART_SetDigO2_Channel(uartMuxChannel); - uartMuxChannel++; + if(uartMuxChannel < MAX_ADC_CHANNEL - 1) + { + uartMuxChannel++; + } } else { @@ -628,18 +634,29 @@ { tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; } - index2 = 0; /* used for target channel */ + for(index = 0; index < MAX_MUX_CHANNEL; index++) { - if(tmpMuxMapping[index] != 0xff) - { - UART_MapDigO2_Channel(index2, index); - index2++; - } + UART_MapDigO2_Channel(tmpMuxMapping[index], index); } + externalAutoDetect = DETECTION_OFF; externalInterface_SwitchUART(0); UART_SetDigO2_Channel(0); + for(index = 0; index < MAX_ADC_CHANNEL; index++) + { + if(tmpSensorMap[index] != SENSOR_NONE) + { + break; + } + } + + if(index == MAX_ADC_CHANNEL) /* return default sensor map if no sensor at all has been detected */ + { + tmpSensorMap[0] = SENSOR_OPTIC; + tmpSensorMap[1] = SENSOR_OPTIC; + tmpSensorMap[2] = SENSOR_OPTIC; + } memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap)); break;
--- a/Small_CPU/Src/uart.c Mon May 29 20:26:38 2023 +0200 +++ b/Small_CPU/Src/uart.c Tue May 30 18:44:20 2023 +0200 @@ -158,9 +158,9 @@ break; case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR"); break; - case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY"); + case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#MOXY"); break; - case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#DRAW"); + case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#MRAW"); break; default: *cmdLength = 0; break; @@ -478,7 +478,7 @@ void UART_HandleDigitalO2(void) { static uint32_t lastO2ReqTick = 0; - + static uint8_t errorStr[] = "#ERRO"; static uartO2RxState_t rxState = O2RX_IDLE; static uint32_t lastReceiveTick = 0; static uint8_t lastAlive = 0; @@ -487,13 +487,15 @@ static uint8_t cmdLength = 0; static uint8_t cmdString[10]; static uint8_t cmdReadIndex = 0; + static uint8_t errorReadIndex = 0; static uint32_t tickToTX = 0; static uint32_t delayStartTick = 0; static uint16_t requestIntervall = 0; static uint8_t retryRequest = 1; static uint8_t lastComState = 0; + static uint8_t respondErrorDetected = 0; + static uint8_t switchChannel = 0; - uint8_t switchChannel = 0; uint8_t index = 0; uint32_t tmpO2 = 0; uint32_t tmpData = 0; @@ -532,7 +534,11 @@ rxState = O2RX_CONFIRM; cmdReadIndex = 0; + errorReadIndex = 0; + respondErrorDetected = 0; + digO2Connected = 0; lastO2ReqTick = tick; + switchChannel = 1; requestIntervall = 0; for(index = 0; index < MAX_MUX_CHANNEL; index++) @@ -556,7 +562,7 @@ { lastO2ReqTick = tick; index = activeSensor; - if(lastComState == Comstatus_O2) + if((lastComState == Comstatus_O2) && (Comstatus_O2 != UART_O2_IDLE)) { if(retryRequest) { @@ -577,6 +583,7 @@ retryRequest = 1; if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */ { + switchChannel = 0; if(activeSensor < MAX_MUX_CHANNEL) { do @@ -586,7 +593,7 @@ { index = 0; } - if(pmap[index] == SENSOR_DIGO2) + if((pmap[index] == SENSOR_DIGO2) && (index != activeSensor)) { activeSensor = index; switchChannel = 1; @@ -600,6 +607,7 @@ } if(switchChannel) { + switchChannel = 0; delayStartTick = tick; DigitalO2_SelectSensor(activeSensor); externalInterface_GetSensorData(activeSensor + 1, (uint8_t*)&tmpSensorDataDiveO2); @@ -624,13 +632,46 @@ case O2RX_CONFIRM: if(rxBuffer[localRX] == '#') { cmdReadIndex = 0; + errorReadIndex = 0; + } + if(errorReadIndex < sizeof(errorStr)-1) + { + if(rxBuffer[localRX] == errorStr[errorReadIndex]) + { + errorReadIndex++; + } + else + { + errorReadIndex = 0; + } + } + else + { + respondErrorDetected = 1; } if(rxBuffer[localRX] == cmdString[cmdReadIndex]) { cmdReadIndex++; if(cmdReadIndex == cmdLength - 1) { - digO2Connected = 1; + if((activeSensor == MAX_MUX_CHANNEL)) + { + if(respondErrorDetected) + { + digO2Connected = 0; /* the multiplexer mirrors the incoming message and does not generate an error information => no mux connected */ + } + else + { + digO2Connected = 1; + } + } + else /* handle sensors which should respond with an error message after channel switch */ + { + if(respondErrorDetected) + { + digO2Connected = 1; + } + } tmpRxIdx = 0; memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf)); switch (Comstatus_O2) @@ -738,12 +779,8 @@ case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&tmpSensorDataDiveO2.sensorId); externalInterface_SetSensorData(activeSensor+1,(uint8_t*)&tmpSensorDataDiveO2); index = activeSensor; - - if(switchChannel == 0) - { - Comstatus_O2 = UART_O2_IDLE; - rxState = O2RX_IDLE; - } + Comstatus_O2 = UART_O2_IDLE; + rxState = O2RX_IDLE; break; default: Comstatus_O2 = UART_O2_IDLE; rxState = O2RX_IDLE;