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