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