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