annotate Small_CPU/Src/externalInterface.c @ 847:61f14abce25d

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