diff Small_CPU/Src/externalInterface.c @ 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 f1b40364b0af
children d646a0f724a7
line wrap: on
line diff
--- 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];