comparison Small_CPU/Src/uartProtocol_Sentinel.c @ 842:c3dd461ca3f9 Evo_2_23

Migrated Sentinel protocol to new UART structure: The Sentinel protocol had not been migrated to the new UART structure which was introduced with the introduction of the UART MUX. The Sentinel is now supported by autodetection again (development version only)
author Ideenmodellierer
date Mon, 15 Jan 2024 21:44:18 +0100
parents
children 3e499569baf3
comparison
equal deleted inserted replaced
841:70092f552f5a 842:c3dd461ca3f9
1 /**
2 ******************************************************************************
3 * @file uartProtocol_Co2.c
4 * @author heinrichs weikamp gmbh
5 * @version V0.0.1
6 * @date 15-Jan-2024
7 * @brief Interface functionality to read data from Sentinel rebreather
8 *
9 @verbatim
10
11
12 @endverbatim
13 ******************************************************************************
14 * @attention
15 *
16 * <h2><center>&copy; COPYRIGHT(c) 2024 heinrichs weikamp</center></h2>
17 *
18 ******************************************************************************
19 */
20 /* Includes ------------------------------------------------------------------*/
21
22 #include <string.h>
23 #include <uartProtocol_Sentinel.h>
24 #include "uart.h"
25 #include "externalInterface.h"
26
27
28 #ifdef ENABLE_SENTINEL_MODE
29 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */
30 static receiveStateSentinel_t rxState = SENTRX_Ready;
31
32 void ConvertByteToHexString(uint8_t byte, char* str)
33 {
34 uint8_t worker = 0;
35 uint8_t digit = 0;
36 uint8_t digitCnt = 1;
37
38 worker = byte;
39 while((worker!=0) && (digitCnt != 255))
40 {
41 digit = worker % 16;
42 if( digit < 10)
43 {
44 digit += '0';
45 }
46 else
47 {
48 digit += 'A' - 10;
49 }
50 str[digitCnt--]= digit;
51 worker = worker / 16;
52 }
53 }
54
55 void uartSentinel_Control(void)
56 {
57 uint8_t activeSensor = externalInterface_GetActiveUartSensor();
58 uartSentinelStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET);
59
60 if(localComState == UART_SENTINEL_INIT)
61 {
62 SentinelConnected = 0;
63 UART_StartDMA_Receiption();
64 localComState = UART_SENTINEL_IDLE;
65 }
66 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState);
67 }
68
69 void uartSentinel_ProcessData(uint8_t data)
70 {
71 static uint8_t dataType = 0;
72 static uint32_t dataValue[3];
73 static uint8_t dataValueIdx = 0;
74
75 static uint8_t lastAlive = 0;
76 static uint8_t curAlive = 0;
77 static uint8_t checksum = 0;
78 static char checksum_str[]="00";
79
80 uint8_t activeSensor = externalInterface_GetActiveUartSensor();
81 uartSentinelStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET);
82
83 switch(rxState)
84 {
85 case SENTRX_Ready: if((data >= 'a') && (data <= 'z'))
86 {
87 rxState = SENTRX_DetectStart;
88 curAlive = data;
89 checksum = 0;
90 }
91 break;
92
93 case SENTRX_DetectStart: checksum += data;
94 if(data == '1')
95 {
96 rxState = SENTRX_SelectData;
97 dataType = 0xFF;
98
99 }
100 else
101 {
102 rxState = SENTRX_Ready;
103 }
104 break;
105
106 case SENTRX_SelectData: checksum += data;
107 switch(data)
108 {
109 case 'T': dataType = data;
110 break;
111 case '0': if(dataType != 0xff)
112 {
113 rxState = SENTRX_Data0;
114 dataValueIdx = 0;
115 dataValue[0] = 0;
116
117 }
118 else
119 {
120 rxState = SENTRX_Ready;
121 }
122 break;
123 default: rxState = SENTRX_Ready;
124 }
125 break;
126
127 case SENTRX_Data0:
128 case SENTRX_Data1:
129 case SENTRX_Data2:
130 case SENTRX_Data4:
131 case SENTRX_Data5:
132 case SENTRX_Data6:
133 case SENTRX_Data8:
134 case SENTRX_Data9:
135 case SENTRX_Data10: checksum += data;
136 if((data >= '0') && (data <= '9'))
137 {
138 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (data - '0');
139 rxState++;
140 }
141 else
142 {
143 rxState = SENTRX_Ready;
144 }
145 break;
146
147 case SENTRX_Data3:
148 case SENTRX_Data7: checksum += data;
149 if(data == '0')
150 {
151 rxState++;
152 dataValueIdx++;
153 dataValue[dataValueIdx] = 0;
154 }
155 else
156 {
157 rxState = SENTRX_Ready;
158 }
159 break;
160 case SENTRX_Data11: rxState = SENTRX_DataComplete;
161 ConvertByteToHexString(checksum,checksum_str);
162 if(data == checksum_str[0])
163 {
164 rxState = SENTRX_DataComplete;
165 }
166 else
167 {
168 rxState = SENTRX_Ready;
169 }
170
171 break;
172
173 case SENTRX_DataComplete: if(data == checksum_str[1])
174 {
175 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0));
176 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0));
177 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0));
178 SentinelConnected = 1;
179 lastAlive = curAlive;
180 localComState = UART_SENTINEL_OPERATING;
181 }
182 rxState = SENTRX_Ready;
183 break;
184
185
186 default: rxState = SENTRX_Ready;
187 break;
188
189 }
190 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState);
191 }
192
193 uint8_t uartSentinel_isSensorConnected()
194 {
195 return SentinelConnected;
196 }
197
198 #endif
199