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