/**
  * @brief serve tcp connection  
  * @param conn: connection socket 
  * @retval None
  */
void http_server_serve(int conn) 
{
  int buflen = 1500;
  int ret;
  struct fs_file * file;
  unsigned char recv_buffer[1500];
  unsigned char *fed_back = "yes u r right";
				
  /* Read in the request */
  ret = read(conn, recv_buffer, buflen); 
  if(ret < 0) return;

  /* Check if request to get ST.gif */
  if (strncmp((char *)recv_buffer,"GET /STM32F4x7_files/ST.gif",27)==0)
  {
    file = fs_open("/STM32F4x7_files/ST.gif"); 
    write(conn, (const unsigned char*)(file->data), (size_t)file->len);
    if(file) fs_close(file);
  }
  /* Check if request to get stm32.jpeg */
  else if (strncmp((char *)recv_buffer,"GET /STM32F4x7_files/stm32.jpg",30)==0)
  {
    file = fs_open("/STM32F4x7_files/stm32.jpg"); 
    write(conn, (const unsigned char*)(file->data), (size_t)file->len);
    if(file) fs_close(file);
  }
  /* Check if request to get ST logo.jpeg */
  else if (strncmp((char *)recv_buffer,"GET /STM32F4x7_files/logo.jpg", 29) == 0)
  {
    file = fs_open("/STM32F4x7_files/logo.jpg"); 
    write(conn, (const unsigned char*)(file->data), (size_t)file->len);
    if(file) fs_close(file);
  }
  else if(strncmp((char *)recv_buffer, "GET /STM32F4x7TASKS.html", 24) == 0)
  {
    /* Load dynamic page */
    DynWebPage(conn);
  }
  else if((strncmp((char *)recv_buffer, "GET /STM32F4x7.html", 19) == 0)||(strncmp((char *)recv_buffer, "GET / ", 6) == 0))
  {
    /* Load STM32F4x7 page */
    file = fs_open("/STM32F4x7.html"); 
    write(conn, (const unsigned char*)(file->data), (size_t)file->len);
    if(file) fs_close(file);
  }
  else
  {
    /* Load 404 page */
    //file = fs_open("/404.html"); 
    //write(conn, (const unsigned char*)(file->data), (size_t)file->len);
	write(conn, (const unsigned char*)(fed_back), (size_t)strlen(fed_back));
    if(file) fs_close(file);
  }
  /* Close connection socket */
  close(conn);
}
/**
  * @brief serve tcp connection  
  * @param conn: pointer on connection structure 
  * @retval None
  */
void http_server_serve(struct netconn *conn) 
{
  struct netbuf *inbuf;
  err_t recv_err;
  char* buf;
  u16_t buflen;
  struct fs_file * file;
  
  /* Read the data from the port, blocking if nothing yet there. 
   We assume the request (the part we care about) is in one netbuf */
  recv_err = netconn_recv(conn, &inbuf);
  
  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK) 
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);
    
      /* Is this an HTTP GET command? (only check the first 5 chars, since
      there are other formats for GET, and we're keeping it very simple )*/
      if ((buflen >=5) && (strncmp(buf, "GET /", 5) == 0))
      {
        /* Check if request to get ST.gif */ 
        if (strncmp((char const *)buf,"GET /STM32F4xx_files/ST.gif",27)==0)
        {
          file = fs_open("/STM32F4xx_files/ST.gif"); 
          netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
          fs_close(file);
        }   
        /* Check if request to get stm32.jpeg */
        else if (strncmp((char const *)buf,"GET /STM32F4xx_files/stm32.jpg",30)==0)
        {
          file = fs_open("/STM32F4xx_files/stm32.jpg"); 
          netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
          fs_close(file);
        }
        else if (strncmp((char const *)buf,"GET /STM32F4xx_files/logo.jpg", 29) == 0)                                           
        {
          /* Check if request to get ST logo.jpg */
          file = fs_open("/STM32F4xx_files/logo.jpg"); 
          netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
          fs_close(file);
        }
        else if(strncmp(buf, "GET /STM32F4xxTASKS.html", 24) == 0)
        {
           /* Load dynamic page */
           DynWebPage(conn);
        }
        else if((strncmp(buf, "GET /STM32F4xx.html", 19) == 0)||(strncmp(buf, "GET / ", 6) == 0)) 
        {
          /* Load STM32F4x7 page */
          file = fs_open("/STM32F4xx.html"); 
          netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
          fs_close(file);
        }
        else 
        {
          /* Load Error page */
          file = fs_open("/404.html"); 
          netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
          fs_close(file);
        }
      }      
    }
  }
  /* Close the connection (server closes in HTTP) */
  netconn_close(conn);
  
  /* Delete the buffer (netconn_recv gives us ownership,
   so we have to make sure to deallocate the buffer) */
  netbuf_delete(inbuf);
}
Beispiel #3
0
/**
  * @brief serve tcp connection  
  * @param conn: pointer on connection structure 
  * @retval None
  */
