annotate Discovery/Src/tComm.c @ 972:12426391edd9 Evo_2_23 tip

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