Select one of the symbols to view example projects that use it.
 
Outline
#include "main.h"
#include "lwip/debug.h"
#include "lwip/tcp.h"
#include "lwip/apps/httpd.h"
#include "http_cgi_ssi.h"
#include <string.h>
#include <stdlib.h>
ADC_Page_SSI_Handler
ADC_not_configured
hadc
TAGCHAR
TAGS
LEDS_CGI
CGI_TAB
ADC_Configuration()
ADC_Handler(int, char *, int)
LEDS_CGI_Handler(int, int, char **, char **)
http_server_init()
Files
loading...
CodeScopeSTM32 Libraries and SamplesLwIP_HTTP_Server_RawSrc/httpd_cgi_ssi.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file LwIP/LwIP_HTTP_Server_Raw/Src/httpd_cg_ssi.c * @author MCD Application Team * @brief Webserver SSI and CGI handlers ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "lwip/debug.h" #include "lwip/tcp.h" #include "lwip/apps/httpd.h" #include "http_cgi_ssi.h" #include <string.h> #include <stdlib.h> 7 includes tSSIHandler ADC_Page_SSI_Handler; uint32_t ADC_not_configured=1; ADC_HandleTypeDef hadc; /* we will use character "t" as tag for CGI */ char const* TAGCHAR="t"; char const** TAGS=&TAGCHAR; /* CGI handler for LED control */ const char * LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]); /* Html request for "/leds.cgi" will start LEDS_CGI_Handler */ const tCGI LEDS_CGI={"/leds.cgi", LEDS_CGI_Handler}; /* Cgi call table, only one CGI used */ tCGI CGI_TAB[1]; /** * @brief Configures the ADC. * @param None * @retval None *//* ... */ static void ADC_Configuration(void) { ADC_ChannelConfTypeDef sConfig; /* ADC3 Configuration ------------------------------------------------------*/ hadc.Instance = ADC3; hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; hadc.Init.Resolution = ADC_RESOLUTION_12B; hadc.Init.ScanConvMode = DISABLE; hadc.Init.ContinuousConvMode = ENABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.NbrOfConversion = 1; HAL_ADC_Init(&hadc); /* ADC3 Regular Channel Config */ sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; sConfig.Offset = 0; HAL_ADC_ConfigChannel(&hadc, &sConfig); /* Enable EOC interrupt */ HAL_ADC_Start(&hadc); }{ ... } /** * @brief ADC_Handler : SSI handler for ADC page *//* ... */ u16_t ADC_Handler(int iIndex, char *pcInsert, int iInsertLen) { /* We have only one SSI handler iIndex = 0 */ if (iIndex ==0) { char Digit1=0, Digit2=0, Digit3=0, Digit4=0; uint32_t ADCVal = 0; /* configure ADC if not yet configured */ if (ADC_not_configured ==1) { ADC_Configuration(); ADC_not_configured=0; }if (ADC_not_configured ==1) { ... } HAL_ADC_PollForConversion(&hadc, 10); /* get ADC conversion value */ ADCVal = HAL_ADC_GetValue(&hadc); /* convert to Voltage, step = 0.8 mV */ ADCVal = (uint32_t)(ADCVal * 0.8); /* get digits to display */ Digit1= ADCVal/1000; Digit2= (ADCVal-(Digit1*1000))/100; Digit3= (ADCVal-((Digit1*1000)+(Digit2*100)))/10; Digit4= ADCVal -((Digit1*1000)+(Digit2*100)+ (Digit3*10)); /* prepare data to be inserted in html */ *pcInsert = (char)(Digit1+0x30); *(pcInsert + 1) = (char)(Digit2+0x30); *(pcInsert + 2) = (char)(Digit3+0x30); *(pcInsert + 3) = (char)(Digit4+0x30); /* 4 characters need to be inserted in html*/ return 4; }if (iIndex ==0) { ... } return 0; }{ ... } /** * @brief CGI handler for LEDs control *//* ... */ const char * LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) { uint32_t i=0; /* We have only one SSI handler iIndex = 0 */ if (iIndex==0) { /* All LEDs off */ BSP_LED_Off(LED1); BSP_LED_Off(LED2); BSP_LED_Off(LED3); BSP_LED_Off(LED4); /* Check cgi parameter : example GET /leds.cgi?led=2&led=4 */ for (i=0; i<iNumParams; i++) { /* check parameter "led" */ if (strcmp(pcParam[i] , "led")==0) { /* Switch LED1 ON if 1 */ if(strcmp(pcValue[i], "1") ==0) BSP_LED_On(LED1); /* Switch LED2 ON if 2 */ else if(strcmp(pcValue[i], "2") ==0) BSP_LED_On(LED2); /* Switch LED3 ON if 3 */ else if(strcmp(pcValue[i], "3") ==0) BSP_LED_On(LED3); /* Switch LED4 ON if 4 */ else if(strcmp(pcValue[i], "4") ==0) BSP_LED_On(LED4); }if (strcmp(pcParam[i] , "led")==0) { ... } }for (i=0; i }if (iIndex==0) { ... } /* uri to send after cgi call*/ return "/STM32F4xxLED.html"; }{ ... } /** * @brief Http webserver Init *//* ... */ void http_server_init(void) { /* Httpd Init */ httpd_init(); /* configure SSI handlers (ADC page SSI) */ http_set_ssi_handler(ADC_Handler, (char const **)TAGS, 1); /* configure CGI handlers (LEDs control CGI) */ CGI_TAB[0] = LEDS_CGI; http_set_cgi_handlers(CGI_TAB, 1); }{ ... }