Vous êtes sur la page 1sur 24

bung 11

HSD / SBS4

Daniel Pfeil
Name:
Gruppe 2
Gruppe:
1/2
Punkte:

/ 12

Ethernet Teil 4 - HTTP


Aufgabe
In der letzten Ethernet-bung wird nun der eigentliche Webserver implementiert. Der
vorgegebene Code muss noch an einigen Stellen (mit TODO gekennzeichnet) ergnzt
werden.
Die Webseiten werden im Speicher des STM32 abgelegt. Diese wurden zuvor konvertiert und
in Header-Dateien abgelegt. Somit knnen sie direkt in das Projekt eingebunden werden.
Alternativ wre eine Anbindung des SD-Karten-Interfaces zum dynamischen Laden der
Webseitendateien mglich. Der aktuelle Sourcecode beinhaltet dies allerdings noch nicht.
Der Webserver soll die LEDs am Board einschalten und einen Text am Display anzeigen
knnen. Zustzlich sollen Tastenwerte und Analogwert auslesen und visualisieren knnen.
Dazu wird die Webseite am MCBSTM32F200 Board zur Laufzeit zusammengesetzt und an
den Client (Webbrowser) bertragen. Implementieren Sie diese dazu notwendigen
Funktionen im vorgegebenen Code.
Beschreiben Sie, wie der Ablauf zum Laden einer Webseite mittels GET ist bzw. was bei
einem POST passiert. Wie knnen Variablen vom MCBSTM32F200-Board (z.B. Taste gedrckt
ja/nein) in die Webseite eingebaut und zur Laufzeit (beim Laden der Webseite vom Board) an
den Webbrowser bertragen werden? Beschreiben Sie dazu die Funktionsweise von Server
Side Includes.

Link zu HTTP auf Wikipedia


http://de.wikipedia.org/wiki/Hypertext_Transfer_Protocol

Abgabe
Sourcecode (genderte Stellen) (5 Punkte)
Beschreibung der Ablufe bzw. Server Side Includes (5 Punkte)
Screenshot von Wireshark (Verbindungsaufbau, Webseite laden,

Verbindungsabbau) + Screenshot des Browsers + Foto des GLCD (2 Punkte)

Seite 1 von 1

Oyrer Andreas


SBS4: Ubung
11

Daniel Pfeil - S1410306042

Daniel Pfeil - S1410306042

Ubung
11

Inhaltsverzeichnis
Beispiel 1
Funktionsbeschreibung der Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Beschreibung der Abl
aufe bzw. Server Side Includes . . . . . . . . . . . . . . . . . . . . . . . . . .
Beschreiben Sie, wie der Ablauf zum Laden einer Webseite mittels GET ist bzw. was bei einem
POST passiert. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wie k
onnen Variablen vom MCBSTM32F200-Board (z.B. Taste gedr
uckt ja/nein) in die Webseite eingebaut und zur Laufzeit (beim Laden der Webseite vom Board) an den Webbrowser u
bertragen werden? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Beschreiben Sie dazu die Funktionsweise von Server Side Includes. . . . . . . . . . . . . . . .
Sourcecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Screenshot von Wireshark (Verbindungsaufbau, Webseite laden,Verbindungsabbau) . . . . . . . . .
Screenshot des Browsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Foto vom GLCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4
4
4
4

4
4
5
18
19
22

Seite 3 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1

Hier wird die L


osung f
ur die Ubung
11 in SBS4 beschrieben.

Wie auch in den anderen Ubungen


kann es auch hier passieren, dass Latex den Code nicht ordentlich formatiert.

Funktionsbeschreibung der Software

Die Schritte der Ubung


10 wurden hier nicht mehr dokumentiert (ARP, DHCP etc). Es wurde auerdem
mit einer fixen IP gearbeitet, da das mit dem DHCP Server so ein Herumgetue ist. Es wurde sich auf das
wesentlichste beschr
ankt und der Fokus auf die geforderten Funktionen gelegt.
Die einzelnen L
ucken wurden ausef
ullt und die Funktionen getestet.

Beschreibung der Abl


aufe bzw. Server Side Includes
Quelle: Wikipedia
Beschreiben Sie, wie der Ablauf zum Laden einer Webseite mittels GET ist bzw. was bei einem
POST passiert.
GET
Mittels GET werden Daten vom Server geladen. Die Quelle und welche Daten geladen werden sollten
sind in der URL enthalten. Der Client stellt mittels dem GET (HTTP) eine Anfrage an den Server,
dass er gerne Daten haben w
urde. Der Server antwortet mit OK (HTTP). Somit wei der Client, dass
der Server die Anfrage verstanden hat und nun wei, was zu tun ist. Jetzt werden die angeforderten

