Mercurial > public > ostc4
annotate Discovery/Src/tComm.c @ 1040:74be24428049 GasConsumption
Bugfix Fontpack update for large blocks:
The update of a font pack with a size > 768000 byte was interrupted and a manuel switch to bootloader had to be performed to get the font pack flashed. Rootcause was a missing address adjustment during the block read back function which caused a false error detection. Blocks > 768000 are read in two step while only one buffer is used for comparation. To fill the correct data into this buffer a dummy read of the flash data was added to get the data pointers to the correct offset. Another bug was regardings the read back itself where only the first byte was checked. After array indexing the complete buffer is noch verified.
| author | Ideenmodellierer |
|---|---|
| date | Mon, 13 Oct 2025 20:54:25 +0200 |
| parents | 158100a84ebd |
| children | b018e1f3082e |
| 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 { | |
| 1027 | 331 check_and_correct_settings(EF_SETTINGS); |
| 38 | 332 createDiveSettings(); |
| 333 tM_rebuild_menu_after_tComm(); | |
| 334 } | |
| 335 #endif | |
| 336 updateSettingsAndMenuOnExit = 0; | |
| 337 | |
| 338 if(status.base == BaseComm) | |
| 339 { | |
| 340 #ifndef BOOTLOADER_STANDALONE | |
| 341 set_globalState_tHome(); | |
| 342 #else | |
| 343 set_globalState_Base(); | |
| 344 #endif | |
| 345 } | |
| 462 | 346 settingsGetPointer()->bluetoothActive = 0; |
| 347 MX_Bluetooth_PowerOff(); // Power down Bluetooth on the way out | |
| 38 | 348 } |
| 349 | |
| 350 | |
| 351 uint8_t tComm_Set_Bluetooth_Name(uint8_t force) | |
| 352 { | |
| 353 uint8_t answer = 0; | |
| 354 | |
| 355 if(hardwareDataGetPointer()->secondarySerial != 0xFFFF) | |
| 356 { | |
| 357 if(force || (hardwareDataGetPointer()->secondary_bluetooth_name_set == 0xFF)) | |
| 358 answer = HW_Set_Bluetooth_Name(hardwareDataGetPointer()->secondarySerial, 0); | |
| 359 #ifdef BOOTLOADER_STANDALONE | |
| 360 if(answer == HAL_OK) | |
| 361 hardware_programmSecondaryBluetoothNameSet(); | |
| 362 #endif | |
| 363 } | |
| 364 else | |
| 365 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) | |
| 366 { | |
| 367 if(force || (hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF)) | |
| 368 answer = HW_Set_Bluetooth_Name(hardwareDataGetPointer()->primarySerial, 0); | |
| 369 #ifdef BOOTLOADER_STANDALONE | |
| 370 if(answer == HAL_OK) | |
| 371 hardware_programmPrimaryBluetoothNameSet(); | |
| 372 #endif | |
| 373 } | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
374 else /* no serial set at all => do default configuration of the module */ |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
375 { |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
376 #define NINAB22103B00 |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
377 #ifdef NINAB22103B00 |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
378 answer = 0xFF; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
379 #endif |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
380 } |
| 38 | 381 return answer; |
| 382 } | |
| 383 | |
| 384 | |
| 385 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence) | |
| 386 { | |
| 387 uint8_t answer = HAL_OK; | |
| 388 uint8_t aRxBuffer[50]; | |
| 970 | 389 char aTxBufferName[50]; |
| 38 | 390 |
| 391 // char aTxFactoryDefaults[50] = "AT&F1\r"; | |
| 392 | |
| 966 | 393 char aTxBufferEscapeSequence[50] = "+++"; /* factory default */ |
| 38 | 394 // limit is 19 chars, with 7 chars shown in BLE advertising mode |
| 395 //________________________123456789012345678901 | |
| 966 | 396 |
| 970 | 397 tComm_GetBTCmdStr(BT_CMD_NAME, aTxBufferName); |
| 398 | |
| 396 | 399 char answerOkay[6] = "\r\nOK\r\n"; |
| 38 | 400 |
| 401 gfx_number_to_string(5,1,&aTxBufferName[15],serial); | |
| 402 | |
| 403 // store active configuration in non-volatile memory | |
| 404 char aTxBufferWrite[50] = "AT&W\r"; | |
| 405 | |
| 406 // char aTxBufferReset[50] = "AT+RESET\r"; | |
| 407 | |
| 408 | |
| 409 HAL_Delay(1010); | |
| 410 if(withEscapeSequence) | |
| 411 { | |
| 412 aRxBuffer[0] = 0; | |
| 413 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000)!= HAL_OK) | |
| 414 answer = HAL_ERROR; | |
| 415 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 3, 2000); | |
| 416 HAL_Delay(1010); | |
| 417 | |
| 418 for(int i=0;i<3;i++) | |
| 419 if(aRxBuffer[i] != '+') | |
| 420 answer = HAL_ERROR; | |
| 421 } | |
| 422 | |
| 423 aRxBuffer[0] = 0; | |
| 424 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferName, 21, 2000)!= HAL_OK) | |
| 425 answer = HAL_ERROR; | |
| 426 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 21+6, 2000); | |
| 427 | |
| 428 for(int i=0;i<21;i++) | |
| 429 if(aRxBuffer[i] != aTxBufferName[i]) | |
| 430 answer = HAL_ERROR; | |
| 431 | |
| 432 for(int i=0;i<6;i++) | |
| 433 if(aRxBuffer[21+i] != answerOkay[i]) | |
| 434 answer = HAL_ERROR; | |
| 435 | |
| 436 HAL_Delay(200); | |
| 437 | |
| 438 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferWrite, 5, 2000)!= HAL_OK) | |
| 439 answer = HAL_ERROR; | |
| 440 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5+6, 2000); | |
| 441 | |
| 442 for(int i=0;i<5;i++) | |
| 443 if(aRxBuffer[i] != aTxBufferWrite[i]) | |
| 444 answer = HAL_ERROR; | |
| 445 | |
| 446 for(int i=0;i<6;i++) | |
| 447 if(aRxBuffer[5+i] != answerOkay[i]) | |
| 448 answer = HAL_ERROR; | |
| 449 | |
| 450 answer = HAL_OK; | |
| 451 return answer; | |
| 452 } | |
| 870 | 453 #ifndef BOOTLOADER_STANDALONE |
| 396 | 454 void tComm_Disconnect() |
| 455 { | |
| 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 | |
|
1022
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1073 aTxBuffer[count++] = 0x3B; // hardware descriptor LOW byte // 0x3B is OSTC 4/5 // 0x1A is OTSC3 |
| 38 | 1074 aTxBuffer[count++] = 0x00; // feature descriptor HIGH byte |
| 138 | 1075 aTxBuffer[count++] = 0x00; // feature descriptor LOW byte |
|
1022
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1076 if (isNewDisplay()) { |
|
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1077 aTxBuffer[count++] = 0x44; // model id OSTC5 |
|
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1078 } else { |
|
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1079 aTxBuffer[count++] = 0x43; // model id OSTC4 |
|
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1080 } |
| 38 | 1081 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
| 1082 break; | |
| 1083 | |
| 1084 // get model | |
| 1085 case 0x6A: | |
|
1022
ca713e199f22
Add model ID 0x44 for the OSTC5 to the 0x60 (HARDWARE2) endpoint. The OSTC4 stays at model ID 0x43.
heinrichsweikamp
parents:
1017
diff
changeset
|
1086 aTxBuffer[count++] = 0x3B; // 0x3B is OSTC 4/5 // 0x1A is OTSC3 |
| 38 | 1087 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
| 1088 break; | |
| 1089 | |
| 1090 // get all firmware version and status (OSTC4 only) | |
| 1091 case 0x6B: | |
| 1092 switch(*aRxBuffer) | |
| 1093 { | |
| 1094 case 0xFF: | |
| 1095 // firmware | |
| 1096 aTxBuffer[count++] = firmwareDataGetPointer()->versionFirst; | |
| 1097 aTxBuffer[count++] = firmwareDataGetPointer()->versionSecond; | |
| 1098 aTxBuffer[count++] = firmwareDataGetPointer()->versionThird; | |
| 1099 aTxBuffer[count++] = firmwareDataGetPointer()->versionBeta; | |
| 1100 break; | |
| 1101 case 0xFE: | |
| 1102 // RTE | |
| 1103 getActualRTEandFONTversion(&tempHigh, &tempLow, 0, 0); // RTE | |
| 1104 aTxBuffer[count++] = tempHigh; | |
| 1105 aTxBuffer[count++] = tempLow; | |
| 1106 aTxBuffer[count++] = 0; | |
| 1107 aTxBuffer[count++] = 0; | |
| 1108 break; | |
| 1109 case 0x10: | |
| 1110 getActualRTEandFONTversion( 0, 0, &tempHigh, &tempLow); // font | |
| 1111 aTxBuffer[count++] = tempHigh; | |
| 1112 aTxBuffer[count++] = tempLow; | |
| 1113 aTxBuffer[count++] = 0; | |
| 1114 aTxBuffer[count++] = 0; | |
| 1115 break; | |
| 1116 default: | |
| 1117 // not supported | |
| 1118 aTxBuffer[count++] = 0xFF; | |
| 1119 aTxBuffer[count++] = 0xFF; | |
| 1120 aTxBuffer[count++] = 0xFF; | |
| 1121 aTxBuffer[count++] = 0xFF; | |
| 1122 break; | |
| 1123 /* Jef Driesen Test | |
| 1124 default: | |
| 1125 // not supported | |
| 1126 aTxBuffer[count++] = 0x1; | |
| 1127 aTxBuffer[count++] = 0x1; | |
| 1128 aTxBuffer[count++] = 0x1; | |
| 1129 aTxBuffer[count++] = 0x1; | |
| 1130 break; | |
| 1131 */ | |
| 1132 } | |
| 1133 /* | |
| 1134 // serial | |
| 1135 aTxBuffer[count++] = pSettings->serialLow; | |
| 1136 aTxBuffer[count++] = pSettings->serialHigh; | |
| 1137 // batch code (date) | |
| 1138 hardwareBatchCode(&tempHigh, &tempLow); | |
| 1139 aTxBuffer[count++] = tempLow; | |
| 1140 aTxBuffer[count++] = tempHigh; | |
| 1141 // status and status detail (future feature) | |
| 1142 aTxBuffer[count++] = 0; | |
| 1143 aTxBuffer[count++] = 0; | |
| 1144 aTxBuffer[count++] = 0; | |
| 1145 aTxBuffer[count++] = 0; | |
| 1146 */ | |
| 1147 // prompt | |
| 1148 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1149 break; | |
| 1150 | |
| 396 | 1151 /* Trigger Bluetooth signal strength evaluation */ |
| 1152 case 0x6C: tComm_EvaluateBluetoothStrength(); | |
| 1153 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1154 break; | |
| 38 | 1155 // display text |
| 1156 case 0x6E: | |
| 1157 for(int i=0;i<16;i++) | |
| 1158 display_text[i] = aRxBuffer[i]; | |
| 1159 display_text[15] = 0; | |
| 1160 display_text[255] = 16; | |
| 1161 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1162 break; | |
| 1163 | |
| 1164 // version / identify | |
| 1165 case 0x69: | |
| 1166 #ifndef BOOTLOADER_STANDALONE | |
| 1167 aTxBuffer[count++] = pSettings->serialLow; | |
| 1168 aTxBuffer[count++] = pSettings->serialHigh; | |
| 1169 aTxBuffer[count++] = firmwareVersion_16bit_low(); | |
| 1170 aTxBuffer[count++] = firmwareVersion_16bit_high(); | |
| 1171 memcpy(&aTxBuffer[count], pSettings->customtext, 60); | |
| 1172 #else | |
| 1173 aTxBuffer[count++] = 0;//pSettings->serialLow; | |
| 1174 aTxBuffer[count++] = 0;//pSettings->serialHigh; | |
| 1175 aTxBuffer[count++] = 0;//firmwareVersion_16bit_low(); | |
| 1176 aTxBuffer[count++] = 0;//firmwareVersion_16bit_high(); | |
| 1177 memset(&aTxBuffer[count], 0, 60); | |
| 1178 #endif | |
| 1179 count += 60; | |
| 1180 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1181 break; | |
| 1182 | |
| 1183 #ifndef BOOTLOADER_STANDALONE | |
| 1184 //Reset all setting | |
| 1185 case 0x78: | |
| 1027 | 1186 set_settings_to_Standard(EF_SETTINGS); |
| 38 | 1187 updateSettingsAndMenuOnExit = 1; |
| 1188 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1189 break; | |
| 1190 #endif | |
| 1191 | |
| 1192 #ifndef BOOTLOADER_STANDALONE | |
| 1193 // full headers (256 byte) | |
| 1194 case 0x61: | |
| 1195 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
| 1196 { | |
| 1197 logbook_getHeader(StepBackwards, &logbookHeader); | |
| 1198 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
| 1199 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
| 1200 return 0; | |
| 1201 } | |
| 1202 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1203 break; | |
| 1204 | |
| 1205 // compact headers (16 byte) | |
| 1206 case 0x6D: | |
| 1207 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
| 1208 { | |
| 1209 logbook_getHeader(StepBackwards, &logbookHeader); | |
| 1210 plogbookHeaderOSTC3compact = logbook_build_ostc3header_compact(&logbookHeader); | |
| 1211 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3compact, 16,5000)!= HAL_OK) | |
| 1212 return 0; | |
| 1213 } | |
| 1214 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1215 break; | |
| 1216 | |
| 1217 // set clock & date | |
| 1218 case 0x62: | |
| 1219 // ToDo | |
| 1220 stimestructure.Hours = aRxBuffer[0]; | |
| 1221 stimestructure.Minutes = aRxBuffer[1]; | |
| 1222 stimestructure.Seconds = aRxBuffer[2]; | |
| 1223 sdatestructure.Month = aRxBuffer[3]; | |
| 1224 sdatestructure.Date = aRxBuffer[4]; | |
| 1225 sdatestructure.Year = aRxBuffer[5]; // This parameter must be a number between Min_Data = 0 and Max_Data = 99 | |
| 1226 setWeekday(&sdatestructure); | |
| 1227 | |
| 1228 if( ( stimestructure.Hours < 24 ) | |
| 1229 &&( stimestructure.Minutes < 60 ) | |
| 1230 &&( stimestructure.Seconds < 60 ) | |
| 1231 &&( sdatestructure.Month < 13 ) | |
| 1232 &&( sdatestructure.Date < 32 ) | |
| 1233 &&( sdatestructure.Year < 100 )) | |
| 1234 { | |
| 1235 setTime(stimestructure); | |
| 1236 setDate(sdatestructure); | |
| 1237 set_globalState(StUART_RTECONNECT); | |
| 1238 HAL_Delay(1); | |
| 1239 set_globalState(StUART_STANDARD); | |
| 1240 } | |
| 1241 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1242 break; | |
| 1243 | |
| 1244 case 0x63: | |
| 1245 for(int i=0;i<60;i++) | |
| 1246 pSettings->customtext[i] = aRxBuffer[i]; | |
| 1247 pSettings->customtext[59] = 0; | |
| 1248 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1249 break; | |
| 1250 | |
| 1251 // get dive profile | |
| 1252 case 0x66: | |
| 1253 logbook_getHeader(255 - aRxBuffer[0], &logbookHeader); | |
| 1254 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
| 1255 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
| 1256 return 0; | |
|
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1257 |
|
467
5387e684d797
Cmd Get profile: transmit dummy profile if necessary
ideenmodellierer
parents:
464
diff
changeset
|
1258 OSTC3_profileLength = (plogbookHeaderOSTC3->profileLength[2] << 16) + (plogbookHeaderOSTC3->profileLength[1] << 8) |
|
5387e684d797
Cmd Get profile: transmit dummy profile if necessary
ideenmodellierer
parents:
464
diff
changeset
|
1259 + plogbookHeaderOSTC3->profileLength[0] -3; |
|
5387e684d797
Cmd Get profile: transmit dummy profile if necessary
ideenmodellierer
parents:
464
diff
changeset
|
1260 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
|
1261 |
|
5387e684d797
Cmd Get profile: transmit dummy profile if necessary
ideenmodellierer
parents:
464
diff
changeset
|
1262 if(OSTC3_profileLength != header_profileLength) /* has headerdata been changed to dummy data? */ |
| 38 | 1263 { |
| 458 | 1264 sampleTotalLength = logbook_fillDummySampleBuffer(&logbookHeader); |
|
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1265 while(sampleTotalLength >= 128) |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1266 { |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1267 logbook_readDummySamples(aTxBuffer,128); |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1268 sampleTotalLength -= 128; |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1269 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1270 return 0; |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1271 } |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1272 if(sampleTotalLength) |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1273 { |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1274 logbook_readDummySamples(aTxBuffer,sampleTotalLength); |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1275 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
|
1276 return 0; |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1277 } |
| 38 | 1278 } |
|
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1279 else |
| 38 | 1280 { |
|
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1281 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
|
1282 while(sampleTotalLength >= 128) |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1283 { |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1284 ext_flash_read_next_sample_part(aTxBuffer,128); |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1285 sampleTotalLength -= 128; |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1286 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
|
1287 return 0; |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1288 } |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1289 if(sampleTotalLength) |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1290 { |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1291 ext_flash_read_next_sample_part(aTxBuffer,sampleTotalLength); |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1292 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
|
1293 return 0; |
|
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1294 } |
| 38 | 1295 } |
|
456
5e38b09d2c45
Transfer a dummy profile in case of missing sample information:
ideenmodellierer
parents:
434
diff
changeset
|
1296 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
| 38 | 1297 break; |
| 1298 | |
| 1299 // read min,default,max setting | |
| 1300 case 0x70: | |
| 1301 count += readDataLimits__8and16BitValues_4and7BytesOutput(aRxBuffer[0],&aTxBuffer[count]); | |
| 1302 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1303 break; | |
| 1304 | |
| 1305 // read setting | |
| 1306 case 0x72: | |
| 1307 readData(aRxBuffer[0],&aTxBuffer[count]); | |
| 1308 count += 4; | |
| 1309 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1310 break; | |
| 1311 | |
| 1312 // write setting | |
| 1313 case 0x77: | |
| 1314 writeData(aRxBuffer); | |
| 1315 updateSettingsAndMenuOnExit = 1; | |
| 1316 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1317 break; | |
| 1318 #else | |
| 1319 /* bootloader dummies */ | |
| 1320 // full headers (256 byte) | |
| 1321 case 0x61: | |
| 1322 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
| 1323 { | |
| 1324 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
| 1325 return 0; | |
| 1326 } | |
| 1327 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1328 break; | |
| 1329 // compact headers (16 byte) | |
| 1330 case 0x6D: | |
| 1331 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
| 1332 { | |
| 1333 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 16,5000)!= HAL_OK) | |
| 1334 return 0; | |
| 1335 } | |
| 1336 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1337 break; | |
| 1338 // set clock & date | |
| 1339 case 0x62: | |
| 1340 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1341 break; | |
| 1342 // set custom text | |
| 1343 case 0x63: | |
| 1344 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1345 break; | |
| 1346 // get dive profile | |
| 1347 case 0x66: | |
| 1348 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
| 1349 return 0; | |
| 1350 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1351 break; | |
| 1352 // read min,default,max setting | |
| 1353 // read settings | |
| 1354 | |
| 1355 | |
| 1356 case 0x72: | |
| 1357 memcpy(&aTxBuffer[count], dummyForBootloader, 4); | |
| 1358 count += 4; | |
| 1359 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1360 break; | |
| 1361 // write settings | |
| 1362 case 0x77: | |
| 1363 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
| 1364 break; | |
| 1365 #endif | |
| 1366 } | |
| 1367 | |
| 1368 if(count) | |
| 1369 { | |
| 1370 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
| 1371 return 0; | |
| 1372 else | |
| 1373 return prompt4D4C(receiveStartByteUart); | |
| 1374 } | |
| 1375 return 0; | |
| 1376 } | |
| 1377 | |
| 396 | 1378 #define BLOCKSIZE 0x1000 |
| 38 | 1379 |
| 1380 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size) | |
| 1381 { | |
| 396 | 1382 uint16_t length_4k_blocks; |
| 1383 uint16_t length_4k_remainder; | |
| 38 | 1384 uint32_t temp; |
| 1385 HAL_StatusTypeDef result = HAL_OK; | |
| 1386 uint32_t pDataLocal; | |
| 1387 | |
| 396 | 1388 length_4k_blocks = (uint16_t) (Size / BLOCKSIZE); |
| 1389 temp = length_4k_blocks; | |
| 1390 temp *= BLOCKSIZE; | |
| 1391 length_4k_remainder = (uint16_t) ( Size - temp); | |
| 38 | 1392 |
| 1393 pDataLocal = (uint32_t)pData; | |
| 1394 | |
|
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
|
1395 |
| 396 | 1396 while((result == HAL_OK) && length_4k_blocks) |
| 38 | 1397 { |
| 396 | 1398 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, BLOCKSIZE , UART_TIMEOUT_LARGE_BLOCK); |
| 1399 pDataLocal += BLOCKSIZE; | |
| 1400 length_4k_blocks--; | |
| 38 | 1401 } |
| 396 | 1402 |
| 1403 if((result == HAL_OK) && length_4k_remainder) | |
| 38 | 1404 { |
| 396 | 1405 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, length_4k_remainder , UART_TIMEOUT_LARGE_BLOCK); |
| 38 | 1406 } |
| 1407 return result; | |
| 1408 } | |
| 1409 | |
| 1410 | |
| 1411 /* for safety reason (memory blocking this code is main and sub */ | |
| 1412 | |
| 1413 #ifdef BOOTLOADER_STANDALONE | |
| 1414 | |
| 1415 uint8_t receive_update_data_cpu2(void) | |
| 1416 { | |
| 1417 uint8_t answer; | |
| 1418 | |
| 1419 uint8_t* pBuffer = (uint8_t*)getFrame(20); | |
| 1420 answer = receive_update_data_cpu2_sub(pBuffer); | |
| 1421 releaseFrame(20,(uint32_t)pBuffer); | |
| 1422 return answer; | |
| 1423 } | |
| 1424 | |
| 1425 | |
| 1426 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer) | |
| 1427 { | |
| 1428 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
|
1429 uint32_t length, offsetTotal, checksum, checksumCalc; |
| 38 | 1430 uint8_t id; |
| 1431 const uint8_t id_RTE = 0xFE; | |
| 1432 | |
| 1433 //Get length | |
| 1434 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1435 { | |
| 1436 return 0; | |
| 1437 } | |
| 1438 length = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
| 1439 | |
| 1440 //Get id | |
| 1441 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1442 { | |
| 1443 return 0; | |
| 1444 } | |
| 1445 id = pBuffer[0]; | |
| 1446 offsetTotal = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
| 1447 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1448 // get checksum, bytes are in different order on Dev C++ code!!! |
| 38 | 1449 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
| 1450 { | |
| 1451 return 0; | |
| 1452 } | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1453 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
|
1454 checksumCalc = length + offsetTotal; |
| 38 | 1455 |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1456 // 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
|
1457 if(checksumCalc != checksum) |
| 38 | 1458 { |
| 1459 return 0; | |
| 1460 } | |
| 1461 | |
| 1462 //get Code | |
| 1463 if(receive_uart_large_size(&UartHandle, pBuffer, length)!= HAL_OK) | |
| 1464 { | |
| 1465 return 0; | |
| 1466 } | |
| 1467 | |
| 1468 //get Checksum | |
| 1469 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 580000 | |
| 1470 { | |
| 1471 return 0; | |
| 1472 } | |
| 870 | 1473 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; |
| 38 | 1474 // uint32_t checksumCalc = crc32c_checksum(pBuffer, length,0,0); |
| 870 | 1475 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer, length/4); |
| 38 | 1476 |
| 1477 if(checksum != checksumCalc) | |
| 1478 { | |
| 1479 return 0; | |
| 1480 } | |
| 1481 | |
| 1482 if(id != id_RTE) | |
| 1483 { | |
| 1484 strcpy(display_text,"wrong data."); | |
| 1485 display_text[255] = 32; | |
| 1486 return 0; | |
| 1487 } | |
| 1488 | |
| 1489 strcpy(display_text," RTE update."); | |
| 1490 display_text[255] = 32; | |
| 1491 | |
| 1492 return extCPU2bootloader(pBuffer,length,display_text); | |
| 1493 } | |
| 1494 #endif // BOOTLOADER_STANDALONE | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED) | |
| 1499 { | |
| 1500 uint8_t answer; | |
| 1501 | |
| 1502 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
| 1503 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
| 1504 | |
| 1505 answer = receive_update_data_flex(pBuffer1, pBuffer2, isRTEupdateALLOWED); | |
| 1506 | |
| 1507 releaseFrame(20,(uint32_t)pBuffer1); | |
| 1508 releaseFrame(20,(uint32_t)pBuffer2); | |
| 1509 | |
| 1510 return answer; | |
| 1511 } | |
| 1512 | |
| 1513 uint8_t receive_update_data_mainCPU_firmware(void) | |
| 1514 { | |
| 1515 uint8_t answer; | |
| 1516 | |
| 1517 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
| 1518 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1519 answer = receive_update_data_mainCPU_firmware_subroutine(1, pBuffer1, 0); |
| 38 | 1520 |
| 1521 releaseFrame(20,(uint32_t)pBuffer1); | |
| 1522 | |
| 1523 return answer; | |
| 1524 } | |
| 1525 | |
| 1526 /* multi buffer (long data) not tested yet */ | |
| 1527 uint8_t receive_update_data_mainCPU_variable_firmware(void) | |
| 1528 { | |
| 1529 uint8_t answer; | |
| 1530 | |
| 1531 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
| 1532 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
| 1533 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1534 answer = receive_update_data_mainCPU_firmware_subroutine(2, pBuffer1, pBuffer2); |
| 38 | 1535 |
| 1536 releaseFrame(20,(uint32_t)pBuffer1); | |
| 1537 releaseFrame(20,(uint32_t)pBuffer2); | |
| 1538 | |
| 1539 return answer; | |
| 1540 } | |
| 1541 | |
| 1542 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED) | |
| 1543 { | |
| 1544 uint8_t sBuffer[10]; | |
| 1545 uint8_t serialBuffer[10]; | |
| 1546 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
|
1547 uint32_t lengthTotal, offsetTotal; |
|
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1548 uint32_t checksum, checksumCalc = 0; |
| 38 | 1549 uint8_t id; |
| 1550 const uint8_t id_Region1_firmware = 0xFF; | |
| 1551 const uint8_t id_RTE = 0xFE; | |
| 1552 uint8_t textpointer = 0; | |
| 1040 | 1553 uint32_t index = 0; |
| 38 | 1554 |
| 1555 //Get length | |
| 1556 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1557 { | |
| 1558 return 0; | |
| 1559 } | |
| 1560 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1561 | |
| 1562 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
| 1563 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1564 { | |
| 1565 return 0; | |
| 1566 } | |
| 1567 id = sBuffer[0]; | |
| 1568 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1569 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
|
1570 checksumCalc += lengthTotal; |
|
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1571 //old, does no longer work because of the fonts: checksumCalc = lengthTotal + offsetTotal; |
| 38 | 1572 |
| 1573 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
| 1574 { | |
| 1575 return 0; | |
| 1576 } | |
| 1577 | |
| 1578 // neu 110212 | |
| 1579 if(id == id_FONT) | |
| 1017 | 1580 { |
| 38 | 1581 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; |
| 1017 | 1582 /* todo set offset depending on font version offsetTotal = 0; */ |
| 1583 } | |
| 38 | 1584 else |
| 1585 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1586 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1587 // get checksum, bytes are in different order on Dev C++ code!!! |
| 38 | 1588 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
| 1589 { | |
| 1590 return 0; | |
| 1591 } | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1592 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
| 38 | 1593 |
| 1594 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1595 if(checksumCalc != checksum) |
| 38 | 1596 { |
| 1597 uint8_t ptr = 0; | |
| 1598 strcpy(&display_text[ptr]," checksum error"); | |
| 1599 ptr += 15; | |
| 1600 strcpy(&display_text[ptr],"\n\r"); | |
| 1601 ptr += 2; | |
| 1602 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
| 1603 display_text[ptr] = 0; | |
| 1604 display_text[255] = ptr + 1; | |
| 1605 return 0xFF; | |
| 1606 } | |
| 1607 | |
| 1608 //Get serial (new since 160211) | |
| 1609 if(HAL_UART_Receive(&UartHandle, serialBuffer, 4,5000)!= HAL_OK) | |
| 1610 { | |
| 1611 return 0; | |
| 1612 } | |
| 1613 | |
| 1614 if(lengthTotal > 768000) | |
| 1615 { | |
| 1616 length1 = 768000; | |
| 1617 length2 = lengthTotal - length1; | |
| 1618 } | |
| 1619 else | |
| 1620 { | |
| 1621 length1 = lengthTotal; | |
| 1622 length2 = 0; | |
| 1623 } | |
| 1624 | |
| 1625 if((pBuffer2 == 0) && (length2 != 0)) | |
| 1626 return 0; | |
| 1627 | |
| 1628 //get Code | |
| 1629 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
| 1630 return 0; | |
| 1631 | |
| 1632 if(length2) | |
| 1633 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
| 1634 return 0; | |
| 1635 | |
| 1636 //get Checksum | |
| 1637 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1638 return 0; | |
| 1639 | |
| 1640 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1641 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
| 1642 if(length2) | |
| 1643 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
| 1644 else | |
| 1645 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
| 1646 | |
| 1647 /* check id now */ | |
| 1648 /* | |
| 1649 if(region == 2) | |
| 1650 { | |
| 1651 if((id == id_Region1_firmware) || (id == id_RTE)) | |
| 1652 { | |
| 1653 strcpy(display_text,"wrong data."); | |
| 1654 display_text[255] = 32; | |
| 1655 return 0; | |
| 1656 } | |
| 1657 } | |
| 1658 else | |
| 1659 { | |
| 1660 if(id != id_Region1_firmware) | |
| 1661 { | |
| 1662 strcpy(display_text,"wrong data."); | |
| 1663 display_text[255] = 32; | |
| 1664 return 0; | |
| 1665 } | |
| 1666 } | |
| 1667 */ | |
| 1668 /* test checksum */ | |
| 1669 if(checksum != checksumCalc) | |
| 1670 { | |
| 1671 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
|
1672 strcpy(&display_text[ptr]," checksum error"); |
| 38 | 1673 ptr += 15; |
| 1674 strcpy(&display_text[ptr],"\n\r"); | |
| 1675 display_text[ptr] = 0; | |
| 1676 display_text[255] = ptr + 1; | |
| 1677 return 0xFF; | |
| 1678 } | |
| 1679 | |
| 1680 if(id == id_Region1_firmware) | |
| 1681 { | |
| 1682 uint8_t ptr = 0; | |
| 1683 display_text[ptr++] = 'V'; | |
| 1684 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
| 1685 display_text[ptr++] = '.'; | |
| 1686 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
| 1687 display_text[ptr++] = '.'; | |
| 1688 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
| 1689 display_text[ptr++] = ' '; | |
| 1690 if(pBuffer1[0x10003]) | |
| 1691 { | |
| 1692 strcpy(&display_text[ptr],"beta "); | |
| 1693 ptr +=5; | |
| 1694 } | |
| 1695 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
|
1696 ptr += 25; |
| 38 | 1697 display_text[255] = ptr + 1; |
| 1698 } | |
| 1699 else if(id == id_RTE) | |
| 1700 { | |
| 1701 if(RTEupdateALLOWED) | |
| 1702 { | |
| 1703 strcpy(display_text," RTE update.\n\r"); | |
| 1704 textpointer = 0; | |
| 1705 while((display_text[textpointer] != 0) && (textpointer < 50)) | |
| 1706 textpointer++; | |
| 1707 #ifndef BOOTLOADER_STANDALONE | |
| 1708 if(textpointer < 50) | |
| 1709 { | |
| 1710 // display_text[textpointer++] = | |
| 1711 display_text[textpointer++] = '\025'; | |
| 1712 display_text[textpointer++] = TXT_2BYTE; | |
| 1713 display_text[textpointer++] = TXT2BYTE_DecoDataLost; | |
| 1714 display_text[textpointer] = 0; | |
| 1715 } | |
| 1716 #endif | |
| 1717 display_text[255] = textpointer+1; | |
| 1718 return extCPU2bootloader(pBuffer1,length1,display_text); | |
| 1719 } | |
| 1720 else | |
| 1721 return 0xFF; | |
| 1722 } | |
| 1723 else | |
| 1040 | 1724 if(id == id_FONT) |
| 38 | 1725 { |
| 1726 uint8_t ptr = 0; | |
| 1727 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
| 1728 strcpy(&display_text[ptr]," bytes with "); | |
| 1729 ptr += 12; | |
| 1730 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
| 1731 strcpy(&display_text[ptr]," offset"); | |
| 1732 ptr += 7; | |
| 1733 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
|
1734 ptr += 25; |
| 38 | 1735 display_text[255] = ptr + 1; |
| 1736 } | |
| 1737 | |
| 1738 | |
| 1040 | 1739 /* only non RTE !! (at this point RTE path already performed a return some lines above */ |
| 38 | 1740 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); |
| 1741 ByteCompareStatus = 0; | |
| 1742 | |
| 1743 if(id == id_Region1_firmware) | |
| 1744 { | |
| 1745 /* standard firmware limited to 768000 */ | |
| 1746 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
| 1747 ext_flash_erase_firmware(); | |
| 1748 ext_flash_write_firmware(pBuffer1, length1); | |
| 1749 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
| 1750 | |
| 1751 if(lengthCompare != length1) | |
| 1752 ByteCompareStatus = 10000; | |
| 1040 | 1753 for(index = 0; index < length1; index++) |
| 38 | 1754 { |
| 1040 | 1755 if(pBuffer1[index] != pBufferCompare[index]) |
| 38 | 1756 ByteCompareStatus++; |
| 1757 } | |
| 1758 } | |
| 1759 else | |
| 1040 | 1760 if(id == id_FONT) |
| 38 | 1761 { |
| 1762 /* upper region firmware can be larger (1MB) */ | |
| 1763 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
| 1764 ext_flash_erase_firmware2(); | |
| 1765 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
| 1766 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
| 1767 | |
| 1768 if(lengthCompare != length1 + length2) | |
| 1769 ByteCompareStatus = 10000; | |
| 1770 if(offsetTotal != offsetCompare) | |
| 1771 ByteCompareStatus += 20000; | |
| 1040 | 1772 for(index = 0; index < length1; index++) |
| 38 | 1773 { |
| 1040 | 1774 if(pBuffer1[index] != pBufferCompare[index]) |
| 38 | 1775 ByteCompareStatus++; |
| 1776 } | |
| 1777 | |
| 1778 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
| 1040 | 1779 for(index = 0; index < length2; index++) |
| 38 | 1780 { |
| 1040 | 1781 if(pBuffer2[index] != pBufferCompare[index]) |
| 38 | 1782 ByteCompareStatus++; |
| 1783 } | |
| 1784 } | |
| 1785 | |
| 1786 releaseFrame(20,(uint32_t)pBufferCompare); | |
| 1787 | |
| 1788 if(ByteCompareStatus != 0) | |
| 1789 { | |
| 1790 strcpy(&display_text[0],"\n\rcopy error."); | |
| 1791 display_text[255] = 21; | |
| 1792 return 0; | |
| 1793 } | |
| 1794 else | |
| 1795 { | |
| 1796 strcpy(&display_text[0],"\n\rready to install."); | |
| 1797 display_text[255] = 21; | |
| 1798 return 1; | |
| 1799 } | |
| 1800 } | |
| 1801 | |
| 1802 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1803 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2) |
| 38 | 1804 { |
| 1805 uint8_t sBuffer[10]; | |
| 1806 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
|
1807 uint32_t lengthTotal, offsetTotal, checksum, checksumCalc = 0; |
| 38 | 1808 uint8_t id; |
| 1809 | |
| 1810 //Get length | |
| 1811 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1812 return 0; | |
| 1813 | |
| 1814 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1815 | |
| 1816 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
| 1817 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1818 return 0; | |
| 1819 | |
| 1820 id = sBuffer[0]; | |
| 1821 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1822 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
|
1823 checksumCalc += lengthTotal; |
| 38 | 1824 |
| 1825 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
| 1826 return 0; | |
| 1827 | |
| 1828 if(id == id_FONT) | |
| 1829 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
| 1830 // alt, prior to id for font | |
| 1831 else | |
| 1832 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1833 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1834 // get checksum, bytes are in different order on Dev C++ code!!! |
| 38 | 1835 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
| 1836 return 0; | |
| 1837 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1838 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
| 38 | 1839 |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1840 //old: checksumCalc = lengthTotal + offsetTotal; |
| 38 | 1841 |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1842 if(checksumCalc != checksum) |
| 38 | 1843 { |
| 1844 uint8_t ptr = 0; | |
| 1845 strcpy(&display_text[ptr]," checksum error"); | |
| 1846 ptr += 15; | |
| 1847 strcpy(&display_text[ptr],"\n\r"); | |
| 1848 ptr += 2; | |
| 1849 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
| 1850 display_text[ptr] = 0; | |
| 1851 display_text[255] = ptr + 1; | |
| 1852 return 0xFF; | |
| 1853 } | |
| 1854 | |
| 1855 if(lengthTotal > 768000) | |
| 1856 { | |
| 1857 length1 = 768000; | |
| 1858 length2 = lengthTotal - length1; | |
| 1859 } | |
| 1860 else | |
| 1861 { | |
| 1862 length1 = lengthTotal; | |
| 1863 length2 = 0; | |
| 1864 } | |
| 1865 | |
| 1866 if((pBuffer2 == 0) && (length2 != 0)) | |
| 1867 return 0; | |
| 1868 | |
| 1869 //get Code | |
| 1870 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
| 1871 return 0; | |
| 1872 | |
| 1873 if(length2) | |
| 1874 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
| 1875 return 0; | |
| 1876 | |
| 1877 //get Checksum | |
| 1878 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1879 return 0; | |
| 1880 | |
| 1881 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1882 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
| 1883 if(length2) | |
| 1884 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
| 1885 else | |
| 1886 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
| 1887 | |
| 1888 /* check id now */ | |
| 1889 if(region == 2) | |
| 1890 { | |
| 1891 if((id == id_Region1_firmware) || (id == id_RTE)) | |
| 1892 { | |
| 1893 strcpy(display_text,"wrong data."); | |
| 1894 display_text[255] = 32; | |
| 1895 return 0; | |
| 1896 } | |
| 1897 } | |
| 1898 else | |
| 1899 { | |
| 1900 if(id != id_Region1_firmware) | |
| 1901 { | |
| 1902 strcpy(display_text,"wrong data."); | |
| 1903 display_text[255] = 32; | |
| 1904 return 0; | |
| 1905 } | |
| 1906 } | |
| 1907 | |
| 1908 /* test checksum */ | |
| 1909 if(checksum != checksumCalc) | |
| 1910 { | |
| 1911 uint8_t ptr = 0; | |
| 1912 strcpy(&display_text[ptr]," pruefsummen error"); | |
| 1913 ptr += 15; | |
| 1914 strcpy(&display_text[ptr],"\n\r"); | |
| 1915 display_text[ptr] = 0; | |
| 1916 display_text[255] = ptr + 1; | |
| 1917 return 0xFF; | |
| 1918 } | |
| 1919 | |
| 1920 if(region == 2) | |
| 1921 { | |
| 1922 uint8_t ptr = 0; | |
| 1923 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
| 1924 strcpy(&display_text[ptr]," bytes with "); | |
| 1925 ptr += 12; | |
| 1926 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
| 1927 strcpy(&display_text[ptr]," offset"); | |
| 1928 ptr += 7; | |
| 1929 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
|
1930 ptr += 25; |
| 38 | 1931 display_text[255] = ptr + 1; |
| 1932 | |
| 1933 } | |
| 1934 else | |
| 1935 { | |
| 1936 uint8_t ptr = 0; | |
| 1937 display_text[ptr++] = 'V'; | |
| 1938 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
| 1939 display_text[ptr++] = '.'; | |
| 1940 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
| 1941 display_text[ptr++] = '.'; | |
| 1942 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
| 1943 display_text[ptr++] = ' '; | |
| 1944 if(pBuffer1[0x10003]) | |
| 1945 { | |
| 1946 strcpy(&display_text[ptr],"beta "); | |
| 1947 ptr +=5; | |
| 1948 } | |
| 1949 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
|
1950 ptr += 25; |
| 38 | 1951 display_text[255] = ptr + 1; |
| 1952 } | |
| 1953 | |
| 1954 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
| 1955 ByteCompareStatus = 0; | |
| 1956 | |
| 1957 if(region == 2) | |
| 1958 { | |
| 1959 /* upper region firmware can be larger (1MB) */ | |
| 1960 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
| 1961 ext_flash_erase_firmware2(); | |
| 1962 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
| 1963 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
| 1964 | |
| 1965 if(lengthCompare != length1 + length2) | |
| 1966 ByteCompareStatus = 10000; | |
| 1967 if(offsetTotal != offsetCompare) | |
| 1968 ByteCompareStatus += 20000; | |
| 1969 for(int i = 0; i < length1; i++) | |
| 1970 { | |
| 1971 if(pBuffer1[0] != pBufferCompare[0]) | |
| 1972 ByteCompareStatus++; | |
| 1973 } | |
| 1974 | |
| 1975 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
| 1976 for(int i = 0; i < length2; i++) | |
| 1977 { | |
| 1978 if(pBuffer2[0] != pBufferCompare[0]) | |
| 1979 ByteCompareStatus++; | |
| 1980 } | |
| 1981 } | |
| 1982 else | |
| 1983 { | |
| 1984 /* standard firmware limited to 768000 */ | |
| 1985 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
| 1986 ext_flash_erase_firmware(); | |
| 1987 ext_flash_write_firmware(pBuffer1, length1); | |
| 1988 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
| 1989 | |
| 1990 if(lengthCompare != length1) | |
| 1991 ByteCompareStatus = 10000; | |
| 1992 for(int i = 0; i < length1; i++) | |
| 1993 { | |
| 1994 if(pBuffer1[0] != pBufferCompare[0]) | |
| 1995 ByteCompareStatus++; | |
| 1996 } | |
| 1997 } | |
| 1998 | |
| 1999 releaseFrame(20,(uint32_t)pBufferCompare); | |
| 2000 | |
| 2001 if(ByteCompareStatus != 0) | |
| 2002 { | |
| 2003 strcpy(&display_text[0],"\n\rcopy error."); | |
| 2004 display_text[255] = 21; | |
| 2005 return 0; | |
| 2006 } | |
| 2007 else | |
| 2008 { | |
| 2009 strcpy(&display_text[0],"\n\rready to install."); | |
| 2010 display_text[255] = 21; | |
| 2011 return 1; | |
| 2012 } | |
| 2013 } | |
| 2014 | |
| 396 | 2015 void tComm_RequestBluetoothStrength(void) |
| 2016 { | |
| 2017 EvaluateBluetoothSignalStrength = 1; | |
| 2018 } | |
| 2019 | |
| 2020 /* read, validate the modul answer and flush rx que if necessary */ | |
| 2021 uint8_t tComm_CheckAnswerOK() | |
| 2022 { | |
| 2023 char answerOkay[] = "\r\nOK\r\n"; | |
| 400 | 2024 char aRxBuffer[UART_CMD_BUF_SIZE]; |
| 396 | 2025 uint8_t sizeAnswer = sizeof(answerOkay) -1; |
| 2026 uint8_t result = HAL_OK; | |
| 664 | 2027 uint8_t indexRef = 0; |
| 2028 uint8_t indexBuf = 0; | |
| 396 | 2029 uint8_t answer; |
| 2030 | |
| 400 | 2031 memset(aRxBuffer,0,UART_CMD_BUF_SIZE); |
|
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
2032 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, UART_OPERATION_TIMEOUT) == HAL_OK) |
| 396 | 2033 { |
| 2034 do | |
| 2035 { | |
| 664 | 2036 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) |
| 396 | 2037 { |
| 664 | 2038 indexRef++; |
| 396 | 2039 } |
| 2040 else | |
| 2041 { | |
| 664 | 2042 if(indexRef != 0) |
| 2043 { | |
| 2044 indexRef = 0; | |
| 2045 } | |
| 396 | 2046 } |
| 664 | 2047 indexBuf++; |
| 2048 }while(indexBuf < sizeAnswer); | |
| 2049 | |
| 2050 if(indexRef != sizeAnswer) /* unexpected answer => there might be characters left in RX que => read and check all rx bytes */ | |
| 2051 { | |
| 2052 do | |
| 2053 { | |
| 886 | 2054 answer = HAL_ERROR; |
| 664 | 2055 if (indexBuf < UART_CMD_BUF_SIZE) |
| 2056 { | |
| 886 | 2057 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10); |
| 2058 | |
| 664 | 2059 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) |
| 2060 { | |
| 2061 indexRef++; | |
| 2062 } | |
| 2063 else | |
| 2064 { | |
| 2065 if(indexRef != 0) | |
| 2066 { | |
| 2067 indexRef = 0; | |
| 2068 } | |
| 2069 } | |
| 2070 indexBuf++; | |
| 2071 } | |
| 886 | 2072 }while((answer == HAL_OK) && (indexRef != sizeAnswer)); |
| 664 | 2073 if(indexRef != sizeAnswer) |
| 2074 { | |
| 2075 result = HAL_ERROR; | |
| 2076 } | |
| 2077 } | |
| 396 | 2078 } |
| 2079 else | |
| 2080 { | |
| 2081 result = HAL_ERROR; | |
| 2082 } | |
| 2083 return result; | |
| 2084 | |
| 2085 } | |
| 400 | 2086 |
| 396 | 2087 |
| 2088 void tComm_EvaluateBluetoothStrength(void) | |
| 2089 { | |
| 2090 char aTxBufferBarSSI[] = "AT+BARSSI\r"; | |
| 2091 char aTxBufferEscapeSequence[] = "+++"; | |
| 2092 char aTxBufferEnd[] = "ATO\r"; | |
| 2093 uint8_t sizeRequest = sizeof(aTxBufferBarSSI) -1; | |
| 2094 | |
| 2095 uint8_t answer = HAL_OK; | |
| 400 | 2096 char aRxBuffer[UART_CMD_BUF_SIZE]; |
| 2097 char SignalStr[UART_CMD_BUF_SIZE]; | |
| 396 | 2098 uint8_t index = 0; |
| 2099 uint8_t strindex = 0; | |
| 2100 int8_t sigqual = 0; | |
| 2101 | |
| 2102 HAL_Delay(200); | |
| 2103 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000)== HAL_OK) | |
| 2104 { | |
| 2105 if(tComm_CheckAnswerOK() == HAL_OK) | |
| 2106 { | |
| 2107 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferBarSSI,sizeRequest , 2000); | |
| 2108 { | |
| 2109 index = 0; | |
| 2110 do /* Answer is not the common one. Instead the signal strength is received => read all available bytes one by one*/ | |
| 2111 { | |
| 2112 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 100); | |
| 400 | 2113 if(index < UART_CMD_BUF_SIZE) |
| 2114 { | |
| 2115 index++; | |
| 2116 } | |
| 396 | 2117 }while(answer == HAL_OK); |
| 2118 | |
| 2119 if((aRxBuffer[index] != 'E') && (aRxBuffer[index] != 0)) /* E represents the first letter of the string ERROR */ | |
| 2120 { | |
| 2121 index = 0; | |
| 2122 strindex = 0; | |
| 2123 do | |
| 2124 { | |
| 2125 SignalStr[strindex++] = aRxBuffer[index++]; | |
| 400 | 2126 }while ((index < UART_CMD_BUF_SIZE - 1) && (aRxBuffer[index] != '\r')); |
| 396 | 2127 SignalStr[strindex] = 0; /* terminate String */ |
| 2128 sigqual = strtol(SignalStr,NULL,0); | |
| 2129 /* Map db to abstract Bargraph */ | |
| 2130 if(sigqual > 0) | |
| 2131 { | |
| 400 | 2132 sprintf(SignalStr,"Bluetooth ||||||||"); |
| 396 | 2133 } |
| 2134 else | |
| 2135 { | |
| 2136 sprintf(SignalStr,"Bluetooth |"); | |
| 2137 strindex = strlen(SignalStr); | |
| 2138 sigqual *=-1; | |
| 2139 sigqual = 100 - sigqual; /* invert because of negative db value */ | |
| 2140 while(sigqual / 10 > 0 ) | |
| 2141 { | |
| 2142 SignalStr[strindex++] = '|'; | |
| 2143 sigqual -= 10; | |
| 2144 } | |
| 2145 SignalStr[strindex] = 0; | |
| 2146 } | |
| 2147 strcpy(display_text,SignalStr); | |
| 2148 display_text[255] = strlen(SignalStr); | |
| 2149 EvaluateBluetoothSignalStrength = 0; | |
| 2150 } | |
| 2151 } | |
| 2152 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, 2000); /* exit terminal mode */ | |
| 2153 index = 0; | |
| 2154 do /* module will answer with current connection state */ | |
| 2155 { | |
| 2156 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 100); | |
| 400 | 2157 if(index < UART_CMD_BUF_SIZE) |
| 2158 { | |
| 2159 index++; | |
| 2160 } | |
| 396 | 2161 }while(answer == HAL_OK); |
| 2162 } | |
| 2163 } | |
| 2164 } | |
| 2165 | |
| 873 | 2166 #ifdef BOOTLOADER_STANDALONE |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2167 void tComm_StartBlueModBaseInit() |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2168 { |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2169 BmTmpConfig = BM_INIT_TRIGGER_ON; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2170 } |
| 873 | 2171 #endif |
| 2172 | |
| 970 | 2173 |
| 2174 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr) | |
| 2175 { | |
| 2176 uint8_t ret = 0; | |
| 2177 uint8_t oldModule = 1; | |
| 2178 | |
| 2179 if(isNewDisplay()) | |
| 2180 { | |
| 2181 oldModule = 0; | |
| 2182 } | |
| 2183 | |
| 2184 switch (cmdId) | |
| 2185 { | |
| 2186 case BT_CMD_ECHO: sprintf(pCmdStr,"ATE0\r"); | |
| 2187 ret = 1; | |
| 2188 break; | |
| 2189 case BT_CMD_SILENCE: if(oldModule) | |
| 2190 { | |
| 2191 strcpy(pCmdStr,"ATS30=0\r"); | |
| 2192 ret = 1; | |
| 2193 } | |
| 2194 break; | |
| 2195 case BT_CMD_ESCAPE_DELAY: if(oldModule) | |
| 2196 { | |
| 2197 strcpy(pCmdStr,"ATS12=10\r"); | |
| 2198 ret = 1; | |
| 2199 } | |
| 2200 break; | |
| 2201 case BT_CMD_SIGNAL_POLL: if(oldModule) | |
| 2202 { | |
| 2203 strcpy(pCmdStr,"AT+BSTPOLL=100\r"); | |
| 2204 ret = 1; | |
| 2205 } | |
| 2206 break; | |
| 2207 case BT_CMD_BAUDRATE_115: if(oldModule) | |
| 2208 { | |
| 2209 strcpy(pCmdStr,"AT%B8\r"); | |
| 2210 } | |
| 2211 else | |
| 2212 { | |
| 2213 strcpy(pCmdStr,"AT+UMRS=115200,1,8,1,1,1\r"); | |
| 2214 } | |
| 2215 ret = 1; | |
| 2216 break; | |
| 2217 | |
| 2218 case BT_CMD_BAUDRATE_460: if(oldModule) | |
| 2219 { | |
| 2220 strcpy(pCmdStr,"AT%B22\r"); | |
| 2221 } | |
| 2222 else | |
| 2223 { | |
| 2224 strcpy(pCmdStr,"AT+UMRS=460800,1,8,1,1,1\r"); | |
| 2225 } | |
| 2226 ret = 1; | |
| 2227 break; | |
| 2228 case BT_CMD_NAME: if(oldModule) | |
| 2229 { | |
| 2230 strcpy(pCmdStr,"AT+BNAME=OSTC4-12345\r"); | |
| 2231 } | |
| 2232 else | |
| 2233 { | |
| 2234 strcpy(pCmdStr,"AT+UBTLN=OSTC5-12345\r"); | |
| 2235 } | |
| 2236 ret = 1; | |
| 2237 break; | |
| 2238 case BT_CMD_EXIT_CMD: if(oldModule) | |
| 2239 { | |
| 2240 strcpy(pCmdStr,"ATO\r"); | |
| 2241 } | |
| 2242 else | |
| 2243 { | |
| 2244 strcpy(pCmdStr,"ATO1\r"); | |
| 2245 } | |
| 2246 ret = 1; | |
| 2247 break; | |
| 2248 default: | |
| 2249 break; | |
| 2250 } | |
| 2251 return ret; | |
| 2252 } | |
| 2253 | |
| 396 | 2254 void tComm_StartBlueModConfig() |
| 2255 { | |
| 2256 uint8_t answer = HAL_OK; | |
| 400 | 2257 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; |
| 396 | 2258 uint8_t index = 0; |
| 2259 | |
| 2260 BmTmpConfig = BM_CONFIG_ECHO; | |
| 2261 do /* flush RX buffer */ | |
| 2262 { | |
| 2263 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&RxBuffer[index], 1, 10); | |
| 400 | 2264 if(index < UART_CMD_BUF_SIZE) index++; |
| 396 | 2265 }while(answer == HAL_OK); |
| 2266 } | |
| 2267 | |
| 2268 uint8_t tComm_HandleBlueModConfig() | |
| 2269 { | |
| 400 | 2270 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ |
| 2271 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ | |
| 396 | 2272 |
| 400 | 2273 char TxBuffer[UART_CMD_BUF_SIZE]; |
| 396 | 2274 uint8_t CmdSize = 0; |
| 2275 | |
| 2276 uint8_t result = HAL_OK; | |
| 2277 | |
| 970 | 2278 memset(TxBuffer, 0, sizeof(TxBuffer)); |
| 400 | 2279 |
| 396 | 2280 switch (BmTmpConfig) |
| 2281 { | |
| 970 | 2282 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); |
| 396 | 2283 break; |
| 970 | 2284 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); |
| 396 | 2285 break; |
| 970 | 2286 case BM_CONFIG_ESCAPE_DELAY: tComm_GetBTCmdStr (BT_CMD_ESCAPE_DELAY, TxBuffer); |
| 396 | 2287 break; |
| 970 | 2288 case BM_CONFIG_SIGNAL_POLL: tComm_GetBTCmdStr(BT_CMD_SIGNAL_POLL, TxBuffer); |
| 396 | 2289 break; |
| 893 | 2290 case BM_CONFIG_BAUD: |
| 2291 #ifdef ENABLE_FAST_COMM | |
| 970 | 2292 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); |
| 893 | 2293 #else |
| 966 | 2294 BmTmpConfig = BM_CONFIG_DONE; |
| 893 | 2295 #endif |
| 396 | 2296 break; |
| 400 | 2297 case BM_CONFIG_RETRY: ConfigRetryCnt--; |
| 2298 HAL_Delay(1); | |
| 2299 if(ConfigRetryCnt == 0) | |
| 2300 { | |
| 2301 MX_Bluetooth_PowerOn(); | |
| 2302 tComm_StartBlueModConfig(); | |
| 2303 } | |
| 2304 break; | |
| 396 | 2305 case BM_CONFIG_DONE: |
| 2306 case BM_CONFIG_OFF: | |
| 2307 ConfigRetryCnt = 0; | |
| 400 | 2308 RestartModule = 1; |
| 396 | 2309 break; |
| 970 | 2310 #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
|
2311 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2312 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
|
2313 BmTmpConfig++; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2314 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2315 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2316 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
|
2317 HAL_Delay(2000); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2318 BmTmpConfig++; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2319 break; |
| 879 | 2320 case BM_INIT_ECHO: sprintf(TxBuffer,"ATE0\r"); |
| 2321 break; | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2322 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
|
2323 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2324 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
|
2325 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2326 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
|
2327 break; |
| 970 | 2328 case BM_INIT_NAME: sprintf(TxBuffer,"AT+UBTLN=OSTC5-12345\r"); /* Bluetooth name */ |
| 2329 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) /* module reinit? => restore old name */ | |
| 2330 { | |
| 2331 gfx_number_to_string(5,1,&TxBuffer[15],hardwareDataGetPointer()->primarySerial); | |
| 2332 } | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2333 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2334 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
|
2335 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2336 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
|
2337 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2338 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
|
2339 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2340 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
|
2341 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2342 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
|
2343 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2344 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
|
2345 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2346 case BM_INIT_DONE: BmTmpConfig = BM_CONFIG_ECHO; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2347 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2348 #endif |
| 396 | 2349 default: |
| 2350 break; | |
| 2351 } | |
| 400 | 2352 if(TxBuffer[0] != 0) /* forward command to module */ |
| 396 | 2353 { |
| 2354 CmdSize = strlen(TxBuffer); | |
| 2355 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000) == HAL_OK) | |
| 2356 { | |
| 2357 result = tComm_CheckAnswerOK(); | |
| 2358 | |
| 2359 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ | |
| 2360 { | |
| 2361 HAL_UART_DeInit(&UartHandle); | |
| 2362 HAL_Delay(1); | |
| 2363 UartHandle.Init.BaudRate = 460800; | |
| 2364 HAL_UART_Init(&UartHandle); | |
| 2365 } | |
| 893 | 2366 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 | 2367 { |
| 970 | 2368 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_115, TxBuffer); |
| 2369 | |
| 664 | 2370 CmdSize = strlen(TxBuffer); |
| 2371 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2372 HAL_UART_DeInit(&UartHandle); | |
| 2373 HAL_Delay(10); | |
| 2374 UartHandle.Init.BaudRate = 115200; | |
| 2375 HAL_UART_Init(&UartHandle); | |
| 2376 sprintf(TxBuffer,"AT&W\r"); /* write configuration */ | |
| 2377 CmdSize = strlen(TxBuffer); | |
| 2378 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2379 } | |
| 396 | 2380 if(result == HAL_OK) |
| 2381 { | |
| 2382 BmTmpConfig++; | |
| 966 | 2383 if(BmTmpConfig == BM_CONFIG_RETRY) |
| 2384 { | |
| 2385 BmTmpConfig = BM_CONFIG_DONE; | |
| 2386 } | |
| 396 | 2387 } |
| 879 | 2388 if(BmTmpConfig == BM_CONFIG_ECHO) |
| 396 | 2389 { |
| 879 | 2390 BmTmpConfig = BM_CONFIG_DONE; |
| 396 | 2391 ConfigRetryCnt = 0; |
| 664 | 2392 RestartModule = 1; |
| 396 | 2393 } |
| 2394 } | |
| 2395 } | |
| 970 | 2396 else /* no command for the configuration step found => skip step */ |
| 2397 { | |
| 2398 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) | |
| 2399 { | |
| 2400 BmTmpConfig++; | |
| 2401 } | |
| 2402 } | |
| 396 | 2403 if(result != HAL_OK) |
| 2404 { | |
| 2405 ConfigRetryCnt++; | |
| 2406 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | |
| 2407 { | |
| 2408 MX_Bluetooth_PowerOff(); | |
| 400 | 2409 if(RestartModule) |
| 2410 { | |
| 2411 RestartModule = 0; /* only one try */ | |
| 2412 ConfigRetryCnt = 200; /* used for delay to startup module again */ | |
| 664 | 2413 |
| 970 | 2414 if((BmTmpConfig == BM_CONFIG_ECHO) || (BmTmpConfig == BM_INIT_ECHO)) /* the module did not answer even once => try again with alternative baud rate */ |
| 664 | 2415 { |
| 2416 HAL_UART_DeInit(&UartHandle); | |
| 2417 HAL_Delay(1); | |
| 2418 UartHandle.Init.BaudRate = 460800; | |
| 2419 HAL_UART_Init(&UartHandle); | |
| 2420 } | |
| 400 | 2421 BmTmpConfig = BM_CONFIG_RETRY; |
| 2422 } | |
| 2423 else /* even restarting module failed => switch bluetooth off */ | |
| 2424 { | |
| 2425 ConfigRetryCnt = 0; | |
| 2426 BmTmpConfig = BM_CONFIG_OFF; | |
| 2427 settingsGetPointer()->bluetoothActive = 0; | |
| 2428 } | |
| 396 | 2429 } |
| 2430 } | |
| 2431 return result; | |
| 2432 } | |
| 2433 | |
| 38 | 2434 static void tComm_Error_Handler(void) |
| 2435 { | |
| 2436 while(1) | |
| 2437 {} | |
| 2438 } |