static void http_ipcam_serve(struct netconn *conn)
{
  struct netbuf *inbuf;
  char* buf;
  uint16_t buflen;
  uint16_t index;
  struct fs_file * file;
  static  uint32_t RequestIndex = 0;


 /* Read the data from the port, blocking if nothing yet there. 
   We assume the request (the part we care about) is in one netbuf */
  inbuf = netconn_recv(conn);

  if (inbuf != NULL)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

      /* Is this an HTTP GET command? (only check the first 5 chars, since
      there are other formats for GET, and we're keeping it very simple )*/
      if ((buflen >=5) && (strncmp(buf, "GET /", 5) == 0))
      {
        if((Global_Config.b.DistantControlEnabled != 0) && \
           (Global_Config.b.BackgroundModeEnabled != 0) && \
           (EthernetSettings.DistantControlEnabled == 1))
        {
          if (strncmp(buf, "GET /cmds", 9) == 0)
          {
            index = 9;
            DC_Global_Config.d32 = 0;

            while(buf[index] != 0x20) /* */
            {
              index++; 
              if (buf[index] == 0x63) /* c */
              {
                index++;
                if (buf[index] ==  0x6d) /* m */
                {
                  index++;
                  if (buf[index] ==  0x64) /* d*/
                  {
                    index+=2;

                    if(buf[index]==0x31) /* 1: Distant Control Cmd */
                    {
                      DC_Global_Config.b.DistantControlEnabled = 1;
                    }
                    if(buf[index]==0x32) /* 2: Background Mode Cmd */
                    {
                      DC_Global_Config.b.BackgroundModeEnabled = 1;
                    }
                    if(buf[index]==0x33) /* 3: Low Power Mode Cmd */
                    {
                      DC_Global_Config.b.LowPowerModeEnabled = 1;
                    }
                    if(buf[index]==0x34) /* 4: LCD Power Saving Cmd */
                    {
                      DC_Global_Config.b.LCDPowerSavingEnabled = 1;
                    }
                  }
                }
              }
            }
            if(Global_Config.b.LCDPowerSavingEnabled != DC_Global_Config.b.LCDPowerSavingEnabled)
            {
              Global_Config.b.LCDPowerSavingEnabled = DC_Global_Config.b.LCDPowerSavingEnabled;
              MOD_SetParam(GLOBAL_SETTINGS_MEM , &Global_Config.d32);
              Global_Config.b.Configuration_Changed = 1;
              SYSTEM_RefreshSetting();
            }

            if(DC_Global_Config.b.DistantControlEnabled == 0)
            {
              EthernetSettings.DisableDControlLater = 1;
            }

            if(DC_Global_Config.b.BackgroundModeEnabled == 0)
            {
              EthernetSettings.DisableBackgroundLater = 1;
            }

            /* Open the STM32DC.html */
            file = fs_open("/STM32DC.html");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get ST logo.jpg */
          else if (strncmp((char const *)buf, "GET /STM32_files/logo.jpg", 25) == 0)
          {
            file = fs_open("/STM32_files/logo.jpg");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get STM32TASKS.html */
          else if((strncmp(buf, "GET /STM32TASKS.html", 20) == 0)||(strncmp(buf, "GET /STM32TASKSDC.html", 22) == 0))
          {
            /* Load dynamic page */
            DynWebPage(conn);
          }
          /* Check if request to get STM32DC.html */
          else if((strncmp(buf, "GET /STM32DC.html", 17) == 0) || (strncmp(buf, "GET / ", 6) == 0))
          {
            file = fs_open("/STM32DC.html");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Load Error page */
          else
          {
            file = fs_open("/404.html");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
        }
        else
        {
          if ((strncmp((char const *)buf, "GET /STM32_files/CamImage.bmp", 29)==0)||(strncmp(buf, "GET /CamImage.bmp", 17) == 0))
          {
            if(IPCAM_ImageBuffer.BufferStatus == BUFFER_FILLED)
            {
              /* Prepare the received image for transfer */
              IPCAM_PrepareImage();
              netconn_write(conn, (const unsigned char*)(IPCAM_ImageBuffer.ImageHeader), (size_t)IPCAM_ImageBuffer.ImageHeaderLen, NETCONN_NOCOPY);
              netconn_write(conn, (const unsigned char*)IPCAM_ImageBuffer.ImageData, IPCAM_ImageBuffer.MaxImageLen, NETCONN_NOCOPY);

              /* Start new image capture */
              IPCAM_CaptureNextImage();
              RequestIndex = 0;
            }
            else
            {
              RequestIndex++;
              if(RequestIndex == 10)
              {
                RequestIndex = 0;
                file = fs_open("/STM32F4x7_files/Error.jpg");
                netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
                fs_close(file);
              }
              /* Start new image capture */
              IPCAM_CaptureNextImage();
              netconn_close(conn);
              netbuf_delete(inbuf);
            }
          }
          /* Check if request to get ST.gif */ 
          else if (strncmp((char const *)buf, "GET /STM32_files/ST.gif", 23)==0)
          {
            file = fs_open("/STM32_files/ST.gif"); 
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get stm32f4.jpeg */
          else if (strncmp((char const *)buf, "GET /STM32_files/stm32f4.jpg", 28)==0)
          {
            file = fs_open("/STM32_files/stm32f4.jpg"); 
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get stm32f2.jpeg */
          else if (strncmp((char const *)buf, "GET /STM32_files/stm32f2.jpg", 28)==0)
          {
            file = fs_open("/STM32_files/stm32f2.jpg");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get ST logo.jpg */
          else if (strncmp((char const *)buf, "GET /STM32_files/logo.jpg", 25) == 0)
          {
            file = fs_open("/STM32_files/logo.jpg"); 
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get STM32TASKS.html */
          else if((strncmp(buf, "GET /STM32TASKS.html", 20) == 0)||(strncmp(buf, "GET /STM32TASKSDC.html", 22) == 0))
          {
            /* Load dynamic page */
            DynWebPage(conn);
          }
          /* Check if request to get STM32IPCAM.html */
          else if(strncmp(buf, "GET /STM32IPCAM.html", 20) == 0)
          {
            file = fs_open("/STM32IPCAM.html");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Check if request to get STM32F4x7.html */
          else if((strncmp(buf, "GET /index.html", 15) == 0)||(strncmp(buf, "GET / ", 6) == 0))
          {
            #if defined (STM32F2XX)
             file = fs_open("/STM32F2x7.html");
            #elif defined (STM32F4XX)
             file = fs_open("/STM32F4x7.html");
            #endif
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
          /* Load Error page */
          else
          {
            file = fs_open("/404.html");
            netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
            fs_close(file);
          }
        }
      }
    }
  }
  netconn_close(conn);
  netconn_delete(conn);
  netbuf_delete(inbuf);
}
/**
  * @brief serve tcp connection  
  * @param conn: pointer on connection structure 
  * @retval None
  */
void http_server_serve(struct netconn *conn) 
{
  struct netbuf *inbuf;
  err_t recv_err;
  char* buf;
  u16_t buflen;
  //struct fs_file * file;
  
  /* Read the data from the port, blocking if nothing yet there. 
   We assume the request (the part we care about) is in one netbuf */
  recv_err = netconn_recv(conn, &inbuf);
  
  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK) 
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);
    
      /* Is this an HTTP GET command? (only check the first 5 chars, since
      there are other formats for GET, and we're keeping it very simple )*/
      if ((buflen >=5) && (strncmp(buf, "GET /", 5) == 0))
      {
        
        if(strncmp(buf, "GET /task", 9) == 0)
        {
           /* Load dynamic page */
           DynWebPage(conn);
        }
				
				else if((strncmp(buf, "GET /light.html?code=1", 15) == 0)||(strncmp(buf, "GET / ", 6) == 0)) 
        {
          netconn_write(conn, (const unsigned char*)(file__light_html->data), (size_t)file__light_html->len, NETCONN_NOCOPY);
					OnActive = 1;
					OnActive = 1;
        }
				else if((strncmp(buf, "GET /light.html?code=0", 15) == 0)||(strncmp(buf, "GET / ", 6) == 0)) 
        {
          netconn_write(conn, (const unsigned char*)(file__light_html->data), (size_t)file__light_html->len, NETCONN_NOCOPY);
					OffActive = 1;
        }
				 else if((strncmp(buf, "GET /light.html", 15) == 0)||(strncmp(buf, "GET / ", 6) == 0)) 
        {
          netconn_write(conn, (const unsigned char*)(file__light_html->data), (size_t)file__light_html->len, NETCONN_NOCOPY);
        }
        else 
        {
          /* Load Error page */
          //file = fs_open("/404.html"); 
          netconn_write(conn, (const unsigned char*)(file__404_html->data), (size_t)file__404_html->len, NETCONN_NOCOPY);
          //fs_close(file);
        }
      }      
    }
  }
  /* Close the connection (server closes in HTTP) */
  netconn_close(conn);
  
  /* Delete the buffer (netconn_recv gives us ownership,
   so we have to make sure to deallocate the buffer) */
  netbuf_delete(inbuf);
}
Beispiel #5
0
/**
  * @brief serve tcp connection  
  * @param conn: pointer on connection structure 
  * @retval None
  */
void http_server_serve(struct netconn *conn) 
{
  struct netbuf *inbuf;
  err_t recv_err;
  char* buf;
  u16_t buflen;
  struct fs_file * file;
  
  /* Read the data from the port, blocking if nothing yet there. 
   We assume the request (the part we care about) is in one netbuf */
  recv_err = netconn_recv(conn, &inbuf);
  
  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK) 
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);
    
      /* Is this an HTTP GET command? (only check the first 5 chars, since
      there are other formats for GET, and we're keeping it very simple )*/
      if ((buflen >=5) && (strncmp(buf, "GET /", 5) == 0))
      {

					 if (strncmp((char const *)buf,"GET /main_test.html",19)==0||(strncmp(buf, "GET / ", 6) == 0)) 
        {
          file = fs_open("/main_test.html"); 
          netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
          fs_close(file);
        }  
						else if((strncmp(buf, "GET /stats_12345678.html", 24) == 0)) 
							{
								/* Load STM32F4x7 page */
								file = fs_open("/stats_12345678.html"); 
								netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
								fs_close(file);
							}
							
													else if((strncmp(buf, "GET /style.css", 14) == 0)) 
							{
								/* Load STM32F4x7 page */
								file = fs_open("/style.css"); 
								netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
								fs_close(file);
							}
							
						else if(strncmp(buf, "GET /control.html", 17) == 0)
								{
									 DynWebPage(conn);
								}
									else if(strncmp(buf, "GET /script.js", 14) == 0)
									{
										file = fs_open("/script.js"); 
										netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
										fs_close(file);
									}								
								
						else if(strncmp(buf, "GET /table", 10) == 0)
								{

									char PAGE_BODY[35];
									uint32_t temp,*p ;
									static uint32_t count=0;
									p=&temp;
									uint8_t *Mem= "Mem", *Time = "Time", *Param = "Param";
									uint8_t table[35];
									memset(PAGE_BODY, 0,35);
									strcpy(table, Mem);
									strcpy(table + 9, Time);
									strcpy(table + 22, Param);
									temp = xPortGetFreeHeapSize();
									temp = 40560;
									sprintf(table + 3,"%d",temp);
									sprintf(table + 13,"%d",87654321);
									sprintf(table + 27,"%d",(count++)&0xFFFF);
									
									for(uint8_t i = 0; i < 28; i++)
											if(table[i] == 0)
													table[i] = 1;
											
									memcpy(PAGE_BODY, table, sizeof(table) );	
									netconn_write(conn, PAGE_BODY, strlen((char*)PAGE_BODY), NETCONN_COPY);
								}
        else 
        {
          /* Load Error page */
         // file = fs_open("/404.html"); 
         // netconn_write(conn, (const unsigned char*)(file->data), (size_t)file->len, NETCONN_NOCOPY);
         // fs_close(file);
        }
      }      
    }
  }
  /* Close the connection (server closes in HTTP) */
  netconn_close(conn);
  
  /* Delete the buffer (netconn_recv gives us ownership,
   so we have to make sure to deallocate the buffer) */
  netbuf_delete(inbuf);
}