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