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

📄 http.lst

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

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

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

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


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2733    ----
   CONSTANT SIZE    =    104    ----
   XDATA SIZE       =   ----      39
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   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 + -