Daten u
wird die Verbindung Serverseitig beendet.
bertragen. Nach der Ubertragung
POST
Mit dem HTTP Befehl POST k
onnen Daten zum Server geschickt werden. Im Gegensatz zu GET sind
aber die Daten nicht in der URL enthalten. Somit ist es moglich auch groe Datenmengen zum Server
zu u
bertragen. schickt unbegrenzte, je nach physischer Ausstattung des eingesetzten Servers, Mengen
an Daten zur weiteren Verarbeitung zum Server, diese werden als Inhalt der Nachricht u
bertragen und
k
onnen beispielsweise aus Name-Wert-Paaren bestehen, die aus einem HTML-Formular stammen. Es
k
onnen so neue Ressourcen auf dem Server entstehen oder bestehende modifiziert werden. POST-Daten
werden im Allgemeinen nicht von Caches zwischengespeichert. Zusatzlich konnen bei dieser Art der

Ubermittlung
auch Daten wie in der GET-Methode an den URI gehangt werden.

Wie k
onnen Variablen vom MCBSTM32F200-Board (z.B. Taste gedr
uckt ja/nein) in die Webseite eingebaut und zur Laufzeit (beim Laden der Webseite vom Board) an den Webbrowser
u
bertragen werden?
Dies wird mittels Server Side Includes realisiert. Dies Funktionsweise wird im nachsten Punkt beschrieben.
Beschreiben Sie dazu die Funktionsweise von Server Side Includes.
Server Side Includes sind in HTML-Dokumente eingebettete, einfach zu nutzende Skript-Befehle, die auf
dem Webserver ausgef
uhrt werden, bevor das Dokument an den Client ausgeliefert wird. Sie stellen eine
einfach zu verwendende Alternative zu Programmen bzw. Skripten dar, die das ganze Dokument dynamisch
generieren.

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 4 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Zusammengefasst kann man mit den SSIs den Inhalt der Webseite verandern. Vor dem Senden der Website
an den Client werden die Werte vom Server eingetragen. Der Browser baut dann die Seite mit den aktuellen
Werten auf. Somit kann dynamisch die Website geandert werden.
Syntax f
ur eine SSI:
<!--#befehl parametername1="wert" parametername2="wert" -->

Sourcecode

Es wurden nur die ge


anderten Dateien eingebunden. Alle anderen f
ur diese Ubung
relevanten Module wurden

aus Ubung
10 u
ur fehlen sollte, bitte melden :-)
bernommen. Wenn etwas f
Listing 1: main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

/**
******************************************************************************
LwIP/LwIP_TCP_Echo_Server/Src/main.c
* @file
* @author MCD Application Team
* @version V1.1.0
13-March-2014
* @date
This sample code implements a TCP Echo Server application based on
* @brief
Raw API of LwIP stack. This application uses STM32F2xx the
*
ETH HAL API to transmit and receive data.
*
The communication is done with a web browser of a remote PC.
*
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
http://www.st.com/software_license_agreement_liberty_v2
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

30
31
32
33
34
35
36
37
38
39

/* Includes ------------------------------------------------------------------*/
#include "lwip/opt.h"
#include "lwip/init.h"
#include "lwip/netif.h"
#include "lwip/lwip_timers.h"
#include "netif/etharp.h"
#include "ethernetif.h"
#include "app_ethernet.h"
#include "tcp_echoserver.h"

40

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 5 von 24

Daniel Pfeil - S1410306042

41
42
43
44
45
46

#include
#include
#include
#include
#include
#include

Ubung
11

Beispiel 1 (fortgesetzt)

"stm32f2xx_hal.h"
"board_glcd.h"
"board_led.h"
"board_buttons.h"
"httpd.h"
<string.h>

47
48
49

extern GLCD_FONT GLCD_Font_16x24;


extern GLCD_FONT GLCD_Font_6x8;

50
51
52
53
54

/* Private typedef -----------------------------------------------------------*/


/* Private define ------------------------------------------------------------*/
#define LCD_FONT_H 6
#define LCD_FONT_W 8

55
56
57
58
59

/* Private macro -------------------------------------------------------------*/


/* Private variables ---------------------------------------------------------*/
s t a t i c struct netif gnetif;
s t a t i c uint16_t const cPort = 1234;

