comparison 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
comparison
equal deleted inserted replaced
713:1fbcca5bdf5d 714:045ff7800501
22 ****************************************************************************** 22 ******************************************************************************
23 */ 23 */
24 /* Includes ------------------------------------------------------------------*/ 24 /* Includes ------------------------------------------------------------------*/
25 25
26 #include <math.h> 26 #include <math.h>
27 #include <string.h>
27 #include "i2c.h" 28 #include "i2c.h"
28 #include "externalInterface.h" 29 #include "externalInterface.h"
29 #include "scheduler.h" 30 #include "scheduler.h"
30 #include "uart.h" 31 #include "uart.h"
31 #include "data_exchange.h" 32 #include "data_exchange.h"
59 static uint8_t externalADC_On = 0; 60 static uint8_t externalADC_On = 0;
60 static uint8_t externalUART_Protocol = 0; 61 static uint8_t externalUART_Protocol = 0;
61 static uint16_t externalCO2Value; 62 static uint16_t externalCO2Value;
62 static uint16_t externalCO2SignalStrength; 63 static uint16_t externalCO2SignalStrength;
63 static uint16_t externalCO2Status = 0; 64 static uint16_t externalCO2Status = 0;
65
66 static uint8_t sensorDataId = 0;
67 static SSensorDataDiveO2 sensorDataDiveO2;
64 68
65 69
66 void externalInterface_Init(void) 70 void externalInterface_Init(void)
67 { 71 {
68 activeChannel = 0; 72 activeChannel = 0;
249 } 253 }
250 } 254 }
251 } 255 }
252 void externalInterface_SwitchADC(uint8_t state) 256 void externalInterface_SwitchADC(uint8_t state)
253 { 257 {
258 uint8_t loop = 0;
254 if((state) && (externalInterfacePresent)) 259 if((state) && (externalInterfacePresent))
255 { 260 {
256 externalInterface_StartConversion(activeChannel); 261 externalInterface_StartConversion(activeChannel);
257 externalADC_On = 1; 262 externalADC_On = 1;
258 } 263 }
259 else 264 else
260 { 265 {
261 externalADC_On = 0; 266 externalADC_On = 0;
267 for(loop = 0; loop < MAX_ADC_CHANNEL; loop++)
268 {
269 externalChannel_mV[loop] = 0;
270 }
262 } 271 }
263 } 272 }
264 273
265 void externalInterface_SwitchUART(uint8_t protocol) 274 void externalInterface_SwitchUART(uint8_t protocol)
266 { 275 {
267 if(protocol < 0x08) 276 if(protocol < 0x08)
268 { 277 {
278 sensorDataId = 0;
269 externalUART_Protocol = protocol; 279 externalUART_Protocol = protocol;
270 MX_USART1_UART_DeInit(); 280 MX_USART1_UART_DeInit();
271 if( protocol != 0) 281 if( protocol != 0)
272 { 282 {
273 MX_USART1_UART_Init(); 283 MX_USART1_UART_Init();
302 } 312 }
303 313
304 uint16_t externalInterface_GetCO2State(void) 314 uint16_t externalInterface_GetCO2State(void)
305 { 315 {
306 return externalCO2Status; 316 return externalCO2Status;
317 }
318
319
320 uint8_t externalInterface_GetSensorData(uint8_t* pDataStruct)
321 {
322
323 if((pDataStruct != NULL) && sensorDataId != 0)
324 {
325 memcpy(pDataStruct, &sensorDataDiveO2, sizeof(sensorDataDiveO2));
326 }
327 return sensorDataId;
328 }
329
330 void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct)
331 {
332 if(pDataStruct != NULL)
333 {
334 if(dataId != 0)
335 {
336 memcpy(&sensorDataDiveO2, pDataStruct, sizeof(sensorDataDiveO2));
337 }
338 else
339 {
340 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2));
341 }
342 sensorDataId = dataId;
343 }
307 } 344 }
308 345
309 void externalInterface_ExecuteCmd(uint16_t Cmd) 346 void externalInterface_ExecuteCmd(uint16_t Cmd)
310 { 347 {
311 char cmdString[10]; 348 char cmdString[10];