⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http.lst

📁 Keil_C51程序,C8051实现的TCP/IP功能源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 193   2            conxn[nr].my_sequence = conxn[nr].old_sequence;   
 194   2         }
 195   1         
 196   1         // Start off with no request
 197   1         request = NONE;
 198   1            
 199   1              // TODO: Calling strstr() on a large buffer takes a lot of time
 200   1         // so perhaps we could speed things up by limiting the search
 201   1         // range to the portion of the buffer where the item is expected
 202   1         // to be found
 203   1              
 204   1              // If it is a POST, then set a flag to start looking for the post
 205   1              // data of interest, which is the string "switch=".  It may arrive
 206   1              // in a later segment (Netscape seems to split up the POST message)
 207   1         if (strstr(tcp_data, "POST") != NULL) post_flg = TRUE; 
 208   1                 
 209   1         // See if this is a GET message
 210   1         else if (strstr(tcp_data, "GET") != NULL)
 211   1         {
 212   2            post_flg = FALSE;
 213   2            if (strstr(tcp_data, "photo1") != NULL) request = GET_JPEG;
 214   2            else if (strstr(tcp_data, "index") != NULL) request = GET_PAGE;
 215   2            else if (strstr(tcp_data, "/ ") != NULL) request = GET_PAGE;
 216   2         }
 217   1         
 218   1         // If POST flag is "armed" then look for the "switch=" string
 219   1         // and if found, turn the LED on or off according to whether 
 220   1         // the browser is sending a 1 or a 0.
 221   1         if (post_flg)
 222   1         {
 223   2            ptr = strstr(tcp_data, "switch=");
 224   2            if (ptr != NULL)
 225   2            {
 226   3               // Move to space after equals sign
 227   3               // Set control indicator accordingly
 228   3               post_flg = FALSE;
 229   3               request = POST_PAGE;
 230   3               ptr += 7;
 231   3               if (*ptr == '1') {CONTROL_LED=0x0;}   
 232   3               else if (*ptr == '0') {CONTROL_LED=0x1;}
 233   3      //               LightONOFF(CONTROL_LED);
 234   3            }
 235   2         }
 236   1      
 237   1         if ((request == GET_PAGE) || (request == POST_PAGE))
 238   1         {
 239   2            // Figure out sizes
 240   2            hhdr_len = strlen(html_header);
 241   2            page_len = strlen(web_page);
C51 COMPILER V7.20   HTTP                                                                  03/07/2006 14:49:15 PAGE 5   

 242   2            body_len = hhdr_len + page_len;
 243   2            
 244   2            // Free memory holding received message.  The message from the
 245   2            // browser can be 500+ bytes long so this is a significant 
 246   2            // chunk out of the available malloc space of 1500 bytes
 247   2            if (!resend) {free(inbuf); rcve_buf_allocated = FALSE;}
 248   2      
 249   2            // Allocate memory for entire outgoing message including
 250   2            // 14 byte Ethernet + 20 byte IP + 20 byte TCP headers
 251   2            // Allow 1 byte for NULL char at the end
 252   2            outbuf = (UCHAR xdata *)malloc(54 + body_len + 1);
 253   2            if (outbuf == NULL)
 254   2            {
 255   3               if (debug) SendCommString("TCP: Oops, out of memory\r");
 256   3               return 0;
 257   3            }
 258   2            
 259   2            // Copy page data.  This moves data from flash into RAM.  It is
 260   2            // an undesirable process, but must get data into RAM to replace
 261   2            // tags 
 262   2                      memcpy(outbuf + 54, html_header, hhdr_len);
 263   2                      memcpy(outbuf + 54 + hhdr_len, web_page, page_len);
 264   2                              
 265   2              outbuf[54 + body_len] = 0;              // Append NULL 
 266   2         
 267   2            // Replace length tag with actual value
 268   2                   itoa(page_len, text, 10);
 269   2                      replace_tag(outbuf + 54, "TAG:LEN1", text);
 270   2                      
 271   2                      // Replace CPU temperature tag with actual value
 272   2                      itoa(100/100, text, 10);//cpu_temperature
 273   2                      i=strlen(text);
 274   2                      text[i]='.';
 275   2                      i++;
 276   2                      itoa(32%100, text+i, 10);//cpu_temperature
 277   2                      replace_tag(outbuf + 54, "TAG:TMP1", text);
 278   2      
 279   2                      itoa(10000/1000, text, 10);//air_temperature
 280   2                      i=strlen(text);
 281   2                      text[i]='.';
 282   2                      i++;
 283   2                      itoa(100001%1000, text+i, 10);//air_temperature
 284   2                      replace_tag(outbuf + 54, "TAG:TMP2", text);
 285   2      
 286   2                      // Replace CPU voltage tag with actual value X 100
 287   2                      // Insert decimal point between first and second digits
 288   2                      itoa(10000/1000, text, 10);//cpu_voltage
 289   2                      i=strlen(text);
 290   2                      text[i]='.';
 291   2                      i++;
 292   2                      itoa(10001%1000, text+i, 10);//cpu_voltage
 293   2                      replace_tag(outbuf + 54, "TAG:VOL1", text);
 294   2            
 295   2            // Insert the word CHECKED into the html so the browser will
 296   2                      // check the correct LED state indicator box 
 297   2            if (CONTROL_LED == OFF) replace_tag(outbuf + 54, "TAG:CHK1", "CHECKED");
 298   2            else replace_tag(outbuf + 54, "TAG:CHK2", "CHECKED");
 299   2            
 300   2            // Segment length = body_len + 20
 301   2            http_send(outbuf, body_len + 20, nr);
 302   2            conxn[nr].my_sequence += body_len;
 303   2         }
