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