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