comparison Discovery/Src/tDebug.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children 717f335cc5c9
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/tDebug.c
5 /// \brief Screen with Terminal Out
6 /// \author heinrichs weikamp gmbh
7 /// \date 06-April-2016
8 ///
9 /// \details
10 ///
11 /// $Id$
12 ///////////////////////////////////////////////////////////////////////////////
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
14 ///
15 /// This program is free software: you can redistribute it and/or modify
16 /// it under the terms of the GNU General Public License as published by
17 /// the Free Software Foundation, either version 3 of the License, or
18 /// (at your option) any later version.
19 ///
20 /// This program is distributed in the hope that it will be useful,
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 /// GNU General Public License for more details.
24 ///
25 /// You should have received a copy of the GNU General Public License
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
27 //////////////////////////////////////////////////////////////////////////////
28
29 /* Includes ------------------------------------------------------------------*/
30 #include "tDebug.h"
31
32 #include "data_exchange_main.h"
33 #include "gfx_engine.h"
34 #include "gfx_fonts.h"
35 #include "ostc.h"
36 #include "tInfo.h"
37
38 #include "stm32f4xx_hal.h"
39
40 #include <string.h>
41
42 uint8_t tD_selection_page = 1;
43 uint8_t tD_debugModeActive = 0;
44 uint8_t tD_status = 0;
45
46 char tD_communication[6][40];
47
48 void tDebug_Action(void);
49 void tDebug_NextPage(void);
50
51
52 void setDebugMode(void)
53 {
54 tD_debugModeActive = 1;
55 }
56
57
58 void exitDebugMode(void)
59 {
60 MX_Bluetooth_PowerOff();
61 settingsGetPointer()->debugModeOnStart = 0;
62 tD_debugModeActive = 0;
63 }
64
65
66 uint8_t inDebugMode(void)
67 {
68 return tD_debugModeActive;
69 /*
70 if(settingsGetPointer()->showDebugInfo == 2)
71 return 1;
72 else
73 return 0;
74 */
75 }
76
77
78 void tDebug_start(void)
79 {
80 MX_Bluetooth_PowerOn();
81
82 tD_debugModeActive = 1;
83 tD_status = 0;
84 for(int i=0;i<6;i++)
85 tD_communication[i][0] = 0;
86
87 set_globalState(StIDEBUG);
88 }
89
90
91 void tDebugControl(uint8_t sendAction)
92 {
93 switch(sendAction)
94 {
95 case ACTION_BUTTON_ENTER:
96 tDebug_Action();
97 break;
98 case ACTION_BUTTON_NEXT:
99 tDebug_NextPage();
100 break;
101 case ACTION_TIMEOUT:
102 case ACTION_MODE_CHANGE:
103 case ACTION_BUTTON_BACK:
104 exitInfo();
105 default:
106 break;
107 case ACTION_IDLE_TICK:
108 case ACTION_IDLE_SECOND:
109 break;
110 }
111 }
112
113
114 void tDebug_refresh(void)
115 {
116 uint8_t color;
117 char text[50];
118
119 tInfo_write_content_simple( 700,780, 20, &FontT24, "\0021/1", CLUT_NiceGreen);
120
121 tInfo_write_content_simple( 20,780, 20, &FontT24, "Debug Terminal", CLUT_NiceGreen);
122 /*
123 snprintf(text,50,"X: %i Y: %i Z: %i %03.0f %03.0f"
124 ,stateUsed->lifeData.compass_DX_f
125 ,stateUsed->lifeData.compass_DY_f
126 ,stateUsed->lifeData.compass_DZ_f
127 ,stateUsed->lifeData.compass_roll
128 ,stateUsed->lifeData.compass_pitch
129 );
130 */
131 snprintf(text,50,"roll %.0f pitch %.0f"
132 ,stateUsed->lifeData.compass_roll
133 ,stateUsed->lifeData.compass_pitch
134 );
135
136 tInfo_write_content_simple( 20,780, 60, &FontT24, text, CLUT_NiceGreen);
137
138 for(int i=0;i<6;i++)
139 {
140 if(i%2)
141 color = CLUT_WarningRed;
142 else
143 color = CLUT_WarningYellow;
144 tInfo_write_content_simple( 20,780, (60*i)+100, &FontT42, tD_communication[i], color);
145 }
146 }
147
148
149 void tDebug_NextPage(void)
150 {
151
152 }
153
154
155 void tDebug_helper_replaceCRLF(char *text, uint8_t maxlength)
156 {
157 for(int i=0; i<maxlength; i++)
158 {
159 if(text[i] == 0)
160 break;
161 if((text[i] == '\r') || (text[i] == '\n'))
162 text[i] = ' ';
163 }
164 }
165
166
167 void tDebug_Action(void)
168 {
169 char aRxBuffer[50];
170
171 char aTxBufferEscapeSequence[4] = "+++";
172 char aTxBufferName[22] = "AT+BNAME=OSTC4-12345\r";
173 char aTxBufferWrite[6] = "AT&W\r";
174 gfx_number_to_string(5,1,&aTxBufferName[15],hardwareDataGetPointer()->primarySerial);
175
176 tD_status++;
177
178 switch(tD_status)
179 {
180 case 1:
181 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000) == HAL_OK)
182 {
183 strcpy(tD_communication[0],aTxBufferEscapeSequence);
184 }
185 else
186 {
187 strcpy(tD_communication[0],"Error.");
188 }
189
190 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 3, 2000) == HAL_OK)
191 {
192 aRxBuffer[3] = 0;
193 tDebug_helper_replaceCRLF(aRxBuffer, 3);
194 strcpy(tD_communication[1],aRxBuffer);
195 }
196 else
197 {
198 strcpy(tD_communication[1],"Error.");
199 }
200 break;
201
202 case 2:
203 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferName, 21, 2000) == HAL_OK)
204 {
205 strcpy(tD_communication[2],aTxBufferName);
206 }
207 else
208 {
209 strcpy(tD_communication[2],"Error.");
210 }
211
212 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 21+6, 2000) == HAL_OK)
213 {
214 aRxBuffer[21+6] = 0;
215 tDebug_helper_replaceCRLF(aRxBuffer, 21+6);
216 strcpy(tD_communication[3],aRxBuffer);
217 }
218 else
219 {
220 strcpy(tD_communication[3],"Error.");
221 }
222 break;
223
224 case 3:
225 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferWrite, 5, 2000) == HAL_OK)
226 {
227 strcpy(tD_communication[4],aTxBufferWrite);
228 }
229 else
230 {
231 strcpy(tD_communication[4],"Error.");
232 }
233
234 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5+6, 2000) == HAL_OK)
235 {
236 aRxBuffer[5+6] = 0;
237 tDebug_helper_replaceCRLF(aRxBuffer, 5+6);
238 strcpy(tD_communication[5],aRxBuffer);
239 }
240 else
241 {
242 strcpy(tD_communication[5],"Error.");
243 }
244 break;
245
246 default:
247 tD_status = 0;
248 break;
249 }
250 }
251
252
253
254 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
255