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