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