60
61
62
63

/* Private function prototypes -----------------------------------------------*/


s t a t i c void SystemClock_Config(void);
s t a t i c void Netif_Config(void);

64
65

/* Private functions ---------------------------------------------------------*/

66
67
68
69
70

/**

71

* @brief Main program.


* @param None
* @retval None
*/
int main(void)
{
GLCD_FONT *font = &GLCD_Font_6x8;
//char displayBuf[50];

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

/* STM32F2xx HAL library initialization:


- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
LED_Initialize();
Buttons_Initialize();

89
90
91
92

//init GLCD
GLCD_Initialize();
color: black, background color: white

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

// default: foreground

Seite 6 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

GLCD_ClearScreen();
GLCD_SetFont(font);

93
94
95

/* TODO: initialize GLCD and display a startup message */


GLCD_DrawString(0,0,"Startup done.");

96
97
98

/* Configure the Network interface */


Netif_Config();

99
100
101

/* Notify user about the network interface config */


User_notification(&gnetif);

102
103
104

/* TODO: do tcp echo server init */


//tcp_echoserver_init(cPort);
httpd_init();

105
106
107
108
109
110

/* Infinite loop */
while (1)
{
/* Check for link changes */
ethernetif_set_link(&gnetif);

111
112
113
114
115
116

/* read a received packet and send it to LWIP */


ethernetif_input(&gnetif);

117
118
119

/* handle timeouts */
sys_check_timeouts();

120
121
122
123
124
125
126

#i f d e f USE_DHCP_SERVER
/* handle DHCP process */
DHCP_process(&gnetif);
#endif

127
128

129
130

131
132
133
134

/**

135

* @brief Configurates the network interface


* @param None
* @retval None
*/
s t a t i c void Netif_Config(void)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;

136
137
138
139
140
141
142
143
144
145

/* Initilaize the LwIP stack */

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 7 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

lwip_init();

146
147
148
149
150
151
152
153
154
155
156
157
158

#i f d e f USE_DHCP_SERVER
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
IP4_ADDR(&gw, 0, 0, 0, 0);
#e l s e
IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
#endif
/* add the network interface */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &
ethernet_input);

159

/* Registers the default network interface */


netif_set_default(&gnetif);

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

/* check the current state */


i f (netif_is_link_up(&gnetif))
{
#ifndef USE_DHCP_SERVER
/* When the netif is fully configured this function must be called */
netif_set_up(&gnetif);
#endif
}
else
{
/* When the netif link is down this function must be called */
netif_set_down(&gnetif);
}

176

/* Set the link callback function, this function is called on change of link
status*/
netif_set_link_callback(&gnetif, ethernetif_update_config);

177

178
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

/**
* @brief
*
*
*
*
*
*
*
*
*
*
*
*
*
*

System Clock Configuration


The system Clock is configured as follow :
System Clock source
= PLL (HSE)
SYSCLK(Hz)
= 120000000
HCLK(Hz)
= 120000000
AHB Prescaler
= 1
APB1 Prescaler
= 4
APB2 Prescaler
= 2
HSE Frequency(Hz)
= 25000000
PLL_M
= 25
PLL_N
= 240
PLL_P
= 2
PLL_Q
= 5
VDD(V)
= 3.3
Flash Latency(WS)
= 3

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 8 von 24

Daniel Pfeil - S1410306042

197
198
199
200
201
202
203

Ubung
11

Beispiel 1 (fortgesetzt)

* @param None
* @retval None
*/
s t a t i c void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;

204

/* Enable HSE Oscillator and activate PLL with HSE as source */


RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 240;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 5;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

205
206
207
208
209
210
211
212
213
214
215

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);

216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235

/*----------------------------------------------------------------------------this method is called when running HAL_Init()


we change the default clock to 120MHz using HSE and update the SysTick
*----------------------------------------------------------------------------*/
void HAL_MspInit(void) {
SystemClock_Config();
// call this method to update the value of SystemCoreClock
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock / 1000);

236

/* Set Systick Interrupt to the highest priority */


HAL_NVIC_SetPriority(SysTick_IRQn, 0x0, 0x0);

237
238
239

240
241
242
243
244
245
246
247

#i f d e f RTE_CMSIS_RTOS_RTX
/*----------------------------------------------------------------------------this method is needed because SysTick_Handler is used for the OS
but HAL_Delay needs a tick timer (i.e. HAL_Delay which is used for GLCD
so we have to provide the tick counter from the os
*----------------------------------------------------------------------------*/
extern uint32_t os_time;

