Mercurial > public > ostc4
comparison Small_CPU/Src/externalInterface.c @ 809:9602a7338f28
DevBugfix CO2 sensor in streaming mode:
In standalone mode (no multiplexer) the CO2 sensor is working in streaming mode => it could happen that the OSTC received data before the scaling factor was requested. As result the CO2 values were calculated with a zero value. This problem has been fixed.
In addition some code cleanup has been done. Unifying usage of changeBaudrate function instead of old baud selection based on protocol request of Discovery firmware.
author | Ideenmodellierer |
---|---|
date | Sun, 27 Aug 2023 20:51:13 +0200 |
parents | 391b3d420a39 |
children | 061174d88af9 |
comparison
equal
deleted
inserted
replaced
808:ea3267866120 | 809:9602a7338f28 |
---|---|
92 static uint16_t externalInterfaceMuxReqIntervall = 0xffff; /* delay between switching from one MUX channel to the next */ | 92 static uint16_t externalInterfaceMuxReqIntervall = 0xffff; /* delay between switching from one MUX channel to the next */ |
93 static uint8_t activeUartChannel = 0; /* Index of the sensor port which is selected by the mux or 0 if no mux is connected */ | 93 static uint8_t activeUartChannel = 0; /* Index of the sensor port which is selected by the mux or 0 if no mux is connected */ |
94 | 94 |
95 | 95 |
96 static void externalInface_MapUartToLegacyADC(uint8_t* pMap); | 96 static void externalInface_MapUartToLegacyADC(uint8_t* pMap); |
97 static void externalInterface_CheckBaudrate(uint8_t sensorType); | |
97 | 98 |
98 void externalInterface_Init(void) | 99 void externalInterface_Init(void) |
99 { | 100 { |
100 uint16_t index; | 101 uint16_t index; |
101 uint16_t coeff; | 102 uint16_t coeff; |
742 } | 743 } |
743 externalAutoDetect++; | 744 externalAutoDetect++; |
744 #ifdef ENABLE_CO2_SUPPORT | 745 #ifdef ENABLE_CO2_SUPPORT |
745 if(externalAutoDetect == DETECTION_CO2_0) | 746 if(externalAutoDetect == DETECTION_CO2_0) |
746 { | 747 { |
747 UART_MUX_SelectAddress(0); | 748 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
749 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | |
750 { | |
751 UART_MUX_SelectAddress(0); | |
752 } | |
748 activeUartChannel = 0; | 753 activeUartChannel = 0; |
749 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | 754 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
750 uartMuxChannel = 1; | 755 uartMuxChannel = 1; |
751 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_CO2; | 756 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_CO2; |
752 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; | 757 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
753 externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8); | 758 externalInterface_CheckBaudrate(SENSOR_CO2); |
754 if(tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* switch sensor operation mode depending on HW config */ | 759 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* switch sensor operation mode depending on HW config */ |
755 { | 760 { |
756 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); | 761 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); |
757 } | 762 } |
758 else | 763 else |
759 { | 764 { |
769 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_CO2; | 774 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_CO2; |
770 externalAutoDetect = DETECTION_DONE; /* only one CO2 sensor supported */ | 775 externalAutoDetect = DETECTION_DONE; /* only one CO2 sensor supported */ |
771 } | 776 } |
772 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | 777 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
773 { | 778 { |
774 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); | 779 externalInterface_CheckBaudrate(SENSOR_DIGO2); |
775 UART_MUX_SelectAddress(uartMuxChannel); | 780 UART_MUX_SelectAddress(uartMuxChannel); |
776 activeUartChannel = uartMuxChannel; | 781 activeUartChannel = uartMuxChannel; |
777 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | 782 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
778 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2; | 783 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2; |
779 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT; | 784 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT; |
780 externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8); | 785 externalInterface_CheckBaudrate(SENSOR_CO2); |
781 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); | 786 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); |
782 externalAutoDetect++; | 787 externalAutoDetect++; |
783 uartMuxChannel++; | 788 uartMuxChannel++; |
784 } | 789 } |
785 else | 790 else |
930 return newChannel; | 935 return newChannel; |
931 } | 936 } |
932 | 937 |
933 void externalInterface_CheckBaudrate(uint8_t sensorType) | 938 void externalInterface_CheckBaudrate(uint8_t sensorType) |
934 { | 939 { |
935 static uint32_t lastBaudRate = 0; | |
936 uint32_t newBaudrate = 0; | 940 uint32_t newBaudrate = 0; |
937 | 941 |
938 switch(sensorType) | 942 switch(sensorType) |
939 { | 943 { |
940 case SENSOR_CO2: newBaudrate = 9600; | 944 case SENSOR_CO2: newBaudrate = 9600; |
941 break; | 945 break; |
942 case SENSOR_DIGO2: | 946 case SENSOR_DIGO2: |
943 default: newBaudrate = 19200; | 947 default: newBaudrate = 19200; |
944 break; | 948 break; |
945 } | 949 } |
946 if(lastBaudRate != newBaudrate) | 950 if(huart1.Init.BaudRate != newBaudrate) |
947 { | 951 { |
948 UART_ChangeBaudrate(newBaudrate); | 952 UART_ChangeBaudrate(newBaudrate); |
949 lastBaudRate = newBaudrate; | |
950 } | 953 } |
951 } | 954 } |
952 | 955 |
953 void externalInterface_HandleUART() | 956 void externalInterface_HandleUART() |
954 { | 957 { |
965 { | 968 { |
966 UART_ReadData(pmap[activeSensorId]); | 969 UART_ReadData(pmap[activeSensorId]); |
967 | 970 |
968 if(activeUartChannel == 0xFF) | 971 if(activeUartChannel == 0xFF) |
969 { | 972 { |
973 MX_USART1_UART_Init(); | |
970 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0); | 974 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0); |
971 uartO2_SetChannel(activeUartChannel); | 975 uartO2_SetChannel(activeUartChannel); |
972 | 976 |
973 switch(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]) | 977 switch(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]) |
974 { | 978 { |
975 case SENSOR_CO2: externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8); | 979 case SENSOR_CO2: externalInterface_CheckBaudrate(SENSOR_CO2); |
976 break; | 980 break; |
977 default: | 981 default: |
978 case SENSOR_DIGO2: externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); | 982 case SENSOR_DIGO2: externalInterface_CheckBaudrate(SENSOR_DIGO2); |
979 break; | 983 break; |
980 } | 984 } |
981 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | 985 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
982 { | 986 { |
983 UART_MUX_SelectAddress(activeUartChannel); | 987 UART_MUX_SelectAddress(activeUartChannel); |