Mercurial > public > ostc4
annotate Discovery/Src/tComm.c @ 1028:3d9552e4997c GasConsumption
Code improvment: line <=> menu id function:
In generell the structure of the menus is defined by the tStructure.h using global state defines. In some implementation hardcoded line numbers are used. Risk: In case the order of menu items change the update of other code sections could be forgotten (in the case the update of the top menu) causing unintended behavior. To avoid this the hard coded lines have been replaced by a function connecting the intended function to the menu item defined in the tstructure.h.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 07 Sep 2025 19:08:43 +0200 |
| parents | 158100a84ebd |
| children | 74be24428049 |
| 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; | |
| 1553 | |
| 1554 //Get length | |
| 1555 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1556 { | |
| 1557 return 0; | |
| 1558 } | |
| 1559 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1560 | |
| 1561 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
| 1562 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1563 { | |
| 1564 return 0; | |
| 1565 } | |
| 1566 id = sBuffer[0]; | |
| 1567 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1568 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
|
1569 checksumCalc += lengthTotal; |
|
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1570 //old, does no longer work because of the fonts: checksumCalc = lengthTotal + offsetTotal; |
| 38 | 1571 |
| 1572 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
| 1573 { | |
| 1574 return 0; | |
| 1575 } | |
| 1576 | |
| 1577 // neu 110212 | |
| 1578 if(id == id_FONT) | |
| 1017 | 1579 { |
| 38 | 1580 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; |
| 1017 | 1581 /* todo set offset depending on font version offsetTotal = 0; */ |
| 1582 } | |
| 38 | 1583 else |
| 1584 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1585 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1586 // get checksum, bytes are in different order on Dev C++ code!!! |
| 38 | 1587 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
| 1588 { | |
| 1589 return 0; | |
| 1590 } | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1591 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
| 38 | 1592 |
| 1593 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1594 if(checksumCalc != checksum) |
| 38 | 1595 { |
| 1596 uint8_t ptr = 0; | |
| 1597 strcpy(&display_text[ptr]," checksum error"); | |
| 1598 ptr += 15; | |
| 1599 strcpy(&display_text[ptr],"\n\r"); | |
| 1600 ptr += 2; | |
| 1601 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
| 1602 display_text[ptr] = 0; | |
| 1603 display_text[255] = ptr + 1; | |
| 1604 return 0xFF; | |
| 1605 } | |
| 1606 | |
| 1607 //Get serial (new since 160211) | |
| 1608 if(HAL_UART_Receive(&UartHandle, serialBuffer, 4,5000)!= HAL_OK) | |
| 1609 { | |
| 1610 return 0; | |
| 1611 } | |
| 1612 | |
| 1613 if(lengthTotal > 768000) | |
| 1614 { | |
| 1615 length1 = 768000; | |
| 1616 length2 = lengthTotal - length1; | |
| 1617 } | |
| 1618 else | |
| 1619 { | |
| 1620 length1 = lengthTotal; | |
| 1621 length2 = 0; | |
| 1622 } | |
| 1623 | |
| 1624 if((pBuffer2 == 0) && (length2 != 0)) | |
| 1625 return 0; | |
| 1626 | |
| 1627 //get Code | |
| 1628 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
| 1629 return 0; | |
| 1630 | |
| 1631 if(length2) | |
| 1632 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
| 1633 return 0; | |
| 1634 | |
| 1635 //get Checksum | |
| 1636 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1637 return 0; | |
| 1638 | |
| 1639 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1640 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
| 1641 if(length2) | |
| 1642 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
| 1643 else | |
| 1644 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
| 1645 | |
| 1646 /* check id now */ | |
| 1647 /* | |
| 1648 if(region == 2) | |
| 1649 { | |
| 1650 if((id == id_Region1_firmware) || (id == id_RTE)) | |
| 1651 { | |
| 1652 strcpy(display_text,"wrong data."); | |
| 1653 display_text[255] = 32; | |
| 1654 return 0; | |
| 1655 } | |
| 1656 } | |
| 1657 else | |
| 1658 { | |
| 1659 if(id != id_Region1_firmware) | |
| 1660 { | |
| 1661 strcpy(display_text,"wrong data."); | |
| 1662 display_text[255] = 32; | |
| 1663 return 0; | |
| 1664 } | |
| 1665 } | |
| 1666 */ | |
| 1667 /* test checksum */ | |
| 1668 if(checksum != checksumCalc) | |
| 1669 { | |
| 1670 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
|
1671 strcpy(&display_text[ptr]," checksum error"); |
| 38 | 1672 ptr += 15; |
| 1673 strcpy(&display_text[ptr],"\n\r"); | |
| 1674 display_text[ptr] = 0; | |
| 1675 display_text[255] = ptr + 1; | |
| 1676 return 0xFF; | |
| 1677 } | |
| 1678 | |
| 1679 if(id == id_Region1_firmware) | |
| 1680 { | |
| 1681 uint8_t ptr = 0; | |
| 1682 display_text[ptr++] = 'V'; | |
| 1683 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
| 1684 display_text[ptr++] = '.'; | |
| 1685 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
| 1686 display_text[ptr++] = '.'; | |
| 1687 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
| 1688 display_text[ptr++] = ' '; | |
| 1689 if(pBuffer1[0x10003]) | |
| 1690 { | |
| 1691 strcpy(&display_text[ptr],"beta "); | |
| 1692 ptr +=5; | |
| 1693 } | |
| 1694 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
|
1695 ptr += 25; |
| 38 | 1696 display_text[255] = ptr + 1; |
| 1697 } | |
| 1698 else if(id == id_RTE) | |
| 1699 { | |
| 1700 if(RTEupdateALLOWED) | |
| 1701 { | |
| 1702 strcpy(display_text," RTE update.\n\r"); | |
| 1703 textpointer = 0; | |
| 1704 while((display_text[textpointer] != 0) && (textpointer < 50)) | |
| 1705 textpointer++; | |
| 1706 #ifndef BOOTLOADER_STANDALONE | |
| 1707 if(textpointer < 50) | |
| 1708 { | |
| 1709 // display_text[textpointer++] = | |
| 1710 display_text[textpointer++] = '\025'; | |
| 1711 display_text[textpointer++] = TXT_2BYTE; | |
| 1712 display_text[textpointer++] = TXT2BYTE_DecoDataLost; | |
| 1713 display_text[textpointer] = 0; | |
| 1714 } | |
| 1715 #endif | |
| 1716 display_text[255] = textpointer+1; | |
| 1717 return extCPU2bootloader(pBuffer1,length1,display_text); | |
| 1718 } | |
| 1719 else | |
| 1720 return 0xFF; | |
| 1721 } | |
| 1722 else | |
| 1723 //if(region == 2) | |
| 1724 { | |
| 1725 uint8_t ptr = 0; | |
| 1726 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
| 1727 strcpy(&display_text[ptr]," bytes with "); | |
| 1728 ptr += 12; | |
| 1729 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
| 1730 strcpy(&display_text[ptr]," offset"); | |
| 1731 ptr += 7; | |
| 1732 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
|
1733 ptr += 25; |
| 38 | 1734 display_text[255] = ptr + 1; |
| 1735 } | |
| 1736 | |
| 1737 | |
| 1738 // only non RTE !! | |
| 1739 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
| 1740 ByteCompareStatus = 0; | |
| 1741 | |
| 1742 if(id == id_Region1_firmware) | |
| 1743 { | |
| 1744 /* standard firmware limited to 768000 */ | |
| 1745 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
| 1746 ext_flash_erase_firmware(); | |
| 1747 ext_flash_write_firmware(pBuffer1, length1); | |
| 1748 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
| 1749 | |
| 1750 if(lengthCompare != length1) | |
| 1751 ByteCompareStatus = 10000; | |
| 1752 for(int i = 0; i < length1; i++) | |
| 1753 { | |
| 1754 if(pBuffer1[0] != pBufferCompare[0]) | |
| 1755 ByteCompareStatus++; | |
| 1756 } | |
| 1757 } | |
| 1758 else | |
| 1759 //if(region == 2) | |
| 1760 { | |
| 1761 /* upper region firmware can be larger (1MB) */ | |
| 1762 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
| 1763 ext_flash_erase_firmware2(); | |
| 1764 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
| 1765 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
| 1766 | |
| 1767 if(lengthCompare != length1 + length2) | |
| 1768 ByteCompareStatus = 10000; | |
| 1769 if(offsetTotal != offsetCompare) | |
| 1770 ByteCompareStatus += 20000; | |
| 1771 for(int i = 0; i < length1; i++) | |
| 1772 { | |
| 1773 if(pBuffer1[0] != pBufferCompare[0]) | |
| 1774 ByteCompareStatus++; | |
| 1775 } | |
| 1776 | |
| 1777 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
| 1778 for(int i = 0; i < length2; i++) | |
| 1779 { | |
| 1780 if(pBuffer2[0] != pBufferCompare[0]) | |
| 1781 ByteCompareStatus++; | |
| 1782 } | |
| 1783 } | |
| 1784 | |
| 1785 releaseFrame(20,(uint32_t)pBufferCompare); | |
| 1786 | |
| 1787 if(ByteCompareStatus != 0) | |
| 1788 { | |
| 1789 strcpy(&display_text[0],"\n\rcopy error."); | |
| 1790 display_text[255] = 21; | |
| 1791 return 0; | |
| 1792 } | |
| 1793 else | |
| 1794 { | |
| 1795 strcpy(&display_text[0],"\n\rready to install."); | |
| 1796 display_text[255] = 21; | |
| 1797 return 1; | |
| 1798 } | |
| 1799 } | |
| 1800 | |
| 1801 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1802 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2) |
| 38 | 1803 { |
| 1804 uint8_t sBuffer[10]; | |
| 1805 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
|
1806 uint32_t lengthTotal, offsetTotal, checksum, checksumCalc = 0; |
| 38 | 1807 uint8_t id; |
| 1808 | |
| 1809 //Get length | |
| 1810 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1811 return 0; | |
| 1812 | |
| 1813 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1814 | |
| 1815 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
| 1816 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1817 return 0; | |
| 1818 | |
| 1819 id = sBuffer[0]; | |
| 1820 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1821 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
|
1822 checksumCalc += lengthTotal; |
| 38 | 1823 |
| 1824 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
| 1825 return 0; | |
| 1826 | |
| 1827 if(id == id_FONT) | |
| 1828 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
| 1829 // alt, prior to id for font | |
| 1830 else | |
| 1831 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1832 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1833 // get checksum, bytes are in different order on Dev C++ code!!! |
| 38 | 1834 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
| 1835 return 0; | |
| 1836 | |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1837 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
| 38 | 1838 |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1839 //old: checksumCalc = lengthTotal + offsetTotal; |
| 38 | 1840 |
|
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1841 if(checksumCalc != checksum) |
| 38 | 1842 { |
| 1843 uint8_t ptr = 0; | |
| 1844 strcpy(&display_text[ptr]," checksum error"); | |
| 1845 ptr += 15; | |
| 1846 strcpy(&display_text[ptr],"\n\r"); | |
| 1847 ptr += 2; | |
| 1848 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
| 1849 display_text[ptr] = 0; | |
| 1850 display_text[255] = ptr + 1; | |
| 1851 return 0xFF; | |
| 1852 } | |
| 1853 | |
| 1854 if(lengthTotal > 768000) | |
| 1855 { | |
| 1856 length1 = 768000; | |
| 1857 length2 = lengthTotal - length1; | |
| 1858 } | |
| 1859 else | |
| 1860 { | |
| 1861 length1 = lengthTotal; | |
| 1862 length2 = 0; | |
| 1863 } | |
| 1864 | |
| 1865 if((pBuffer2 == 0) && (length2 != 0)) | |
| 1866 return 0; | |
| 1867 | |
| 1868 //get Code | |
| 1869 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
| 1870 return 0; | |
| 1871 | |
| 1872 if(length2) | |
| 1873 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
| 1874 return 0; | |
| 1875 | |
| 1876 //get Checksum | |
| 1877 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
| 1878 return 0; | |
| 1879 | |
| 1880 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
| 1881 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
| 1882 if(length2) | |
| 1883 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
| 1884 else | |
| 1885 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
| 1886 | |
| 1887 /* check id now */ | |
| 1888 if(region == 2) | |
| 1889 { | |
| 1890 if((id == id_Region1_firmware) || (id == id_RTE)) | |
| 1891 { | |
| 1892 strcpy(display_text,"wrong data."); | |
| 1893 display_text[255] = 32; | |
| 1894 return 0; | |
| 1895 } | |
| 1896 } | |
| 1897 else | |
| 1898 { | |
| 1899 if(id != id_Region1_firmware) | |
| 1900 { | |
| 1901 strcpy(display_text,"wrong data."); | |
| 1902 display_text[255] = 32; | |
| 1903 return 0; | |
| 1904 } | |
| 1905 } | |
| 1906 | |
| 1907 /* test checksum */ | |
| 1908 if(checksum != checksumCalc) | |
| 1909 { | |
| 1910 uint8_t ptr = 0; | |
| 1911 strcpy(&display_text[ptr]," pruefsummen error"); | |
| 1912 ptr += 15; | |
| 1913 strcpy(&display_text[ptr],"\n\r"); | |
| 1914 display_text[ptr] = 0; | |
| 1915 display_text[255] = ptr + 1; | |
| 1916 return 0xFF; | |
| 1917 } | |
| 1918 | |
| 1919 if(region == 2) | |
| 1920 { | |
| 1921 uint8_t ptr = 0; | |
| 1922 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
| 1923 strcpy(&display_text[ptr]," bytes with "); | |
| 1924 ptr += 12; | |
| 1925 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
| 1926 strcpy(&display_text[ptr]," offset"); | |
| 1927 ptr += 7; | |
| 1928 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
|
1929 ptr += 25; |
| 38 | 1930 display_text[255] = ptr + 1; |
| 1931 | |
| 1932 } | |
| 1933 else | |
| 1934 { | |
| 1935 uint8_t ptr = 0; | |
| 1936 display_text[ptr++] = 'V'; | |
| 1937 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
| 1938 display_text[ptr++] = '.'; | |
| 1939 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
| 1940 display_text[ptr++] = '.'; | |
| 1941 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
| 1942 display_text[ptr++] = ' '; | |
| 1943 if(pBuffer1[0x10003]) | |
| 1944 { | |
| 1945 strcpy(&display_text[ptr],"beta "); | |
| 1946 ptr +=5; | |
| 1947 } | |
| 1948 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
|
1949 ptr += 25; |
| 38 | 1950 display_text[255] = ptr + 1; |
| 1951 } | |
| 1952 | |
| 1953 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
| 1954 ByteCompareStatus = 0; | |
| 1955 | |
| 1956 if(region == 2) | |
| 1957 { | |
| 1958 /* upper region firmware can be larger (1MB) */ | |
| 1959 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
| 1960 ext_flash_erase_firmware2(); | |
| 1961 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
| 1962 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
| 1963 | |
| 1964 if(lengthCompare != length1 + length2) | |
| 1965 ByteCompareStatus = 10000; | |
| 1966 if(offsetTotal != offsetCompare) | |
| 1967 ByteCompareStatus += 20000; | |
| 1968 for(int i = 0; i < length1; i++) | |
| 1969 { | |
| 1970 if(pBuffer1[0] != pBufferCompare[0]) | |
| 1971 ByteCompareStatus++; | |
| 1972 } | |
| 1973 | |
| 1974 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
| 1975 for(int i = 0; i < length2; i++) | |
| 1976 { | |
| 1977 if(pBuffer2[0] != pBufferCompare[0]) | |
| 1978 ByteCompareStatus++; | |
| 1979 } | |
| 1980 } | |
| 1981 else | |
| 1982 { | |
| 1983 /* standard firmware limited to 768000 */ | |
| 1984 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
| 1985 ext_flash_erase_firmware(); | |
| 1986 ext_flash_write_firmware(pBuffer1, length1); | |
| 1987 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
| 1988 | |
| 1989 if(lengthCompare != length1) | |
| 1990 ByteCompareStatus = 10000; | |
| 1991 for(int i = 0; i < length1; i++) | |
| 1992 { | |
| 1993 if(pBuffer1[0] != pBufferCompare[0]) | |
| 1994 ByteCompareStatus++; | |
| 1995 } | |
| 1996 } | |
| 1997 | |
| 1998 releaseFrame(20,(uint32_t)pBufferCompare); | |
| 1999 | |
| 2000 if(ByteCompareStatus != 0) | |
| 2001 { | |
| 2002 strcpy(&display_text[0],"\n\rcopy error."); | |
| 2003 display_text[255] = 21; | |
| 2004 return 0; | |
| 2005 } | |
| 2006 else | |
| 2007 { | |
| 2008 strcpy(&display_text[0],"\n\rready to install."); | |
| 2009 display_text[255] = 21; | |
| 2010 return 1; | |
| 2011 } | |
| 2012 } | |
| 2013 | |
| 396 | 2014 void tComm_RequestBluetoothStrength(void) |
| 2015 { | |
| 2016 EvaluateBluetoothSignalStrength = 1; | |
| 2017 } | |
| 2018 | |
| 2019 /* read, validate the modul answer and flush rx que if necessary */ | |
| 2020 uint8_t tComm_CheckAnswerOK() | |
| 2021 { | |
| 2022 char answerOkay[] = "\r\nOK\r\n"; | |
| 400 | 2023 char aRxBuffer[UART_CMD_BUF_SIZE]; |
| 396 | 2024 uint8_t sizeAnswer = sizeof(answerOkay) -1; |
| 2025 uint8_t result = HAL_OK; | |
| 664 | 2026 uint8_t indexRef = 0; |
| 2027 uint8_t indexBuf = 0; | |
| 396 | 2028 uint8_t answer; |
| 2029 | |
| 400 | 2030 memset(aRxBuffer,0,UART_CMD_BUF_SIZE); |
|
434
f68f2c4d71c7
Reduced timeout for common UART communication:
ideenmodellierer
parents:
400
diff
changeset
|
2031 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, UART_OPERATION_TIMEOUT) == HAL_OK) |
| 396 | 2032 { |
| 2033 do | |
| 2034 { | |
| 664 | 2035 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) |
| 396 | 2036 { |
| 664 | 2037 indexRef++; |
| 396 | 2038 } |
| 2039 else | |
| 2040 { | |
| 664 | 2041 if(indexRef != 0) |
| 2042 { | |
| 2043 indexRef = 0; | |
| 2044 } | |
| 396 | 2045 } |
| 664 | 2046 indexBuf++; |
| 2047 }while(indexBuf < sizeAnswer); | |
| 2048 | |
| 2049 if(indexRef != sizeAnswer) /* unexpected answer => there might be characters left in RX que => read and check all rx bytes */ | |
| 2050 { | |
| 2051 do | |
| 2052 { | |
| 886 | 2053 answer = HAL_ERROR; |
| 664 | 2054 if (indexBuf < UART_CMD_BUF_SIZE) |
| 2055 { | |
| 886 | 2056 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10); |
| 2057 | |
| 664 | 2058 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) |
| 2059 { | |
| 2060 indexRef++; | |
| 2061 } | |
| 2062 else | |
| 2063 { | |
| 2064 if(indexRef != 0) | |
| 2065 { | |
| 2066 indexRef = 0; | |
| 2067 } | |
| 2068 } | |
| 2069 indexBuf++; | |
| 2070 } | |
| 886 | 2071 }while((answer == HAL_OK) && (indexRef != sizeAnswer)); |
| 664 | 2072 if(indexRef != sizeAnswer) |
| 2073 { | |
| 2074 result = HAL_ERROR; | |
| 2075 } | |
| 2076 } | |
| 396 | 2077 } |
| 2078 else | |
| 2079 { | |
| 2080 result = HAL_ERROR; | |
| 2081 } | |
| 2082 return result; | |
| 2083 | |
| 2084 } | |
| 400 | 2085 |
| 396 | 2086 |
| 2087 void tComm_EvaluateBluetoothStrength(void) | |
| 2088 { | |
| 2089 char aTxBufferBarSSI[] = "AT+BARSSI\r"; | |
| 2090 char aTxBufferEscapeSequence[] = "+++"; | |
| 2091 char aTxBufferEnd[] = "ATO\r"; | |
| 2092 uint8_t sizeRequest = sizeof(aTxBufferBarSSI) -1; | |
| 2093 | |
| 2094 uint8_t answer = HAL_OK; | |
| 400 | 2095 char aRxBuffer[UART_CMD_BUF_SIZE]; |
| 2096 char SignalStr[UART_CMD_BUF_SIZE]; | |
| 396 | 2097 uint8_t index = 0; |
| 2098 uint8_t strindex = 0; | |
| 2099 int8_t sigqual = 0; | |
| 2100 | |
| 2101 HAL_Delay(200); | |
| 2102 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000)== HAL_OK) | |
| 2103 { | |
| 2104 if(tComm_CheckAnswerOK() == HAL_OK) | |
| 2105 { | |
| 2106 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferBarSSI,sizeRequest , 2000); | |
| 2107 { | |
| 2108 index = 0; | |
| 2109 do /* Answer is not the common one. Instead the signal strength is received => read all available bytes one by one*/ | |
| 2110 { | |
| 2111 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 100); | |
| 400 | 2112 if(index < UART_CMD_BUF_SIZE) |
| 2113 { | |
| 2114 index++; | |
| 2115 } | |
| 396 | 2116 }while(answer == HAL_OK); |
| 2117 | |
| 2118 if((aRxBuffer[index] != 'E') && (aRxBuffer[index] != 0)) /* E represents the first letter of the string ERROR */ | |
| 2119 { | |
| 2120 index = 0; | |
| 2121 strindex = 0; | |
| 2122 do | |
| 2123 { | |
| 2124 SignalStr[strindex++] = aRxBuffer[index++]; | |
| 400 | 2125 }while ((index < UART_CMD_BUF_SIZE - 1) && (aRxBuffer[index] != '\r')); |
| 396 | 2126 SignalStr[strindex] = 0; /* terminate String */ |
| 2127 sigqual = strtol(SignalStr,NULL,0); | |
| 2128 /* Map db to abstract Bargraph */ | |
| 2129 if(sigqual > 0) | |
| 2130 { | |
| 400 | 2131 sprintf(SignalStr,"Bluetooth ||||||||"); |
| 396 | 2132 } |
| 2133 else | |
| 2134 { | |
| 2135 sprintf(SignalStr,"Bluetooth |"); | |
| 2136 strindex = strlen(SignalStr); | |
| 2137 sigqual *=-1; | |
| 2138 sigqual = 100 - sigqual; /* invert because of negative db value */ | |
| 2139 while(sigqual / 10 > 0 ) | |
| 2140 { | |
| 2141 SignalStr[strindex++] = '|'; | |
| 2142 sigqual -= 10; | |
| 2143 } | |
| 2144 SignalStr[strindex] = 0; | |
| 2145 } | |
| 2146 strcpy(display_text,SignalStr); | |
| 2147 display_text[255] = strlen(SignalStr); | |
| 2148 EvaluateBluetoothSignalStrength = 0; | |
| 2149 } | |
| 2150 } | |
| 2151 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, 2000); /* exit terminal mode */ | |
| 2152 index = 0; | |
| 2153 do /* module will answer with current connection state */ | |
| 2154 { | |
| 2155 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[index], 1, 100); | |
| 400 | 2156 if(index < UART_CMD_BUF_SIZE) |
| 2157 { | |
| 2158 index++; | |
| 2159 } | |
| 396 | 2160 }while(answer == HAL_OK); |
| 2161 } | |
| 2162 } | |
| 2163 } | |
| 2164 | |
| 873 | 2165 #ifdef BOOTLOADER_STANDALONE |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2166 void tComm_StartBlueModBaseInit() |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2167 { |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2168 BmTmpConfig = BM_INIT_TRIGGER_ON; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2169 } |
| 873 | 2170 #endif |
| 2171 | |
| 970 | 2172 |
| 2173 uint8_t tComm_GetBTCmdStr(BTCmd cmdId, char* pCmdStr) | |
| 2174 { | |
| 2175 uint8_t ret = 0; | |
| 2176 uint8_t oldModule = 1; | |
| 2177 | |
| 2178 if(isNewDisplay()) | |
| 2179 { | |
| 2180 oldModule = 0; | |
| 2181 } | |
| 2182 | |
| 2183 switch (cmdId) | |
| 2184 { | |
| 2185 case BT_CMD_ECHO: sprintf(pCmdStr,"ATE0\r"); | |
| 2186 ret = 1; | |
| 2187 break; | |
| 2188 case BT_CMD_SILENCE: if(oldModule) | |
| 2189 { | |
| 2190 strcpy(pCmdStr,"ATS30=0\r"); | |
| 2191 ret = 1; | |
| 2192 } | |
| 2193 break; | |
| 2194 case BT_CMD_ESCAPE_DELAY: if(oldModule) | |
| 2195 { | |
| 2196 strcpy(pCmdStr,"ATS12=10\r"); | |
| 2197 ret = 1; | |
| 2198 } | |
| 2199 break; | |
| 2200 case BT_CMD_SIGNAL_POLL: if(oldModule) | |
| 2201 { | |
| 2202 strcpy(pCmdStr,"AT+BSTPOLL=100\r"); | |
| 2203 ret = 1; | |
| 2204 } | |
| 2205 break; | |
| 2206 case BT_CMD_BAUDRATE_115: if(oldModule) | |
| 2207 { | |
| 2208 strcpy(pCmdStr,"AT%B8\r"); | |
| 2209 } | |
| 2210 else | |
| 2211 { | |
| 2212 strcpy(pCmdStr,"AT+UMRS=115200,1,8,1,1,1\r"); | |
| 2213 } | |
| 2214 ret = 1; | |
| 2215 break; | |
| 2216 | |
| 2217 case BT_CMD_BAUDRATE_460: if(oldModule) | |
| 2218 { | |
| 2219 strcpy(pCmdStr,"AT%B22\r"); | |
| 2220 } | |
| 2221 else | |
| 2222 { | |
| 2223 strcpy(pCmdStr,"AT+UMRS=460800,1,8,1,1,1\r"); | |
| 2224 } | |
| 2225 ret = 1; | |
| 2226 break; | |
| 2227 case BT_CMD_NAME: if(oldModule) | |
| 2228 { | |
| 2229 strcpy(pCmdStr,"AT+BNAME=OSTC4-12345\r"); | |
| 2230 } | |
| 2231 else | |
| 2232 { | |
| 2233 strcpy(pCmdStr,"AT+UBTLN=OSTC5-12345\r"); | |
| 2234 } | |
| 2235 ret = 1; | |
| 2236 break; | |
| 2237 case BT_CMD_EXIT_CMD: if(oldModule) | |
| 2238 { | |
| 2239 strcpy(pCmdStr,"ATO\r"); | |
| 2240 } | |
| 2241 else | |
| 2242 { | |
| 2243 strcpy(pCmdStr,"ATO1\r"); | |
| 2244 } | |
| 2245 ret = 1; | |
| 2246 break; | |
| 2247 default: | |
| 2248 break; | |
| 2249 } | |
| 2250 return ret; | |
| 2251 } | |
| 2252 | |
| 396 | 2253 void tComm_StartBlueModConfig() |
| 2254 { | |
| 2255 uint8_t answer = HAL_OK; | |
| 400 | 2256 uint8_t RxBuffer[UART_CMD_BUF_SIZE]; |
| 396 | 2257 uint8_t index = 0; |
| 2258 | |
| 2259 BmTmpConfig = BM_CONFIG_ECHO; | |
| 2260 do /* flush RX buffer */ | |
| 2261 { | |
| 2262 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&RxBuffer[index], 1, 10); | |
| 400 | 2263 if(index < UART_CMD_BUF_SIZE) index++; |
| 396 | 2264 }while(answer == HAL_OK); |
| 2265 } | |
| 2266 | |
| 2267 uint8_t tComm_HandleBlueModConfig() | |
| 2268 { | |
| 400 | 2269 static uint8_t RestartModule = 1; /* used to do power off / on cycle */ |
| 2270 static uint8_t ConfigRetryCnt = 0; /* Retry count without power cycle */ | |
| 396 | 2271 |
| 400 | 2272 char TxBuffer[UART_CMD_BUF_SIZE]; |
| 396 | 2273 uint8_t CmdSize = 0; |
| 2274 | |
| 2275 uint8_t result = HAL_OK; | |
| 2276 | |
| 970 | 2277 memset(TxBuffer, 0, sizeof(TxBuffer)); |
| 400 | 2278 |
| 396 | 2279 switch (BmTmpConfig) |
| 2280 { | |
| 970 | 2281 case BM_CONFIG_ECHO: tComm_GetBTCmdStr (BT_CMD_ECHO, TxBuffer); |
| 396 | 2282 break; |
| 970 | 2283 case BM_CONFIG_SILENCE: tComm_GetBTCmdStr (BT_CMD_SILENCE, TxBuffer); |
| 396 | 2284 break; |
| 970 | 2285 case BM_CONFIG_ESCAPE_DELAY: tComm_GetBTCmdStr (BT_CMD_ESCAPE_DELAY, TxBuffer); |
| 396 | 2286 break; |
| 970 | 2287 case BM_CONFIG_SIGNAL_POLL: tComm_GetBTCmdStr(BT_CMD_SIGNAL_POLL, TxBuffer); |
| 396 | 2288 break; |
| 893 | 2289 case BM_CONFIG_BAUD: |
| 2290 #ifdef ENABLE_FAST_COMM | |
| 970 | 2291 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_460, TxBuffer); |
| 893 | 2292 #else |
| 966 | 2293 BmTmpConfig = BM_CONFIG_DONE; |
| 893 | 2294 #endif |
| 396 | 2295 break; |
| 400 | 2296 case BM_CONFIG_RETRY: ConfigRetryCnt--; |
| 2297 HAL_Delay(1); | |
| 2298 if(ConfigRetryCnt == 0) | |
| 2299 { | |
| 2300 MX_Bluetooth_PowerOn(); | |
| 2301 tComm_StartBlueModConfig(); | |
| 2302 } | |
| 2303 break; | |
| 396 | 2304 case BM_CONFIG_DONE: |
| 2305 case BM_CONFIG_OFF: | |
| 2306 ConfigRetryCnt = 0; | |
| 400 | 2307 RestartModule = 1; |
| 396 | 2308 break; |
| 970 | 2309 #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
|
2310 case BM_INIT_TRIGGER_ON: HAL_Delay(2000); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2311 HAL_GPIO_WritePin(BLE_UBLOX_DSR_GPIO_PORT,BLE_UBLOX_DSR_PIN,GPIO_PIN_RESET); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2312 BmTmpConfig++; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2313 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2314 case BM_INIT_TRIGGER_OFF: HAL_Delay(1); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2315 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
|
2316 HAL_Delay(2000); |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2317 BmTmpConfig++; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2318 break; |
| 879 | 2319 case BM_INIT_ECHO: sprintf(TxBuffer,"ATE0\r"); |
| 2320 break; | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2321 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
|
2322 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2323 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
|
2324 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2325 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
|
2326 break; |
| 970 | 2327 case BM_INIT_NAME: sprintf(TxBuffer,"AT+UBTLN=OSTC5-12345\r"); /* Bluetooth name */ |
| 2328 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) /* module reinit? => restore old name */ | |
| 2329 { | |
| 2330 gfx_number_to_string(5,1,&TxBuffer[15],hardwareDataGetPointer()->primarySerial); | |
| 2331 } | |
|
872
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2332 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2333 case BM_INIT_SSP_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
|
2334 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2335 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
|
2336 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2337 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
|
2338 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2339 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
|
2340 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2341 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
|
2342 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2343 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
|
2344 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2345 case BM_INIT_DONE: BmTmpConfig = BM_CONFIG_ECHO; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2346 break; |
|
5e027b0f7475
Added first time initialization for new bluetooth module:
Ideenmodellierer
parents:
870
diff
changeset
|
2347 #endif |
| 396 | 2348 default: |
| 2349 break; | |
| 2350 } | |
| 400 | 2351 if(TxBuffer[0] != 0) /* forward command to module */ |
| 396 | 2352 { |
| 2353 CmdSize = strlen(TxBuffer); | |
| 2354 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000) == HAL_OK) | |
| 2355 { | |
| 2356 result = tComm_CheckAnswerOK(); | |
| 2357 | |
| 2358 if((BmTmpConfig == BM_CONFIG_BAUD) && (result == HAL_OK) && (UartHandle.Init.BaudRate != 460800)) /* is com already switched to fast speed? */ | |
| 2359 { | |
| 2360 HAL_UART_DeInit(&UartHandle); | |
| 2361 HAL_Delay(1); | |
| 2362 UartHandle.Init.BaudRate = 460800; | |
| 2363 HAL_UART_Init(&UartHandle); | |
| 2364 } | |
| 893 | 2365 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 | 2366 { |
| 970 | 2367 tComm_GetBTCmdStr(BT_CMD_BAUDRATE_115, TxBuffer); |
| 2368 | |
| 664 | 2369 CmdSize = strlen(TxBuffer); |
| 2370 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2371 HAL_UART_DeInit(&UartHandle); | |
| 2372 HAL_Delay(10); | |
| 2373 UartHandle.Init.BaudRate = 115200; | |
| 2374 HAL_UART_Init(&UartHandle); | |
| 2375 sprintf(TxBuffer,"AT&W\r"); /* write configuration */ | |
| 2376 CmdSize = strlen(TxBuffer); | |
| 2377 HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000); | |
| 2378 } | |
| 396 | 2379 if(result == HAL_OK) |
| 2380 { | |
| 2381 BmTmpConfig++; | |
| 966 | 2382 if(BmTmpConfig == BM_CONFIG_RETRY) |
| 2383 { | |
| 2384 BmTmpConfig = BM_CONFIG_DONE; | |
| 2385 } | |
| 396 | 2386 } |
| 879 | 2387 if(BmTmpConfig == BM_CONFIG_ECHO) |
| 396 | 2388 { |
| 879 | 2389 BmTmpConfig = BM_CONFIG_DONE; |
| 396 | 2390 ConfigRetryCnt = 0; |
| 664 | 2391 RestartModule = 1; |
| 396 | 2392 } |
| 2393 } | |
| 2394 } | |
| 970 | 2395 else /* no command for the configuration step found => skip step */ |
| 2396 { | |
| 2397 if((BmTmpConfig > BM_CONFIG_OFF) && (BmTmpConfig < BM_CONFIG_DONE)) | |
| 2398 { | |
| 2399 BmTmpConfig++; | |
| 2400 } | |
| 2401 } | |
| 396 | 2402 if(result != HAL_OK) |
| 2403 { | |
| 2404 ConfigRetryCnt++; | |
| 2405 if(ConfigRetryCnt > 3) /* Configuration failed => switch off module */ | |
| 2406 { | |
| 2407 MX_Bluetooth_PowerOff(); | |
| 400 | 2408 if(RestartModule) |
| 2409 { | |
| 2410 RestartModule = 0; /* only one try */ | |
| 2411 ConfigRetryCnt = 200; /* used for delay to startup module again */ | |
| 664 | 2412 |
| 970 | 2413 if((BmTmpConfig == BM_CONFIG_ECHO) || (BmTmpConfig == BM_INIT_ECHO)) /* the module did not answer even once => try again with alternative baud rate */ |
| 664 | 2414 { |
| 2415 HAL_UART_DeInit(&UartHandle); | |
| 2416 HAL_Delay(1); | |
| 2417 UartHandle.Init.BaudRate = 460800; | |
| 2418 HAL_UART_Init(&UartHandle); | |
| 2419 } | |
| 400 | 2420 BmTmpConfig = BM_CONFIG_RETRY; |
| 2421 } | |
| 2422 else /* even restarting module failed => switch bluetooth off */ | |
| 2423 { | |
| 2424 ConfigRetryCnt = 0; | |
| 2425 BmTmpConfig = BM_CONFIG_OFF; | |
| 2426 settingsGetPointer()->bluetoothActive = 0; | |
| 2427 } | |
| 396 | 2428 } |
| 2429 } | |
| 2430 return result; | |
| 2431 } | |
| 2432 | |
| 38 | 2433 static void tComm_Error_Handler(void) |
| 2434 { | |
| 2435 while(1) | |
| 2436 {} | |
| 2437 } |
