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