comparison Small_CPU/Inc/uart.h @ 794:bb37d4f3e50e

Restructure UART based sensor handling: In the previous version every UART sensor instance had its own protocol handling instance (requests, timeout, errors). With the introduction of the multiplexer these functionalities had to be harmonized. E.g. only one errorhandling which is applied to all sensors. In the new structure the sensor communication is split into one function which takes care for the control needs of a sensor and one function which handles the incoming data. The functions behalf the same independend if the sensor are connected to multiplexer or directly to the OSTC. Second big change in the external sensor concepts is that the data processing is no longer focussed at the three existing ADC channels. Every external sensor (up to 3 ADC and 4 UART) sensor has its own instance. If the ADC slots are not in use then they may be used for visiualization of UART sensors by creating a mirror instance but this is no longer a must.
author Ideenmodellierer
date Mon, 31 Jul 2023 19:46:29 +0200
parents 0b5f45448eb6
children e9eba334b942
comparison
equal deleted inserted replaced
793:9da81033ad44 794:bb37d4f3e50e
23 #endif 23 #endif
24 24
25 #include "stm32f4xx_hal.h" 25 #include "stm32f4xx_hal.h"
26 26
27 27
28 #define BUFFER_NODATA (7u) /* The read function needs a byte which indecated that no data for processing is available.*/
29 /* This byte shall never appear in a normal data steam */
30
31 typedef enum
32 {
33 UART_CO2_INIT = 0,
34 UART_CO2_SETUP, /* collecting data needed to be read out of the sensor once at startup */
35 UART_CO2_OPERATING, /* normal operation */
36 } uartCO2Status_t;
37
28 typedef enum 38 typedef enum
29 { 39 {
30 RX_Ready= 0, /* Initial state */ 40 RX_Ready= 0, /* Initial state */
31 RX_DetectStart, /* validate start byte */ 41 RX_DetectStart, /* validate start byte */
32 RX_SelectData, /* Data contained in this frame */ 42 RX_SelectData, /* Data contained in this frame */
44 RX_Data11, 54 RX_Data11,
45 RX_Data12, 55 RX_Data12,
46 RX_DataComplete 56 RX_DataComplete
47 } receiveState_t; 57 } receiveState_t;
48 58
49 typedef enum
50 {
51 UART_O2_INIT = 0,
52 UART_O2_CHECK, /* send blink command and check if sensor answers */
53 UART_O2_REQ_INFO, /* request information about available internal sensors of sensor */
54 UART_O2_REQ_ID, /* request ID of sensor */
55 UART_O2_IDLE, /* sensor detected and no communication pending */
56 UART_O2_REQ_O2, /* O2 value has been requested and is in receiption progress */
57 UART_O2_REQ_RAW, /* Request O2 and extended raw data */
58 UART_O2_ERROR /* Error state which could not be resolved => only exit via de-/activation cycle */
59 } uartO2Status_t;
60 59
61 60 typedef enum
62 typedef enum 61 {
63 { 62 CO2CMD_MODE_POLL, /* Set operation mode of sensor to polling => only send data if requested */
64 O2RX_IDLE = 0, /* no reception pending */ 63 CO2CMD_MODE_STREAM, /* Set operation mode of sensor to streaming => send data every two seconds */
65 O2RX_CONFIRM, /* check the command echo */ 64 CO2CMD_CALIBRATE, /* Calibrate sensor */
66 O2RX_GETNR, /* extract the sensor number */ 65 CO2CMD_GETSCALE, /* Get scaling factor */
67 O2RX_GETO2, /* extract the ppo2 */ 66 CO2CMD_GETDATA /* Read sensor data */
68 O2RX_GETTEMP, /* extract the temperature */ 67 } co2SensorCmd_t;
69 O2RX_GETSTATUS, /* extract the sensor status */
70 O2RX_GETTYPE, /* extract the sensor type (should be 8) */
71 O2RX_GETCHANNEL, /* extract the number of sensor channels (should be 1) */
72 O2RX_GETVERSION, /* extract the sensor version */
73 O2RX_GETSUBSENSORS, /* extract the available measures (O2, temperature, humidity etc) */
74 O2RX_GETDPHI, /* extract phase shift */
75 O2RX_INTENSITY, /* extract intensity of signal */
76 O2RX_AMBIENTLIGHT, /* extract the intensity of the ambient light */
77 O2RX_PRESSURE, /* extract pressor within the sensor housing */
78 O2RX_HUMIDITY /* extract humidity within the sensor housing */
79 } uartO2RxState_t;
80
81
82 68
83 void MX_USART1_UART_Init(void); 69 void MX_USART1_UART_Init(void);
84 void MX_USART1_UART_DeInit(void); 70 void MX_USART1_UART_DeInit(void);
85 void MX_USART1_DMA_Init(void); 71 void MX_USART1_DMA_Init(void);
86 uint8_t UART_ButtonAdjust(uint8_t *array); 72 uint8_t UART_ButtonAdjust(uint8_t *array);
87 void UART_StartDMA_Receiption(void); 73 void UART_StartDMA_Receiption(void);
88 #ifdef ENABLE_CO2_SUPPORT 74 #ifdef ENABLE_CO2_SUPPORT
89 void UART_HandleCO2Data(void); 75 void UART_HandleCO2Data(void);
76 void DigitalCO2_SendCmd(uint8_t CO2Cmd, uint8_t *cmdString, uint8_t *cmdLength);
90 #endif 77 #endif
91 #ifdef ENABLE_SENTINEL_MODE 78 #ifdef ENABLE_SENTINEL_MODE
92 void UART_HandleSentinelData(void); 79 void UART_HandleSentinelData(void);
93 #endif 80 #endif
94 void UART_HandleDigitalO2(void);
95 void UART_MapDigO2_Channel(uint8_t channel, uint8_t muxAddress);
96 void UART_SetDigO2_Channel(uint8_t channel);
97 uint8_t UART_isDigO2Connected();
98 uint8_t UART_isCO2Connected(); 81 uint8_t UART_isCO2Connected();
99 uint8_t UART_isSentinelConnected(); 82 uint8_t UART_isSentinelConnected();
100 void UART_setTargetChannel(uint8_t channel); 83 void UART_setTargetChannel(uint8_t channel);
84 void UART_MUX_SelectAddress(uint8_t muxAddress);
85 void UART_SendCmdString(uint8_t *cmdString);
86 void UART_ReadData(uint8_t sensorType);
87 void UART_FlushRxBuffer(void);
101 88
102 89
90 void StringToInt(char *pstr, uint32_t *puInt32);
91 void StringToUInt64(char *pstr, uint64_t *puint64);
103 92
104 #ifdef __cplusplus 93 #ifdef __cplusplus
105 } 94 }
106 #endif 95 #endif
107 96