Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 790:3b5f9557c053
Fix bug introduced in 04b98a2, causing the deco planner to not show deco stops.
author | heinrichsweikamp |
---|---|
date | Tue, 25 Jul 2023 14:48:58 +0200 |
parents | aeb72882f30a |
children | bb37d4f3e50e |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file uart.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @version V0.0.1 | |
6 * @date 27-March-2014 | |
7 * @brief button control | |
8 * | |
9 @verbatim | |
10 ============================================================================== | |
11 ##### How to use ##### | |
12 ============================================================================== | |
13 @endverbatim | |
14 ****************************************************************************** | |
15 * @attention | |
16 * | |
17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
18 * | |
19 ****************************************************************************** | |
20 */ | |
21 /* Includes ------------------------------------------------------------------*/ | |
22 #include "uart.h" | |
662 | 23 #include "externalInterface.h" |
24 #include "data_exchange.h" | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
25 #include <string.h> /* memset */ |
38 | 26 |
27 /* Private variables ---------------------------------------------------------*/ | |
28 | |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
29 #define BUFFER_NODATA (7u) /* The read function needs a byte which indecated that no data for processing is available.*/ |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
30 /* This byte shall never appear in a normal data steam */ |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
31 |
781 | 32 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */ |
33 #define CHUNKS_PER_BUFFER (5u) | |
34 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */ | |
35 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor */ | |
662 | 36 UART_HandleTypeDef huart1; |
37 | |
38 DMA_HandleTypeDef hdma_usart1_rx; | |
38 | 39 |
662 | 40 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
41 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
42 static uint8_t rxReadIndex; /* Index at which new data is stared */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
43 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
44 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
45 static uint8_t digO2Connected = 0; /* Binary indicator if a sensor is connected or not */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
46 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */ |
742 | 47 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */ |
38 | 48 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
49 static SSensorDataDiveO2 tmpSensorDataDiveO2; /* intermediate storage for additional sensor data */ |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
50 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
51 char tmpRxBuf[30]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
52 uint8_t tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
53 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
54 static uartO2Status_t Comstatus_O2 = UART_O2_INIT; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
55 static uint8_t activeSensor = 0; |
781 | 56 static uint8_t sensorMapping[MAX_MUX_CHANNEL]; /* The mapping is used to assign the visible sensor channel to the mux address (DiveO2) */ |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
57 |
662 | 58 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */ |
59 float LED_ZeroOffset = 0.0; | |
60 float pCO2 = 0.0; | |
38 | 61 /* Exported functions --------------------------------------------------------*/ |
62 | |
662 | 63 void MX_USART1_UART_Init(void) |
38 | 64 { |
662 | 65 /* regular init */ |
66 | |
67 huart1.Instance = USART1; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
68 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
69 if(externalInterface_GetUARTProtocol() == 0x04) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
70 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
71 huart1.Init.BaudRate = 19200; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
72 Comstatus_O2 = UART_O2_INIT; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
73 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
74 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
75 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
76 huart1.Init.BaudRate = 9600; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
77 } |
662 | 78 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
79 huart1.Init.StopBits = UART_STOPBITS_1; | |
80 huart1.Init.Parity = UART_PARITY_NONE; | |
81 huart1.Init.Mode = UART_MODE_TX_RX; | |
82 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
83 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
84 | |
85 HAL_UART_Init(&huart1); | |
86 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
87 MX_USART1_DMA_Init(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
88 |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
89 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer)); |
662 | 90 rxReadIndex = 0; |
91 lastCmdIndex = 0; | |
92 rxWriteIndex = 0; | |
93 dmaActive = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
94 digO2Connected = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
95 CO2Connected = 0; |
742 | 96 SentinelConnected = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
97 Comstatus_O2 = UART_O2_INIT; |
662 | 98 } |
38 | 99 |
662 | 100 void MX_USART1_UART_DeInit(void) |
101 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
102 HAL_DMA_Abort(&hdma_usart1_rx); |
662 | 103 HAL_DMA_DeInit(&hdma_usart1_rx); |
104 HAL_UART_DeInit(&huart1); | |
105 } | |
106 | |
107 void MX_USART1_DMA_Init() | |
108 { | |
109 /* DMA controller clock enable */ | |
110 __DMA2_CLK_ENABLE(); | |
111 | |
112 /* Peripheral DMA init*/ | |
113 hdma_usart1_rx.Instance = DMA2_Stream5; | |
114 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
115 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
116 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
117 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
118 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
119 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
120 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
121 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
122 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
123 HAL_DMA_Init(&hdma_usart1_rx); | |
124 | |
125 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
126 | |
127 /* DMA interrupt init */ | |
128 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0); | |
129 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); | |
38 | 130 } |
131 | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
132 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
133 void DigitalO2_SelectSensor(uint8_t channel) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
134 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
135 uint8_t indexstr[4]; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
136 uint8_t muxAddress = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
137 indexstr[0] = '~'; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
138 indexstr[1] = '1'; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
139 indexstr[2] = 0x0D; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
140 indexstr[3] = 0x0A; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
141 |
781 | 142 /* Lookup mux address mapped to the provided channel. If no mapping is found the the MUX itself will be selected */ |
143 for(muxAddress = 0; muxAddress < MAX_MUX_CHANNEL; muxAddress++) | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
144 { |
781 | 145 if(sensorMapping[muxAddress] == channel) |
146 { | |
147 break; | |
148 } | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
149 } |
781 | 150 indexstr[1] = muxAddress; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
151 HAL_UART_Transmit(&huart1,indexstr,4,10); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
152 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
153 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
154 void DigitalO2_SetupCmd(uint8_t O2State, uint8_t *cmdString, uint8_t *cmdLength) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
155 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
156 switch (O2State) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
157 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
158 case UART_O2_CHECK: *cmdLength = snprintf((char*)cmdString, 10, "#LOGO"); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
159 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
160 case UART_O2_REQ_INFO: *cmdLength = snprintf((char*)cmdString, 10, "#VERS"); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
161 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
162 case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR"); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
163 break; |
785
3c0b16473af4
Change support from Pyroscience -> DiveO2 sensors
heinrichsweikamp
parents:
784
diff
changeset
|
164 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY"); |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
165 break; |
785
3c0b16473af4
Change support from Pyroscience -> DiveO2 sensors
heinrichsweikamp
parents:
784
diff
changeset
|
166 case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#DRAW"); |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
167 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
168 default: *cmdLength = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
169 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
170 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
171 if(*cmdLength != 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
172 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
173 cmdString[*cmdLength] = 0x0D; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
174 *cmdLength = *cmdLength + 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
175 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
176 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
177 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
178 void StringToInt(char *pstr, uint32_t *puInt32) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
179 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
180 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
181 uint32_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
182 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
183 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
184 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
185 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
186 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
187 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
188 *puInt32 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
189 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
190 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
191 void StringToUInt64(char *pstr, uint64_t *puint64) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
192 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
193 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
194 uint64_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
195 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
196 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
197 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
198 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
199 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
200 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
201 *puint64 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
202 } |
690 | 203 void ConvertByteToHexString(uint8_t byte, char* str) |
204 { | |
205 uint8_t worker = 0; | |
206 uint8_t digit = 0; | |
207 uint8_t digitCnt = 1; | |
38 | 208 |
690 | 209 worker = byte; |
210 while((worker!=0) && (digitCnt != 255)) | |
211 { | |
212 digit = worker % 16; | |
213 if( digit < 10) | |
214 { | |
215 digit += '0'; | |
216 } | |
217 else | |
218 { | |
219 digit += 'A' - 10; | |
220 } | |
221 str[digitCnt--]= digit; | |
222 worker = worker / 16; | |
223 } | |
224 } | |
662 | 225 |
742 | 226 void UART_StartDMA_Receiption() |
227 { | |
228 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
229 { | |
230 dmaActive = 1; | |
231 } | |
232 } | |
690 | 233 |
234 #ifdef ENABLE_CO2_SUPPORT | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
235 void UART_HandleCO2Data(void) |
38 | 236 { |
662 | 237 uint8_t localRX = rxReadIndex; |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
742
diff
changeset
|
238 static uint8_t dataType = 0; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
742
diff
changeset
|
239 static uint32_t dataValue = 0; |
662 | 240 static receiveState_t rxState = RX_Ready; |
241 static uint32_t lastReceiveTick = 0; | |
242 | |
725 | 243 |
244 while((rxBuffer[localRX]!=0)) | |
662 | 245 { |
246 lastReceiveTick = HAL_GetTick(); | |
247 if(rxState == RX_Ready) /* identify data content */ | |
248 { | |
249 switch(rxBuffer[localRX]) | |
250 { | |
251 case 'l': | |
252 case 'D': | |
253 case 'Z': | |
254 dataType = rxBuffer[localRX]; | |
255 rxState = RX_Data0; | |
256 dataValue = 0; | |
257 break; | |
258 | |
259 default: /* unknown or corrupted => ignore */ | |
260 break; | |
261 } | |
262 } | |
725 | 263 else if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) |
662 | 264 { |
725 | 265 if((rxState >= RX_Data0) && (rxState <= RX_Data4)) |
662 | 266 { |
267 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0'); | |
268 rxState++; | |
725 | 269 if(rxState == RX_Data5) |
270 { | |
271 rxState = RX_DataComplete; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
272 CO2Connected = 1; |
725 | 273 } |
274 } | |
275 else /* protocol error data has max 5 digits */ | |
276 { | |
277 rxState = RX_Ready; | |
662 | 278 } |
279 } | |
280 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */ | |
281 { | |
282 if(rxState == RX_DataComplete) | |
283 { | |
284 if(externalInterface_GetCO2State() == 0) | |
285 { | |
286 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); | |
287 } | |
288 switch(dataType) | |
289 { | |
290 case 'D': externalInterface_SetCO2SignalStrength(dataValue); | |
291 break; | |
292 case 'l': LED_ZeroOffset = dataValue; | |
293 break; | |
294 case 'Z': externalInterface_SetCO2Value(dataValue); | |
295 break; | |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
742
diff
changeset
|
296 default: rxState = RX_Ready; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
742
diff
changeset
|
297 break; |
662 | 298 } |
299 } | |
300 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ | |
301 { | |
302 rxState = RX_Ready; | |
303 } | |
304 } | |
742 | 305 rxBuffer[localRX] = 0; |
662 | 306 localRX++; |
307 rxReadIndex++; | |
308 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
309 { | |
310 localRX = 0; | |
311 rxReadIndex = 0; | |
312 } | |
313 } | |
314 | |
315 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */ | |
316 { | |
317 externalInterface_SetCO2State(0); | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
318 CO2Connected = 0; |
662 | 319 } |
320 | |
321 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
322 { | |
742 | 323 UART_StartDMA_Receiption(); |
662 | 324 } |
38 | 325 } |
690 | 326 #endif |
327 | |
328 #ifdef ENABLE_SENTINEL_MODE | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
329 void UART_HandleSentinelData(void) |
690 | 330 { |
331 uint8_t localRX = rxReadIndex; | |
332 static uint8_t dataType = 0; | |
333 static uint32_t dataValue[3]; | |
334 static uint8_t dataValueIdx = 0; | |
335 static receiveState_t rxState = RX_Ready; | |
336 static uint32_t lastReceiveTick = 0; | |
337 static uint8_t lastAlive = 0; | |
338 static uint8_t curAlive = 0; | |
339 static uint8_t checksum = 0; | |
742 | 340 static char checksum_str[]="00"; |
690 | 341 |
742 | 342 while((rxBuffer[localRX]!=0)) |
690 | 343 { |
344 lastReceiveTick = HAL_GetTick(); | |
345 | |
346 switch(rxState) | |
347 { | |
348 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z')) | |
349 { | |
350 rxState = RX_DetectStart; | |
351 curAlive = rxBuffer[localRX]; | |
352 checksum = 0; | |
353 } | |
354 break; | |
355 | |
356 case RX_DetectStart: checksum += rxBuffer[localRX]; | |
357 if(rxBuffer[localRX] == '1') | |
358 { | |
359 rxState = RX_SelectData; | |
360 dataType = 0xFF; | |
361 | |
362 } | |
363 else | |
364 { | |
365 rxState = RX_Ready; | |
366 } | |
367 break; | |
368 | |
369 case RX_SelectData: checksum += rxBuffer[localRX]; | |
370 switch(rxBuffer[localRX]) | |
371 { | |
372 case 'T': dataType = rxBuffer[localRX]; | |
373 break; | |
374 case '0': if(dataType != 0xff) | |
375 { | |
376 rxState = RX_Data0; | |
377 dataValueIdx = 0; | |
378 dataValue[0] = 0; | |
379 | |
380 } | |
381 else | |
382 { | |
383 rxState = RX_Ready; | |
384 } | |
385 break; | |
386 default: rxState = RX_Ready; | |
387 } | |
388 break; | |
389 | |
390 case RX_Data0: | |
391 case RX_Data1: | |
392 case RX_Data2: | |
393 case RX_Data4: | |
394 case RX_Data5: | |
395 case RX_Data6: | |
396 case RX_Data8: | |
397 case RX_Data9: | |
398 case RX_Data10: checksum += rxBuffer[localRX]; | |
399 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) | |
400 { | |
401 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0'); | |
402 rxState++; | |
403 } | |
404 else | |
405 { | |
406 rxState = RX_Ready; | |
407 } | |
408 break; | |
409 | |
410 case RX_Data3: | |
411 case RX_Data7: checksum += rxBuffer[localRX]; | |
412 if(rxBuffer[localRX] == '0') | |
413 { | |
414 rxState++; | |
415 dataValueIdx++; | |
416 dataValue[dataValueIdx] = 0; | |
417 } | |
418 else | |
419 { | |
420 rxState = RX_Ready; | |
421 } | |
422 break; | |
423 case RX_Data11: rxState = RX_DataComplete; | |
424 ConvertByteToHexString(checksum,checksum_str); | |
425 if(rxBuffer[localRX] == checksum_str[0]) | |
426 { | |
427 rxState = RX_DataComplete; | |
428 } | |
429 else | |
430 { | |
431 rxState = RX_Ready; | |
432 } | |
433 | |
434 break; | |
435 | |
436 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) | |
437 { | |
438 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); | |
439 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); | |
440 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); | |
742 | 441 SentinelConnected = 1; |
690 | 442 } |
443 rxState = RX_Ready; | |
444 break; | |
445 | |
446 | |
447 default: rxState = RX_Ready; | |
448 break; | |
449 | |
450 } | |
451 localRX++; | |
452 rxReadIndex++; | |
453 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
454 { | |
455 localRX = 0; | |
456 rxReadIndex = 0; | |
457 } | |
458 } | |
459 | |
460 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ | |
461 { | |
462 if(curAlive == lastAlive) | |
463 { | |
464 setExternalInterfaceChannel(0,0.0); | |
465 setExternalInterfaceChannel(1,0.0); | |
466 setExternalInterfaceChannel(2,0.0); | |
742 | 467 SentinelConnected = 0; |
690 | 468 } |
469 lastAlive = curAlive; | |
470 } | |
471 | |
472 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
473 { | |
742 | 474 UART_StartDMA_Receiption(); |
690 | 475 } |
476 } | |
477 #endif | |
38 | 478 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
479 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
480 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
481 void UART_HandleDigitalO2(void) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
482 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
483 static uint32_t lastO2ReqTick = 0; |
784 | 484 static uint8_t errorStr[] = "#ERRO"; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
485 static uartO2RxState_t rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
486 static uint32_t lastReceiveTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
487 static uint8_t lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
488 static uint8_t curAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
489 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
490 static uint8_t cmdLength = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
491 static uint8_t cmdString[10]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
492 static uint8_t cmdReadIndex = 0; |
784 | 493 static uint8_t errorReadIndex = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
494 static uint32_t tickToTX = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
495 static uint32_t delayStartTick = 0; |
781 | 496 static uint16_t requestIntervall = 0; |
497 static uint8_t retryRequest = 1; | |
498 static uint8_t lastComState = 0; | |
784 | 499 static uint8_t respondErrorDetected = 0; |
500 static uint8_t switchChannel = 0; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
501 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
502 uint8_t index = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
503 uint32_t tmpO2 = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
504 uint32_t tmpData = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
505 uint8_t localRX = rxReadIndex; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
506 uint32_t tick = HAL_GetTick(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
507 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
508 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
509 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
510 /* The channel switch will cause the sensor to respond with an error message. */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
511 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
512 if((tickToTX) && (time_elapsed_ms(delayStartTick,tick) >= tickToTX )) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
513 { |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
514 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
515 tickToTX = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
516 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
517 else |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
518 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
519 if(Comstatus_O2 == UART_O2_INIT) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
520 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
521 memset((char*)&rxBuffer[rxWriteIndex],(int)BUFFER_NODATA, sizeof(rxBuffer)); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
522 memset((char*) &tmpSensorDataDiveO2, 0, sizeof(tmpSensorDataDiveO2)); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
523 externalInterface_SetSensorData(0xFF,(uint8_t*)&tmpSensorDataDiveO2); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
524 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
525 lastAlive = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
526 curAlive = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
527 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
528 Comstatus_O2 = UART_O2_CHECK; |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
529 lastComState = UART_O2_IDLE; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
530 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
531 |
781 | 532 if(activeSensor < MAX_MUX_CHANNEL) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
533 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
534 externalInterface_GetSensorData(activeSensor, (uint8_t*)&tmpSensorDataDiveO2); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
535 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
536 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
537 tickToTX = COMMAND_TX_DELAY; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
538 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
539 rxState = O2RX_CONFIRM; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
540 cmdReadIndex = 0; |
784 | 541 errorReadIndex = 0; |
542 respondErrorDetected = 0; | |
543 digO2Connected = 0; | |
544 switchChannel = 1; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
545 |
781 | 546 requestIntervall = 0; |
547 for(index = 0; index < MAX_MUX_CHANNEL; index++) | |
548 { | |
549 if(pmap[index] == SENSOR_DIGO2) | |
550 { | |
551 requestIntervall++; | |
552 } | |
553 } | |
554 if(requestIntervall != 0) | |
555 { | |
556 requestIntervall = REQUEST_INT_SENSOR_MS / requestIntervall; | |
557 } | |
558 else | |
559 { | |
560 requestIntervall = REQUEST_INT_SENSOR_MS; | |
561 } | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
562 UART_StartDMA_Receiption(); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
563 lastO2ReqTick = tick + requestIntervall + 1; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
564 } |
781 | 565 if(time_elapsed_ms(lastO2ReqTick,tick) > requestIntervall) /* repeat request or iterate to next sensor */ |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
566 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
567 respondErrorDetected = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
568 lastO2ReqTick = tick; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
569 index = activeSensor; |
784 | 570 if((lastComState == Comstatus_O2) && (Comstatus_O2 != UART_O2_IDLE)) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
571 { |
781 | 572 if(retryRequest) |
573 { | |
574 retryRequest = 0; | |
575 } | |
576 else /* no answer even repeating the request => abort request */ | |
577 { | |
578 if(Comstatus_O2 == UART_O2_REQ_RAW) | |
579 { | |
580 setExternalInterfaceChannel(activeSensor,0.0); | |
581 } | |
582 Comstatus_O2 = UART_O2_IDLE; | |
583 } | |
584 } | |
585 lastComState = Comstatus_O2; | |
586 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ | |
587 { | |
588 retryRequest = 1; | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
589 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
590 { |
781 | 591 if(activeSensor < MAX_MUX_CHANNEL) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
592 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
593 do |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
594 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
595 index++; |
781 | 596 if(index == MAX_MUX_CHANNEL) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
597 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
598 index = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
599 } |
784 | 600 if((pmap[index] == SENSOR_DIGO2) && (index != activeSensor)) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
601 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
602 activeSensor = index; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
603 switchChannel = 1; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
604 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
605 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
606 } while(index != activeSensor); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
607 externalInterface_GetSensorData(activeSensor, (uint8_t*)&tmpSensorDataDiveO2); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
608 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
609 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
610 if((activeSensor != MAX_MUX_CHANNEL) && (tmpSensorDataDiveO2.sensorId == 0)) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
611 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
612 Comstatus_O2 = UART_O2_REQ_ID; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
613 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
614 else |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
615 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
616 Comstatus_O2 = UART_O2_REQ_RAW; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
617 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
618 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
619 rxState = O2RX_CONFIRM; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
620 if(switchChannel) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
621 { |
784 | 622 switchChannel = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
623 delayStartTick = tick; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
624 DigitalO2_SelectSensor(activeSensor); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
625 tickToTX = COMMAND_TX_DELAY; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
626 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
627 else |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
628 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
629 tickToTX = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
630 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
631 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
632 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
633 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
634 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
635 while((rxBuffer[localRX] != BUFFER_NODATA)) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
636 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
637 lastReceiveTick = tick; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
638 switch(rxState) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
639 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
640 case O2RX_CONFIRM: if(rxBuffer[localRX] == '#') |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
641 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
642 cmdReadIndex = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
643 errorReadIndex = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
644 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
645 if(errorReadIndex < sizeof(errorStr)-1) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
646 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
647 if(rxBuffer[localRX] == errorStr[errorReadIndex]) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
648 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
649 errorReadIndex++; |
784 | 650 } |
651 else | |
652 { | |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
653 errorReadIndex = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
654 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
655 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
656 else |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
657 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
658 respondErrorDetected = 1; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
659 errorReadIndex = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
660 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
661 if(rxBuffer[localRX] == cmdString[cmdReadIndex]) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
662 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
663 cmdReadIndex++; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
664 if(cmdReadIndex == cmdLength - 1) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
665 { |
784 | 666 if((activeSensor == MAX_MUX_CHANNEL)) |
667 { | |
668 if(respondErrorDetected) | |
669 { | |
670 digO2Connected = 0; /* the multiplexer mirrors the incoming message and does not generate an error information => no mux connected */ | |
671 } | |
672 else | |
673 { | |
674 digO2Connected = 1; | |
675 } | |
676 } | |
677 else /* handle sensors which should respond with an error message after channel switch */ | |
678 { | |
679 if(respondErrorDetected) | |
680 { | |
681 digO2Connected = 1; | |
682 } | |
683 } | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
684 tmpRxIdx = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
685 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf)); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
686 cmdReadIndex = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
687 switch (Comstatus_O2) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
688 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
689 case UART_O2_CHECK: Comstatus_O2 = UART_O2_IDLE; |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
690 rxState = O2RX_IDLE; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
691 break; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
692 case UART_O2_REQ_ID: rxState = O2RX_GETNR; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
693 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
694 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
695 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
696 case UART_O2_REQ_RAW: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
697 case UART_O2_REQ_O2: rxState = O2RX_GETO2; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
698 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
699 default: Comstatus_O2 = UART_O2_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
700 rxState = O2RX_IDLE; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
701 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
702 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
703 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
704 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
705 else |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
706 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
707 cmdReadIndex = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
708 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
709 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
710 |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
711 case O2RX_GETSTATUS: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
712 case O2RX_GETTEMP: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
713 case O2RX_GETTYPE: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
714 case O2RX_GETVERSION: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
715 case O2RX_GETCHANNEL: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
716 case O2RX_GETSUBSENSORS: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
717 case O2RX_GETO2: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
718 case O2RX_GETNR: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
719 case O2RX_GETDPHI: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
720 case O2RX_INTENSITY: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
721 case O2RX_AMBIENTLIGHT: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
722 case O2RX_PRESSURE: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
723 case O2RX_HUMIDITY: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
724 if(rxBuffer[localRX] != 0x0D) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
725 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
726 if(rxBuffer[localRX] != ' ') /* the following data entities are placed within the data stream => no need to store data at the end */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
727 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
728 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX]; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
729 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
730 else |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
731 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
732 if(tmpRxIdx != 0) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
733 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
734 switch(rxState) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
735 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
736 case O2RX_GETCHANNEL: StringToInt(tmpRxBuf,&tmpData); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
737 rxState = O2RX_GETVERSION; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
738 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
739 case O2RX_GETVERSION: StringToInt(tmpRxBuf,&tmpData); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
740 rxState = O2RX_GETSUBSENSORS; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
741 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
742 case O2RX_GETTYPE: StringToInt(tmpRxBuf,&tmpData); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
743 rxState = O2RX_GETCHANNEL; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
744 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
745 |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
746 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
747 setExternalInterfaceChannel(activeSensor,(float)(tmpO2 / 10000.0)); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
748 rxState = O2RX_GETTEMP; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
749 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
750 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.temperature); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
751 rxState = O2RX_GETSTATUS; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
752 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
753 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&tmpSensorDataDiveO2.status); /* raw data cycle */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
754 rxState = O2RX_GETDPHI; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
755 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
756 case O2RX_GETDPHI: /* ignored to save memory and most likly irrelevant for diver */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
757 rxState = O2RX_INTENSITY; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
758 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
759 case O2RX_INTENSITY: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.intensity); /* raw data cycle */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
760 rxState = O2RX_AMBIENTLIGHT; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
761 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
762 case O2RX_AMBIENTLIGHT: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.ambient); /* raw data cycle */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
763 rxState = O2RX_PRESSURE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
764 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
765 case O2RX_PRESSURE: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.pressure); /* raw data cycle */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
766 rxState = O2RX_HUMIDITY; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
767 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
768 default: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
769 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
770 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
771 memset((char*) tmpRxBuf, 0, tmpRxIdx); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
772 tmpRxIdx = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
773 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
774 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
775 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
776 else |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
777 { /* the following data items are the last of a sensor respond => store temporal data */ |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
778 switch (rxState) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
779 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
780 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&tmpSensorDataDiveO2.status); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
781 externalInterface_SetSensorData(activeSensor,(uint8_t*)&tmpSensorDataDiveO2); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
782 Comstatus_O2 = UART_O2_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
783 rxState = O2RX_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
784 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
785 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
786 Comstatus_O2 = UART_O2_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
787 rxState = O2RX_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
788 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
789 case O2RX_HUMIDITY: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.humidity); /* raw data cycle */ |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
790 externalInterface_SetSensorData(activeSensor,(uint8_t*)&tmpSensorDataDiveO2); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
791 Comstatus_O2 = UART_O2_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
792 rxState = O2RX_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
793 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
794 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&tmpSensorDataDiveO2.sensorId); |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
795 externalInterface_SetSensorData(activeSensor,(uint8_t*)&tmpSensorDataDiveO2); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
796 index = activeSensor; |
784 | 797 Comstatus_O2 = UART_O2_IDLE; |
798 rxState = O2RX_IDLE; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
799 break; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
800 default: Comstatus_O2 = UART_O2_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
801 rxState = O2RX_IDLE; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
802 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
803 } |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
804 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
805 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
806 default: rxState = O2RX_IDLE; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
807 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
808 |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
809 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
810 rxBuffer[localRX] = BUFFER_NODATA; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
811 localRX++; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
812 rxReadIndex++; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
813 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
814 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
815 localRX = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
816 rxReadIndex = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
817 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
818 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
819 |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
820 if((digO2Connected) && time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
821 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
822 digO2Connected = 0; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
823 if(curAlive == lastAlive) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
824 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
825 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
826 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
827 if(pmap[index] == SENSOR_DIGO2) |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
828 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
829 setExternalInterfaceChannel(index,0.0); |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
830 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
831 } |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
832 } |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
833 lastAlive = curAlive; |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
834 } |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
835 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
836 { |
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
837 UART_StartDMA_Receiption(); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
838 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
839 } |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
840 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
841 void UART_SetDigO2_Channel(uint8_t channel) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
842 { |
781 | 843 if(channel <= MAX_MUX_CHANNEL) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
844 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
845 activeSensor = channel; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
846 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
847 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
848 void UART_MapDigO2_Channel(uint8_t channel, uint8_t muxAddress) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
849 { |
781 | 850 if(((channel < MAX_ADC_CHANNEL) || (channel == 0xff)) && (muxAddress < MAX_MUX_CHANNEL)) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
851 { |
781 | 852 sensorMapping[muxAddress] = channel; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
853 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
854 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
855 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
856 uint8_t UART_isDigO2Connected() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
857 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
858 return digO2Connected; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
859 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
860 uint8_t UART_isCO2Connected() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
861 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
862 return CO2Connected; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
863 } |
742 | 864 uint8_t UART_isSentinelConnected() |
865 { | |
866 return SentinelConnected; | |
867 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
868 |
662 | 869 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 870 { |
662 | 871 if(huart == &huart1) |
872 { | |
873 dmaActive = 0; | |
874 rxWriteIndex+=CHUNK_SIZE; | |
875 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
876 { | |
877 rxWriteIndex = 0; | |
878 } | |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
879 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */ |
662 | 880 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
881 if(externalInterface_GetUARTProtocol() != 0) |
662 | 882 { |
742 | 883 UART_StartDMA_Receiption(); |
662 | 884 } |
885 } | |
886 } | |
38 | 887 } |
888 | |
889 | |
662 | 890 |
38 | 891 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |