Mercurial > public > ostc4
annotate Discovery/Src/tComm.c @ 466:538eb1c976e9 Improve_Logtansfer
Removed invalidate header function because it is no lonnger needed
Added new function allowing to read the profile length from sample data
Added function which validates the wrap around detection
In older versions a corruption of the sample index could occure reseting the sample index to its start. For some code sections this looks like a wrap around of the sample ring. To avoid problems a function to check this by reading the last bytes of the sample ring (should be != 0xff if used) has been added
author | ideenmodellierer |
---|---|
date | Tue, 14 Apr 2020 19:27:04 +0200 |
parents | 05c5c3d10902 |
children | 5387e684d797 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tComm.c | |
5 /// \brief Main file for communication with PC | |
6 /// \author heinrichs weikamp gmbh | |
7 /// \date 08-Aug-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /** | |
30 ============================================================================== | |
31 ##### How to use ##### | |
32 ============================================================================== | |
33 ============================================================================== | |
34 ##### History ##### | |
35 ============================================================================== | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
36 160211 added 4 bytes Serial in update Files after checksum prior to binary |
38 | 37 160211 0x6B changed to version only |
38 160623 fixed 0x72 (in V1.0.9) | |
39 160623 fixed rebuild menu (before update) for V1.0.10 | |
40 | |
41 ============================================================================== | |
42 ##### CTS / RTS ##### | |
43 ============================================================================== | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
44 RTS is Output, CTS is Input |
38 | 45 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
46 BlueMod Pin D7 UART-RTS# is Output |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
47 connected to STM32F429 PA11 CTS (Input) |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
48 also STM32 PA12 RTS is connected to BlueMod UART-CTS# F3 |
38 | 49 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
50 see BlueMod_SR_HWreference_r06.pdf, page 156 |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
51 and MAIN_CPU STM32F4 Reference manual DM00031020.pdf, page 990 |
38 | 52 |
53 | |
54 ============================================================================== | |
55 ##### Codes ##### | |
56 ============================================================================== | |
57 [0x73] upload CPU2 firmware in SDRAM and update CPU2 | |
58 | |
59 [0x74] upload MainCPU firmware in EEPROM and start bootloader | |
60 | |
61 */ | |
62 | |
63 /* Includes ------------------------------------------------------------------*/ | |
64 | |
65 #include "tComm.h" | |
66 | |
67 #include "externCPU2bootloader.h" | |
68 #include "externLogbookFlash.h" | |
69 #include "gfx_colors.h" | |
70 #include "gfx_engine.h" | |
71 #include "gfx_fonts.h" | |
72 #include "ostc.h" | |
73 | |
74 #ifndef BOOTLOADER_STANDALONE | |
75 # include "base.h" | |
76 # include "tHome.h" | |
77 # include "logbook.h" | |
78 # include "tMenu.h" | |
79 #else | |
80 # include "base_bootloader.h" | |
81 # include "firmwareEraseProgram.h" | |
82 #endif | |
83 | |
84 #ifdef SPECIALPROGRAMM | |
85 # include "firmwareEraseProgram.h" | |
86 #endif | |
396 | 87 #include <stdlib.h> |
38 | 88 #include <string.h> |
89 | |
90 | |
91 /* Private variables ---------------------------------------------------------*/ | |
92 GFX_DrawCfgScreen tCscreen; | |
93 GFX_DrawCfgWindow tCwindow; | |
94 | |
95 uint8_t receiveStartByteUart = 0; | |
96 uint8_t bluetoothActiveLastTime = 0; | |
97 | |
98 uint8_t StartListeningToUART = 0; | |
229
2c0b502b0a72
cleanup: fix recent extra compiler warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
218
diff
changeset
|
99 char display_text[256] = { 0 }; |
38 | 100 |
101 uint8_t setForcedBluetoothName = 0; | |
102 | |
103 uint8_t updateSettingsAndMenuOnExit = 0; | |
104 | |
105 /* Private types -------------------------------------------------------------*/ | |
316
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
106 #define BYTE_DOWNLOAD_MODE (0xBB) |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
107 #define BYTE_SERVICE_MODE (0xAA) |
38 | 108 |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
109 #define UART_OPERATION_TIMEOUT (500u) /* Timeout for common read / write operations (ms) */ |
316
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
110 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ |
400 | 111 #define UART_TIMEOUT_LARGE_BLOCK (6000u) /* Timeout (ms) for reception of an 16K data block (typical RX time ~4,5seconds) */ |
112 | |
113 #define UART_CMD_BUF_SIZE (20u) /* size of buffer for command exchange */ | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
114 |
38 | 115 const uint8_t id_Region1_firmware = 0xFF; |
116 const uint8_t id_RTE = 0xFE; | |
117 const uint8_t id_FONT = 0x10; | |
118 const uint8_t id_FONT_OLD = 0x00; | |
119 | |
396 | 120 static BlueModTmpConfig_t BmTmpConfig = BM_CONFIG_OFF; /* Config BlueMod without storing the changes */ |
121 static uint8_t EvaluateBluetoothSignalStrength = 0; | |
122 static uint8_t RequestDisconnection = 0; /* Disconnection from remote device requested */ | |
38 | 123 /* Private function prototypes -----------------------------------------------*/ |
396 | 124 static void tComm_Disconnect(void); |
38 | 125 static void tComm_Error_Handler(void); |
126 static uint8_t select_mode(uint8_t aRxByte); | |
396 | 127 static uint8_t tComm_CheckAnswerOK(void); |
128 static uint8_t tComm_HandleBlueModConfig(void); | |
129 static void tComm_EvaluateBluetoothStrength(void); | |
38 | 130 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED); |
131 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED); | |
132 uint8_t receive_update_data_mainCPU_firmware(void); | |
133 uint8_t receive_update_data_mainCPU_variable_firmware(void); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
134 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2); |
38 | 135 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size); |
136 static uint8_t openComm(uint8_t aRxByte); | |
137 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence); | |
138 uint8_t prompt4D4C(uint8_t mode); | |
139 | |
140 #ifdef BOOTLOADER_STANDALONE | |
141 static uint8_t receive_update_data_cpu2(void); | |
142 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer); | |
143 #endif | |
144 | |
145 /* Exported functions --------------------------------------------------------*/ | |
146 | |
147 void tComm_init(void) | |
148 { | |
149 tCscreen.FBStartAdress = 0; | |
150 tCscreen.ImageHeight = 480; | |
151 tCscreen.ImageWidth = 800; | |
152 tCscreen.LayerIndex = 1; | |
153 | |
154 tCwindow.Image = &tCscreen; | |
155 tCwindow.WindowNumberOfTextLines = 6; | |
156 tCwindow.WindowLineSpacing = 65; | |
157 tCwindow.WindowTab = 400; | |
158 tCwindow.WindowX0 = 20; | |
159 tCwindow.WindowX1 = 779; | |
316
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
160 |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
161 |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
162 if(!settingsGetPointer()->FlipDisplay) |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
163 { |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
164 tCwindow.WindowY0 = 0; |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
165 tCwindow.WindowY1 = 479; |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
166 } |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
167 else |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
168 { |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
169 tCwindow.WindowY0 = 479 - 390; |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
170 tCwindow.WindowY1 = 479 - 25; |
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
171 } |
38 | 172 |
173 StartListeningToUART = 1; | |
174 } | |
175 | |
176 uint8_t tComm_control(void) | |
177 { | |
178 uint8_t answer = 0; | |
179 #ifndef BOOTLOADER_STANDALONE | |
180 | |
181 /* should do something like reset UART ... */ | |
182 if( settingsGetPointer()->bluetoothActive == 0) | |
183 { | |
184 if(bluetoothActiveLastTime) | |
185 { | |
396 | 186 HAL_UART_AbortReceive_IT(&UartHandle); |
38 | 187 HAL_UART_DeInit(&UartHandle); |
188 HAL_Delay(1); | |
396 | 189 UartHandle.Init.BaudRate = 115200; /* Module will be operating at default baud rate if powered again */ |
190 BmTmpConfig = BM_CONFIG_OFF; /* Restart configuration if powered again */ | |
38 | 191 HAL_UART_Init(&UartHandle); |
192 HAL_Delay(1); | |
193 UartReady = RESET; | |
194 StartListeningToUART = 1; | |
195 bluetoothActiveLastTime = 0; | |
196 receiveStartByteUart = 0; | |
396 | 197 RequestDisconnection = 0; |
38 | 198 } |
199 return 0; | |
200 } | |
201 else | |
202 { | |
203 bluetoothActiveLastTime = 1; | |
396 | 204 if(RequestDisconnection) |
205 { | |
206 RequestDisconnection = 0; | |
207 tComm_Disconnect(); | |
208 } | |
38 | 209 } |
210 | |
211 #endif | |
212 | |
396 | 213 if(BmTmpConfig != BM_CONFIG_DONE) |
214 { | |
215 tComm_HandleBlueModConfig(); | |
216 } | |
217 else | |
218 { | |
38 | 219 /*##-2- Put UART peripheral in reception process ###########################*/ |
220 | |
396 | 221 if((UartReady == RESET) && StartListeningToUART) |
222 { | |
223 StartListeningToUART = 0; | |
224 if(HAL_UART_Receive_IT(&UartHandle, &receiveStartByteUart, 1) != HAL_OK) | |
225 tComm_Error_Handler(); | |
226 } | |
227 /* Reset transmission flag */ | |
228 if(UartReady == SET) | |
229 { | |
230 UartReady = RESET; | |
231 if((receiveStartByteUart == BYTE_DOWNLOAD_MODE) || (receiveStartByteUart == BYTE_SERVICE_MODE)) | |
232 answer = openComm(receiveStartByteUart); | |
233 StartListeningToUART = 1; | |
234 return answer; | |
235 } | |
38 | 236 } |
237 return 0; | |
238 } | |
239 | |
240 | |
241 void tComm_refresh(void) | |
242 { | |
243 if(tCscreen.FBStartAdress == 0) | |
244 { | |
245 GFX_hwBackgroundOn(); | |
246 tCscreen.FBStartAdress = getFrame(18); | |
247 write_content_simple(&tCscreen, 0, 800, 480-24, &FontT24,"Exit",CLUT_ButtonSurfaceScreen); | |
396 | 248 write_content_simple(&tCscreen, 800 - 70, 800, 480-24, &FontT24,"Signal",CLUT_ButtonSurfaceScreen); |
249 | |
38 | 250 if(receiveStartByteUart == BYTE_SERVICE_MODE) |
251 GFX_write_string(&FontT48, &tCwindow, "Service mode enabled",2); | |
252 else | |
253 GFX_write_string(&FontT48, &tCwindow, "Download mode enabled",2); | |
166
255eedad4155
cleanup: get rid of some compile warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
138
diff
changeset
|
254 GFX_SetFramesTopBottom(tCscreen.FBStartAdress, 0,480); |
38 | 255 display_text[0] = 0; |
256 display_text[255] = 0; | |
257 } | |
258 else if(display_text[255]) | |
259 { | |
316
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
260 display_text[(uint8_t)display_text[255]] = 0; |
38 | 261 releaseFrame(18,tCscreen.FBStartAdress); |
262 tCscreen.FBStartAdress = getFrame(18); | |
263 write_content_simple(&tCscreen, 0, 800, 480-24, &FontT24,"Exit",CLUT_ButtonSurfaceScreen); | |
396 | 264 write_content_simple(&tCscreen, 800 - 70, 800, 480-24, &FontT24,"Signal",CLUT_ButtonSurfaceScreen); |
38 | 265 GFX_write_string(&FontT48, &tCwindow, display_text,2); |
266 GFX_SetFrameTop(tCscreen.FBStartAdress); | |
267 display_text[0] = 0; | |
268 display_text[255] = 0; | |
269 } | |
270 } | |
271 | |
272 | |
273 void tComm_verlauf(uint8_t percentage_complete) | |
274 { | |
275 uint32_t pDestination; | |
276 | |
277 pDestination = (uint32_t)tCscreen.FBStartAdress; | |
278 pDestination += 150 * tCscreen.ImageHeight * 2; | |
279 pDestination += 100 * 2; | |
280 | |
281 if(percentage_complete > 100) | |
282 percentage_complete = 100; | |
283 | |
284 int i = 1; | |
285 while(i<=percentage_complete) | |
286 { | |
287 i += 1; | |
288 for(int y=0;y<4;y++) | |
289 { | |
290 for(int x=0;x<40;x++) | |
291 { | |
292 *(__IO uint16_t*)pDestination = 0xFF00 + 00; | |
293 pDestination += 2; | |
294 } | |
295 pDestination += (tCscreen.ImageHeight - 40 )* 2; | |
296 } | |
297 pDestination += tCscreen.ImageHeight * 2; // one spare line | |
298 } | |
299 } | |
300 | |
301 | |
302 void tComm_exit(void) | |
303 { | |
304 SStateList status; | |
305 get_globalStateList(&status); | |
306 | |
307 releaseFrame(18,tCscreen.FBStartAdress); | |
308 tCscreen.FBStartAdress = 0; | |
309 GFX_hwBackgroundOff(); | |
310 | |
311 if(setForcedBluetoothName) | |
312 { | |
313 setForcedBluetoothName = 0; | |
314 MX_Bluetooth_PowerOff(); | |
315 HAL_Delay(1000); | |
316 MX_Bluetooth_PowerOn(); | |
317 tComm_Set_Bluetooth_Name(1); | |
396 | 318 tComm_StartBlueModConfig(); |
38 | 319 } |
320 #ifndef BOOTLOADER_STANDALONE | |
321 if(updateSettingsAndMenuOnExit) | |
322 { | |
323 check_and_correct_settings(); | |
324 createDiveSettings(); | |
325 tM_rebuild_menu_after_tComm(); | |
326 } | |
327 #endif | |
328 updateSettingsAndMenuOnExit = 0; | |
329 | |
330 if(status.base == BaseComm) | |
331 { | |
332 #ifndef BOOTLOADER_STANDALONE | |
333 set_globalState_tHome(); | |
334 #else | |
335 set_globalState_Base(); | |
336 #endif | |
337 } | |
462 | 338 settingsGetPointer()->bluetoothActive = 0; |
339 MX_Bluetooth_PowerOff(); // Power down Bluetooth on the way out | |
38 | 340 } |
341 | |
342 | |
343 uint8_t tComm_Set_Bluetooth_Name(uint8_t force) | |
344 { | |
345 uint8_t answer = 0; | |
346 | |
347 if(hardwareDataGetPointer()->secondarySerial != 0xFFFF) | |
348 { | |
349 if(force || (hardwareDataGetPointer()->secondary_bluetooth_name_set == 0xFF)) | |
350 answer = HW_Set_Bluetooth_Name(hardwareDataGetPointer()->secondarySerial, 0); | |
351 #ifdef BOOTLOADER_STANDALONE | |
352 if(answer == HAL_OK) | |
353 hardware_programmSecondaryBluetoothNameSet(); | |
354 #endif | |
355 } | |
356 else | |
357 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) | |
358 { | |
359 if(force || (hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF)) | |
360 answer = HW_Set_Bluetooth_Name(hardwareDataGetPointer()->primarySerial, 0); | |
361 #ifdef BOOTLOADER_STANDALONE | |
362 if(answer == HAL_OK) | |
363 hardware_programmPrimaryBluetoothNameSet(); | |
364 #endif | |
365 } | |
366 return answer; | |
367 } | |
368 | |
369 | |
370 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence) | |
371 { | |
372 uint8_t answer = HAL_OK; | |
373 uint8_t aRxBuffer[50]; | |
374 | |
375 // char aTxFactoryDefaults[50] = "AT&F1\r"; | |
376 | |
377 char aTxBufferEscapeSequence[50] = "+++"; | |
378 // limit is 19 chars, with 7 chars shown in BLE advertising mode | |
379 //________________________123456789012345678901 | |
380 char aTxBufferName[50] = "AT+BNAME=OSTC4-12345\r"; | |
396 | 381 char answerOkay[6] = "\r\nOK\r\n"; |
38 | 382 |
383 gfx_number_to_string(5,1,&aTxBufferName[15],serial); | |
384 | |
385 // store active configuration in non-volatile memory | |
386 char aTxBufferWrite[50] = "AT&W\r"; | |
387 | |
388 // char aTxBufferReset[50] = "AT+RESET\r"; | |
389 | |
390 | |
391 HAL_Delay(1010); | |
392 if(withEscapeSequence) | |
393 { | |
394 aRxBuffer[0] = 0; | |
395 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000)!= HAL_OK) | |
396 answer = HAL_ERROR; | |
397 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 3, 2000); | |
398 HAL_Delay(1010); | |
399 | |
400 for(int i=0;i<3;i++) | |
401 if(aRxBuffer[i] != '+') | |
402 answer = HAL_ERROR; | |
403 } | |
404 | |
405 aRxBuffer[0] = 0; | |
406 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferName, 21, 2000)!= HAL_OK) | |
407 answer = HAL_ERROR; | |
408 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 21+6, 2000); | |
409 | |
410 for(int i=0;i<21;i++) | |
411 if(aRxBuffer[i] != aTxBufferName[i]) | |
412 answer = HAL_ERROR; | |
413 | |
414 for(int i=0;i<6;i++) | |
415 if(aRxBuffer[21+i] != answerOkay[i]) | |
416 answer = HAL_ERROR; | |
417 | |
418 HAL_Delay(200); | |
419 | |
420 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferWrite, 5, 2000)!= HAL_OK) | |
421 answer = HAL_ERROR; | |
422 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5+6, 2000); | |
423 | |
424 for(int i=0;i<5;i++) | |
425 if(aRxBuffer[i] != aTxBufferWrite[i]) | |
426 answer = HAL_ERROR; | |
427 | |
428 for(int i=0;i<6;i++) | |
429 if(aRxBuffer[5+i] != answerOkay[i]) | |
430 answer = HAL_ERROR; | |
431 | |
432 answer = HAL_OK; | |
433 return answer; | |
434 } | |
435 | |
396 | 436 void tComm_Disconnect() |
437 { | |
438 uint8_t answer; | |
439 uint8_t retrycnt = 3; | |
440 char aTxDisconnect[] ="ATH\r"; | |
441 char aTxBufferEnd[] = "ATO\r"; | |
442 char aTxBufferEscapeSequence[] = "+++"; | |
443 | |
444 uint8_t sizeDisconnect = sizeof(aTxDisconnect) -1; | |
445 | |
446 HAL_UART_AbortReceive_IT(&UartHandle); | |
447 do | |
448 { | |
449 HAL_Delay(200); | |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
450 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) |
396 | 451 { |
452 answer = tComm_CheckAnswerOK(); | |
453 } | |
454 retrycnt--; | |
455 } | |
456 while((answer != HAL_OK) && (retrycnt > 0)); | |
457 | |
458 if(answer == HAL_OK) | |
459 { | |
460 answer = HAL_ERROR; | |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
461 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , UART_OPERATION_TIMEOUT)== HAL_OK) |
396 | 462 { |
463 answer = HAL_ERROR; | |
464 if(tComm_CheckAnswerOK() == HAL_OK) | |
465 { | |
466 answer = HAL_ERROR; | |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
467 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, UART_OPERATION_TIMEOUT) == HAL_OK) /* exit terminal mode */ |
396 | 468 { |
469 answer = tComm_CheckAnswerOK(); | |
470 } | |
471 } | |
472 } | |
473 } | |
474 | |
475 if(answer != HAL_OK) /* we are somehow not able to do a clean disconnect => fallback to "previous" power off implementation" */ | |
476 { | |
477 settingsGetPointer()->bluetoothActive = 0; | |
478 MX_Bluetooth_PowerOff(); | |
479 } | |
480 } | |
481 | |
38 | 482 |
483 uint8_t openComm(uint8_t aRxByte) | |
484 { | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
485 SStateList status; |
396 | 486 uint8_t localRx; |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
487 uint8_t timeoutCounter = 0; |
38 | 488 uint8_t answer = 0; |
489 uint8_t service_mode_last_three_bytes[3]; | |
490 uint8_t service_mode_response[5] = | |
491 { | |
492 0x4B, | |
493 0xAB, | |
494 0xCD, | |
495 0xEF, | |
496 0x4C | |
497 }; | |
498 uint8_t download_mode_response[2] = | |
499 { | |
500 0xBB, | |
501 0x4D | |
502 }; | |
503 | |
504 if((aRxByte != BYTE_DOWNLOAD_MODE) && (aRxByte != BYTE_SERVICE_MODE)) | |
505 return 0; | |
506 | |
507 set_globalState(StUART_STANDARD); | |
508 | |
509 /* service mode is four bytes | |
510 0xAA 0xAB 0xCD 0xEF | |
511 answer is | |
512 */ | |
396 | 513 localRx = aRxByte; |
38 | 514 |
515 if(aRxByte == BYTE_SERVICE_MODE) | |
516 { | |
517 if((HAL_UART_Receive(&UartHandle, (uint8_t*)service_mode_last_three_bytes, 3, 2000)!= HAL_OK)) | |
518 answer = 0x00; | |
519 else | |
520 { | |
521 if((service_mode_last_three_bytes[0] != 0xAB) || (service_mode_last_three_bytes[1] != 0xCD) || (service_mode_last_three_bytes[2] != 0xEF)) | |
522 answer = 0x00; | |
523 else | |
524 { | |
525 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)service_mode_response, 5, 2000)!= HAL_OK) | |
526 answer = 0x00; | |
527 else | |
528 answer = prompt4D4C(receiveStartByteUart); | |
529 } | |
530 } | |
531 } | |
532 else //if(aRxByte == BYTE_SERVICE_MODE) | |
533 { | |
534 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)download_mode_response, 2, 2000)!= HAL_OK) | |
535 answer = 0x00; | |
536 else | |
537 answer = prompt4D4C(receiveStartByteUart); | |
538 } | |
396 | 539 |
540 while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS)) /* try receive once a second */ | |
38 | 541 { |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
542 if(HAL_UART_Receive(&UartHandle, (uint8_t*)&localRx, 1, UART_OPERATION_TIMEOUT)!= HAL_OK) |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
543 { |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
544 timeoutCounter++; |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
545 get_globalStateList(&status); |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
546 if (status.base != BaseComm) |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
547 { |
396 | 548 timeoutCounter = UART_TIMEOUT_SECONDS; /* Abort action triggered outside main loop => exit */ |
549 } | |
550 if(EvaluateBluetoothSignalStrength) | |
551 { | |
552 tComm_EvaluateBluetoothStrength(); | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
553 } |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
554 } |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
555 else |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
556 { |
396 | 557 answer = select_mode(localRx); |
558 timeoutCounter = 0; | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
559 } |
38 | 560 } |
561 set_returnFromComm(); | |
562 return 1; | |
563 } | |
564 | |
565 | |
566 uint8_t prompt4D4C(uint8_t mode) | |
567 { | |
568 if(mode == BYTE_SERVICE_MODE) | |
569 return 0x4C; | |
570 else | |
571 return 0x4D; | |
572 } | |
573 | |
574 | |
575 uint8_t select_mode(uint8_t type) | |
576 { | |
577 #ifndef BOOTLOADER_STANDALONE | |
578 SLogbookHeader logbookHeader; | |
579 SLogbookHeaderOSTC3 * plogbookHeaderOSTC3; | |
580 SLogbookHeaderOSTC3compact * plogbookHeaderOSTC3compact; | |
581 uint32_t sampleTotalLength; | |
582 SSettings* pSettings = settingsGetPointer(); | |
583 RTC_DateTypeDef sdatestructure; | |
584 RTC_TimeTypeDef stimestructure; | |
585 #else | |
586 uint8_t dummyForBootloader[256] = {0}; | |
587 #endif | |
588 uint8_t count; | |
589 uint8_t aTxBuffer[128]; | |
590 uint8_t aRxBuffer[68]; | |
591 uint8_t answer; | |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
592 uint16_t index; |
38 | 593 aTxBuffer[0] = type; |
594 aTxBuffer[1] = prompt4D4C(receiveStartByteUart); | |
595 uint8_t tempHigh, tempLow; | |
596 count = 0; | |
597 | |
598 // service mode only commands | |
599 if(receiveStartByteUart == BYTE_SERVICE_MODE) | |
600 { | |
601 // first part | |
602 switch(type) | |
603 { | |
604 // start communication (again) | |
605 case 0xAA: | |
606 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 2, 1000)!= HAL_OK) | |
607 return 0; | |
608 else | |
609 return prompt4D4C(receiveStartByteUart); | |
610 | |
611 /* | |
612 // update firmware main preparation | |
613 case 0x74: | |
614 ext_flash_erase_firmware_if_not_empty(); | |
615 break; | |
616 | |
617 // update firmware main with variable full access memory location preparation | |
618 case 0x76: | |
619 ext_flash_erase_firmware2_if_not_empty(); | |
620 break; | |
621 */ | |
622 default: | |
623 break; | |
624 } | |
625 | |
626 #ifndef BOOTLOADER_STANDALONE | |
627 uint32_t logCopyDataPtr = 0; | |
628 convert_Type logCopyDataLength; | |
629 uint32_t logCopyDataPtrTemp = 0; | |
630 uint32_t logCopyDataLengthTemp = 0; | |
631 uint8_t logDummyByte = 0; | |
632 uint8_t logStepBackwards = 0; | |
633 convert16_Type totalDiveCount; | |
634 logCopyDataLength.u32bit = 0; | |
635 totalDiveCount.u16bit = 0; | |
636 #endif | |
637 | |
399
523892f62ce0
Revert change to keep connection open in case of BlueMod messages:
ideenmodellierer
parents:
398
diff
changeset
|
638 // Exit communication on Text like RING, CONNECT, ... or 0xFF command |
523892f62ce0
Revert change to keep connection open in case of BlueMod messages:
ideenmodellierer
parents:
398
diff
changeset
|
639 if((type < 0x60) || (type == 0xFF)) |
523892f62ce0
Revert change to keep connection open in case of BlueMod messages:
ideenmodellierer
parents:
398
diff
changeset
|
640 return 0; |
523892f62ce0
Revert change to keep connection open in case of BlueMod messages:
ideenmodellierer
parents:
398
diff
changeset
|
641 |
38 | 642 // return of command for (almost) all commands |
643 switch(type) | |
644 { | |
645 // not supported yet case 0x20: // send hi:lo:temp1 bytes starting from ext_flash_address:3 | |
646 // not supported yet case 0x22: // Resets all logbook pointers and the logbook (!) | |
647 // not supported yet case 0x23: // Resets battery gauge registers | |
648 // not supported yet case 0x30: // write bytes starting from ext_flash_address:3 (Stop when timeout) | |
649 // not supported yet case 0x40: // erases 4kB block from ext_flash_address:3 (Warning: No confirmation or built-in security here...) | |
650 // not supported yet case 0x42: // erases range in 4kB steps (Get 3 bytes address and 1byte amount of 4kB blocks) | |
651 // not supported yet case 0x50: // sends firmware from external flash from 0x3E0000 to 0x3FD000 (118784bytes) via comm | |
652 case 0xFE: // hw unit_tests | |
653 case 0x71: // hw read manufacturing data | |
654 case 0x73: // hw update FLEX | |
655 case 0x79: // hw read device data | |
656 #ifdef BOOTLOADER_STANDALONE | |
657 case 0x74: // hw update Firmware | |
658 case 0x75: // hw update RTE | |
659 case 0x76: // hw update Fonts | |
660 case 0x80: // hw write manufacturing data | |
661 case 0x81: // hw write second serial | |
662 case 0x82: // hw set bluetooth name | |
663 #else | |
664 case 0x83: // hw copy logbook entry - read | |
665 case 0x84: // hw copy logbook entry - write | |
666 case 0x85: // hw read entire logbook memory | |
667 case 0x86: // hw overwrite entire logbook memory | |
668 case 0x87: // hw ext_flash_repair_SPECIAL_dive_numbers_starting_count_with memory(x) | |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
669 case 0x88: /* read entire sample memory */ |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
670 case 0x89: /* write entire sample memory */ |
38 | 671 |
672 #endif | |
673 case 0xC1: // Start low-level bootloader | |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
674 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, UART_OPERATION_TIMEOUT)!= HAL_OK) |
38 | 675 return 0; |
676 break; | |
677 default: | |
678 break; | |
679 } | |
680 | |
681 // now send content or update firmware | |
682 switch(type) | |
683 { | |
684 case 0xFE: | |
685 // work to do :-) 12. Oct. 2015 | |
686 // 256 bytes output | |
687 memset(aTxBuffer,0,128); | |
688 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
689 return 0; | |
690 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
691 return 0; | |
692 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
693 break; | |
694 | |
695 case 0x71: | |
696 memcpy(aTxBuffer,hardwareDataGetPointer(),64); | |
697 count += 64; | |
698 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
699 break; | |
700 | |
701 case 0x73: | |
702 #ifndef BOOTLOADER_STANDALONE | |
703 answer = receive_update_flex(1); | |
704 #else | |
705 answer = receive_update_flex(0); | |
706 #endif | |
707 if(answer == 0) | |
708 return 0; | |
709 else if(answer == 2) // 2 = RTE without bootToBootloader | |
710 { | |
711 aTxBuffer[0] = 0xFF; | |
712 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000); | |
713 return 0; | |
714 } | |
715 else | |
716 { | |
717 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
718 if(answer == 1) /* 0xFF is checksum error, 2 = RTE without bootToBootloader */ | |
719 { | |
720 extern uint8_t bootToBootloader; | |
721 bootToBootloader = 1; | |
722 } | |
723 } | |
724 break; | |
725 | |
726 case 0x79: | |
727 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000)!= HAL_OK) | |
728 return 0; | |
729 ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(aTxBuffer); | |
730 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
731 return 0; | |
732 aTxBuffer[0] = prompt4D4C(receiveStartByteUart); | |
733 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000)!= HAL_OK) | |
734 return 0; | |
735 else | |
736 return prompt4D4C(receiveStartByteUart); | |
737 | |
738 case 0x82: | |
739 #ifdef BOOTLOADER_STANDALONE | |
740 setForcedBluetoothName = 1; | |
741 return 0; | |
742 #else | |
743 settingsGetPointer()->debugModeOnStart = 1; | |
744 extern uint8_t bootToBootloader; | |
745 bootToBootloader = 1; | |
746 return prompt4D4C(receiveStartByteUart); | |
747 #endif | |
748 | |
749 #ifdef BOOTLOADER_STANDALONE | |
750 case 0x74: | |
751 answer = receive_update_data_mainCPU_firmware(); | |
752 if(answer != 0) | |
753 { | |
754 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
755 if(answer == 1) // 0xFF is checksum error | |
756 { | |
757 extern uint8_t bootToBootloader; | |
758 bootToBootloader = 1; | |
759 } | |
760 } | |
761 else | |
762 return 0; | |
763 break; | |
764 | |
765 case 0x75: | |
766 receive_update_data_cpu2(); | |
767 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
768 break; | |
769 | |
770 case 0x76: | |
771 answer = receive_update_data_mainCPU_variable_firmware(); | |
772 if(answer != 0) | |
773 { | |
774 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
775 if(answer == 1) // 0xFF is checksum error | |
776 { | |
777 extern uint8_t bootToBootloader; | |
778 bootToBootloader = 1; | |
779 } | |
780 } | |
781 else | |
782 return 0; | |
783 break; | |
784 | |
785 case 0x80: | |
786 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 52, 5000)!= HAL_OK) | |
787 return 0; | |
788 if(hardware_programmProductionData(aRxBuffer) == HAL_OK) | |
789 { | |
790 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
791 } | |
792 else | |
793 return 0; | |
794 break; | |
795 | |
796 case 0x81: | |
797 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 12, 1000)!= HAL_OK) | |
798 return 0; | |
799 if(hardware_programmSecondarySerial(aRxBuffer) == HAL_OK) | |
800 { | |
801 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
802 } | |
803 else | |
804 return 0; | |
805 break; | |
806 | |
807 #else | |
808 | |
809 #ifdef SPECIALPROGRAMM | |
810 case 0x80: | |
811 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 52, 5000)!= HAL_OK) | |
812 return 0; | |
813 if(hardware_programmProductionData(aRxBuffer) == HAL_OK) | |
814 { | |
815 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
816 } | |
817 else | |
818 return 0; | |
819 break; | |
820 #endif | |
821 case 0x83: | |
822 if(HAL_UART_Receive(&UartHandle, &logStepBackwards, 1, 1000)!= HAL_OK) | |
823 return 0; | |
824 logCopyDataPtr = getFrame(98); | |
825 logCopyDataPtrTemp = logCopyDataPtr; | |
826 logCopyDataLength.u32bit = ext_flash_read_dive_raw_with_double_header_1K((uint8_t *)logCopyDataPtr, 1000000,logStepBackwards); | |
827 answer = HAL_OK; | |
828 if(answer == HAL_OK) | |
829 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteLow), 1,2000); | |
830 if(answer == HAL_OK) | |
831 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteMidLow), 1,2000); | |
832 if(answer == HAL_OK) | |
833 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteMidHigh), 1,2000); | |
834 if(answer == HAL_OK) | |
835 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteHigh), 1,2000); | |
836 logCopyDataLengthTemp = logCopyDataLength.u32bit; | |
837 while((logCopyDataLengthTemp >= 0xFFFF) && (answer == HAL_OK)) | |
838 { | |
839 answer = HAL_UART_Transmit(&UartHandle, (uint8_t *)logCopyDataPtrTemp, 0xFFFF,30000); | |
840 logCopyDataLengthTemp -= 0xFFFF; | |
841 logCopyDataPtrTemp += 0xFFFF; | |
842 } | |
843 if((logCopyDataLengthTemp > 0) && (answer == HAL_OK)) | |
844 answer = HAL_UART_Transmit(&UartHandle, (uint8_t *)logCopyDataPtrTemp, (uint16_t)logCopyDataLengthTemp,30000); | |
845 releaseFrame(98,logCopyDataPtr); | |
846 if(answer == HAL_OK) | |
847 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
848 else | |
849 return 0; | |
850 break; | |
851 | |
852 case 0x84: | |
853 logCopyDataPtr = getFrame(98); | |
854 logCopyDataPtrTemp = logCopyDataPtr; | |
855 answer = HAL_OK; | |
856 if(answer == HAL_OK) | |
857 answer = HAL_UART_Receive(&UartHandle, &logDummyByte, 1,2000); | |
858 if(answer == HAL_OK) | |
859 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteLow), 1,2000); | |
860 if(answer == HAL_OK) | |
861 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteMidLow), 1,2000); | |
862 if(answer == HAL_OK) | |
863 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteMidHigh), 1,2000); | |
864 if(answer == HAL_OK) | |
865 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteHigh), 1,2000); | |
866 logCopyDataLengthTemp = logCopyDataLength.u32bit; | |
867 while((logCopyDataLengthTemp >= 0xFFFF) && (answer == HAL_OK)) | |
868 { | |
869 answer = HAL_UART_Receive(&UartHandle, (uint8_t *)logCopyDataPtrTemp, 0xFFFF,30000); | |
870 logCopyDataLengthTemp -= 0xFFFF; | |
871 logCopyDataPtrTemp += 0xFFFF; | |
872 } | |
873 if((logCopyDataLengthTemp > 0) && (answer == HAL_OK)) | |
874 answer = HAL_UART_Receive(&UartHandle, (uint8_t *)logCopyDataPtrTemp, (uint16_t)logCopyDataLengthTemp,30000); | |
875 if(answer == HAL_OK) | |
876 ext_flash_write_dive_raw_with_double_header_1K((uint8_t *)logCopyDataPtr, logCopyDataLength.u32bit); | |
877 releaseFrame(98,logCopyDataPtr); | |
878 if(answer == HAL_OK) | |
879 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
880 else | |
881 return 0; | |
882 break; | |
883 | |
884 case 0x85: | |
885 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
886 logCopyDataPtr = getFrame(98); | |
887 ext_flash_read_header_memory((uint8_t *)logCopyDataPtr); | |
888 for(int i=0;i<8;i++) | |
889 HAL_UART_Transmit(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * i)), (uint16_t)0x8000,60000); | |
890 releaseFrame(98,logCopyDataPtr); | |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
891 #ifdef SEND_DATA_DETAILS |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
892 HAL_UART_Transmit(&UartHandle, (uint8_t*)&pSettings->lastDiveLogId, 1,60000); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
893 #endif |
38 | 894 break; |
895 | |
896 case 0x86: | |
897 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
898 logCopyDataPtr = getFrame(98); | |
899 for(int i=0;i<8;i++) | |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
900 { |
38 | 901 HAL_UART_Receive(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * i)), (uint16_t)0x8000,60000); |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
902 } |
38 | 903 ext_flash_write_header_memory((uint8_t *)logCopyDataPtr); |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
904 #ifdef SEND_DATA_DETAILS |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
905 if(HAL_UART_Receive(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * 8)), (uint16_t)0x01,60000) == HAL_OK) /* receive lastlogID */ |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
906 { |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
907 pSettings->lastDiveLogId = *(uint8_t*)(logCopyDataPtr + (0x40000)); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
908 } |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
909 #endif |
38 | 910 releaseFrame(98,logCopyDataPtr); |
911 break; | |
912 | |
913 case 0x87: | |
914 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 4, 1000)!= HAL_OK) | |
915 return 0; | |
916 if(((aRxBuffer[0] ^ aRxBuffer[2]) != 0xFF) || ((aRxBuffer[1] ^ aRxBuffer[3]) != 0xFF)) | |
917 return 0; | |
918 totalDiveCount.u8bit.byteLow = aRxBuffer[1]; | |
919 totalDiveCount.u8bit.byteHigh = aRxBuffer[0]; | |
920 ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(totalDiveCount.u16bit); | |
921 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
922 break; | |
464
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
923 case 0x88: |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
924 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
925 logCopyDataPtr = getFrame(98); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
926 |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
927 for(index = 0; index <384; index++) /* transmit in 32k blocks */ |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
928 { |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
929 ext_flash_read_sample_memory((uint8_t *)logCopyDataPtr, index); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
930 if(HAL_UART_Transmit(&UartHandle, (uint8_t *)(logCopyDataPtr), (uint16_t)0x8000,60000) != HAL_OK) |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
931 { |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
932 break; |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
933 } |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
934 } |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
935 releaseFrame(98,logCopyDataPtr); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
936 HAL_UART_Transmit(&UartHandle, (uint8_t*)&pSettings->logFlashNextSampleStartAddress, 4,60000); /* send next sample pos */ |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
937 break; |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
938 case 0x89: |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
939 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
940 logCopyDataPtr = getFrame(98); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
941 |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
942 for(index = 0; index <384; index++) /* transmit in 32k blocks 384*/ |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
943 { |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
944 |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
945 if(HAL_UART_Receive(&UartHandle, (uint8_t *)(logCopyDataPtr), (uint16_t)0x8000,60000) != HAL_OK) |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
946 { |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
947 break; |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
948 } |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
949 ext_flash_write_sample_memory((uint8_t *)logCopyDataPtr, index); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
950 } |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
951 |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
952 releaseFrame(98,logCopyDataPtr); |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
953 HAL_UART_Receive(&UartHandle, (uint8_t*)&pSettings->logFlashNextSampleStartAddress, 4,60000); /* send next sample pos */ |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
954 break; |
05c5c3d10902
Added compile switch to handle additional data during raw header request:
ideenmodellierer
parents:
462
diff
changeset
|
955 |
38 | 956 #endif |
957 } | |
958 | |
959 // was service command? Yes, finish and exit | |
960 if(count) | |
961 { | |
962 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
963 return 0; | |
964 else | |
965 return prompt4D4C(receiveStartByteUart); | |
966 } | |
967 } | |
968 | |
969 | |
970 // download mode commands | |
971 switch(type) | |
972 { | |
973 // return of command for almost all commands | |
974 case 0x60: // get model + features | |
975 case 0x61: // get all headers full (256 bytes) | |
976 case 0x62: // set clock | |
977 case 0x63: // set custom text | |
978 case 0x66: // get dive profile | |
979 case 0x69: // get serial, old version numbering, custom text | |
980 case 0x6A: // get model | |
981 case 0x6B: // get specific firmware version | |
396 | 982 case 0x6C: /* Display Bluetooth signal strength */ |
38 | 983 case 0x6D: // get all compact headers (16 byte) |
984 case 0x6E: // display text | |
985 case 0x70: // read min, default, max setting | |
986 case 0x72: // read setting | |
987 case 0x77: // write setting | |
988 case 0x78: // reset all settings | |
989 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) | |
990 return 0; | |
991 break; | |
992 | |
993 // start communication (again) | |
994 case 0xBB: | |
995 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 2, 1000)!= HAL_OK) | |
996 return 0; | |
997 else | |
998 return prompt4D4C(receiveStartByteUart); | |
999 | |
1000 // stop communication | |
1001 case 0xFF: | |
1002 HAL_UART_Transmit(&UartHandle, (uint8_t*)&aTxBuffer, 1, 1000); | |
1003 return 0; | |
1004 | |
1005 default: | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1006 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
38 | 1007 break; |
1008 } | |
1009 | |
1010 switch(type) | |
1011 { | |
1012 case 0x62: | |
1013 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 6, 2000)!= HAL_OK) | |
1014 return 0; | |
1015 break; | |
1016 case 0x63: | |
1017 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 60, 5000)!= HAL_OK) | |
1018 return 0; | |
1019 break; | |
1020 case 0x66: | |
1021 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 1000)!= HAL_OK) | |
1022 return 0; | |
1023 break; | |
1024 case 0x6B: | |
1025 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 1000)!= HAL_OK) | |
1026 return 0; | |
1027 break; | |
1028 case 0x6E: | |
1029 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 16, 5000)!= HAL_OK) | |
1030 return 0; | |
1031 break; | |
1032 case 0x77: | |
1033 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5, 5000)!= HAL_OK) | |
1034 return 0; | |
1035 break; | |
1036 case 0x72: | |
1037 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 5000)!= HAL_OK) | |
1038 return 0; | |
1039 break; | |
1040 case 0x70: | |
1041 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 5000)!= HAL_OK) | |
1042 return 0; | |
1043 break; | |
1044 } | |
1045 | |
1046 switch(type) | |
1047 { | |
1048 /* common to standard and bootloader */ | |
1049 | |
1050 // get model + features | |
1051 case 0x60: | |
1052 aTxBuffer[count++] = 0x00; // hardware descriptor HIGH byte | |
1053 aTxBuffer[count++] = 0x3B; // hardware descriptor LOW byte // 0x3B is OSTC4 // 0x1A is OTSC3 | |
1054 aTxBuffer[count++] = 0x00; // feature descriptor HIGH byte | |
138 | 1055 aTxBuffer[count++] = 0x00; // feature descriptor LOW byte |
38 | 1056 aTxBuffer[count++] = 0x43; // model id |
1057 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1058 break; | |
1059 | |
1060 // get model | |
1061 case 0x6A: | |
1062 aTxBuffer[count++] = 0x3B; // 0x3B is OSTC4 // 0x1A is OTSC3 | |
1063 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1064 break; | |
1065 | |
1066 // get all firmware version and status (OSTC4 only) | |
1067 case 0x6B: | |
1068 switch(*aRxBuffer) | |
1069 { | |
1070 case 0xFF: | |
1071 // firmware | |
1072 aTxBuffer[count++] = firmwareDataGetPointer()->versionFirst; | |
1073 aTxBuffer[count++] = firmwareDataGetPointer()->versionSecond; | |
1074 aTxBuffer[count++] = firmwareDataGetPointer()->versionThird; | |
1075 aTxBuffer[count++] = firmwareDataGetPointer()->versionBeta; | |
1076 break; | |
1077 case 0xFE: | |
1078 // RTE | |
1079 getActualRTEandFONTversion(&tempHigh, &tempLow, 0, 0); // RTE | |
1080 aTxBuffer[count++] = tempHigh; | |
1081 aTxBuffer[count++] = tempLow; | |
1082 aTxBuffer[count++] = 0; | |
1083 aTxBuffer[count++] = 0; | |
1084 break; | |
1085 case 0x10: | |
1086 getActualRTEandFONTversion( 0, 0, &tempHigh, &tempLow); // font | |
1087 aTxBuffer[count++] = tempHigh; | |
1088 aTxBuffer[count++] = tempLow; | |
1089 aTxBuffer[count++] = 0; | |
1090 aTxBuffer[count++] = 0; | |
1091 break; | |
1092 default: | |
1093 // not supported | |
1094 aTxBuffer[count++] = 0xFF; | |
1095 aTxBuffer[count++] = 0xFF; | |
1096 aTxBuffer[count++] = 0xFF; | |
1097 aTxBuffer[count++] = 0xFF; | |
1098 break; | |
1099 /* Jef Driesen Test | |
1100 default: | |
1101 // not supported | |
1102 aTxBuffer[count++] = 0x1; | |
1103 aTxBuffer[count++] = 0x1; | |
1104 aTxBuffer[count++] = 0x1; | |
1105 aTxBuffer[count++] = 0x1; | |
1106 break; | |
1107 */ | |
1108 } | |
1109 /* | |
1110 // serial | |
1111 aTxBuffer[count++] = pSettings->serialLow; | |
1112 aTxBuffer[count++] = pSettings->serialHigh; | |
1113 // batch code (date) | |
1114 hardwareBatchCode(&tempHigh, &tempLow); | |
1115 aTxBuffer[count++] = tempLow; | |
1116 aTxBuffer[count++] = tempHigh; | |
1117 // status and status detail (future feature) | |
1118 aTxBuffer[count++] = 0; | |
1119 aTxBuffer[count++] = 0; | |
1120 aTxBuffer[count++] = 0; | |
1121 aTxBuffer[count++] = 0; | |
1122 */ | |
1123 // prompt | |
1124 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1125 break; | |
1126 | |
396 | 1127 /* Trigger Bluetooth signal strength evaluation */ |
1128 case 0x6C: tComm_EvaluateBluetoothStrength(); | |
1129 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1130 break; | |
38 | 1131 // display text |
1132 case 0x6E: | |
1133 for(int i=0;i<16;i++) | |
1134 display_text[i] = aRxBuffer[i]; | |
1135 display_text[15] = 0; | |
1136 display_text[255] = 16; | |
1137 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1138 break; | |
1139 | |
1140 // version / identify | |
1141 case 0x69: | |
1142 #ifndef BOOTLOADER_STANDALONE | |
1143 aTxBuffer[count++] = pSettings->serialLow; | |
1144 aTxBuffer[count++] = pSettings->serialHigh; | |
1145 aTxBuffer[count++] = firmwareVersion_16bit_low(); | |
1146 aTxBuffer[count++] = firmwareVersion_16bit_high(); | |
1147 memcpy(&aTxBuffer[count], pSettings->customtext, 60); | |
1148 #else | |
1149 aTxBuffer[count++] = 0;//pSettings->serialLow; | |
1150 aTxBuffer[count++] = 0;//pSettings->serialHigh; | |
1151 aTxBuffer[count++] = 0;//firmwareVersion_16bit_low(); | |
1152 aTxBuffer[count++] = 0;//firmwareVersion_16bit_high(); | |
1153 memset(&aTxBuffer[count], 0, 60); | |
1154 #endif | |
1155 count += 60; | |
1156 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1157 break; | |
1158 | |
1159 #ifndef BOOTLOADER_STANDALONE | |
1160 //Reset all setting | |
1161 case 0x78: | |
1162 set_settings_to_Standard(); | |
1163 updateSettingsAndMenuOnExit = 1; | |
1164 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1165 break; | |
1166 #endif | |
1167 | |
1168 #ifndef BOOTLOADER_STANDALONE | |
1169 // full headers (256 byte) | |
1170 case 0x61: | |
1171 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
1172 { | |
1173 logbook_getHeader(StepBackwards, &logbookHeader); | |
1174 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
1175 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
1176 return 0; | |
1177 } | |
1178 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1179 break; | |
1180 | |
1181 // compact headers (16 byte) | |
1182 case 0x6D: | |
1183 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
1184 { | |
1185 logbook_getHeader(StepBackwards, &logbookHeader); | |
1186 plogbookHeaderOSTC3compact = logbook_build_ostc3header_compact(&logbookHeader); | |
1187 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3compact, 16,5000)!= HAL_OK) | |
1188 return 0; | |
1189 } | |
1190 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1191 break; | |
1192 | |
1193 // set clock & date | |
1194 case 0x62: | |
1195 // ToDo | |
1196 stimestructure.Hours = aRxBuffer[0]; | |
1197 stimestructure.Minutes = aRxBuffer[1]; | |
1198 stimestructure.Seconds = aRxBuffer[2]; | |
1199 sdatestructure.Month = aRxBuffer[3]; | |
1200 sdatestructure.Date = aRxBuffer[4]; | |
1201 sdatestructure.Year = aRxBuffer[5]; // This parameter must be a number between Min_Data = 0 and Max_Data = 99 | |
1202 setWeekday(&sdatestructure); | |
1203 | |
1204 if( ( stimestructure.Hours < 24 ) | |
1205 &&( stimestructure.Minutes < 60 ) | |
1206 &&( stimestructure.Seconds < 60 ) | |
1207 &&( sdatestructure.Month < 13 ) | |
1208 &&( sdatestructure.Date < 32 ) | |
1209 &&( sdatestructure.Year < 100 )) | |
1210 { | |
1211 setTime(stimestructure); | |
1212 setDate(sdatestructure); | |
1213 set_globalState(StUART_RTECONNECT); | |
1214 HAL_Delay(1); | |
1215 set_globalState(StUART_STANDARD); | |
1216 } | |
1217 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1218 break; | |
1219 | |
1220 case 0x63: | |
1221 for(int i=0;i<60;i++) | |
1222 pSettings->customtext[i] = aRxBuffer[i]; | |
1223 pSettings->customtext[59] = 0; | |
1224 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1225 break; | |
1226 | |
1227 // get dive profile | |
1228 case 0x66: | |
1229 logbook_getHeader(255 - aRxBuffer[0], &logbookHeader); | |
1230 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
1231 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
1232 return 0; | |
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1233 |
458 | 1234 if((logbookHeader.pBeginProfileData[0]==0) /* no sample information */ |
1235 && (logbookHeader.pBeginProfileData[1]==0) | |
1236 && (logbookHeader.pBeginProfileData[2]==0)) | |
38 | 1237 { |
458 | 1238 sampleTotalLength = logbook_fillDummySampleBuffer(&logbookHeader); |
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1239 while(sampleTotalLength >= 128) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1240 { |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1241 logbook_readDummySamples(aTxBuffer,128); |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1242 sampleTotalLength -= 128; |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1243 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1244 return 0; |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1245 } |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1246 if(sampleTotalLength) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1247 { |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1248 logbook_readDummySamples(aTxBuffer,sampleTotalLength); |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1249 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, sampleTotalLength,5000)!= HAL_OK) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1250 return 0; |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1251 } |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1252 |
38 | 1253 } |
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1254 else |
38 | 1255 { |
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1256 ext_flash_open_read_sample(255 - aRxBuffer[0], &sampleTotalLength); |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1257 while(sampleTotalLength >= 128) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1258 { |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1259 ext_flash_read_next_sample_part(aTxBuffer,128); |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1260 sampleTotalLength -= 128; |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1261 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1262 return 0; |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1263 } |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1264 if(sampleTotalLength) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1265 { |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1266 ext_flash_read_next_sample_part(aTxBuffer,sampleTotalLength); |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1267 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, sampleTotalLength,5000)!= HAL_OK) |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1268 return 0; |
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1269 } |
38 | 1270 } |
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1271 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
38 | 1272 break; |
1273 | |
1274 // read min,default,max setting | |
1275 case 0x70: | |
1276 count += readDataLimits__8and16BitValues_4and7BytesOutput(aRxBuffer[0],&aTxBuffer[count]); | |
1277 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1278 break; | |
1279 | |
1280 // read setting | |
1281 case 0x72: | |
1282 readData(aRxBuffer[0],&aTxBuffer[count]); | |
1283 count += 4; | |
1284 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1285 break; | |
1286 | |
1287 // write setting | |
1288 case 0x77: | |
1289 writeData(aRxBuffer); | |
1290 updateSettingsAndMenuOnExit = 1; | |
1291 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1292 break; | |
1293 #else | |
1294 /* bootloader dummies */ | |
1295 // full headers (256 byte) | |
1296 case 0x61: | |
1297 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
1298 { | |
1299 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
1300 return 0; | |
1301 } | |
1302 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1303 break; | |
1304 // compact headers (16 byte) | |
1305 case 0x6D: | |
1306 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
1307 { | |
1308 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 16,5000)!= HAL_OK) | |
1309 return 0; | |
1310 } | |
1311 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1312 break; | |
1313 // set clock & date | |
1314 case 0x62: | |
1315 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1316 break; | |
1317 // set custom text | |
1318 case 0x63: | |
1319 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1320 break; | |
1321 // get dive profile | |
1322 case 0x66: | |
1323 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
1324 return 0; | |
1325 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1326 break; | |
1327 // read min,default,max setting | |
1328 // read settings | |
1329 | |
1330 | |
1331 case 0x72: | |
1332 memcpy(&aTxBuffer[count], dummyForBootloader, 4); | |
1333 count += 4; | |
1334 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1335 break; | |
1336 // write settings | |
1337 case 0x77: | |
1338 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1339 break; | |
1340 #endif | |
1341 } | |
1342 | |
1343 if(count) | |
1344 { | |
1345 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
1346 return 0; | |
1347 else | |
1348 return prompt4D4C(receiveStartByteUart); | |
1349 } | |
1350 return 0; | |
1351 } | |
1352 | |
396 | 1353 #define BLOCKSIZE 0x1000 |
38 | 1354 |
1355 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size) | |
1356 { | |
396 | 1357 uint16_t length_4k_blocks; |
1358 uint16_t length_4k_remainder; | |
38 | 1359 uint32_t temp; |
1360 HAL_StatusTypeDef result = HAL_OK; | |
1361 uint32_t pDataLocal; | |
1362 | |
396 | 1363 length_4k_blocks = (uint16_t) (Size / BLOCKSIZE); |
1364 temp = length_4k_blocks; | |
1365 temp *= BLOCKSIZE; | |
1366 length_4k_remainder = (uint16_t) ( Size - temp); | |
38 | 1367 |
1368 pDataLocal = (uint32_t)pData; | |
1369 | |
316
4da2bffb07ca
Bugfix text display in update mode (flipped display) and reduction of timeout in case of a failed firmware update
ideenmodellierer
parents:
236
diff
changeset
|
1370 |
396 | 1371 while((result == HAL_OK) && length_4k_blocks) |
38 | 1372 { |
396 | 1373 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, BLOCKSIZE , UART_TIMEOUT_LARGE_BLOCK); |
1374 pDataLocal += BLOCKSIZE; | |
1375 length_4k_blocks--; | |
38 | 1376 } |
396 | 1377 |
1378 if((result == HAL_OK) && length_4k_remainder) | |
38 | 1379 { |
396 | 1380 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, length_4k_remainder , UART_TIMEOUT_LARGE_BLOCK); |
38 | 1381 } |
1382 return result; | |
1383 } | |
1384 | |
1385 | |
1386 /* for safety reason (memory blocking this code is main and sub */ | |
1387 | |
1388 #ifdef BOOTLOADER_STANDALONE | |
1389 | |
1390 uint8_t receive_update_data_cpu2(void) | |
1391 { | |
1392 uint8_t answer; | |
1393 | |
1394 uint8_t* pBuffer = (uint8_t*)getFrame(20); | |
1395 answer = receive_update_data_cpu2_sub(pBuffer); | |
1396 releaseFrame(20,(uint32_t)pBuffer); | |
1397 return answer; | |
1398 } | |
1399 | |
1400 | |
1401 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer) | |
1402 { | |
1403 uint8_t sBuffer[10]; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1404 uint32_t length, offsetTotal, checksum, checksumCalc; |
38 | 1405 uint8_t id; |
1406 const uint8_t id_RTE = 0xFE; | |
1407 | |
1408 //Get length | |
1409 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
1410 { | |
1411 return 0; | |
1412 } | |
1413 length = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
1414 | |
1415 //Get id | |
1416 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
1417 { | |
1418 return 0; | |
1419 } | |
1420 id = pBuffer[0]; | |
1421 offsetTotal = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
1422 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1423 // get checksum, bytes are in different order on Dev C++ code!!! |
38 | 1424 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
1425 { | |
1426 return 0; | |
1427 } | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1428 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1429 checksumCalc = length + offsetTotal; |
38 | 1430 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1431 // no need to get code if checksum == length is wrong |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1432 if(checksumCalc != checksum) |
38 | 1433 { |
1434 return 0; | |
1435 } | |
1436 | |
1437 //get Code | |
1438 if(receive_uart_large_size(&UartHandle, pBuffer, length)!= HAL_OK) | |
1439 { | |
1440 return 0; | |
1441 } | |
1442 | |
1443 //get Checksum | |
1444 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 580000 | |
1445 { | |
1446 return 0; | |
1447 } | |
1448 uint32_t checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1449 // uint32_t checksumCalc = crc32c_checksum(pBuffer, length,0,0); | |
1450 uint32_t checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer, length/4); | |
1451 | |
1452 if(checksum != checksumCalc) | |
1453 { | |
1454 return 0; | |
1455 } | |
1456 | |
1457 if(id != id_RTE) | |
1458 { | |
1459 strcpy(display_text,"wrong data."); | |
1460 display_text[255] = 32; | |
1461 return 0; | |
1462 } | |
1463 | |
1464 strcpy(display_text," RTE update."); | |
1465 display_text[255] = 32; | |
1466 | |
1467 return extCPU2bootloader(pBuffer,length,display_text); | |
1468 } | |
1469 #endif // BOOTLOADER_STANDALONE | |
1470 | |
1471 | |
1472 | |
1473 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED) | |
1474 { | |
1475 uint8_t answer; | |
1476 | |
1477 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1478 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
1479 | |
1480 answer = receive_update_data_flex(pBuffer1, pBuffer2, isRTEupdateALLOWED); | |
1481 | |
1482 releaseFrame(20,(uint32_t)pBuffer1); | |
1483 releaseFrame(20,(uint32_t)pBuffer2); | |
1484 | |
1485 return answer; | |
1486 } | |
1487 | |
1488 uint8_t receive_update_data_mainCPU_firmware(void) | |
1489 { | |
1490 uint8_t answer; | |
1491 | |
1492 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1493 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1494 answer = receive_update_data_mainCPU_firmware_subroutine(1, pBuffer1, 0); |
38 | 1495 |
1496 releaseFrame(20,(uint32_t)pBuffer1); | |
1497 | |
1498 return answer; | |
1499 } | |
1500 | |
1501 /* multi buffer (long data) not tested yet */ | |
1502 uint8_t receive_update_data_mainCPU_variable_firmware(void) | |
1503 { | |
1504 uint8_t answer; | |
1505 | |
1506 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1507 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
1508 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1509 answer = receive_update_data_mainCPU_firmware_subroutine(2, pBuffer1, pBuffer2); |
38 | 1510 |
1511 releaseFrame(20,(uint32_t)pBuffer1); | |
1512 releaseFrame(20,(uint32_t)pBuffer2); | |
1513 | |
1514 return answer; | |
1515 } | |
1516 | |
1517 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED) | |
1518 { | |
1519 uint8_t sBuffer[10]; | |
1520 uint8_t serialBuffer[10]; | |
1521 uint32_t length1, length2, lengthCompare, offsetCompare, ByteCompareStatus; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1522 uint32_t lengthTotal, offsetTotal; |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1523 uint32_t checksum, checksumCalc = 0; |
38 | 1524 uint8_t id; |
1525 const uint8_t id_Region1_firmware = 0xFF; | |
1526 const uint8_t id_RTE = 0xFE; | |
1527 uint8_t textpointer = 0; | |
1528 | |
1529 //Get length | |
1530 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1531 { | |
1532 return 0; | |
1533 } | |
1534 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1535 | |
1536 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
1537 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1538 { | |
1539 return 0; | |
1540 } | |
1541 id = sBuffer[0]; | |
1542 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1543 checksumCalc = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1544 checksumCalc += lengthTotal; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1545 //old, does no longer work because of the fonts: checksumCalc = lengthTotal + offsetTotal; |
38 | 1546 |
1547 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
1548 { | |
1549 return 0; | |
1550 } | |
1551 | |
1552 // neu 110212 | |
1553 if(id == id_FONT) | |
1554 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
1555 else | |
1556 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1557 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1558 // get checksum, bytes are in different order on Dev C++ code!!! |
38 | 1559 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
1560 { | |
1561 return 0; | |
1562 } | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1563 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
38 | 1564 |
1565 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1566 if(checksumCalc != checksum) |
38 | 1567 { |
1568 uint8_t ptr = 0; | |
1569 strcpy(&display_text[ptr]," checksum error"); | |
1570 ptr += 15; | |
1571 strcpy(&display_text[ptr],"\n\r"); | |
1572 ptr += 2; | |
1573 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
1574 display_text[ptr] = 0; | |
1575 display_text[255] = ptr + 1; | |
1576 return 0xFF; | |
1577 } | |
1578 | |
1579 //Get serial (new since 160211) | |
1580 if(HAL_UART_Receive(&UartHandle, serialBuffer, 4,5000)!= HAL_OK) | |
1581 { | |
1582 return 0; | |
1583 } | |
1584 | |
1585 if(lengthTotal > 768000) | |
1586 { | |
1587 length1 = 768000; | |
1588 length2 = lengthTotal - length1; | |
1589 } | |
1590 else | |
1591 { | |
1592 length1 = lengthTotal; | |
1593 length2 = 0; | |
1594 } | |
1595 | |
1596 if((pBuffer2 == 0) && (length2 != 0)) | |
1597 return 0; | |
1598 | |
1599 //get Code | |
1600 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
1601 return 0; | |
1602 | |
1603 if(length2) | |
1604 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
1605 return 0; | |
1606 | |
1607 //get Checksum | |
1608 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1609 return 0; | |
1610 | |
1611 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1612 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
1613 if(length2) | |
1614 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
1615 else | |
1616 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
1617 | |
1618 /* check id now */ | |
1619 /* | |
1620 if(region == 2) | |
1621 { | |
1622 if((id == id_Region1_firmware) || (id == id_RTE)) | |
1623 { | |
1624 strcpy(display_text,"wrong data."); | |
1625 display_text[255] = 32; | |
1626 return 0; | |
1627 } | |
1628 } | |
1629 else | |
1630 { | |
1631 if(id != id_Region1_firmware) | |
1632 { | |
1633 strcpy(display_text,"wrong data."); | |
1634 display_text[255] = 32; | |
1635 return 0; | |
1636 } | |
1637 } | |
1638 */ | |
1639 /* test checksum */ | |
1640 if(checksum != checksumCalc) | |
1641 { | |
1642 uint8_t ptr = 0; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1643 strcpy(&display_text[ptr]," checksum error"); |
38 | 1644 ptr += 15; |
1645 strcpy(&display_text[ptr],"\n\r"); | |
1646 display_text[ptr] = 0; | |
1647 display_text[255] = ptr + 1; | |
1648 return 0xFF; | |
1649 } | |
1650 | |
1651 if(id == id_Region1_firmware) | |
1652 { | |
1653 uint8_t ptr = 0; | |
1654 display_text[ptr++] = 'V'; | |
1655 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
1656 display_text[ptr++] = '.'; | |
1657 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
1658 display_text[ptr++] = '.'; | |
1659 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
1660 display_text[ptr++] = ' '; | |
1661 if(pBuffer1[0x10003]) | |
1662 { | |
1663 strcpy(&display_text[ptr],"beta "); | |
1664 ptr +=5; | |
1665 } | |
1666 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1667 ptr += 25; |
38 | 1668 display_text[255] = ptr + 1; |
1669 } | |
1670 else if(id == id_RTE) | |
1671 { | |
1672 if(RTEupdateALLOWED) | |
1673 { | |
1674 strcpy(display_text," RTE update.\n\r"); | |
1675 textpointer = 0; | |
1676 while((display_text[textpointer] != 0) && (textpointer < 50)) | |
1677 textpointer++; | |
1678 #ifndef BOOTLOADER_STANDALONE | |
1679 if(textpointer < 50) | |
1680 { | |
1681 // display_text[textpointer++] = | |
1682 display_text[textpointer++] = '\025'; | |
1683 display_text[textpointer++] = TXT_2BYTE; | |
1684 display_text[textpointer++] = TXT2BYTE_DecoDataLost; | |
1685 display_text[textpointer] = 0; | |
1686 } | |
1687 #endif | |
1688 display_text[255] = textpointer+1; | |
1689 return extCPU2bootloader(pBuffer1,length1,display_text); | |
1690 } | |
1691 else | |
1692 return 0xFF; | |
1693 } | |
1694 else | |
1695 //if(region == 2) | |
1696 { | |
1697 uint8_t ptr = 0; | |
1698 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
1699 strcpy(&display_text[ptr]," bytes with "); | |
1700 ptr += 12; | |
1701 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
1702 strcpy(&display_text[ptr]," offset"); | |
1703 ptr += 7; | |
1704 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1705 ptr += 25; |
38 | 1706 display_text[255] = ptr + 1; |
1707 } | |
1708 | |
1709 | |
1710 // only non RTE !! | |
1711 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
1712 ByteCompareStatus = 0; | |
1713 | |
1714 if(id == id_Region1_firmware) | |
1715 { | |
1716 /* standard firmware limited to 768000 */ | |
1717 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
1718 ext_flash_erase_firmware(); | |
1719 ext_flash_write_firmware(pBuffer1, length1); | |
1720 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
1721 | |
1722 if(lengthCompare != length1) | |
1723 ByteCompareStatus = 10000; | |
1724 for(int i = 0; i < length1; i++) | |
1725 { | |
1726 if(pBuffer1[0] != pBufferCompare[0]) | |
1727 ByteCompareStatus++; | |
1728 } | |
1729 } | |
1730 else | |
1731 //if(region == 2) | |
1732 { | |
1733 /* upper region firmware can be larger (1MB) */ | |
1734 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
1735 ext_flash_erase_firmware2(); | |
1736 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
1737 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
1738 | |
1739 if(lengthCompare != length1 + length2) | |
1740 ByteCompareStatus = 10000; | |
1741 if(offsetTotal != offsetCompare) | |
1742 ByteCompareStatus += 20000; | |
1743 for(int i = 0; i < length1; i++) | |
1744 { | |
1745 if(pBuffer1[0] != pBufferCompare[0]) | |
1746 ByteCompareStatus++; | |
1747 } | |
1748 | |
1749 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
1750 for(int i = 0; i < length2; i++) | |
1751 { | |
1752 if(pBuffer2[0] != pBufferCompare[0]) | |
1753 ByteCompareStatus++; | |
1754 } | |
1755 } | |
1756 | |
1757 releaseFrame(20,(uint32_t)pBufferCompare); | |
1758 | |
1759 if(ByteCompareStatus != 0) | |
1760 { | |
1761 strcpy(&display_text[0],"\n\rcopy error."); | |
1762 display_text[255] = 21; | |
1763 return 0; | |
1764 } | |
1765 else | |
1766 { | |
1767 strcpy(&display_text[0],"\n\rready to install."); | |
1768 display_text[255] = 21; | |
1769 return 1; | |
1770 } | |
1771 } | |
1772 | |
1773 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1774 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2) |
38 | 1775 { |
1776 uint8_t sBuffer[10]; | |
1777 uint32_t length1, length2, lengthCompare, offsetCompare, ByteCompareStatus; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1778 uint32_t lengthTotal, offsetTotal, checksum, checksumCalc = 0; |
38 | 1779 uint8_t id; |
1780 | |
1781 //Get length | |
1782 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1783 return 0; | |
1784 | |
1785 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1786 | |
1787 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
1788 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1789 return 0; | |
1790 | |
1791 id = sBuffer[0]; | |
1792 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1793 checksumCalc = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1794 checksumCalc += lengthTotal; |
38 | 1795 |
1796 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
1797 return 0; | |
1798 | |
1799 if(id == id_FONT) | |
1800 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
1801 // alt, prior to id for font | |
1802 else | |
1803 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1804 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1805 // get checksum, bytes are in different order on Dev C++ code!!! |
38 | 1806 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
1807 return 0; | |
1808 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1809 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
38 | 1810 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1811 //old: checksumCalc = lengthTotal + offsetTotal; |
38 | 1812 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1813 if(checksumCalc != checksum) |
38 | 1814 { |
1815 uint8_t ptr = 0; | |
1816 strcpy(&display_text[ptr]," checksum error"); | |
1817 ptr += 15; | |
1818 strcpy(&display_text[ptr],"\n\r"); | |
1819 ptr += 2; | |
1820 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
1821 display_text[ptr] = 0; | |
1822 display_text[255] = ptr + 1; | |
1823 return 0xFF; | |
1824 } | |
1825 | |
1826 if(lengthTotal > 768000) | |
1827 { | |
1828 length1 = 768000; | |
1829 length2 = lengthTotal - length1; | |
1830 } | |
1831 else | |
1832 { | |
1833 length1 = lengthTotal; | |
1834 length2 = 0; | |
1835 } | |
1836 | |
1837 if((pBuffer2 == 0) && (length2 != 0)) | |
1838 return 0; | |
1839 | |
1840 //get Code | |
1841 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
1842 return 0; | |
1843 | |
1844 if(length2) | |
1845 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
1846 return 0; | |
1847 | |
1848 //get Checksum | |
1849 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1850 return 0; | |
1851 | |
1852 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1853 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
1854 if(length2) | |
1855 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
1856 else | |
1857 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
1858 | |
1859 /* check id now */ | |
1860 if(region == 2) | |
1861 { | |
1862 if((id == id_Region1_firmware) || (id == id_RTE)) | |
1863 { | |
1864 strcpy(display_text,"wrong data."); | |
1865 display_text[255] = 32; | |
1866 return 0; | |
1867 } | |
1868 } | |
1869 else | |
1870 { | |
1871 if(id != id_Region1_firmware) | |
1872 { | |
1873 strcpy(display_text,"wrong data."); | |
1874 display_text[255] = 32; | |
1875 return 0; | |
1876 } | |
1877 } | |
1878 | |
1879 /* test checksum */ | |
1880 if(checksum != checksumCalc) | |
1881 { | |
1882 uint8_t ptr = 0; | |
1883 strcpy(&display_text[ptr]," pruefsummen error"); | |
1884 ptr += 15; | |
1885 strcpy(&display_text[ptr],"\n\r"); | |
1886 display_text[ptr] = 0; | |
1887 display_text[255] = ptr + 1; | |
1888 return 0xFF; | |
1889 } | |
1890 | |
1891 if(region == 2) | |
1892 { | |
1893 uint8_t ptr = 0; | |
1894 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
1895 strcpy(&display_text[ptr]," bytes with "); | |
1896 ptr += 12; | |
1897 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
1898 strcpy(&display_text[ptr]," offset"); | |
1899 ptr += 7; | |
1900 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1901 ptr += 25; |
38 | 1902 display_text[255] = ptr + 1; |
1903 | |
1904 } | |
1905 else | |
1906 { | |
1907 uint8_t ptr = 0; | |
1908 display_text[ptr++] = 'V'; | |
1909 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
1910 display_text[ptr++] = '.'; | |
1911 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
1912 display_text[ptr++] = '.'; | |
1913 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
1914 display_text[ptr++] = ' '; | |
1915 if(pBuffer1[0x10003]) | |
1916 { | |
1917 strcpy(&display_text[ptr],"beta "); | |
1918 ptr +=5; | |
1919 } | |
1920 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1921 ptr += 25; |
38 | 1922 display_text[255] = ptr + 1; |
1923 } | |
1924 | |
1925 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
1926 ByteCompareStatus = 0; | |
1927 | |
1928 if(region == 2) | |
1929 { | |
1930 /* upper region firmware can be larger (1MB) */ | |
1931 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
1932 ext_flash_erase_firmware2(); | |
1933 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
1934 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
1935 | |
1936 if(lengthCompare != length1 + length2) | |
1937 ByteCompareStatus = 10000; | |
1938 if(offsetTotal != offsetCompare) | |
1939 ByteCompareStatus += 20000; | |
1940 for(int i = 0; i < length1; i++) | |
1941 { | |
1942 if(pBuffer1[0] != pBufferCompare[0]) | |
1943 ByteCompareStatus++; | |
1944 } | |
1945 | |
1946 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
1947 for(int i = 0; i < length2; i++) | |
1948 { | |
1949 if(pBuffer2[0] != pBufferCompare[0]) | |
1950 ByteCompareStatus++; | |
1951 } | |
1952 } | |
1953 else | |
1954 { | |
1955 /* standard firmware limited to 768000 */ | |
1956 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
1957 ext_flash_erase_firmware(); | |
1958 ext_flash_write_firmware(pBuffer1, length1); | |
1959 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
1960 | |
1961 if(lengthCompare != length1) | |
1962 ByteCompareStatus = 10000; | |
1963 for(int i = 0; i < length1; i++) | |
1964 { | |
1965 if(pBuffer1[0] != pBufferCompare[0]) | |
1966 ByteCompareStatus++; | |
1967 } | |
1968 } | |
1969 | |
1970 releaseFrame(20,(uint32_t)pBufferCompare); | |
1971 | |
1972 if(ByteCompareStatus != 0) | |
1973 { | |
1974 strcpy(&display_text[0],"\n\rcopy error."); | |
1975 display_text[255] = 21; | |
1976 return 0; | |
1977 } | |
1978 else | |
1979 { | |
1980 strcpy(&display_text[0],"\n\rready to install."); | |
1981 display_text[255] = 21; | |
1982 return 1; | |
1983 } | |
1984 } | |
1985 | |
396 | 1986 void tComm_RequestBluetoothStrength(void) |
1987 { | |
1988 EvaluateBluetoothSignalStrength = 1; | |
1989 } | |
1990 | |
1991 /* read, validate the modul answer and flush rx que if necessary */ | |
1992 uint8_t tComm_CheckAnswerOK() | |
1993 { | |
1994 char answerOkay[] = "\r\nOK\r\n"; | |
400 | 1995 char aRxBuffer[UART_CMD_BUF_SIZE]; |
396 | 1996 uint8_t sizeAnswer = sizeof(answerOkay) -1; |
1997 uint8_t result = HAL_OK; | |
1998 uint8_t index = 0; | |
1999 uint8_t answer; | |
2000 | |
400 | 2001 memset(aRxBuffer,0,UART_CMD_BUF_SIZE); |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
2002 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, UART_OPERATION_TIMEOUT) == HAL_OK) |
396 | 2003 { |
2004 do | |
2005 { | |
2006 if(answerOkay[index] != aRxBuffer[index]) | |
2007 { | |
2008 index = sizeAnswer; | |
2009 result = HAL_ERROR; /* unexpected answer => there might be characters left in RX que => read and discard all rx bytes */ | |
2010 do | |
2011 { | |
2012 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 10); | |
400 | 2013 if (index < UART_CMD_BUF_SIZE) |
2014 { | |
2015 index++; | |
2016 } | |
396 | 2017 }while(answer == HAL_OK); |
2018 index = sizeAnswer; | |
2019 } | |
2020 else | |
2021 { | |
2022 index++; | |
2023 } | |
2024 }while(index < sizeAnswer); | |
2025 } | |
2026 else | |
2027 { | |
2028 result = HAL_ERROR; | |
2029 } | |
2030 return result; | |
2031 | |
2032 } | |
400 | 2033 |
396 | 2034 |
2035 void tComm_EvaluateBluetoothStrength(void) | |
2036 { | |
2037 char aTxBufferBarSSI[] = "AT+BARSSI\r"; | |
2038 char aTxBufferEscapeSequence[] = "+++"; | |
2039 char aTxBufferEnd[] = "ATO\r"; | |
2040 uint8_t sizeRequest = sizeof(aTxBufferBarSSI) -1; | |
2041 | |
2042 uint8_t answer = HAL_OK; | |
400 | 2043 char aRxBuffer[UART_CMD_BUF_SIZE]; |
2044 char SignalStr[UART_CMD_BUF_SIZE]; | |
396 | 2045 uint8_t index = 0; |
2046 uint8_t strindex = 0; | |
2047 int8_t sigqual = 0; | |
2048 | |
2049 HAL_Delay(200); | |
2050 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000)== HAL_OK) | |
2051 { | |
2052 if(tComm_CheckAnswerOK() == HAL_OK) | |
2053 { | |
2054 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferBarSSI,sizeRequest , 2000); | |
2055 { | |
2056 index = 0; | |
2057 do /* Answer is not the common one. Instead the signal strength is received => read all available bytes one by one*/ | |
2058 { | |
2059 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 100); | |
400 | 2060 if(index < UART_CMD_BUF_SIZE) |
2061 { | |
2062 index++; | |
2063 } | |
396 | 2064 }while(answer == HAL_OK); |
2065 | |
2066 if((aRxBuffer[index] != 'E') && (aRxBuffer[index] != 0)) /* E represents the first letter of the string ERROR */ | |
2067 { | |
2068 index = 0; | |
2069 strindex = 0; | |
2070 do | |
2071 { | |
2072 SignalStr[strindex++] = aRxBuffer[index++]; | |
400 | 2073 }while ((index < UART_CMD_BUF_SIZE - 1) && (aRxBuffer[index] != '\r')); |
396 | 2074 SignalStr[strindex] = 0; /* terminate String */ |
2075 sigqual = strtol(SignalStr,NULL,0); | |
2076 /* Map db to abstract Bargraph */ | |
2077 if(sigqual > 0) | |
2078 { | |
400 | 2079 sprintf(SignalStr,"Bluetooth ||||||||"); |
396 | 2080 } |
2081 else | |
2082 { | |
2083 sprintf(SignalStr,"Bluetooth |"); | |
2084 strindex = strlen(SignalStr); | |
2085 sigqual *=-1; | |
2086 sigqual = 100 - sigqual; /* invert because of negative db value */ | |
2087 while(sigqual / 10 > 0 ) | |
2088 { | |
2089 SignalStr[strindex++] = '|'; | |
2090 sigqual -= 10; | |
2091 } | |
2092 SignalStr[strindex] = 0; | |
2093 } | |
2094 strcpy(display_text,SignalStr); | |
2095 display_text[255] = strlen(SignalStr); | |
2096 EvaluateBluetoothSignalStrength = 0; | |
2097 } | |
2098 } | |
2099 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, 2000); /* exit terminal mode */ | |
2100 index = 0; | |
2101 do /* module will answer with current connection state */ | |
2102 { | |
2103 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 100); | |
400 | 2104 if(index < UART_CMD_BUF_SIZE) |
2105 { | |
2106 index++; | |
2107 } | |
396 | 2108 }while(answer == HAL_OK); |
2109 } | |
2110 } | |
2111 } | |
2112 | |
2113 void tComm_StartBlueModConfig() | |
2114 { | |
2115 uint8_t answer = HAL_OK; | |
400 | 2116 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; |
396 | 2117 uint8_t index = 0; |
2118 | |
2119 BmTmpConfig = BM_CONFIG_ECHO; | |
2120 do /* flush RX buffer */ | |
2121 { | |
2122 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&RxBuffer[index], 1, 10); | |
400 | 2123 if(index < UART_CMD_BUF_SIZE) index++; |
396 | 2124 }while(answer == HAL_OK); |
2125 } | |
2126 | |
2127 uint8_t tComm_HandleBlueModConfig() | |
2128 { | |
400 | 2129 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ |
2130 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ | |
396 | 2131 |
400 | 2132 char TxBuffer[UART_CMD_BUF_SIZE]; |
396 | 2133 uint8_t CmdSize = 0; |
2134 | |
2135 uint8_t result = HAL_OK; | |
2136 | |
400 | 2137 TxBuffer[0] = 0; |
2138 | |
396 | 2139 switch (BmTmpConfig) |
2140 { | |
2141 case BM_CONFIG_ECHO: sprintf(TxBuffer,"ATE0\r"); | |
2142 break; | |
2143 case BM_CONFIG_SILENCE: sprintf(TxBuffer,"ATS30=0\r"); | |
2144 break; | |
2145 case BM_CONFIG_ESCAPE_DELAY: sprintf(TxBuffer,"ATS12=10\r"); | |
2146 break; | |
2147 case BM_CONFIG_SIGNAL_POLL: sprintf(TxBuffer,"AT+BSTPOLL=100\r"); | |
2148 break; | |
2149 case BM_CONFIG_BAUD: sprintf(TxBuffer,"AT%%B22\r"); | |
2150 break; | |
400 | 2151 case BM_CONFIG_RETRY: ConfigRetryCnt--; |
2152 HAL_Delay(1); | |
2153 if(ConfigRetryCnt == 0) | |
2154 { | |
2155 MX_Bluetooth_PowerOn(); | |
2156 tComm_StartBlueModConfig(); | |
2157 } | |
2158 break; | |
396 | 2159 case BM_CONFIG_DONE: |
2160 case BM_CONFIG_OFF: | |
2161 ConfigRetryCnt = 0; | |
400 | 2162 RestartModule = 1; |
396 | 2163 break; |
2164 default: | |
2165 break; | |
2166 } | |
400 | 2167 if(TxBuffer[0] != 0) /* forward command to module */ |
396 | 2168 { |
2169 CmdSize = strlen(TxBuffer); | |
2170 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000) == HAL_OK) | |
2171 { | |
2172 if(BmTmpConfig == BM_CONFIG_ECHO) /* echo is not yet turned off => read and discard echo */ | |
2173 { | |
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
2174 HAL_UART_Receive(&UartHandle, (uint8_t*)TxBuffer, CmdSize, UART_OPERATION_TIMEOUT); |
396 | 2175 } |
2176 | |
2177 result = tComm_CheckAnswerOK(); | |
2178 | |
2179 | |
2180 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ | |
2181 { | |
2182 HAL_UART_DeInit(&UartHandle); | |
2183 HAL_Delay(1); | |
2184 UartHandle.Init.BaudRate = 460800; | |
2185 HAL_UART_Init(&UartHandle); | |
2186 } | |
2187 if(result == HAL_OK) | |
2188 { | |
2189 BmTmpConfig++; | |
2190 } | |
2191 if(BmTmpConfig == BM_CONFIG_DONE) | |
2192 { | |
2193 ConfigRetryCnt = 0; | |
2194 } | |
2195 } | |
2196 } | |
2197 if(result != HAL_OK) | |
2198 { | |
2199 ConfigRetryCnt++; | |
2200 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | |
2201 { | |
2202 MX_Bluetooth_PowerOff(); | |
400 | 2203 if(RestartModule) |
2204 { | |
2205 RestartModule = 0; /* only one try */ | |
2206 ConfigRetryCnt = 200; /* used for delay to startup module again */ | |
2207 BmTmpConfig = BM_CONFIG_RETRY; | |
2208 } | |
2209 else /* even restarting module failed => switch bluetooth off */ | |
2210 { | |
2211 ConfigRetryCnt = 0; | |
2212 BmTmpConfig = BM_CONFIG_OFF; | |
2213 settingsGetPointer()->bluetoothActive = 0; | |
2214 } | |
396 | 2215 } |
2216 } | |
2217 return result; | |
2218 } | |
2219 | |
38 | 2220 static void tComm_Error_Handler(void) |
2221 { | |
2222 while(1) | |
2223 {} | |
2224 } |