changeset 714:045ff7800501

Added customizable data area for specific sensor data: In future smart sensors will be connected via UART interface. These sensor provide additional data like diagnostics or id numbers which may vary from sensor to sensor. That's why a byte array has been added which stores up to 32 bytes. The layout of this array may be specific to sensor needs. As first example temperature and id number of the DiveO2 sensor are provided.
author Ideenmodellierer
date Sun, 20 Nov 2022 20:42:08 +0100
parents 1fbcca5bdf5d
children 6c620f5f4834
files Common/Inc/data_central.h Common/Inc/data_exchange.h Small_CPU/Inc/externalInterface.h Small_CPU/Inc/uart.h Small_CPU/Src/externalInterface.c Small_CPU/Src/scheduler.c Small_CPU/Src/uart.c
diffstat 7 files changed, 84 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_central.h	Sun Nov 20 20:37:44 2022 +0100
+++ b/Common/Inc/data_central.h	Sun Nov 20 20:42:08 2022 +0100
@@ -197,6 +197,9 @@
 	SDataWireless wireless_data[4];
 	uint8_t buttonPICdata[4];
 	SCO2Sensor CO2_data;
+	uint8_t extIf_sensor_Id;
+	uint8_t UINT64ALIGNMENT;					/* If your program crash check if you changed something in the life data structure ! The external sensor may contain a 64 bit ID */
+	uint8_t extIf_sensor_data[32];
 
 
 	/* by create DiveSettings() and by setActualGas()
--- a/Common/Inc/data_exchange.h	Sun Nov 20 20:37:44 2022 +0100
+++ b/Common/Inc/data_exchange.h	Sun Nov 20 20:42:08 2022 +0100
@@ -52,6 +52,8 @@
 #define DATA_BUFFER_ADC				(0x01u)
 #define DATA_BUFFER_CO2				(0x02u)
 
+#define EXTIF_SENSOR_INFO_SIZE		(32u)		/* size of data array reserved for extended sensor data from external interface */
+
 enum MODE
 {
 	MODE_SURFACE	= 0,
@@ -132,6 +134,13 @@
 
 typedef struct
 {
+	int32_t temperature;
+	uint32_t status;
+	uint64_t sensorId;
+} SSensorDataDiveO2;
+
+typedef struct
+{
 		//pressure
 		float temperature;
 		float pressure_mbar;
@@ -174,7 +183,10 @@
 		uint16_t CO2_ppm;
 		uint16_t CO2_signalStrength;
 		uint16_t externalInterface_CmdAnswer;
-		uint8_t SPARE_OldWireless[44]; /* 64 - 12 for extADC - 6 for CO2 */
+		uint8_t	alignmentdummy;
+		uint8_t externalInterface_SensorID;						/* Used to identify how to read the sensor data array */
+		uint8_t sensor_data[EXTIF_SENSOR_INFO_SIZE];			/* sensor specific data array. Content may vary from sensor type to sensor type */
+		uint8_t SPARE_OldWireless[10]; 							/* 64 - 12 for extADC - 6 for CO2 - 34 for sensor (+dummmy)*/
 		// PIC data
 		uint8_t button_setting[4]; /* see dependency to SLiveData->buttonPICdata */
 		uint8_t SPARE1;
--- a/Small_CPU/Inc/externalInterface.h	Sun Nov 20 20:37:44 2022 +0100
+++ b/Small_CPU/Inc/externalInterface.h	Sun Nov 20 20:42:08 2022 +0100
@@ -54,6 +54,8 @@
 uint16_t externalInterface_GetCO2SignalStrength(void);
 void externalInterface_SetCO2State(uint16_t state);
 uint16_t externalInterface_GetCO2State(void);
+uint8_t externalInterface_GetSensorData(uint8_t* pDataStruct);
+void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct);
 
 void externalInterface_ExecuteCmd(uint16_t Cmd);
 
--- a/Small_CPU/Inc/uart.h	Sun Nov 20 20:37:44 2022 +0100
+++ b/Small_CPU/Inc/uart.h	Sun Nov 20 20:42:08 2022 +0100
@@ -51,7 +51,7 @@
  	UART_O2_INIT = 0,
  	UART_O2_CHECK,			/* send blink command and check if sensor answers */
  	UART_O2_REQ_INFO,		/* request information about available internal sensors of sensor */
-	UART_O2_REQ_ID,		/* request ID of sensor */
+	UART_O2_REQ_ID,			/* request ID of sensor */
  	UART_O2_IDLE,			/* sensor detected and no communication pending */
  	UART_O2_REQ_O2,			/* O2 value has been requested and is in receiption progress */
  	UART_O2_ERROR			/* Error state which could not be resolved => only exit via de-/activation cycle */
--- a/Small_CPU/Src/externalInterface.c	Sun Nov 20 20:37:44 2022 +0100
+++ b/Small_CPU/Src/externalInterface.c	Sun Nov 20 20:42:08 2022 +0100
@@ -24,6 +24,7 @@
 /* Includes ------------------------------------------------------------------*/
 
 #include <math.h>
+#include <string.h>
 #include "i2c.h"
 #include "externalInterface.h"
 #include "scheduler.h"
@@ -62,6 +63,9 @@
 static uint16_t externalCO2SignalStrength;
 static uint16_t  externalCO2Status = 0;
 
+static uint8_t sensorDataId = 0;
+static SSensorDataDiveO2 sensorDataDiveO2;
+
 
 void externalInterface_Init(void)
 {
@@ -251,6 +255,7 @@
 }
 void externalInterface_SwitchADC(uint8_t state)
 {
+	uint8_t loop = 0;
 	if((state) && (externalInterfacePresent))
 	{
 		externalInterface_StartConversion(activeChannel);
@@ -259,6 +264,10 @@
 	else
 	{
 		externalADC_On = 0;
+		for(loop = 0; loop < MAX_ADC_CHANNEL; loop++)
+		{
+			externalChannel_mV[loop] = 0;
+		}
 	}
 }
 
@@ -266,6 +275,7 @@
 {
 	if(protocol < 0x08)
 	{
+		sensorDataId = 0;
 		externalUART_Protocol = protocol;
 		MX_USART1_UART_DeInit();
 		if( protocol != 0)
@@ -306,6 +316,33 @@
 	return externalCO2Status;
 }
 
+
+uint8_t externalInterface_GetSensorData(uint8_t* pDataStruct)
+{
+
+	if((pDataStruct != NULL) && sensorDataId != 0)
+	{
+		memcpy(pDataStruct, &sensorDataDiveO2, sizeof(sensorDataDiveO2));
+	}
+	return sensorDataId;
+}
+
+void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct)
+{
+	if(pDataStruct != NULL)
+	{
+		if(dataId != 0)
+		{
+			memcpy(&sensorDataDiveO2, pDataStruct, sizeof(sensorDataDiveO2));
+		}
+		else
+		{
+			memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2));
+		}
+		sensorDataId = dataId;
+	}
+}
+
 void externalInterface_ExecuteCmd(uint16_t Cmd)
 {
 	char cmdString[10];
--- a/Small_CPU/Src/scheduler.c	Sun Nov 20 20:37:44 2022 +0100
+++ b/Small_CPU/Src/scheduler.c	Sun Nov 20 20:42:08 2022 +0100
@@ -1733,6 +1733,7 @@
 		value = getExternalInterfaceChannel(channel);
 		global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value;
 	}