248
249

uint32_t HAL_GetTick(void) {

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 9 von 24


Ubung
11

Daniel Pfeil - S1410306042

250
251
252
253
254
255
256
257
258
259
260
261

Beispiel 1 (fortgesetzt)

return os_time;
}
#e l s e
/*----------------------------------------------------------------------------this is the SysTick interrupt handler which is called every 1ms
we have to increment the HAL tick counter which is used for HAL_Delay
this is only needed if we dont use a OS
*----------------------------------------------------------------------------*/
void SysTick_Handler(){
HAL_IncTick();
}
#endif

262
263

#i f d e f

USE_FULL_ASSERT

264
265

/**

266

* @brief Reports the name of the source file and the source line number
where the assert_param error has occurred.
*
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

/* Infinite loop */
while (1)
{}
}
#endif

282
283
284

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Listing 2: httpd-cgi-ssi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

/**
******************************************************************************
LwIP/LwIP_HTTP_Server_Raw/Src/httpd_cg_ssi.c
* @file
* @author MCD Application Team
* @version V1.1.0
13-March-2014
* @date
Webserver SSI and CGI handlers
* @brief
******************************************************************************
* @attention
*
*
*
*
*
*
*

<h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>


Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at:

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 10 von 24

Daniel Pfeil - S1410306042

17
18
19
20
21
22
23
24
25
26

Ubung
11

Beispiel 1 (fortgesetzt)

http://www.st.com/software_license_agreement_liberty_v2
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/

27
28
29
30
31
32
33
34
35
36

/* Includes ------------------------------------------------------------------*/
#include "lwip/debug.h"
#include "httpd.h"
#include "lwip/tcp.h"
#include "fs.h"
#include "board_led.h"
#include "board_glcd.h"
#include "board_buttons.h"
#include "stm32f2xx_hal.h"

37
38
39
40

#include <string.h>
#include <stdlib.h>

41
42

uint32_t ADC_not_configured=1;

43
44

ADC_HandleTypeDef hadc;

45
46
47
48
49
50
51
52

//defines
//------#define USER
1
#define TAMPER
2
#define WAKEUP 4
#define LCD_FONT_H 8
#define LCD_FONT_W 6

53
54
55
56
57

// variables
//---------s t a t i c uint16_t adcVal = 0;
s t a t i c bool adcConvCompl = f a l s e ;

58
59
60
61
62

//constants
//--------s t a t i c uint32_t const cMaxVoltage = 3300;
s t a t i c uint32_t const cFactor = 4096;

63
64
65
66
67
68
69

/* we will use character "t" and "led<x>" as tag for SSI */


s t a t i c char const * const SSI_TAGS[] = {
"t",
"led1",
"led2",

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 11 von 24


Ubung
11

Daniel Pfeil - S1410306042

70
71
72
73
74
75
76
77
78
79

Beispiel 1 (fortgesetzt)

"led3",
"led4",
"led5",
"led6",
"led7",
"led8",
"key1",
"key2",
"key3"
};

80
81

#define SSI_TAGS_COUNT

12

82
83
84

85
86

/* CGI handler for LED control */


const char * LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *
pcValue[]);
/* CGI handler for DISPLAY control */
const char * GLCD_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *
pcValue[]);

87
88
89
90
91

/* Html request for "/leds.cgi" will start LEDS_CGI_Handler */


const tCGI LEDS_CGI={"/leds.cgi", LEDS_CGI_Handler};
/* Html request for "/glcd.cgi" will start GLCD_CGI_Handler */
const tCGI GLCD_CGI={"/glcd.cgi", GLCD_CGI_Handler};

92
93

#define CGI_TABS_COUNT

94
95
96
97

/* Cgi call table, two CGIs used */


tCGI CGI_TABS[CGI_TABS_COUNT];

98
99
100
101
102
103
104
105
106
107

/**
* @brief ADC_MspInit
* @param None
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef *heth)
{
/* TODO: configure ADC GPIO and clock */
}

108
109

