嵌入式软件设计第7次实验报告8

学号:140201206             姓名:刘宇新

组别:第7组                实验地点:D19

 

一、实验目的:

1.熟悉WWW技术中的CGI(公共网关接口)技术。

2.学会使用CGI技术编写C语言代码驱动嵌入式开发板的LED灯和蜂鸣器。

二、实验内容:

1.编写代码完成Web服务器端蜂鸣器的驱动。

2.编写代码完成Web服务器端LED灯的驱动。

三、实验过程描述及结果展示:

1.实验原理

CGI技术简介

        公共网关接口CGI(Common Gateway Interface)是WWW技术中最重要的技术之一。CGI是外部应用程序与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的规程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI在物理上是一段程序,运行在服务器上,提供同客户端HTML页面的接口。

绝大多数的CGI程序被用来解释处理来自表单的输入信息,并在服务器产生相应的处理,或将相应的信息反馈给浏览器,CGI程序使网页具有交互功能。

 

2. 代码
#include "sys.h"

#include <string.h>

#include "lwip_comm.h"

 

#define LED1 PFout(10)

#define BEEP PFout(8)

 

void system_init(void);

 

const char* LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]);

const char* BEEP_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]);

extern int FindCGIParameter(const char *pcToFind, char *pcParam[],int iNumParams);

void BEEP_Init(void)

{  

  GPIO_InitTypeDef  GPIO_InitStructure;

 

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//??GPIOF??

 

  //??????????GPIOF8

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//??????

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//????

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//??

  GPIO_Init(GPIOF, &GPIO_InitStructure);//???GPIO

  

  GPIO_ResetBits(GPIOF,GPIO_Pin_8);  //???????GPIOF8??,

}

void LED_Init(void)

{     

  GPIO_InitTypeDef  GPIO_InitStructure;

 

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//??GPIOF??

 

  //GPIOF9,F10?????

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//??????

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//????

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//??

  GPIO_Init(GPIOF, &GPIO_InitStructure);//???

  

   GPIO_SetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10);//GPIOF9,F10???,??

 

}

int main(void){

   system_init();

   BEEP_Init();

   LED_Init();

   while(1){

      lwip_periodic_handle();

   }

  

}

const char* BEEP_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])

{

   u8 i=0;

   iIndex = FindCGIParameter("BEEP",pcParam,iNumParams);

   if (iIndex != -1){

      BEEP = 0;

      for(i=0;i<iNumParams;i++){

         if(strcmp(pcParam[i],"BEEP") == 0){

            if(strcmp(pcValue[i],"BEEPON")==0){

               GPIO_SetBits(GPIOF,GPIO_Pin_8);

            }else if(strcmp(pcValue[i],"BEEPOFF")==0){

               GPIO_ResetBits(GPIOF,GPIO_Pin_8);

            }

         }

      }

   }

}

const char* LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]){

   u8 i=0;

   iIndex = FindCGIParameter("LED",pcParam,iNumParams);

   if (iIndex != -1){

      for(i=0;i<iNumParams;i++){

         if(strcmp(pcParam[i],"LED") == 0){

            if(strcmp(pcValue[i],"LEDON")==0){

               GPIO_ResetBits(GPIOF,GPIO_Pin_10);

            }else if(strcmp(pcValue[i],"LEDOFF")==0){

               GPIO_SetBits(GPIOF,GPIO_Pin_10);

            }

         }

      }

   }

}

四、总结及实验心得:

本次实验我想到使用iframe框架的方式异步完成post操作,从而解决POST提交后提示网页无法打开的问题。

 

原文地址:https://www.cnblogs.com/RIcXayZ/p/6582056.html