Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 736:8a2337c7af52
Fixed logbook download after switch from CCR to extra (OC) gas if the extra gas
was the same as the active diluent
Bugfix from mikeller
author | heinrichsweikamp |
---|---|
date | Fri, 03 Mar 2023 10:41:44 +0100 |
parents | 2a801cfe23ab |
children | e23fe82cbf8c |
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 | |
721 | 29 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */ |
30 #define CHUNKS_PER_BUFFER (5u) | |
662 | 31 UART_HandleTypeDef huart1; |
32 | |
33 DMA_HandleTypeDef hdma_usart1_rx; | |
38 | 34 |
662 | 35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 static uint8_t CO2Connected = 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
|
42 static uint8_t ppO2TargetChannel = 0; /* The OSTC4 supports three slots for visualization of the ppo2. This one is reserved for the digital sensor */ |
38 | 43 |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
44 static SSensorDataDiveO2 sensorDataDiveO2; /* intermediate storage for additional sensor data */ |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
45 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
46 char tmpRxBuf[30]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
47 uint8_t tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
48 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
49 static uartO2Status_t Comstatus_O2 = UART_O2_INIT; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
50 |
662 | 51 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */ |
52 float LED_ZeroOffset = 0.0; | |
53 float pCO2 = 0.0; | |
38 | 54 /* Exported functions --------------------------------------------------------*/ |
55 | |
662 | 56 void MX_USART1_UART_Init(void) |
38 | 57 { |
662 | 58 /* regular init */ |
59 | |
60 huart1.Instance = USART1; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
61 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
62 if(externalInterface_GetUARTProtocol() == 0x04) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
63 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
64 huart1.Init.BaudRate = 19200; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
65 Comstatus_O2 = UART_O2_INIT; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
66 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
67 else |
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 huart1.Init.BaudRate = 9600; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
70 } |
662 | 71 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
72 huart1.Init.StopBits = UART_STOPBITS_1; | |
73 huart1.Init.Parity = UART_PARITY_NONE; | |
74 huart1.Init.Mode = UART_MODE_TX_RX; | |
75 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
76 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
77 | |
78 HAL_UART_Init(&huart1); | |
79 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
80 MX_USART1_DMA_Init(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
81 |
731 | 82 memset(rxBuffer,0,sizeof(rxBuffer)); |
662 | 83 rxReadIndex = 0; |
84 lastCmdIndex = 0; | |
85 rxWriteIndex = 0; | |
86 dmaActive = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
87 digO2Connected = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
88 CO2Connected = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
89 Comstatus_O2 = UART_O2_INIT; |
662 | 90 } |
38 | 91 |
662 | 92 void MX_USART1_UART_DeInit(void) |
93 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
94 HAL_DMA_Abort(&hdma_usart1_rx); |
662 | 95 HAL_DMA_DeInit(&hdma_usart1_rx); |
96 HAL_UART_DeInit(&huart1); | |
97 } | |
98 | |
99 void MX_USART1_DMA_Init() | |
100 { | |
101 /* DMA controller clock enable */ | |
102 __DMA2_CLK_ENABLE(); | |
103 | |
104 /* Peripheral DMA init*/ | |
105 hdma_usart1_rx.Instance = DMA2_Stream5; | |
106 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
107 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
108 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
109 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
110 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
111 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
112 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
113 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
114 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
115 HAL_DMA_Init(&hdma_usart1_rx); | |
116 | |
117 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
118 | |
119 /* DMA interrupt init */ | |
120 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0); | |
121 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); | |
38 | 122 } |
123 | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
124 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
125 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
|
126 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
127 switch (O2State) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
128 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
129 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
|
130 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
131 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
|
132 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
133 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
|
134 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
135 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY"); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
136 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
137 case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#DRAW"); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
138 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
139 default: *cmdLength = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
140 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
141 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
142 if(*cmdLength != 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
143 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
144 cmdString[*cmdLength] = 0x0D; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
145 *cmdLength = *cmdLength + 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
146 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
147 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
148 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
149 void StringToInt(char *pstr, uint32_t *puInt32) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
150 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
151 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
152 uint32_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
153 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
154 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
155 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
156 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
157 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
158 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
159 *puInt32 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
160 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
161 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
162 void StringToUInt64(char *pstr, uint64_t *puint64) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
163 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
164 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
165 uint64_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
166 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
167 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
168 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
169 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
170 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
171 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
172 *puint64 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
173 } |
690 | 174 void ConvertByteToHexString(uint8_t byte, char* str) |
175 { | |
176 uint8_t worker = 0; | |
177 uint8_t digit = 0; | |
178 uint8_t digitCnt = 1; | |
38 | 179 |
690 | 180 worker = byte; |
181 while((worker!=0) && (digitCnt != 255)) | |
182 { | |
183 digit = worker % 16; | |
184 if( digit < 10) | |
185 { | |
186 digit += '0'; | |
187 } | |
188 else | |
189 { | |
190 digit += 'A' - 10; | |
191 } | |
192 str[digitCnt--]= digit; | |
193 worker = worker / 16; | |
194 } | |
195 } | |
662 | 196 |
690 | 197 |
198 #ifdef ENABLE_CO2_SUPPORT | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
199 void UART_HandleCO2Data(void) |
38 | 200 { |
662 | 201 uint8_t localRX = rxReadIndex; |
202 uint8_t dataType = 0; | |
690 | 203 uint32_t dataValue = 0; |
662 | 204 static receiveState_t rxState = RX_Ready; |
205 static uint32_t lastReceiveTick = 0; | |
206 | |
725 | 207 |
208 while((rxBuffer[localRX]!=0)) | |
662 | 209 { |
210 lastReceiveTick = HAL_GetTick(); | |
211 if(rxState == RX_Ready) /* identify data content */ | |
212 { | |
213 switch(rxBuffer[localRX]) | |
214 { | |
215 case 'l': | |
216 case 'D': | |
217 case 'Z': | |
218 dataType = rxBuffer[localRX]; | |
219 rxState = RX_Data0; | |
220 dataValue = 0; | |
221 break; | |
222 | |
223 default: /* unknown or corrupted => ignore */ | |
224 break; | |
225 } | |
226 } | |
725 | 227 else if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) |
662 | 228 { |
725 | 229 if((rxState >= RX_Data0) && (rxState <= RX_Data4)) |
662 | 230 { |
231 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0'); | |
232 rxState++; | |
725 | 233 if(rxState == RX_Data5) |
234 { | |
235 rxState = RX_DataComplete; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
236 CO2Connected = 1; |
725 | 237 } |
238 } | |
239 else /* protocol error data has max 5 digits */ | |
240 { | |
241 rxState = RX_Ready; | |
662 | 242 } |
243 } | |
244 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */ | |
245 { | |
246 if(rxState == RX_DataComplete) | |
247 { | |
248 if(externalInterface_GetCO2State() == 0) | |
249 { | |
250 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); | |
251 } | |
252 switch(dataType) | |
253 { | |
254 case 'D': externalInterface_SetCO2SignalStrength(dataValue); | |
255 break; | |
256 case 'l': LED_ZeroOffset = dataValue; | |
257 break; | |
258 case 'Z': externalInterface_SetCO2Value(dataValue); | |
259 break; | |
260 default: break; | |
261 } | |
262 } | |
263 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ | |
264 { | |
265 rxState = RX_Ready; | |
266 } | |
267 } | |
268 | |
269 localRX++; | |
270 rxReadIndex++; | |
271 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
272 { | |
273 localRX = 0; | |
274 rxReadIndex = 0; | |
275 } | |
276 } | |
277 | |
278 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */ | |
279 { | |
280 externalInterface_SetCO2State(0); | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
281 CO2Connected = 0; |
662 | 282 } |
283 | |
284 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
285 { | |
286 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
287 { | |
288 dmaActive = 1; | |
289 } | |
290 } | |
38 | 291 } |
690 | 292 #endif |
293 | |
294 #ifdef ENABLE_SENTINEL_MODE | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
295 void UART_HandleSentinelData(void) |
690 | 296 { |
297 uint8_t localRX = rxReadIndex; | |
298 static uint8_t dataType = 0; | |
299 static uint32_t dataValue[3]; | |
300 static uint8_t dataValueIdx = 0; | |
301 static receiveState_t rxState = RX_Ready; | |
302 static uint32_t lastReceiveTick = 0; | |
303 static uint8_t lastAlive = 0; | |
304 static uint8_t curAlive = 0; | |
305 static uint8_t checksum = 0; | |
306 char checksum_str[]="00"; | |
307 | |
308 while(localRX != rxWriteIndex) | |
309 { | |
310 lastReceiveTick = HAL_GetTick(); | |
311 | |
312 switch(rxState) | |
313 { | |
314 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z')) | |
315 { | |
316 rxState = RX_DetectStart; | |
317 curAlive = rxBuffer[localRX]; | |
318 checksum = 0; | |
319 } | |
320 break; | |
321 | |
322 case RX_DetectStart: checksum += rxBuffer[localRX]; | |
323 if(rxBuffer[localRX] == '1') | |
324 { | |
325 rxState = RX_SelectData; | |
326 dataType = 0xFF; | |
327 | |
328 } | |
329 else | |
330 { | |
331 rxState = RX_Ready; | |
332 } | |
333 break; | |
334 | |
335 case RX_SelectData: checksum += rxBuffer[localRX]; | |
336 switch(rxBuffer[localRX]) | |
337 { | |
338 case 'T': dataType = rxBuffer[localRX]; | |
339 break; | |
340 case '0': if(dataType != 0xff) | |
341 { | |
342 rxState = RX_Data0; | |
343 dataValueIdx = 0; | |
344 dataValue[0] = 0; | |
345 | |
346 } | |
347 else | |
348 { | |
349 rxState = RX_Ready; | |
350 } | |
351 break; | |
352 default: rxState = RX_Ready; | |
353 } | |
354 break; | |
355 | |
356 case RX_Data0: | |
357 case RX_Data1: | |
358 case RX_Data2: | |
359 case RX_Data4: | |
360 case RX_Data5: | |
361 case RX_Data6: | |
362 case RX_Data8: | |
363 case RX_Data9: | |
364 case RX_Data10: checksum += rxBuffer[localRX]; | |
365 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) | |
366 { | |
367 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0'); | |
368 rxState++; | |
369 } | |
370 else | |
371 { | |
372 rxState = RX_Ready; | |
373 } | |
374 break; | |
375 | |
376 case RX_Data3: | |
377 case RX_Data7: checksum += rxBuffer[localRX]; | |
378 if(rxBuffer[localRX] == '0') | |
379 { | |
380 rxState++; | |
381 dataValueIdx++; | |
382 dataValue[dataValueIdx] = 0; | |
383 } | |
384 else | |
385 { | |
386 rxState = RX_Ready; | |
387 } | |
388 break; | |
389 case RX_Data11: rxState = RX_DataComplete; | |
390 ConvertByteToHexString(checksum,checksum_str); | |
391 if(rxBuffer[localRX] == checksum_str[0]) | |
392 { | |
393 rxState = RX_DataComplete; | |
394 } | |
395 else | |
396 { | |
397 rxState = RX_Ready; | |
398 } | |
399 | |
400 break; | |
401 | |
402 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) | |
403 { | |
404 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); | |
405 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); | |
406 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); | |
407 } | |
408 rxState = RX_Ready; | |
409 break; | |
410 | |
411 | |
412 default: rxState = RX_Ready; | |
413 break; | |
414 | |
415 } | |
416 | |
417 localRX++; | |
418 rxReadIndex++; | |
419 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
420 { | |
421 localRX = 0; | |
422 rxReadIndex = 0; | |
423 } | |
424 } | |
425 | |
426 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ | |
427 { | |
428 if(curAlive == lastAlive) | |
429 { | |
430 setExternalInterfaceChannel(0,0.0); | |
431 setExternalInterfaceChannel(1,0.0); | |
432 setExternalInterfaceChannel(2,0.0); | |
433 } | |
434 lastAlive = curAlive; | |
435 } | |
436 | |
437 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
438 { | |
439 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) | |
440 { | |
441 dmaActive = 1; | |
442 } | |
443 } | |
444 } | |
445 #endif | |
38 | 446 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
447 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
448 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
449 void UART_HandleDigitalO2(void) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
450 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
451 static uint32_t lastO2ReqTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
452 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
453 static uartO2RxState_t rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
454 static uint32_t lastReceiveTick = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
455 static uint8_t lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
456 static uint8_t curAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
457 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
458 static uint8_t cmdLength = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
459 static uint8_t cmdString[10]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
460 static uint8_t cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
461 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
462 uint32_t tmpO2 = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
463 uint32_t tmpData = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
464 uint8_t localRX = rxReadIndex; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
465 uint32_t tick = HAL_GetTick(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
466 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
467 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
468 if(Comstatus_O2 == UART_O2_INIT) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
469 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
470 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
471 memset((char*) &sensorDataDiveO2, 0, sizeof(sensorDataDiveO2)); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
472 externalInterface_SetSensorData(0,(uint8_t*)&sensorDataDiveO2); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
473 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
474 lastAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
475 curAlive = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
476 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
477 Comstatus_O2 = UART_O2_CHECK; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
478 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
479 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
480 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
481 rxState = O2RX_CONFIRM; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
482 cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
483 lastO2ReqTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
484 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
485 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
486 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
487 dmaActive = 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
488 } |
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 if(time_elapsed_ms(lastO2ReqTick,tick) > 1000) /* repeat request once per second */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
491 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
492 lastO2ReqTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
493 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
494 { |
721 | 495 Comstatus_O2 = UART_O2_REQ_RAW; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
496 rxState = O2RX_CONFIRM; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
497 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
498 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
499 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
500 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
501 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
502 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
503 while((rxBuffer[localRX]!=0)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
504 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
505 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
506 lastReceiveTick = tick; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
507 switch(rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
508 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
509 case O2RX_CONFIRM: if(rxBuffer[localRX] == '#') |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
510 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
511 cmdReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
512 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
513 if(rxBuffer[localRX] == cmdString[cmdReadIndex]) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
514 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
515 cmdReadIndex++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
516 if(cmdReadIndex == cmdLength - 1) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
517 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
518 digO2Connected = 1; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
519 tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
520 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf)); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
521 switch (Comstatus_O2) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
522 { |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
523 case UART_O2_CHECK: Comstatus_O2 = UART_O2_REQ_ID; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
524 rxState = O2RX_CONFIRM; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
525 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
526 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
527 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
528 case UART_O2_REQ_ID: rxState = O2RX_GETNR; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
529 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
530 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
531 break; |
721 | 532 case UART_O2_REQ_RAW: |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
533 case UART_O2_REQ_O2: rxState = O2RX_GETO2; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
534 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
535 default: Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
536 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
537 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
538 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
539 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
540 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
541 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
542 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
543 case O2RX_GETSTATUS: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
544 case O2RX_GETTEMP: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
545 case O2RX_GETTYPE: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
546 case O2RX_GETVERSION: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
547 case O2RX_GETCHANNEL: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
548 case O2RX_GETSUBSENSORS: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
549 case O2RX_GETO2: |
721 | 550 case O2RX_GETNR: |
551 case O2RX_GETDPHI: | |
552 case O2RX_INTENSITY: | |
553 case O2RX_AMBIENTLIGHT: | |
554 case O2RX_PRESSURE: | |
555 case O2RX_HUMIDITY: | |
556 if(rxBuffer[localRX] != 0x0D) | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
557 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
558 if(rxBuffer[localRX] != ' ') |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
559 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
560 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX]; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
561 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
562 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
563 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
564 if(tmpRxIdx != 0) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
565 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
566 switch(rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
567 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
568 case O2RX_GETCHANNEL: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
569 rxState = O2RX_GETVERSION; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
570 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
571 case O2RX_GETVERSION: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
572 rxState = O2RX_GETSUBSENSORS; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
573 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
574 case O2RX_GETTYPE: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
575 rxState = O2RX_GETCHANNEL; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
576 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
577 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
578 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2); |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
579 setExternalInterfaceChannel(ppO2TargetChannel,(float)(tmpO2 / 10000.0)); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
580 rxState = O2RX_GETTEMP; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
581 break; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
582 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.temperature); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
583 rxState = O2RX_GETSTATUS; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
584 break; |
721 | 585 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status); /* raw data cycle */ |
586 rxState = O2RX_GETDPHI; | |
587 break; | |
588 case O2RX_GETDPHI: /* ignored to save memory and most likly irrelevant for diver */ | |
589 rxState = O2RX_INTENSITY; | |
590 break; | |
591 case O2RX_INTENSITY: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.intensity); /* raw data cycle */ | |
592 rxState = O2RX_AMBIENTLIGHT; | |
593 break; | |
594 case O2RX_AMBIENTLIGHT: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.ambient); /* raw data cycle */ | |
595 rxState = O2RX_PRESSURE; | |
596 break; | |
597 case O2RX_PRESSURE: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.pressure); /* raw data cycle */ | |
598 rxState = O2RX_HUMIDITY; | |
599 break; | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
600 default: |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
601 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
602 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
603 memset((char*) tmpRxBuf, 0, tmpRxIdx); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
604 tmpRxIdx = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
605 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
606 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
607 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
608 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
609 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
610 switch (rxState) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
611 { |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
612 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&sensorDataDiveO2.status); |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
613 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
614 Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
615 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
616 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
617 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
618 Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
619 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
620 break; |
721 | 621 case O2RX_HUMIDITY: StringToInt(tmpRxBuf,(uint32_t*)&sensorDataDiveO2.humidity); /* raw data cycle */ |
622 externalInterface_SetSensorData(1,(uint8_t*)&sensorDataDiveO2); | |
623 Comstatus_O2 = UART_O2_IDLE; | |
624 rxState = O2RX_IDLE; | |
625 break; | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
626 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&sensorDataDiveO2.sensorId); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
627 /* no break */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
628 default: Comstatus_O2 = UART_O2_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
629 rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
630 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
631 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
632 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
633 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
634 default: rxState = O2RX_IDLE; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
635 break; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
636 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
637 } |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
638 rxBuffer[localRX] = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
639 localRX++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
640 rxReadIndex++; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
641 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
642 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
643 localRX = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
644 rxReadIndex = 0; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
645 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
646 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
647 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
648 if((digO2Connected) && time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
649 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
650 digO2Connected = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
651 if(curAlive == lastAlive) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
652 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
653 setExternalInterfaceChannel(ppO2TargetChannel,0.0); |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
654 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
655 lastAlive = curAlive; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
656 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
657 |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
658 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
659 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
660 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
661 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
662 dmaActive = 1; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
663 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
664 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
665 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
666 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
667 uint8_t UART_isDigO2Connected() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
668 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
669 return digO2Connected; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
670 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
671 uint8_t UART_isCO2Connected() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
672 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
673 return CO2Connected; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
674 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
675 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
676 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
677 void UART_setTargetChannel(uint8_t channel) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
678 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
679 ppO2TargetChannel = channel; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
680 } |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
681 |
662 | 682 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 683 { |
662 | 684 if(huart == &huart1) |
685 { | |
686 dmaActive = 0; | |
687 rxWriteIndex+=CHUNK_SIZE; | |
688 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
689 { | |
690 rxWriteIndex = 0; | |
691 } | |
692 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE)) /* start next transfer if we did not catch up with read index */ | |
693 { | |
694 if(externalInterface_isEnabledPower33()) | |
695 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
696 memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE); |
662 | 697 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
698 { | |
699 dmaActive = 1; | |
700 } | |
701 } | |
702 } | |
703 } | |
38 | 704 } |
705 | |
706 | |
662 | 707 |
38 | 708 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |