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