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