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