This post was last edited by flyword on 2019-2-7 19:17 The Chinese New Year is in full swing, so I will continue to share my experience here. I tried the HTTP_SERVER APP last night and shared it with you. I have seen before that the great gods RSCN and anger0925 have made a webserver, and analyzed the working code. I referred to their posts and used HTTP_SERVER to The sans-serif]APPmodule quickly built its ownwebserver. The specific process is shared as follows:
1. DAVEAPPmodule addition and related configuration operations. This is similar to the previous web application of netizens. We send our instructions to the XMC4800 through the CGI interface to control LED1 and LED2 respectively; and the XMC4800 embeds the value of the ADC module into the web page through the SSI interface and displays it to the client. Therefore, the APPs that need to be added are: 1. HTTP_SERVER 2. ADC_MEASUREMENT 3.DIGITAL_IO
Specifically:
In addition, the web page content here is placed in the file Resources. How to store web pages in rom is generated by the makefsdata program. Here we need to add a script. For details, please refer to APPhelp. The settings here are as follows:
Okay, after the settings, let's take a look at other specific configurations as follows:
1. The settings of HTTP_SERVER APP mainly include two parts. One is the port of webserver and the CGI\SSI enable settings, which are usually 80, but can also be set to 8080, etc. The other is the setting of LWIP. You can use the default settings, but you must confirm that the PHY model is consistent with the circuit board. The last part is the pin assignment. According to the circuit diagram of XMC4800, you can add the relevant pins. 401274401275401276401278401277550127660127850127820127920127021271272 2. ADC, here the polling method is used to read the data. 40127730127740127540127660127840127850127850127920127021271272 3. ADC, here the polling method is used to read the data. 4012773012773012774012775 ...
2. My understanding of CGI and SSI .
Since this is the first time I use LWIP, I don’t quite understand its working principle. By comparing the posts of RSCN and anger0925, I have a preliminary understanding of CGI and SSI. The specific content can be seen in the relevant files of httpd in lwip. The screenshot is as follows: CGI generally submits data to the server in the form of a form through GET. The server then queries the CGI file corresponding to the action submitted in the form, and then queries the corresponding callback function (callback function) through the pCGIs list and executes the function. The corresponding operation corresponds to the corresponding callback function.
SSI is usually done by querying the tags in the form, usually with [an error occurred while processing the directive] as the identifier, where abc is the tag we want to display, usually defined in a tag list TAGS[]. When the server is running, it queries the tags in the web page and performs corresponding operations in the corresponding index, also using callback functions.
CGI and SSI both need to be registered when in use, so that they can be used normally. The registration functions correspond to http_set_cgi_handlers and http_set_ssi_handler. For users, there are three steps to do. A. First, define your own handle function corresponding to the CGI and SSI interfaces. B. Secondly, define the pCGIs list corresponding to CGI and the tag list TAGS corresponding to SSI. C. Finally, enable the registration functions http_set_cgi_handlers and http_set_ssi_handler in turn. We don't need to pay attention to the underlying code at all, we just need to design our own upper-level application. 3. Just add code in main.c to implement your own application. 1. First look at the CGI interface program. Two parts need to be added. One is the c program and the other is the location of the cgi interface in the html program. For the specific program, see the html file content later. The program is as follows: pcValue[0] corresponds to the value of the first parameter submitted. code const char *ledctrl_handler(int iIndex, int iNumParams, char *pcParam[],char *pcValue[]){ if(strcmp(pcValue[0], "led1_on") == 0) { DIGITAL_IO_SetOutputHigh(&LED_1); } if(strcmp(pcValue[0], "led1_off") == 0) { DIGITAL_IO_SetOutputLow (&LED_1); } if(strcmp(pcValue[0], "led2_on") == 0) { DIGITAL_IO_SetOutputHigh(&LED_2); } if(strcmp(pcValue[0], "led2_off") == 0) { DIGITAL_IO_SetOutputLow(&LED_2); } if( strcmp(pcValue[0], "leds_off_all") == 0) { DIGITAL_IO_SetOutputLow(&LED_1); DIGITAL_IO_SetOutputLow(&LED_2); } if(strcmp(pcValue[0], "leds_on_all") == 0) { DIGITAL_IO_SetOutputHigh(&LED_1); DIGITAL_IO_SetOutputHigh(&LED_2); } return "/index.shtml"; // Be sure to return to the homepage, otherwise it may jump Go to an empty page. . } tCGI pCGIs[]={ //The list corresponding to the defined CGIs corresponds to multiple cgi forms in HTML. { .pcCGIName="/ledctrl.cgi", .pfnCGIHandler=ledctrl_handler }, }; int web_cgi_init(void){ http_set_cgi_handlers(pCGIs, 1); //Register the corresponding CGI list to the system. Here there is only one list, so the number is 1. return 0; }[/code] 2.Let's look at the program for the SSIinterface part. We need to add Two parts, one is the c program, the other is the html program cgiInterface location.
- const char *Tags[]={ //Defines the SSI tags in the web page. Used by the server to add related data Go in. "ADC", "INT", }; static uint16_t adc_read_ssihandler(int iIndex, char *pcInsert, int iInsertLen){ uint16_t ADC_value; char value[4]; char num[5]; switch(iIndex){ //iIndex is the index of identifier in the Tags[] case 0: ADC_value = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Channel_A); sprintf(value,"%d",ADC_value); *pcInsert=value[0]; *(pcInsert+1)=value[1]; *(pcInsert+2)=value[2]; * (pcInsert+3)=value[3]; break; case 1: sprintf(num,"%d",12345); *pcInsert=num[0]; *(pcInsert+1)=num[1]; *(pcInsert+2)=num[2]; *(pcInsert+3)=num[3]; *(pcInsert+4)=num[4]; break; default: break; } return strlen(pcInsert);//this is very important to run the ssi handler...It is very important here, you must return the length of the inserted data, otherwise it will not display properly. } int web_ssi_init(void){// Register function. http_set_ssi_handler(adc_read_ssihandler,(char const **)Tags,2); return 0; }
复制代码The completemain function is as follows:
- int main(void) { DAVE_STATUS_t status; status = DAVE_Init(); /* Initialization of DAVE APPs */ if(status != DAVE_STATUS_SUCCESS) { /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */ be replaced with user application code. */ while(1U) { sys_check_timeouts(); //Enable LWIP application} }
复制代码 At this point, our web page has been built. The relevant HTML file is attached. Upload the code will be parsed out... The editor of the forum... Fourth, the specific application implementation effect. After downloading the program, set the IP address of the computer and browse Access xmc4800IP in the browser to get the web page content.
How about it, it's simple! Interested users can experiment. This is my first time using an Infineon MCU. Using the DAVE APP is a different experience. I don’t need to look up the manual or operate the registers in a tedious way. Designing your own project directly for the application is great! ! But there are also disadvantages, that is, the application of APP is not very flexible. If you want to use it flexibly, you must have a deeper understanding of DAVE and APP.
html file
index.shtml
(1.69 KB, downloads: 5)
This content is provided by EEWORLD Forum Original work by netizen flyword. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source