554
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file externalInterface.c
|
|
4 * @author heinrichs weikamp gmbh
|
|
5 * @version V0.0.1
|
|
6 * @date 07-Nov-2020
|
|
7 * @brief Interface functionality to proceed external analog signal via i2c connection
|
|
8 *
|
|
9 @verbatim
|
|
10 ==============================================================================
|
|
11 ##### stm32f4xx_hal_i2c.c modification #####
|
|
12 ==============================================================================
|
|
13 The LTC2942 requires an repeated start condition without stop condition
|
|
14 for data reception.
|
|
15
|
|
16 @endverbatim
|
|
17 ******************************************************************************
|
|
18 * @attention
|
|
19 *
|
|
20 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
|
|
21 *
|
|
22 ******************************************************************************
|
|
23 */
|
|
24 /* Includes ------------------------------------------------------------------*/
|
|
25
|
|
26 #include <math.h>
|
714
|
27 #include <string.h>
|
794
|
28 #include "data_central.h"
|
554
|
29 #include "i2c.h"
|
|
30 #include "externalInterface.h"
|
|
31 #include "scheduler.h"
|
662
|
32 #include "uart.h"
|
|
33 #include "data_exchange.h"
|
747
|
34 #include "pressure.h"
|
794
|
35 #include "uartProtocol_O2.h"
|
798
|
36 #include "uartProtocol_Co2.h"
|
842
|
37 #include "uartProtocol_Sentinel.h"
|
916
|
38 #include "uartProtocol_GNSS.h"
|
554
|
39
|
|
40 extern SGlobal global;
|
662
|
41 extern UART_HandleTypeDef huart1;
|
932
|
42 extern sUartComCtrl Uart1Ctrl;
|
554
|
43
|
921
|
44 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */
|
|
45 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */
|
|
46 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/
|
|
47 #define ADC_CYCLE_INTERVAL_MS (1000u) /* start adc read out once per second*/
|
554
|
48
|
|
49 #define ADC_START_CONVERSION (0x80)
|
|
50 #define ADC_GAIN_4 (0x02)
|
|
51 #define ADC_GAIN_4_VALUE (4.0f)
|
|
52 #define ADC_GAIN_8 (0x03)
|
|
53 #define ADC_GAIN_8_VALUE (8.0f)
|
|
54 #define ADC_RESOLUTION_16BIT (0x08)
|
|
55 #define ADC_RESOLUTION_16BIT_VALUE (16u)
|
|
56 #define ADC_RESOLUTION_18BIT (0x0C)
|
|
57 #define ADC_RESOLUTION_18BIT_VALUE (18u)
|
|
58
|
|
59 #define ANSWER_CONFBYTE_INDEX (4u)
|
|
60
|
747
|
61 #define LOOKUP_CO2_CORR_TABLE_SCALE (1000u)
|
|
62 #define LOOKUP_CO2_CORR_TABLE_MAX (30000u)
|
|
63
|
794
|
64 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */
|
|
65 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */
|
|
66 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */
|
|
67
|
|
68 #define activeSensorId (activeUartChannel + EXT_INTERFACE_MUX_OFFSET) /* Used if UART channels are applied to Sensor map */
|
|
69
|
554
|
70 static uint8_t activeChannel = 0; /* channel which is in request */
|
|
71 static uint8_t recBuf[ADC_ANSWER_LENGTH];
|
|
72 static uint8_t timeoutCnt = 0;
|
|
73 static uint8_t externalInterfacePresent = 0;
|
861
|
74 static uint8_t delayAdcConversion = 0;
|
921
|
75 static uint32_t startTickADC = 0;
|
554
|
76
|
|
77 float externalChannel_mV[MAX_ADC_CHANNEL];
|
662
|
78 static uint8_t externalV33_On = 0;
|
691
|
79 static uint8_t externalADC_On = 0;
|
704
|
80 static uint8_t externalUART_Protocol = 0;
|
662
|
81 static uint16_t externalCO2Value;
|
|
82 static uint16_t externalCO2SignalStrength;
|
794
|
83 static uint16_t externalCO2Status = 0;
|
|
84 static float externalCO2Scale = 0.0;
|
554
|
85
|
779
|
86 static uint8_t lastSensorDataId = 0;
|
794
|
87 static SSensorDataDiveO2 sensorDataDiveO2[EXT_INTERFACE_SENSOR_CNT];
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
88 static externalInterfaceAutoDetect_t externalAutoDetect = DETECTION_OFF;
|
747
|
89 static externalInterfaceSensorType SensorMap[EXT_INTERFACE_SENSOR_CNT] ={ SENSOR_OPTIC, SENSOR_OPTIC, SENSOR_OPTIC, SENSOR_NONE, SENSOR_NONE};
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
90 static externalInterfaceSensorType tmpSensorMap[EXT_INTERFACE_SENSOR_CNT];
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
91 static externalInterfaceSensorType MasterSensorMap[EXT_INTERFACE_SENSOR_CNT];
|
794
|
92 static externalInterfaceSensorType foundSensorMap[EXT_INTERFACE_SENSOR_CNT];
|
|
93 static uint8_t Mux2ADCMap[MAX_ADC_CHANNEL];
|
|
94 static uint8_t externalInterface_SensorState[EXT_INTERFACE_SENSOR_CNT];
|
714
|
95
|
747
|
96 static float LookupCO2PressureCorrection[LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE]; /* lookup table for pressure compensation values */
|
|
97
|
804
|
98 static uint16_t externalInterfaceMuxReqIntervall = 0xffff; /* delay between switching from one MUX channel to the next */
|
916
|
99 static uint8_t activeUartChannel = 0xff;
|
804
|
100
|
|
101
|
|
102 static void externalInface_MapUartToLegacyADC(uint8_t* pMap);
|
809
|
103 static void externalInterface_CheckBaudrate(uint8_t sensorType);
|
554
|
104
|
|
105 void externalInterface_Init(void)
|
|
106 {
|
747
|
107 uint16_t index;
|
|
108 uint16_t coeff;
|
554
|
109 activeChannel = 0;
|
|
110 timeoutCnt = 0;
|
861
|
111 delayAdcConversion = 0;
|
554
|
112 if(externalInterface_StartConversion(activeChannel) == HAL_OK)
|
|
113 {
|
|
114 externalInterfacePresent = 1;
|
|
115 global.deviceDataSendToMaster.hw_Info.extADC = 1;
|
|
116 }
|
559
|
117 global.deviceDataSendToMaster.hw_Info.checkADC = 1;
|
662
|
118
|
804
|
119
|
794
|
120
|
747
|
121 /* Create a lookup table based on GSS application note AN001: PRESSURE COMPENSATION OF A CO2 SENSOR */
|
|
122 /* The main purpose of the sensor in the dive application is to be a warning indicator */
|
753
|
123 /* => no exact values necessary => a lookup table with 1000ppm scaling should be sufficient */
|
747
|
124 LookupCO2PressureCorrection [0] = -0.0014;
|
|
125 for(index = 1; index < (LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE); index++)
|
|
126 {
|
|
127 coeff = index * LOOKUP_CO2_CORR_TABLE_SCALE;
|
|
128 LookupCO2PressureCorrection[index] = 2.811*pow(10,-38)*pow(coeff,6)- 9.817*pow(10,-32)*pow(coeff,5)+1.304*pow(10,-25)*pow(coeff,4)-8.216*pow(10,-20)*pow(coeff,3)+2.311*pow(10,-14)*pow(coeff,2) - 2.195*pow(10,-9)*coeff - 1.471*pow(10,-3);
|
|
129 }
|
738
|
130 externalInterface_InitDatastruct();
|
|
131 }
|
|
132
|
|
133 void externalInterface_InitDatastruct(void)
|
|
134 {
|
|
135 uint8_t index = 0;
|
|
136 /* init data values */
|
804
|
137 externalUART_Protocol = 0;
|
662
|
138 externalCO2Value = 0;
|
|
139 externalCO2SignalStrength = 0;
|
|
140 externalCO2Status = 0;
|
804
|
141 externalCO2Scale = 0.0;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
142 externalAutoDetect = DETECTION_OFF;
|
738
|
143
|
|
144 for(index = 0; index < MAX_ADC_CHANNEL; index++)
|
|
145 {
|
|
146 externalChannel_mV[index] = 0.0;
|
|
147 }
|
798
|
148 memset(externalInterface_SensorState,UART_COMMON_INIT,sizeof(externalInterface_SensorState));
|
804
|
149 externalInface_MapUartToLegacyADC(SensorMap);
|
|
150 activeUartChannel = 0xFF;
|
554
|
151 }
|
|
152
|
|
153
|
|
154 uint8_t externalInterface_StartConversion(uint8_t channel)
|
|
155 {
|
|
156 uint8_t retval = 0;
|
|
157 uint8_t confByte = 0;
|
|
158
|
|
159 if(channel < MAX_ADC_CHANNEL)
|
|
160 {
|
|
161 confByte = ADC_START_CONVERSION | ADC_RESOLUTION_16BIT | ADC_GAIN_8;
|
|
162 confByte |= channel << 5;
|
|
163 retval = I2C_Master_Transmit(DEVICE_EXTERNAL_ADC, &confByte, 1);
|
|
164 }
|
|
165 return retval;
|
|
166 }
|
|
167
|
|
168 /* Check if conversion is done and trigger measurement of next channel */
|
|
169 uint8_t externalInterface_ReadAndSwitch()
|
|
170 {
|
|
171 uint8_t retval = EXTERNAL_ADC_NO_DATA;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
172 uint8_t nextChannel;
|
731
|
173 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0);
|
554
|
174
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
175 if(externalADC_On)
|
554
|
176 {
|
921
|
177 if(time_elapsed_ms(startTickADC, HAL_GetTick()) > ADC_CYCLE_INTERVAL_MS)
|
554
|
178 {
|
921
|
179 if(delayAdcConversion)
|
554
|
180 {
|
921
|
181 if(UART_isComActive(activeUartChannel) == 0)
|
554
|
182 {
|
921
|
183 externalInterface_StartConversion(activeChannel);
|
|
184 delayAdcConversion = 0;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
185 }
|
921
|
186 }
|
|
187 else if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK)
|
|
188 {
|
|
189 if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
190 {
|
921
|
191 retval = activeChannel; /* return channel number providing new data */
|
|
192 nextChannel = activeChannel + 1;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
193 if(nextChannel == MAX_ADC_CHANNEL)
|
704
|
194 {
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
195 nextChannel = 0;
|
704
|
196 }
|
921
|
197
|
|
198 while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel))
|
|
199 {
|
|
200 if(nextChannel == MAX_ADC_CHANNEL)
|
|
201 {
|
|
202 nextChannel = 0;
|
|
203 startTickADC = HAL_GetTick();
|
|
204 }
|
|
205 else
|
|
206 {
|
|
207 nextChannel++;
|
|
208 }
|
|
209 }
|
|
210
|
|
211 activeChannel = nextChannel;
|
|
212 if(activeChannel == 0)
|
|
213 {
|
|
214 delayAdcConversion = 1; /* wait for next cycle interval */
|
|
215 }
|
704
|
216 else
|
|
217 {
|
921
|
218 if(UART_isComActive(activeUartChannel) == 0)
|
|
219 {
|
|
220 externalInterface_StartConversion(activeChannel);
|
|
221 }
|
|
222 else
|
|
223 {
|
|
224 delayAdcConversion = 1;
|
|
225 }
|
704
|
226 }
|
921
|
227 timeoutCnt = 0;
|
554
|
228 }
|
921
|
229 }
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
230
|
861
|
231 if(timeoutCnt++ >= ADC_TIMEOUT)
|
|
232 {
|
|
233 externalInterface_StartConversion(activeChannel);
|
|
234 delayAdcConversion = 0;
|
|
235 timeoutCnt = 0;
|
581
|
236 }
|
921
|
237 }
|
554
|
238 }
|
|
239 return retval;
|
|
240 }
|
|
241 float externalInterface_CalculateADCValue(uint8_t channel)
|
|
242 {
|
|
243 int32_t rawvalue = 0;
|
|
244 float retValue = 0.0;
|
|
245 if(channel < MAX_ADC_CHANNEL)
|
|
246 {
|
|
247
|
|
248 rawvalue = ((recBuf[0] << 16) | (recBuf[1] << 8) | (recBuf[2]));
|
|
249
|
|
250 switch(recBuf[3] & 0x0C) /* confbyte => Resolution bits*/
|
|
251 {
|
|
252 case ADC_RESOLUTION_16BIT: rawvalue = rawvalue >> 8; /* only 2 databytes received shift out confbyte*/
|
|
253 if(rawvalue & (0x1 << (ADC_RESOLUTION_16BIT_VALUE-1))) /* MSB set => negative number */
|
|
254 {
|
|
255 rawvalue |= 0xFFFF0000; /* set MSB for int32 */
|
|
256 }
|
|
257 else
|
|
258 {
|
|
259 rawvalue &= 0x0000FFFF;
|
|
260 }
|
|
261 externalChannel_mV[channel] = ADC_REF_VOLTAGE_MV * 2.0 / (float) pow(2,ADC_RESOLUTION_16BIT_VALUE); /* calculate bit resolution */
|
|
262 break;
|
|
263 case ADC_RESOLUTION_18BIT: if(rawvalue & (0x1 << (ADC_RESOLUTION_18BIT_VALUE-1))) /* MSB set => negative number */
|
|
264 {
|
|
265 rawvalue |= 0xFFFE0000; /* set MSB for int32 */
|
|
266 }
|
|
267 externalChannel_mV[channel] = ADC_REF_VOLTAGE_MV * 2.0 / (float) pow(2,ADC_RESOLUTION_18BIT_VALUE); /* calculate bit resolution */
|
|
268 break;
|
|
269 default: rawvalue = 0;
|
|
270 break;
|
|
271 }
|
|
272 externalChannel_mV[channel] = externalChannel_mV[channel] * rawvalue / ADC_GAIN_8_VALUE;
|
|
273 retValue = externalChannel_mV[channel];
|
|
274 }
|
|
275 return retValue;
|
|
276 }
|
|
277 float getExternalInterfaceChannel(uint8_t channel)
|
|
278 {
|
|
279 float retval = 0;
|
|
280
|
|
281 if(channel < MAX_ADC_CHANNEL)
|
|
282 {
|
|
283 retval = externalChannel_mV[channel];
|
|
284 }
|
|
285 return retval;
|
|
286 }
|
662
|
287
|
691
|
288 uint8_t setExternalInterfaceChannel(uint8_t channel, float value)
|
|
289 {
|
|
290 uint8_t retval = 0;
|
794
|
291 uint8_t localId = channel;
|
|
292 uint8_t index = 0;
|
691
|
293
|
794
|
294 if(localId >= MAX_ADC_CHANNEL) /* at the moment sensor visualization is focused on the three ADC channels => map Mux sensors */
|
691
|
295 {
|
794
|
296 for(index = 0; index < MAX_ADC_CHANNEL; index++)
|
|
297 {
|
|
298 if(Mux2ADCMap[index] == localId)
|
|
299 {
|
|
300 localId = index;
|
|
301 break;
|
|
302 }
|
|
303 }
|
|
304 }
|
|
305
|
|
306 if(localId < MAX_ADC_CHANNEL)
|
|
307 {
|
|
308 externalChannel_mV[localId] = value;
|
691
|
309 retval = 1;
|
|
310 }
|
|
311 return retval;
|
|
312 }
|
|
313
|
662
|
314 void externalInterface_InitPower33(void)
|
|
315 {
|
|
316 GPIO_InitTypeDef GPIO_InitStructure;
|
|
317
|
|
318 GPIO_InitStructure.Pin = GPIO_PIN_7;
|
|
319 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
|
320 GPIO_InitStructure.Pull = GPIO_PULLUP;
|
|
321 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
|
322 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
323 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
|
|
324 }
|
|
325
|
|
326
|
|
327 uint8_t externalInterface_isEnabledPower33()
|
|
328 {
|
|
329 return externalV33_On;
|
|
330 }
|
691
|
331
|
|
332 uint8_t externalInterface_isEnabledADC()
|
|
333 {
|
|
334 return externalADC_On;
|
|
335 }
|
|
336
|
704
|
337 uint8_t externalInterface_GetUARTProtocol()
|
|
338 {
|
|
339 return externalUART_Protocol;
|
|
340 }
|
|
341
|
662
|
342 void externalInterface_SwitchPower33(uint8_t state)
|
|
343 {
|
|
344 if(state != externalV33_On)
|
|
345 {
|
|
346 if(state)
|
|
347 {
|
|
348 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
|
|
349 externalV33_On = 1;
|
|
350 }
|
|
351 else
|
|
352 {
|
731
|
353 if(externalAutoDetect == DETECTION_OFF)
|
|
354 {
|
|
355 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
|
|
356 externalV33_On = 0;
|
|
357 externalInterface_SetCO2Value(0);
|
|
358 externalInterface_SetCO2SignalStrength(0);
|
|
359 }
|
662
|
360 }
|
|
361 }
|
|
362 }
|
691
|
363 void externalInterface_SwitchADC(uint8_t state)
|
|
364 {
|
714
|
365 uint8_t loop = 0;
|
691
|
366 if((state) && (externalInterfacePresent))
|
|
367 {
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
368 if(externalADC_On == 0)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
369 {
|
921
|
370 startTickADC = HAL_GetTick();
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
371 activeChannel = 0;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
372 externalInterface_StartConversion(activeChannel);
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
373 externalADC_On = 1;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
374 }
|
691
|
375 }
|
|
376 else
|
|
377 {
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
378 if(externalAutoDetect == DETECTION_OFF) /* block deactivation requests if auto detection is active */
|
714
|
379 {
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
380 externalADC_On = 0;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
381 for(loop = 0; loop < MAX_ADC_CHANNEL; loop++)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
382 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
383 externalChannel_mV[loop] = 0;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
384 }
|
714
|
385 }
|
691
|
386 }
|
|
387 }
|
662
|
388
|
704
|
389 void externalInterface_SwitchUART(uint8_t protocol)
|
|
390 {
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
391 switch(protocol)
|
704
|
392 {
|
839
|
393 case EXT_INTERFACE_UART_OFF:
|
|
394 case EXT_INTERFACE_UART_CO2:
|
|
395 case EXT_INTERFACE_UART_O2:
|
|
396 case EXT_INTERFACE_UART_SENTINEL:
|
918
|
397 case EXT_INTERFACE_UART_GNSS:
|
779
|
398 if((externalAutoDetect <= DETECTION_START)
|
839
|
399 || ((protocol == EXT_INTERFACE_UART_O2) && (externalAutoDetect >= DETECTION_UARTMUX) && (externalAutoDetect <= DETECTION_DIGO2_3))
|
798
|
400
|
746
|
401 #ifdef ENABLE_CO2_SUPPORT
|
798
|
402 || ((externalAutoDetect >= DETECTION_CO2_0) && (externalAutoDetect <= DETECTION_CO2_3))
|
746
|
403 #endif
|
916
|
404 #ifdef ENABLE_GNSS_SUPPORT
|
|
405 || ((externalAutoDetect >= DETECTION_GNSS_0) && (externalAutoDetect <= DETECTION_GNSS_3))
|
|
406 #endif
|
|
407
|
746
|
408 #ifdef ENABLE_SENTINEL_MODE
|
839
|
409 || ((protocol == EXT_INTERFACE_UART_SENTINEL) && (externalAutoDetect == DETECTION_SENTINEL))
|
746
|
410 #endif
|
|
411 )
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
412 {
|
779
|
413 lastSensorDataId = 0;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
414 externalUART_Protocol = protocol;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
415 MX_USART1_UART_DeInit();
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
416 if( protocol != 0)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
417 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
418 MX_USART1_UART_Init();
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
419 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
420 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
421 break;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
422 default:
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
423 break;
|
704
|
424 }
|
|
425 }
|
|
426
|
794
|
427 uint8_t externalInterface_GetActiveUartSensor()
|
|
428 {
|
|
429 return activeUartChannel;
|
|
430 }
|
|
431
|
|
432 void externalInterface_SetSensorState(uint8_t sensorIdx, uint8_t state)
|
|
433 {
|
|
434 if(sensorIdx < EXT_INTERFACE_SENSOR_CNT)
|
|
435 {
|
|
436 externalInterface_SensorState[sensorIdx] = state;
|
|
437 }
|
|
438 }
|
|
439
|
|
440 uint8_t externalInterface_GetSensorState(uint8_t sensorIdx)
|
|
441 {
|
|
442 uint8_t ret = COMMON_SENSOR_STATE_INVALID;
|
|
443 if(sensorIdx < EXT_INTERFACE_SENSOR_CNT)
|
|
444 {
|
|
445 ret = externalInterface_SensorState[sensorIdx];
|
|
446 }
|
|
447 return ret;
|
|
448 }
|
|
449
|
|
450 /* The supported sensors from GSS have different scaling factors depending on their accuracy. The factor may be read out of the sensor */
|
|
451 void externalInterface_SetCO2Scale(float CO2Scale)
|
|
452 {
|
|
453 if((CO2Scale == 10) || (CO2Scale == 100))
|
|
454 {
|
|
455 externalCO2Scale = CO2Scale;
|
|
456 }
|
|
457 }
|
|
458 float externalInterface_GetCO2Scale()
|
|
459 {
|
|
460 return externalCO2Scale;
|
|
461 }
|
|
462
|
662
|
463 void externalInterface_SetCO2Value(uint16_t CO2_ppm)
|
|
464 {
|
794
|
465 float local_ppm = CO2_ppm * externalCO2Scale;
|
747
|
466
|
|
467 #ifndef ENABLE_EXTERNAL_PRESSURE
|
|
468 float local_corr = 0.0;
|
|
469
|
|
470 if (local_ppm >= LOOKUP_CO2_CORR_TABLE_MAX)
|
|
471 {
|
|
472 local_corr = -0.0014;
|
|
473 }
|
|
474 else
|
|
475 {
|
|
476 local_corr = LookupCO2PressureCorrection[((uint16_t) (local_ppm / LOOKUP_CO2_CORR_TABLE_SCALE))];
|
|
477 }
|
|
478 local_ppm = local_ppm / (1.0 + (local_corr * (get_surface_mbar() - get_pressure_mbar())));
|
|
479 #else
|
|
480 /* The external pressure value is passed via ADC channel2 and calibration is done at firmware => just forward sensor data */
|
|
481 /* compensation is done at firmware side. This is for testing only. Take care the the same algorithm is taken as used for the lookup table */
|
|
482 #endif
|
794
|
483 externalCO2Value = local_ppm / externalCO2Scale;
|
662
|
484 }
|
|
485
|
|
486 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa)
|
|
487 {
|
|
488 externalCO2SignalStrength = LED_qa;
|
|
489 }
|
|
490
|
|
491 uint16_t externalInterface_GetCO2Value(void)
|
|
492 {
|
|
493 return externalCO2Value;
|
|
494 }
|
|
495
|
|
496 uint16_t externalInterface_GetCO2SignalStrength(void)
|
|
497 {
|
|
498 return externalCO2SignalStrength;
|
|
499 }
|
|
500
|
|
501
|
|
502 void externalInterface_SetCO2State(uint16_t state)
|
|
503 {
|
|
504 externalCO2Status = state;
|
|
505 }
|
|
506
|
|
507 uint16_t externalInterface_GetCO2State(void)
|
|
508 {
|
|
509 return externalCO2Status;
|
|
510 }
|
|
511
|
714
|
512
|
779
|
513 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
|
714
|
514 {
|
794
|
515 uint8_t index = 0;
|
779
|
516 uint8_t localId = sensorId;
|
786
|
517 if(localId == 0xFF)
|
779
|
518 {
|
|
519 localId = lastSensorDataId;
|
|
520 }
|
714
|
521
|
794
|
522 if((pDataStruct != NULL) && (localId <= EXT_INTERFACE_SENSOR_CNT))
|
714
|
523 {
|
786
|
524 memcpy(pDataStruct, &sensorDataDiveO2[localId], sizeof(SSensorDataDiveO2));
|
|
525 }
|
|
526 else
|
|
527 {
|
|
528 localId = 0xFF;
|
714
|
529 }
|
794
|
530 if(localId > MAX_ADC_CHANNEL) /* at the moment sensor visualization is focused on the three ADC channels => map Mux sensors */
|
|
531 {
|
|
532 for(index = 0; index < MAX_ADC_CHANNEL; index++)
|
|
533 {
|
|
534 if(Mux2ADCMap[index] == localId)
|
|
535 {
|
|
536 localId = index;
|
|
537 }
|
|
538 }
|
|
539 }
|
|
540
|
779
|
541 return localId;
|
714
|
542 }
|
|
543
|
786
|
544 void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct)
|
714
|
545 {
|
794
|
546 uint8_t index = 0;
|
|
547
|
714
|
548 if(pDataStruct != NULL)
|
|
549 {
|
794
|
550 if((sensorId != 0xFF) && (sensorId < EXT_INTERFACE_SENSOR_CNT))
|
714
|
551 {
|
786
|
552 memcpy(&sensorDataDiveO2[sensorId], pDataStruct, sizeof(SSensorDataDiveO2));
|
|
553 lastSensorDataId = sensorId;
|
804
|
554 if(sensorId >= MAX_ADC_CHANNEL)
|
794
|
555 {
|
804
|
556 for(index = 0; index < MAX_ADC_CHANNEL; index++)
|
794
|
557 {
|
804
|
558 if(Mux2ADCMap[index] == sensorId)
|
|
559 {
|
|
560 memcpy(&sensorDataDiveO2[index], pDataStruct, sizeof(SSensorDataDiveO2));
|
|
561 lastSensorDataId = index;
|
|
562 break;
|
|
563 }
|
794
|
564 }
|
|
565 }
|
714
|
566 }
|
|
567 else
|
|
568 {
|
|
569 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2));
|
786
|
570 lastSensorDataId = 0xFF;
|
714
|
571 }
|
|
572 }
|
|
573 }
|
|
574
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
575 void externalInface_SetSensorMap(uint8_t* pMap)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
576 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
577 if(pMap != NULL)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
578 {
|
794
|
579 memcpy(MasterSensorMap, pMap, EXT_INTERFACE_SENSOR_CNT); /* the map is not directly copied. Copy is done via cmd request */
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
580 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
581
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
582 }
|
804
|
583
|
|
584 void externalInface_MapUartToLegacyADC(uint8_t* pMap)
|
|
585 {
|
|
586 uint8_t index, index2;
|
|
587
|
|
588 memset(Mux2ADCMap,0xFF, sizeof(Mux2ADCMap));
|
|
589
|
|
590 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) /* Unmap old mirror instances */
|
|
591 {
|
918
|
592 if((pMap[index2] == SENSOR_DIGO2M) || (pMap[index2] == SENSOR_CO2M) || (pMap[index2] == SENSOR_GNSSM))
|
804
|
593 {
|
|
594 pMap[index2] = SENSOR_NONE;
|
|
595 }
|
|
596 }
|
|
597
|
|
598 /* Map Mux O2 sensors to ADC Slot if ADC slot is not in use */
|
918
|
599 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_SENSOR_CNT-1; index++)
|
804
|
600 {
|
|
601 if(pMap[index] == SENSOR_DIGO2)
|
|
602 {
|
|
603 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++)
|
|
604 {
|
|
605 if(pMap[index2] == SENSOR_NONE)
|
|
606 {
|
|
607 pMap[index2] = SENSOR_DIGO2M; /* store a mirror instance needed for visualization */
|
|
608 Mux2ADCMap[index2] = index;
|
|
609 break;
|
|
610 }
|
|
611 }
|
|
612 }
|
|
613 }
|
918
|
614 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_SENSOR_CNT-1; index++)
|
804
|
615 {
|
|
616 if(pMap[index] == SENSOR_CO2)
|
|
617 {
|
|
618 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++)
|
|
619 {
|
|
620 if(pMap[index2] == SENSOR_NONE)
|
|
621 {
|
|
622 pMap[index2] = SENSOR_CO2M; /* store a mirror instance needed for visualization */
|
|
623 Mux2ADCMap[index2] = index;
|
|
624 break;
|
|
625 }
|
|
626 }
|
|
627 }
|
|
628 }
|
918
|
629 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_SENSOR_CNT-1; index++)
|
916
|
630 {
|
|
631 if(pMap[index] == SENSOR_GNSS)
|
|
632 {
|
|
633 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++)
|
|
634 {
|
|
635 if(pMap[index2] == SENSOR_NONE)
|
|
636 {
|
|
637 pMap[index2] = SENSOR_GNSSM; /* store a mirror instance needed for visualization */
|
|
638 Mux2ADCMap[index2] = index;
|
|
639 break;
|
|
640 }
|
|
641 }
|
|
642 }
|
|
643 }
|
842
|
644 #ifdef ENABLE_SENTINEL_MODE
|
|
645 if(pMap[EXT_INTERFACE_MUX_OFFSET] == SENSOR_SENTINEL)
|
|
646 {
|
|
647 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++)
|
|
648 {
|
|
649 pMap[index2] = SENSOR_SENTINELM; /* store a mirror instance needed for visualization */
|
|
650 Mux2ADCMap[index2] = index2 + EXT_INTERFACE_MUX_OFFSET;
|
|
651 }
|
|
652 }
|
|
653 #endif
|
804
|
654 }
|
|
655
|
731
|
656 uint8_t* externalInterface_GetSensorMapPointer(uint8_t finalMap)
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
657 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
658 uint8_t* pret;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
659
|
731
|
660 if((externalAutoDetect != DETECTION_OFF) && (!finalMap))
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
661 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
662 pret = tmpSensorMap;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
663 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
664 else
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
665 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
666 pret = SensorMap;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
667 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
668 return pret;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
669 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
670
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
671 void externalInterface_AutodetectSensor()
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
672 {
|
779
|
673 static uint8_t sensorIndex = 0;
|
|
674 static uint8_t uartMuxChannel = 0;
|
918
|
675 #ifdef ENABLE_GNSS_SUPPORT
|
|
676 static uint8_t detectionDelayCnt = 0;
|
|
677 #endif
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
678 uint8_t index = 0;
|
918
|
679
|
794
|
680 uint8_t cntSensor = 0;
|
|
681 uint8_t cntUARTSensor = 0;
|
798
|
682 #ifdef ENABLE_CO2_SUPPORT
|
794
|
683 uint8_t cmdString[10];
|
|
684 uint8_t cmdLength = 0;
|
798
|
685 #endif
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
686
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
687 if(externalAutoDetect != DETECTION_OFF)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
688 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
689 switch(externalAutoDetect)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
690 {
|
804
|
691 case DETECTION_INIT: externalInterfaceMuxReqIntervall = 0;
|
794
|
692 sensorIndex = 0;
|
779
|
693 uartMuxChannel = 0;
|
731
|
694 tmpSensorMap[0] = SENSOR_OPTIC;
|
|
695 tmpSensorMap[1] = SENSOR_OPTIC;
|
|
696 tmpSensorMap[2] = SENSOR_OPTIC;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
697 tmpSensorMap[3] = SENSOR_NONE;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
698 tmpSensorMap[4] = SENSOR_NONE;
|
804
|
699 tmpSensorMap[5] = SENSOR_NONE;
|
|
700 tmpSensorMap[6] = SENSOR_NONE;
|
|
701 tmpSensorMap[7] = SENSOR_NONE;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
702
|
794
|
703 memset(foundSensorMap, SENSOR_NONE, sizeof(foundSensorMap));
|
798
|
704 memset(externalInterface_SensorState,UART_COMMON_INIT,sizeof(externalInterface_SensorState));
|
794
|
705 memset(Mux2ADCMap,0, sizeof(Mux2ADCMap));
|
781
|
706
|
731
|
707 if(externalInterfacePresent)
|
|
708 {
|
|
709 externalInterface_SwitchPower33(0);
|
839
|
710 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF);
|
731
|
711 for(index = 0; index < MAX_ADC_CHANNEL; index++)
|
|
712 {
|
|
713 externalChannel_mV[index] = 0;
|
|
714 }
|
|
715 externalAutoDetect = DETECTION_START;
|
|
716 }
|
|
717 else
|
|
718 {
|
|
719 externalAutoDetect = DETECTION_DONE; /* without external interface O2 values may only be received via optical port => return default sensor map */
|
|
720 }
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
721 break;
|
731
|
722 case DETECTION_START: tmpSensorMap[0] = SENSOR_ANALOG;
|
|
723 tmpSensorMap[1] = SENSOR_ANALOG;
|
|
724 tmpSensorMap[2] = SENSOR_ANALOG;
|
|
725 externalInterface_SwitchPower33(1);
|
|
726 externalInterface_SwitchADC(1);
|
|
727 externalAutoDetect = DETECTION_ANALOG1;
|
|
728 break;
|
|
729 case DETECTION_ANALOG1: externalAutoDetect = DETECTION_ANALOG2; /* do a second loop to make sure all adc channels could be processed */
|
|
730 break;
|
|
731 case DETECTION_ANALOG2: for(index = 0; index < MAX_ADC_CHANNEL; index++)
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
732 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
733 if(externalChannel_mV[index] > MIN_ADC_VOLTAGE_MV)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
734 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
735 tmpSensorMap[sensorIndex++] = SENSOR_ANALOG;
|
794
|
736 foundSensorMap[index] = SENSOR_ANALOG;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
737 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
738 else
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
739 {
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
740 tmpSensorMap[sensorIndex++] = SENSOR_NONE;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
741 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
742 }
|
804
|
743 externalInterfaceMuxReqIntervall = 1100;
|
779
|
744 externalAutoDetect = DETECTION_UARTMUX;
|
839
|
745 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2);
|
916
|
746 externalInterface_CheckBaudrate(SENSOR_DIGO2);
|
794
|
747 UART_MUX_SelectAddress(MAX_MUX_CHANNEL);
|
|
748 uartO2_SetChannel(MAX_MUX_CHANNEL);
|
|
749 activeUartChannel = MAX_MUX_CHANNEL;
|
|
750 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
751 break;
|
916
|
752 case DETECTION_UARTMUX: if(uartO2_isSensorConnected())
|
|
753 {
|
|
754 uartMuxChannel = 1;
|
|
755 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX;
|
|
756 foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX;
|
|
757 }
|
|
758 else
|
|
759 {
|
|
760 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_NONE;
|
|
761 }
|
|
762 externalAutoDetect = DETECTION_DIGO2_0;
|
|
763 uartO2_SetChannel(0);
|
|
764 activeUartChannel = 0;
|
|
765 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2;
|
|
766 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT;
|
|
767 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2);
|
|
768 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)
|
|
769 {
|
|
770 UART_MUX_SelectAddress(0);
|
|
771 }
|
779
|
772 break;
|
|
773 case DETECTION_DIGO2_0:
|
|
774 case DETECTION_DIGO2_1:
|
781
|
775 case DETECTION_DIGO2_2:
|
|
776 case DETECTION_DIGO2_3:
|
794
|
777 if(uartO2_isSensorConnected())
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
778 {
|
794
|
779 foundSensorMap[externalAutoDetect - DETECTION_DIGO2_0 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2;
|
781
|
780 }
|
804
|
781 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
779
|
782 if(uartMuxChannel)
|
|
783 {
|
839
|
784 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2);
|
794
|
785 UART_MUX_SelectAddress(uartMuxChannel);
|
798
|
786 externalInterface_SensorState[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT;
|
794
|
787 uartO2_SetChannel(uartMuxChannel);
|
|
788 activeUartChannel = uartMuxChannel;
|
|
789 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
790 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2;
|
|
791
|
|
792 if(uartMuxChannel < MAX_MUX_CHANNEL - 1)
|
784
|
793 {
|
|
794 uartMuxChannel++;
|
|
795 }
|
779
|
796 }
|
|
797 else
|
|
798 {
|
781
|
799 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */
|
779
|
800 }
|
742
|
801 externalAutoDetect++;
|
|
802 #ifdef ENABLE_CO2_SUPPORT
|
798
|
803 if(externalAutoDetect == DETECTION_CO2_0)
|
779
|
804 {
|
809
|
805 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
806 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)
|
|
807 {
|
|
808 UART_MUX_SelectAddress(0);
|
|
809 }
|
798
|
810 activeUartChannel = 0;
|
|
811 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
812 uartMuxChannel = 1;
|
|
813 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_CO2;
|
|
814 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT;
|
809
|
815 externalInterface_CheckBaudrate(SENSOR_CO2);
|
|
816 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* switch sensor operation mode depending on HW config */
|
794
|
817 {
|
798
|
818 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength);
|
794
|
819 }
|
|
820 else
|
|
821 {
|
798
|
822 uartCo2_SendCmd(CO2CMD_MODE_STREAM, cmdString, &cmdLength);
|
794
|
823 }
|
779
|
824 }
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
825 break;
|
798
|
826 case DETECTION_CO2_0:
|
|
827 case DETECTION_CO2_1:
|
|
828 case DETECTION_CO2_2:
|
|
829 case DETECTION_CO2_3: if(uartCo2_isSensorConnected())
|
|
830 {
|
|
831 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_CO2;
|
916
|
832 #ifdef ENABLE_GNSS_SUPPORT
|
|
833 externalAutoDetect = DETECTION_GNSS_0; /* only one CO2 sensor supported */
|
|
834 #else
|
798
|
835 externalAutoDetect = DETECTION_DONE; /* only one CO2 sensor supported */
|
916
|
836 #endif
|
798
|
837 }
|
|
838 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
839 {
|
809
|
840 externalInterface_CheckBaudrate(SENSOR_DIGO2);
|
798
|
841 UART_MUX_SelectAddress(uartMuxChannel);
|
|
842 activeUartChannel = uartMuxChannel;
|
|
843 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
844 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2;
|
|
845 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT;
|
809
|
846 externalInterface_CheckBaudrate(SENSOR_CO2);
|
798
|
847 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength);
|
|
848 externalAutoDetect++;
|
|
849 uartMuxChannel++;
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
850 }
|
798
|
851 else
|
|
852 {
|
916
|
853
|
|
854
|
|
855 #if defined ENABLE_SENTINEL_MODE || defined ENABLE_GNSS_SUPPORT
|
|
856 #ifdef ENABLE_GNSS_SUPPORT
|
|
857 externalAutoDetect = DETECTION_GNSS_0;
|
918
|
858 externalInterface_SwitchUART(EXT_INTERFACE_UART_GNSS);
|
916
|
859 #else
|
842
|
860 #ifdef ENABLE_SENTINEL_MODE
|
|
861 externalAutoDetect = DETECTION_SENTINEL;
|
916
|
862 #endif
|
|
863 #endif
|
842
|
864 #else
|
798
|
865 externalAutoDetect = DETECTION_DONE;
|
842
|
866 #endif
|
798
|
867 }
|
742
|
868 #endif
|
916
|
869
|
|
870 #ifdef ENABLE_GNSS_SUPPORT
|
|
871 if(externalAutoDetect == DETECTION_GNSS_0)
|
|
872 {
|
|
873 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
874 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)
|
|
875 {
|
|
876 externalInterface_CheckBaudrate(SENSOR_DIGO2);
|
|
877 UART_MUX_SelectAddress(0);
|
|
878 }
|
|
879 activeUartChannel = 0;
|
|
880 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
881 uartMuxChannel = 1;
|
|
882 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_GNSS;
|
|
883 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT;
|
|
884 externalInterface_CheckBaudrate(SENSOR_GNSS);
|
918
|
885 externalInterfaceMuxReqIntervall = 500; /* iterations needed for module config */
|
|
886 detectionDelayCnt = 6;
|
916
|
887 }
|
|
888 break;
|
|
889 case DETECTION_GNSS_0:
|
|
890 case DETECTION_GNSS_1:
|
|
891 case DETECTION_GNSS_2:
|
|
892 case DETECTION_GNSS_3: if(detectionDelayCnt == 0)
|
|
893 {
|
|
894 if(uartGnss_isSensorConnected())
|
|
895 {
|
|
896 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_GNSS;
|
|
897 #ifdef ENABLE_SENTINEL_MODE
|
|
898 externalAutoDetect = DETECTION_SENTINEL; /* only one GNSS sensor supported */
|
|
899 #else
|
|
900 externalAutoDetect = DETECTION_DONE; /* only one GNSS sensor supported */
|
|
901 #endif
|
|
902 }
|
|
903 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)
|
|
904 {
|
|
905 externalInterface_CheckBaudrate(SENSOR_DIGO2);
|
|
906 UART_MUX_SelectAddress(uartMuxChannel);
|
|
907 activeUartChannel = uartMuxChannel;
|
|
908 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE;
|
|
909 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2;
|
|
910 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT;
|
|
911 externalInterface_CheckBaudrate(SENSOR_CO2);
|
|
912 // uartGnss_SendCmd(GNSSCMD_MODE_POLL, cmdString, &cmdLength);
|
|
913 externalAutoDetect++;
|
|
914 detectionDelayCnt = 3;
|
|
915 uartMuxChannel++;
|
|
916 }
|
|
917 else
|
|
918 {
|
|
919 #ifdef ENABLE_SENTINEL_MODE
|
|
920 externalAutoDetect = DETECTION_SENTINEL;
|
|
921 #else
|
|
922 externalAutoDetect = DETECTION_DONE;
|
|
923 #endif
|
|
924 }
|
|
925 }
|
|
926 else
|
|
927 {
|
|
928 detectionDelayCnt--;
|
|
929 }
|
|
930 #endif
|
742
|
931 #ifdef ENABLE_SENTINEL_MODE
|
779
|
932 if(externalAutoDetect == DETECTION_SENTINEL)
|
|
933 {
|
842
|
934 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT;
|
|
935 uartO2_SetChannel(0);
|
|
936 activeUartChannel = 0;
|
|
937 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_SENTINEL;
|
839
|
938 externalInterface_SwitchUART(EXT_INTERFACE_UART_SENTINEL);
|
842
|
939 externalInterface_CheckBaudrate(SENSOR_SENTINEL);
|
932
|
940 UART_StartDMA_Receiption(&Uart1Ctrl);
|
779
|
941 }
|
742
|
942 break;
|
|
943
|
|
944 case DETECTION_SENTINEL:
|
|
945 case DETECTION_SENTINEL2:
|
842
|
946 if(uartSentinel_isSensorConnected())
|
742
|
947 {
|
842
|
948 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_MUX_OFFSET+3; index++)
|
742
|
949 {
|
842
|
950 foundSensorMap[index] = SENSOR_SENTINEL;
|
742
|
951 }
|
|
952 }
|
|
953 externalAutoDetect++;
|
|
954 #endif
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
955 break;
|
794
|
956 case DETECTION_DONE: externalAutoDetect = DETECTION_OFF;
|
839
|
957 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF);
|
794
|
958 activeUartChannel = 0xFF;
|
|
959 cntSensor = 0;
|
|
960 cntUARTSensor = 0;
|
|
961 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT-1; index++)
|
731
|
962 {
|
798
|
963 if((foundSensorMap[index] >= SENSOR_ANALOG) && (foundSensorMap[index] < SENSOR_MUX))
|
794
|
964 {
|
|
965 cntSensor++;
|
|
966 }
|
784
|
967
|
916
|
968 if((foundSensorMap[index] == SENSOR_DIGO2) || (foundSensorMap[index] == SENSOR_CO2) || (foundSensorMap[index] == SENSOR_GNSS))
|
794
|
969 {
|
|
970 cntUARTSensor++;
|
|
971 }
|
842
|
972 #ifdef ENABLE_SENTINEL_MODE
|
|
973 if(foundSensorMap[index] == SENSOR_SENTINEL) /* The Sentinel has a fixed setup */
|
|
974 {
|
|
975 cntSensor = 3;
|
|
976 cntUARTSensor = 1;
|
|
977 break;
|
|
978 }
|
|
979 #endif
|
786
|
980 }
|
804
|
981 externalInface_MapUartToLegacyADC(foundSensorMap);
|
794
|
982 externalInterfaceMuxReqIntervall = 0xFFFF;
|
|
983 if(cntSensor == 0) /* return default sensor map if no sensor at all has been detected */
|
784
|
984 {
|
794
|
985 foundSensorMap[0] = SENSOR_OPTIC;
|
|
986 foundSensorMap[1] = SENSOR_OPTIC;
|
|
987 foundSensorMap[2] = SENSOR_OPTIC;
|
|
988 }
|
|
989 else
|
|
990 {
|
|
991 if(cntUARTSensor != 0)
|
784
|
992 {
|
794
|
993 externalInterfaceMuxReqIntervall = REQUEST_INT_SENSOR_MS / cntUARTSensor;
|
784
|
994 }
|
|
995 }
|
794
|
996 memcpy(SensorMap, foundSensorMap, sizeof(foundSensorMap));
|
798
|
997 memset(externalInterface_SensorState, UART_COMMON_INIT, sizeof(externalInterface_SensorState));
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
998 break;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
999 default:
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1000 break;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1001 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1002 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1003 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1004
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1005
|
662
|
1006 void externalInterface_ExecuteCmd(uint16_t Cmd)
|
|
1007 {
|
|
1008 char cmdString[10];
|
|
1009 uint8_t cmdLength = 0;
|
804
|
1010 uint8_t index;
|
794
|
1011 uint8_t cntUARTSensor = 0;
|
662
|
1012
|
|
1013 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */
|
|
1014 {
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1015 case EXT_INTERFACE_AUTODETECT: externalAutoDetect = DETECTION_INIT;
|
742
|
1016 for(index = 0; index < 3; index++)
|
|
1017 {
|
|
1018 SensorMap[index] = SENSOR_SEARCH;
|
|
1019 }
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1020 break;
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1021 case EXT_INTERFACE_COPY_SENSORMAP: if(externalAutoDetect == DETECTION_OFF)
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1022 {
|
794
|
1023 memcpy(SensorMap, MasterSensorMap, sizeof(MasterSensorMap));
|
|
1024 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++)
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1025 {
|
916
|
1026 if((SensorMap[index] == SENSOR_DIGO2) || (SensorMap[index] == SENSOR_CO2) || (SensorMap[index] == SENSOR_GNSS))
|
794
|
1027 {
|
|
1028 cntUARTSensor++;
|
|
1029 }
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1030 }
|
804
|
1031 externalInface_MapUartToLegacyADC(SensorMap);
|
794
|
1032 if(cntUARTSensor > 0)
|
|
1033 {
|
|
1034 externalInterfaceMuxReqIntervall = REQUEST_INT_SENSOR_MS / cntUARTSensor;
|
|
1035 activeUartChannel = 0xFF;
|
|
1036 }
|
|
1037 else
|
|
1038 {
|
|
1039 externalInterfaceMuxReqIntervall = 0xFFFF;
|
|
1040 }
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1041 }
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
diff
changeset
|
1042 break;
|
957
|
1043 case EXT_INTERFACE_CO2_CALIB: index = (Cmd >> 8) & 0x000F;
|
|
1044 if(SensorMap[index] == SENSOR_CO2M)
|
|
1045 {
|
|
1046 index = Mux2ADCMap[index];
|
|
1047 }
|
|
1048 if(SensorMap[index] == SENSOR_CO2)
|
|
1049 {
|
|
1050 externalInterface_SensorState[index] = UART_CO2_CALIBRATE;
|
|
1051 }
|
|
1052 break;
|
|
1053 case EXT_INTERFACE_O2_INDICATE: index = (Cmd >> 8) & 0x000F;
|
|
1054 if(SensorMap[index] == SENSOR_DIGO2M)
|
|
1055 {
|
|
1056 index = Mux2ADCMap[index];
|
|
1057 }
|
|
1058 if(SensorMap[index] == SENSOR_DIGO2)
|
|
1059 {
|
|
1060 externalInterface_SensorState[index] = UART_O2_CHECK;
|
|
1061 }
|
|
1062 break;
|
|
1063
|
662
|
1064 default:
|
|
1065 break;
|
|
1066 }
|
|
1067 if(cmdLength != 0)
|
|
1068 {
|
|
1069 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10);
|
|
1070 }
|
|
1071 return;
|
|
1072 }
|
|
1073
|
794
|
1074 uint8_t ExternalInterface_SelectUsedMuxChannel(uint8_t currentChannel)
|
|
1075 {
|
|
1076 uint8_t index = currentChannel;
|
|
1077 uint8_t newChannel = index;
|
|
1078 uint8_t *pmap = externalInterface_GetSensorMapPointer(0);
|
|
1079
|
|
1080 do
|
|
1081 {
|
|
1082 index++;
|
|
1083 if(index == MAX_MUX_CHANNEL)
|
|
1084 {
|
|
1085 index = 0;
|
|
1086 }
|
918
|
1087 if(((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2)
|
|
1088 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2)
|
|
1089 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_GNSS))
|
794
|
1090 && (index != activeUartChannel))
|
|
1091 {
|
|
1092 newChannel = index;
|
|
1093 break;
|
|
1094 }
|
|
1095 } while(index != currentChannel);
|
|
1096
|
|
1097 return newChannel;
|
|
1098 }
|
|
1099
|
798
|
1100 void externalInterface_CheckBaudrate(uint8_t sensorType)
|
|
1101 {
|
|
1102 uint32_t newBaudrate = 0;
|
|
1103
|
|
1104 switch(sensorType)
|
|
1105 {
|
916
|
1106 case SENSOR_GNSS:
|
842
|
1107 case SENSOR_SENTINEL:
|
798
|
1108 case SENSOR_CO2: newBaudrate = 9600;
|
|
1109 break;
|
|
1110 case SENSOR_DIGO2:
|
|
1111 default: newBaudrate = 19200;
|
|
1112 break;
|
|
1113 }
|
809
|
1114 if(huart1.Init.BaudRate != newBaudrate)
|
798
|
1115 {
|
|
1116 UART_ChangeBaudrate(newBaudrate);
|
|
1117 }
|
|
1118 }
|
|
1119
|
794
|
1120 void externalInterface_HandleUART()
|
|
1121 {
|
|
1122 static uint8_t retryRequest = 0;
|
|
1123 static uint32_t lastRequestTick = 0;
|
|
1124 static uint32_t TriggerTick = 0;
|
|
1125 uint8_t index = 0;
|
|
1126 static uint8_t timeToTrigger = 0;
|
|
1127 uint32_t tick = HAL_GetTick();
|
|
1128 uint8_t *pmap = externalInterface_GetSensorMapPointer(0);
|
916
|
1129 uint8_t forceMuxChannel = 0;
|
794
|
1130
|
|
1131
|
|
1132 if(externalInterfaceMuxReqIntervall != 0xFFFF)
|
|
1133 {
|
804
|
1134 if(activeUartChannel == 0xFF)
|
|
1135 {
|
809
|
1136 MX_USART1_UART_Init();
|
804
|
1137 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0);
|
|
1138 uartO2_SetChannel(activeUartChannel);
|
|
1139
|
|
1140 switch(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET])
|
|
1141 {
|
916
|
1142 case SENSOR_DIGO2:
|
|
1143 case SENSOR_GNSS:
|
|
1144 case SENSOR_CO2:
|
|
1145 case SENSOR_SENTINEL: externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]);
|
842
|
1146 break;
|
916
|
1147 default: externalInterface_CheckBaudrate(SENSOR_DIGO2);
|
804
|
1148 break;
|
|
1149 }
|
|
1150 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)
|
|
1151 {
|
916
|
1152 HAL_Delay(10); /* make sure MUX is available for reception after wakeup */
|
804
|
1153 UART_MUX_SelectAddress(activeUartChannel);
|
|
1154 }
|
|
1155 }
|
|
1156
|
916
|
1157 if(externalInterface_SensorState[activeSensorId] != UART_COMMON_INIT)
|
|
1158 {
|
|
1159 UART_ReadData(pmap[activeSensorId]);
|
932
|
1160 UART_WriteData(&Uart1Ctrl);
|
916
|
1161 }
|
798
|
1162 if(externalInterface_SensorState[activeSensorId] == UART_COMMON_INIT)
|
794
|
1163 {
|
|
1164 lastRequestTick = tick;
|
|
1165 TriggerTick = tick - 10; /* just to make sure control is triggered */
|
|
1166 timeToTrigger = 1;
|
|
1167 retryRequest = 0;
|
|
1168 }
|
|
1169 else if(((retryRequest == 0) /* timeout or error */
|
|
1170 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (externalInterface_SensorState[activeSensorId] != UART_O2_IDLE)) /* retry if no answer after half request interval */
|
|
1171 || (externalInterface_SensorState[activeSensorId] == UART_O2_ERROR))))
|
|
1172 {
|
|
1173 /* The channel switch will cause the sensor to respond with an error message. */
|
|
1174 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */
|
|
1175
|
|
1176 TriggerTick = tick;
|
|
1177 timeToTrigger = COMMAND_TX_DELAY;
|
|
1178 retryRequest = 1;
|
|
1179 }
|
|
1180
|
|
1181 else if(time_elapsed_ms(lastRequestTick,tick) > externalInterfaceMuxReqIntervall) /* switch sensor and / or trigger next request */
|
|
1182 {
|
|
1183 lastRequestTick = tick;
|
|
1184 TriggerTick = tick;
|
|
1185 retryRequest = 0;
|
|
1186 timeToTrigger = 1;
|
|
1187
|
|
1188 if((externalInterface_SensorState[activeSensorId] == UART_O2_REQ_O2) /* timeout */
|
798
|
1189 || (externalInterface_SensorState[activeSensorId] == UART_O2_REQ_RAW)
|
918
|
1190 || (externalInterface_SensorState[activeSensorId] == UART_CO2_OPERATING)
|
932
|
1191 || (externalInterface_SensorState[activeSensorId] == UART_GNSS_GET_PVT)
|
|
1192 || (externalInterface_SensorState[activeSensorId] == UART_GNSS_GET_SAT))
|
794
|
1193 {
|
916
|
1194 forceMuxChannel = 1;
|
918
|
1195 externalInterface_SensorState[activeSensorId] = UART_O2_IDLE;
|
798
|
1196 switch(pmap[activeSensorId])
|
|
1197 {
|
|
1198 case SENSOR_DIGO2: setExternalInterfaceChannel(activeSensorId,0.0);
|
|
1199 break;
|
|
1200 case SENSOR_CO2: externalInterface_SetCO2Value(0.0);
|
|
1201 externalInterface_SetCO2State(0);
|
|
1202 break;
|
|
1203 default:
|
|
1204 break;
|
|
1205 }
|
794
|
1206 }
|
956
|
1207 if((externalInterface_SensorState[activeSensorId] == UART_CO2_SETUP) /* timeout while setting up sensors */
|
|
1208 || (externalInterface_SensorState[activeSensorId] == UART_O2_CHECK))
|
|
1209 {
|
|
1210 forceMuxChannel = 1;
|
|
1211 }
|
|
1212
|
794
|
1213
|
|
1214 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */
|
|
1215 {
|
|
1216 if(activeUartChannel < MAX_MUX_CHANNEL)
|
|
1217 {
|
|
1218 index = ExternalInterface_SelectUsedMuxChannel(activeUartChannel);
|
916
|
1219 if((index != activeUartChannel) || (forceMuxChannel))
|
794
|
1220 {
|
916
|
1221 forceMuxChannel = 0;
|
794
|
1222 timeToTrigger = 100;
|
|
1223 activeUartChannel = index;
|
957
|
1224 switch(pmap[index + EXT_INTERFACE_MUX_OFFSET])
|
794
|
1225 {
|
957
|
1226 case SENSOR_DIGO2: uartO2_SetChannel(activeUartChannel);
|
|
1227 /* no break */
|
|
1228 case SENSOR_CO2:
|
|
1229 case SENSOR_GNSS: externalInterface_CheckBaudrate(SENSOR_MUX);
|
|
1230 UART_MUX_SelectAddress(activeUartChannel);
|
|
1231 externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]);
|
|
1232 break;
|
|
1233 default:
|
|
1234 break;
|
794
|
1235 }
|
|
1236 }
|
|
1237 }
|
|
1238 }
|
|
1239 else
|
|
1240 {
|
|
1241 timeToTrigger = 1;
|
|
1242 }
|
|
1243 }
|
|
1244 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger))
|
|
1245 {
|
|
1246 timeToTrigger = 0;
|
|
1247 switch (pmap[activeSensorId])
|
|
1248 {
|
|
1249 case SENSOR_MUX:
|
|
1250 case SENSOR_DIGO2: uartO2_Control();
|
|
1251 break;
|
798
|
1252 #ifdef ENABLE_CO2_SUPPORT
|
|
1253 case SENSOR_CO2: uartCo2_Control();
|
794
|
1254 break;
|
798
|
1255 #endif
|
916
|
1256 #ifdef ENABLE_GNSS_SUPPORT
|
|
1257 case SENSOR_GNSS: uartGnss_Control();
|
|
1258 break;
|
|
1259 #endif
|
842
|
1260 #ifdef ENABLE_SENTINEL_MODE
|
|
1261 case SENSOR_SENTINEL: uartSentinel_Control();
|
|
1262 break;
|
|
1263 #endif
|
794
|
1264 default:
|
|
1265 break;
|
|
1266 }
|
|
1267 }
|
921
|
1268 #if 0
|
|
1269 else
|
|
1270 {
|
|
1271 if(((time_elapsed_ms(lastRequestTick,tick) > (externalInterfaceMuxReqIntervall - 100))
|
|
1272 && externalInterface_SensorState[activeSensorId] = UART_COMMON_IDLE))
|
|
1273 {
|
|
1274 externalInterface_ReadAndSwitch();
|
|
1275 }
|
|
1276 }
|
|
1277 #endif
|
794
|
1278 }
|
|
1279
|
|
1280 #if 0
|
|
1281 #ifdef ENABLE_SENTINEL_MODE
|
839
|
1282 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_SENTINEL))
|
794
|
1283 {
|
|
1284 UART_HandleSentinelData();
|
|
1285 }
|
|
1286 #endif
|
|
1287 #endif
|
|
1288 }
|