+	global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData((uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data);
 	global.dataSendToMaster.boolADCO2Data |= boolADCBuffer;
 }
 
--- a/Small_CPU/Src/uart.c	Sun Nov 20 20:37:44 2022 +0100
+++ b/Small_CPU/Src/uart.c	Sun Nov 20 20:42:08 2022 +0100
@@ -38,13 +38,13 @@
 static uint8_t lastCmdIndex;					/* Index of last command which has not been completly received */
 static uint8_t dmaActive;						/* Indicator if DMA receiption needs to be started */
 
+static SSensorDataDiveO2 sensorDataDiveO2;		/* intermediate storage for additional sensor data */
+
 char tmpRxBuf[30];
 uint8_t tmpRxIdx = 0;
 
 static uartO2Status_t Comstatus_O2 = UART_O2_INIT;
 
-static uint32_t DigitalO2ID = 0;
-
 float LED_Level = 0.0;							/* Normalized LED value which may be used as indication for the health status of the sensor */
 float LED_ZeroOffset = 0.0;
 float pCO2 = 0.0;
@@ -400,7 +400,7 @@
 	}
 }
 
-void StringToInt(char *pstr, uint32_t *pInt)
+void StringToInt(char *pstr, uint32_t *puInt32)
 {
 	uint8_t index = 0;
 	uint32_t result = 0;
@@ -410,7 +410,20 @@
 		result += pstr[index] - '0';
 		index++;
 	}
-	*pInt = result;
+	*puInt32 = result;
+}
+
+void StringToUInt64(char *pstr, uint64_t *puint64)
+{
+	uint8_t index = 0;
+	uint64_t result = 0;
+	while((pstr[index] >= '0') && (pstr[index] <= '9'))
+	{
+		result *=10;
+		result += pstr[index] - '0';
+		index++;
+	}
+	*puint64 = result;
 }
 
 void HandleUARTDigitalO2(void)
@@ -435,6 +448,9 @@
 	if(Comstatus_O2 == UART_O2_INIT)
 	{
 		memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE);
+		memset((char*) &sensorDataDiveO2, 0, sizeof(sensorDataDiveO2));
+		externalInterface_SetSensorData(0,(uint8_t*)&sensorDataDiveO2);
+
 		lastAlive = 0;
 		curAlive = 0;
 
@@ -483,7 +499,8 @@
 									memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf));
 									switch (Comstatus_O2)
 									{
-											case UART_O2_CHECK:	Comstatus_O2 = UART_O2_REQ_INFO;
+											case UART_O2_CHECK:	Comstatus_O2 = UART_O2_REQ_ID;
+																rxState = O2RX_CONFIRM;
 																DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength);
 																HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
 												break;
@@ -534,7 +551,8 @@
 																		setExternalInterfaceChannel(0,(float)(tmpO2 / 10000.0));
 																		rxState = O2RX_GETTEMP;
 													break;
-												case O2RX_GETTEMP:		rxState = O2RX_GETSTATUS;
+												case O2RX_GETTEMP:		StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature);
+																		rxState = O2RX_GETSTATUS;
 													break;
 												default:
 													break;
@@ -548,7 +566,8 @@
 								{
 									switch (rxState)
 									{
-										case O2RX_GETSTATUS:		StringToInt(tmpRxBuf,&tmpData);
+										case O2RX_GETSTATUS:		StringToInt(tmpRxBuf,&sensorDataDiveO2.status);
+																	externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2);
 																	Comstatus_O2 = UART_O2_IDLE;
 																	rxState = O2RX_IDLE;
 												break;
@@ -556,7 +575,7 @@
 																	Comstatus_O2 = UART_O2_IDLE;
 																	rxState = O2RX_IDLE;
 												break;
-										case  O2RX_GETNR: 			StringToInt((char*)rxBuffer,&DigitalO2ID);
+										case  O2RX_GETNR: 			StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId);
 											/* no break */
 										default:		Comstatus_O2 = UART_O2_IDLE;
 														rxState = O2RX_IDLE;