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