/**

110

* @brief Configures the ADC.


* @param None
* @retval None
*/
s t a t i c void ADC_Configuration(void)
{
/* TODO: configure and start ADC3 */

111
112
113
114
115
116
117
118
119

//this code is from UE1


//---------------------

120

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 12 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

//Init GPIO with Poti


__GPIOF_CLK_ENABLE();
GPIOF->MODER |= GPIO_MODER_MODER9_0 | GPIO_MODER_MODER9_1; //analog Mode

121
122
123
124

//Init ADC
__ADC3_CLK_ENABLE();
ADC3->SQR3 |= ADC_SQR3_SQ1_0 | ADC_SQR3_SQ1_1 | ADC_SQR3_SQ1_2; //Input
7, Sequence 1

125
126
127

128

//Enable Interrupt for ADC


ADC3->CR1 |= ADC_CR1_EOCIE;
NVIC_EnableIRQ(ADC_IRQn);

129
130
131
132

ADC3->CR2 |= ADC_CR2_ADON; //enable ADC

133
134

135
136
137
138

void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc) {


/* nothing to do here because we poll for results */
}

139
140
141

/**

142

* @brief SSI_Handler : SSI handler for ADC and LED page


*/
u16_t SSI_Handler(int iIndex, char *pcInsert, int iInsertLen)
{
uint32_t voltage = 0;
//in mV
uint32_t keyState = 0;
uint8_t const idxUserKey = 11;
uint8_t const idxTamperKey = 10;
uint8_t const idxWakeupKey = 9;

143
144
145
146
147
148
149
150
151
152
153
154

/* iIndex 0 means ADC */


i f (iIndex == 0)
{

155
156
157

char Digit1=0, Digit2=0, Digit3=0, Digit4=0;


//uint32_t ADCVal = 0;

158
159
160
161
162
163
164

/* configure ADC if not yet configured */


i f (ADC_not_configured ==1)
{
ADC_Configuration();
ADC_not_configured=0;
}

165
166
167
168
169
170
171

//HAL_ADC_PollForConversion(&hadc, 10);
/* TODO: get ADC conversion value and convert it to mV */
ADC3->CR2 |= ADC_CR2_SWSTART; //starts adc conv
while(adcConvCompl == f a l s e );
adcConvCompl = f a l s e ;
voltage = adcVal * cMaxVoltage / cFactor;

172

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 13 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

/* TODO: get the 4 digits to display on the website */


Digit4 = voltage % 10;
voltage /= 10;
Digit3 = voltage % 10;
voltage /= 10;
Digit2 = voltage % 10;
voltage /= 10;
Digit1 = voltage % 10;

173
174
175
176
177
178
179
180
181

/* prepare
*pcInsert
*(pcInsert
*(pcInsert
*(pcInsert

182
183
184
185
186

data to be inserted in html */


= (char)(Digit1+0x30);
+ 1) = (char)(Digit2+0x30);
+ 2) = (char)(Digit3+0x30);
+ 3) = (char)(Digit4+0x30);

187
188
189
190
191
192
193
194
195
196
197
198
199

/* 4 characters need to be inserted in html*/