C51 COMPILER V7.20   HTTP                                                                  03/07/2006 14:49:15 PAGE 6   

 304   1         else if (request == GET_JPEG)
 305   1         {
 306   2            // Ths browser has requested the jpeg image.  First figure out
 307   2            // sizes - cannot use sizeof() for jpeg here because it is in
 308   2            // another module.  Just directly specify length of it
 309   2            jhdr_len = strlen(jpeg_header);
 310   2            jpeg_len = 5705;//6194;
 311   2            body_len = jhdr_len + jpeg_len;
 312   2            
 313   2            // Free memory holding received message.  The message from the
 314   2            // browser can be 500+ bytes long so this is a significant 
 315   2            // chunk out of the available malloc space of 1500 bytes
 316   2            if (!resend) {free(inbuf); rcve_buf_allocated = FALSE;}
 317   2      
 318   2            // First send the header and enough of the jpeg to make 1000 bytes.
 319   2            // The value of 1000 is arbitrary, but must be stay under 1500. 
 320   2            if (body_len < 1000) remaining = body_len; else remaining = 1000; 
 321   2            outbuf = (UCHAR xdata *)malloc(54 + remaining + 1);
 322   2            if (outbuf == NULL)
 323   2            {
 324   3               if (debug) SendCommString("TCP: Oops, out of memory\r");
 325   3               return 0;
 326   3            }
 327   2            
 328   2            memcpy(outbuf + 54, jpeg_header, jhdr_len);
 329   2                      memcpy(outbuf + 54 + jhdr_len, photo1_jpeg, remaining - jhdr_len);
 330   2                        
 331   2            outbuf[54 + remaining] = 0;               // Append NULL
 332   2      
 333   2            // Replace jpeg length tag with actual value
 334   2            itoa(jpeg_len, text, 10);
 335   2                      replace_tag(outbuf + 54, "TAG:LEN2", text);
 336   2      
 337   2            http_send(outbuf, remaining + 20, nr);
 338   2            sent = remaining - jhdr_len;
 339   2            conxn[nr].my_sequence += remaining;
 340   2           
 341   2            // Send the rest of the jpeg file in 1000 byte chunks.  This sends about
 342   2            // 6 segments of 1000 bytes back to back, but we should actually process
 343   2            // acks from the other end to make sure we are not sending more than the
 344   2            // other end can receive.  Most systems can handle 6K
 345   2            while (sent < jpeg_len)
 346   2            {
 347   3               remaining = jpeg_len - sent;
 348   3               if (remaining > 1000) remaining = 1000;
 349   3               outbuf = (UCHAR xdata *)malloc(54 + remaining + 1);
 350   3               if (outbuf == NULL)
 351   3               {
 352   4                  if (debug) SendCommString("TCP: Oops, out of memory\r");
 353   4                  return 0;
 354   4               }
 355   3               
 356   3               memcpy(outbuf + 54, photo1_jpeg + sent, remaining);
 357   3                                 
 358   3               outbuf[54 + remaining] = 0;            // Append NULL
 359   3               http_send(outbuf, remaining + 20, nr);
 360   3               sent += remaining;
 361   3               conxn[nr].my_sequence += remaining;
 362   3            }
 363   2         }
 364   1         else
 365   1         {
C51 COMPILER V7.20   HTTP                                                                  03/07/2006 14:49:15 PAGE 7   

 366   2            // The incoming HTTP message did not warrant a response
 367   2            if (debug) SendCommString("HTTP: No response sent\r");
 368   2            return 0;
 369   2         }
 370   1         
 371   1         // Return number of bytes sent, not including TCP header
 372   1              return(body_len);
 373   1      }
 374          
 375          
 376          
 377          
 378          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1948    ----
   CONSTANT SIZE    =    184    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      39
   IDATA SIZE       =      1      23
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -