changeset 957:3420e3ba698d Evo_2_23

External sensor commands: Add sensor ID to command: In the previous version a command was send without information regarding the target sensor. To have the possibility in future to e.g. calibrate a specific sensor, the sensor ID is now transmitted together with the command. As example in the new implementation the O2 Sensor selected in the sensor menu will blink to enable sensor identification.
author Ideenmodellierer
date Mon, 06 Jan 2025 20:06:35 +0100
parents 083afabc6578
children 902cb199eee6
files Common/Inc/data_exchange.h Discovery/Inc/data_exchange_main.h Discovery/Src/data_exchange_main.c Discovery/Src/tInfoSensor.c Discovery/Src/tMenuEditHardware.c Small_CPU/Src/GNSS.c Small_CPU/Src/externalInterface.c Small_CPU/Src/uartProtocol_O2.c
diffstat 8 files changed, 51 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_exchange.h	Mon Jan 06 17:55:34 2025 +0100
+++ b/Common/Inc/data_exchange.h	Mon Jan 06 20:06:35 2025 +0100
@@ -33,9 +33,9 @@
 
 /* Command definitions for control of external interface */
 /* 1st nibble binary on/off states */
-/* 2nd nibble UART protocol selection */
-/* 3rd nibble reserve */
-/* 4th nibble command channel */
+/* 2nd nibble target sensor ID (if sensor command is active) */
+/* 3rd nibble sensor commands */
+/* 4th nibble control channel */
 #define EXT_INTERFACE_33V_ON		(0x8000u)	/* Bit set to enable 3.3V power interface */
 #define EXT_INTERFACE_ADC_ON		(0x4000u)	/* Bit set to enable ADC conversion */
 #define EXT_INTERFACE_BUZZER_ON		(0x2000u)	/* Bit set to enable the buzzer */
--- a/Discovery/Inc/data_exchange_main.h	Mon Jan 06 17:55:34 2025 +0100
+++ b/Discovery/Inc/data_exchange_main.h	Mon Jan 06 20:06:35 2025 +0100
@@ -56,6 +56,6 @@
 
 uint16_t DataEX_debug_data(uint16_t *dataOut20x5);
 
-void DataEX_setExtInterface_Cmd(uint16_t Cmd);
+void DataEX_setExtInterface_Cmd(uint16_t Cmd,uint8_t sensorId);
 
 #endif /* DATA_EXCHANGE_MAIN_H */
--- a/Discovery/Src/data_exchange_main.c	Mon Jan 06 17:55:34 2025 +0100
+++ b/Discovery/Src/data_exchange_main.c	Mon Jan 06 20:06:35 2025 +0100
@@ -482,7 +482,7 @@
 		
 		settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness);
 		setButtonResponsiveness(settings->ButtonResponsiveness);
-		DataEX_setExtInterface_Cmd(EXT_INTERFACE_COPY_SENSORMAP);
+		DataEX_setExtInterface_Cmd(EXT_INTERFACE_COPY_SENSORMAP, 0);
 	}
 }
 
@@ -1363,9 +1363,14 @@
 	return retval;
 }
 
-void DataEX_setExtInterface_Cmd(uint16_t Cmd)
+void DataEX_setExtInterface_Cmd(uint16_t Cmd, uint8_t sensorId)
 {
-	externalInterface_Cmd = Cmd;
+	if(sensorId < EXT_INTERFACE_SENSOR_CNT - 1)
+	{
+		externalInterface_Cmd |= Cmd;
+		externalInterface_Cmd |= sensorId << 8;
+	}
+
 	return;
 }
 
--- a/Discovery/Src/tInfoSensor.c	Mon Jan 06 17:55:34 2025 +0100
+++ b/Discovery/Src/tInfoSensor.c	Mon Jan 06 20:06:35 2025 +0100
@@ -61,12 +61,12 @@
     	case 0: setBackMenu((uint32_t)openEdit_O2Sensors,0,1);
     	    		break;
     }
-
     sensorActive = 1;
     if(pSettings->ppo2sensors_deactivated & (1 << (activeSensorId)))
     {
     	sensorActive = 0;
     }
+    DataEX_setExtInterface_Cmd(EXT_INTERFACE_O2_INDICATE, activeSensorId);
 }
 
 
@@ -260,7 +260,7 @@
     		break;
 		case ACTION_BUTTON_NEXT:		if(stateRealGetPointer()->lifeData.extIf_sensor_map[activeSensorId] == SENSOR_CO2M)
 										{
-											DataEX_setExtInterface_Cmd(EXT_INTERFACE_CO2_CALIB);
+											DataEX_setExtInterface_Cmd(EXT_INTERFACE_CO2_CALIB, activeSensorId);
 										}
 			break;
 		case ACTION_TIMEOUT:
--- a/Discovery/Src/tMenuEditHardware.c	Mon Jan 06 17:55:34 2025 +0100
+++ b/Discovery/Src/tMenuEditHardware.c	Mon Jan 06 20:06:35 2025 +0100
@@ -843,7 +843,7 @@
 
 uint8_t OnAction_Sensor_Detect(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {
-	DataEX_setExtInterface_Cmd(EXT_INTERFACE_AUTODETECT);
+	DataEX_setExtInterface_Cmd(EXT_INTERFACE_AUTODETECT, 0);
 	return UNSPECIFIC_RETURN;
 }
 
--- a/Small_CPU/Src/GNSS.c	Mon Jan 06 17:55:34 2025 +0100
+++ b/Small_CPU/Src/GNSS.c	Mon Jan 06 20:06:35 2025 +0100
@@ -66,7 +66,7 @@
  * @param GNSS Pointer to main GNSS structure.
  */
 void GNSS_ParseUniqID(GNSS_StateHandle *GNSS) {
-	for (int var = 0; var < 5; var++) {
+	for (int var = 0; var < 4; var++) {
 		GNSS->uniqueID[var] = GNSS_Handle.uartWorkingBuffer[10 + var];
 	}
 }
--- a/Small_CPU/Src/externalInterface.c	Mon Jan 06 17:55:34 2025 +0100
+++ b/Small_CPU/Src/externalInterface.c	Mon Jan 06 20:06:35 2025 +0100
@@ -1018,15 +1018,6 @@
 											SensorMap[index] = SENSOR_SEARCH;
 										}
 			break;
-		case EXT_INTERFACE_CO2_CALIB:	for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++)
-										{
-											if(SensorMap[index] == SENSOR_CO2)
-											{
-												externalInterface_SensorState[index] = UART_CO2_CALIBRATE;
-												break;
-											}
-										}
-			break;
 		case EXT_INTERFACE_COPY_SENSORMAP:	if(externalAutoDetect == DETECTION_OFF)
 											{
 												memcpy(SensorMap, MasterSensorMap, sizeof(MasterSensorMap));
@@ -1049,6 +1040,27 @@
 												}
 											}
 			break;
+		case EXT_INTERFACE_CO2_CALIB:	index = (Cmd >> 8) & 0x000F;
+										if(SensorMap[index] == SENSOR_CO2M)
+										{
+											index = Mux2ADCMap[index];
+										}
+										if(SensorMap[index] == SENSOR_CO2)
+										{
+											externalInterface_SensorState[index] = UART_CO2_CALIBRATE;
+										}
+			break;
+		case EXT_INTERFACE_O2_INDICATE:	index = (Cmd >> 8) & 0x000F;
+										if(SensorMap[index] == SENSOR_DIGO2M)
+										{
+											index = Mux2ADCMap[index];
+										}
+										if(SensorMap[index] == SENSOR_DIGO2)
+										{
+											externalInterface_SensorState[index] = UART_O2_CHECK;
+										}
+			break;
+
 		default:
 			break;
 	}
@@ -1209,14 +1221,17 @@
 						forceMuxChannel = 0;
 						timeToTrigger = 100;
 						activeUartChannel = index;
-						if((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2)
-								|| (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2)
-								|| (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_GNSS))
+						switch(pmap[index + EXT_INTERFACE_MUX_OFFSET])
 						{
-							uartO2_SetChannel(activeUartChannel);
-							externalInterface_CheckBaudrate(SENSOR_MUX);
-							UART_MUX_SelectAddress(activeUartChannel);
-							externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]);
+							case SENSOR_DIGO2: uartO2_SetChannel(activeUartChannel);
+							/* no break */
+							case SENSOR_CO2:
+							case SENSOR_GNSS: 	externalInterface_CheckBaudrate(SENSOR_MUX);
+												UART_MUX_SelectAddress(activeUartChannel);
+												externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]);
+								break;
+							default:
+								break;
 						}
 					}
 				}
--- a/Small_CPU/Src/uartProtocol_O2.c	Mon Jan 06 17:55:34 2025 +0100
+++ b/Small_CPU/Src/uartProtocol_O2.c	Mon Jan 06 20:06:35 2025 +0100
@@ -134,6 +134,10 @@
 		rxState = O2RX_CONFIRM;
 		uartO2_SetupCmd(localComState,cmdString,&cmdLength);
 		UART_SendCmdString(cmdString);
+		if(localComState == UART_O2_CHECK)
+		{
+			localComState = UART_O2_IDLE;	/* confirmation seems to be send after blinking => the response could be longer as the channel switch time => ignore */
+		}
 	}
 	externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState);
 }