return 4;
/* iIndex 1-8 is used for the LEDs */
} e l s e i f (iIndex >= 1 && iIndex <= 8) {
i f (LED_Get(iIndex - 1)) {
strcpy(pcInsert, "checked");
return 7;
}
return 0;
/* iIndex 9-12 is used for the keys */
} e l s e i f (iIndex >= 9 && iIndex < 12) {
//todo

200
201
202
203
204
205
206
207

//
//
//
//
//
//
//

if ( /* pressed ? */ true /*todo*/) {


{
strcpy(pcInsert, "pressed");
return 7;
}
strcpy(pcInsert, "released");
return 8;

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

keyState = Buttons_GetState();
i f (iIndex == idxUserKey)
{
i f (keyState & USER)
{
strcpy(pcInsert, "pressed");
return 7;
}
else
{
strcpy(pcInsert, "released");
return 8;
}
}

224
225

i f (iIndex == idxTamperKey)

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 14 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

226

i f (keyState & TAMPER)


{
strcpy(pcInsert, "pressed");
return 7;
}
else
{
strcpy(pcInsert, "released");
return 8;
}

227
228
229
230
231
232
233
234
235
236

237
238

i f (iIndex == idxWakeupKey)
{
i f (keyState & WAKEUP)
{
strcpy(pcInsert, "pressed");
return 7;
}
else
{
strcpy(pcInsert, "released");
return 8;
}
}

239
240
241
242
243
244
245
246
247
248
249
250
251
252

}
return 0;

253
254
255

256
257

/**

258

* @brief CGI handler for LEDs control


*/
const char * LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *
pcValue[])
{
uint32_t i=0;
uint8_t ledState[LED_COUNT];

259
260

261
262
263
264
265

memset(ledState, 0x00, s i z e o f (ledState));

266
267
268
269
270
271
272
273
274
275
276
277

/* CGI handler iIndex = 0 for LEDs */


i f (iIndex == 0)
{
/* Check cgi parameter : example GET /leds.cgi?led=2&led=4 */
for (i = 0; i < iNumParams; i++)
{
/* check parameter "led" */
i f (strcmp(pcParam[i] , "led") == 0)
{
/* TODO: set the ledState for the given pcValue */
ledState[atoi(pcValue[i]) - 1] = 1;

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 15 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

}
}
/* TODO: now switch on or off the LEDs based on the values in ledState */
for (i = 0; i < LED_COUNT; i++)
{
ledState[i] == 1 ? LED_On(i) : LED_Off(i);
}

278
279
280
281
282
283
284
285

}
/* uri to send after cgi call*/
return "/STM32F2x7LED.shtml";

286
287
288
289

290
291

/**

292

* @brief CGI handler for GLCD control


*/
const char * GLCD_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *
pcValue[])
{
uint32_t i = 0;
uint32_t j = 0;
uint32_t txtLen = 0;

293
294

295
296
297
298
299

/* CGI handler iIndex = 1 for GLCD */


i f (iIndex == 1)
{
/* Check cgi parameter : example GET /glcd.cgi?text=hello */
for (i = 0; i < iNumParams; i++)
{
/* TODO: check parameter for glcd and show on display */
GLCD_DrawString(0,1*LCD_FONT_H, "Text from Homepage:");
GLCD_DrawString(0,2*LCD_FONT_H, "
"); //clear line

300
301
302
303
304
305
306
307
308
309

//find "+" and replace it to blankspace


txtLen = strlen(pcValue[0]);
for(j = 0; j < txtLen; j++)
{
i f (pcValue[0][j] == +)
{
pcValue[0][j] = ;
}
}

310
311
312
313
314
315
316
317
318
319

GLCD_DrawString(0,2*LCD_FONT_H, pcValue[0]);

320

321

}
/* uri to send after cgi call*/
return "/STM32F2x7GLCD.html";

322
323
324
325

326
327
328
329

/**
* Initialize SSI handlers
*/

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 16 von 24

Daniel Pfeil - S1410306042

330
331
332
333
334

Ubung
11

Beispiel 1 (fortgesetzt)

void httpd_ssi_init(void)
{
/* configure SSI handlers (ADC and LED page SSI) */
http_set_ssi_handler(SSI_Handler, (char const **)SSI_TAGS, SSI_TAGS_COUNT);
}

335
336
337
338
339
340
341
342
343
344
345

/**
* Initialize CGI handlers
*/
void httpd_cgi_init(void)
{
/* configure CGI handlers (LEDs and GLCD control CGI) */
CGI_TABS[0] = LEDS_CGI;
CGI_TABS[1] = GLCD_CGI;
http_set_cgi_handlers(CGI_TABS, CGI_TABS_COUNT);
}

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

/**********************************************
\fn
ADC_IRQHandler
\brief
ISR for ADC
\param[in]
none
\returns
none
************************************************/
void ADC_IRQHandler(void)
{
i f (ADC3->SR & ADC_SR_EOC)
//conversion completet
{
adcVal = ADC3->DR;
adcConvCompl = true;
}
}

362
363

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 17 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Screenshot von Wireshark (Verbindungsaufbau, Webseite laden,Verbindungsabbau)


Hier sieht man den Verbindungsaufbau u
ber TCP (SYN) und das Laden der Webeite u
ber HTTP (GET).
Ebenfalls wird auf hier der Verbindungsabbau aufgelistet TCP(FIN). Es sind mehrere GET Aufrufe, da die
Bilder der Homepage ebenfalls geladen werden.

Abbildung 1: Wireshartk Screenshot

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 18 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Screenshot des Browsers

Abbildung 2: Browser Texteingabe

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 19 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Abbildung 3: Browser LED

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 20 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Abbildung 4: Browser ADC und Keys

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 21 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Foto vom GLCD

Abbildung 5: LCD Text

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 22 von 24


Ubung
11

Daniel Pfeil - S1410306042

Beispiel 1 (fortgesetzt)

Abbildung 6: LCD LED

Beispiel 1 auf der n


achsten Seite fortgesetzt. . .

Seite 23 von 24

Daniel Pfeil - S1410306042

Ubung
11

Beispiel 1 (fortgesetzt)

Abbildung 7: LCD ADC und Keys

Seite 24 von 24

Vous aimerez peut-être aussi