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

📄 http.lst

📁 用c8051f340基于51单片机上网
💻 LST
📖 第 1 页 / 共 2 页
字号:
 205   1         // Save first 20 chars and seq number just in case
 206   1         // we need to re-generate page
 207   1         // TODO: if post, then save switch state infomation
 208   1         if (!resend)
 209   1         {
 210   2            tcp_data = inbuf + 34 + header_len;
 211   2            memcpy(conxn[nr].query, tcp_data, 20);
 212   2            conxn[nr].old_sequence = conxn[nr].my_sequence;
 213   2         }
 214   1         // If this is a resend, set sequence number to what it was
 215   1         // the last time we sent this
 216   1         else
 217   1         {
 218   2            tcp_data = inbuf;
 219   2            conxn[nr].my_sequence = conxn[nr].old_sequence;   
 220   2         }
 221   1         
 222   1         // Start off with no request
 223   1         request = NONE;
 224   1            
 225   1              // TODO: Calling strstr() on a large buffer takes a lot of time
 226   1         // so perhaps we could speed things up by limiting the search
 227   1         // range to the portion of the buffer where the item is expected
 228   1         // to be found
 229   1              
 230   1              // If it is a POST, then set a flag to start looking for the post
 231   1              // data of interest, which is the string "switch=".  It may arrive
 232   1              // in a later segment (Netscape seems to split up the POST message)
 233   1         if (strstr(tcp_data, "POST") != NULL) post_flg = TRUE; 
 234   1                 
 235   1         // See if this is a GET message
 236   1         else if (strstr(tcp_data, "GET") != NULL)
 237   1         {
 238   2            post_flg = FALSE;
 239   2            if (strstr(tcp_data, "photo1") != NULL) request = GET_JPEG;
 240   2            else if (strstr(tcp_data, "index") != NULL) request = GET_PAGE;
 241   2            else if (strstr(tcp_data, "/ ") != NULL) request = GET_PAGE;
C51 COMPILER V8.08   HTTP                                                                  11/04/2008 18:45:34 PAGE 5   

 242   2         }
 243   1         
 244   1         // If POST flag is "armed" then look for the "switch=" string
 245   1         // and if found, turn the LED on or off according to whether 
 246   1         // the browser is sending a 1 or a 0.
 247   1         if (post_flg)
 248   1         {
 249   2            ptr = strstr(tcp_data, "switch=");
 250   2            if (ptr != NULL)
 251   2            {
 252   3               // Move to space after equals sign
 253   3               // Set control indicator accordingly
 254   3               post_flg = FALSE;
 255   3               request = POST_PAGE;
 256   3               ptr += 7;
 257   3               if (*ptr == '1') {CONTROL_LED=0x0;}   
 258   3               else if (*ptr == '0') {CONTROL_LED=0x1;}
 259   3                       LightONOFF(CONTROL_LED);
 260   3                       ////////////P36=CONTROL_LED;
 261   3                }
 262   2         }
 263   1      
 264   1         if ((request == GET_PAGE) || (request == POST_PAGE))
 265   1         {
 266   2            // Figure out sizes
 267   2            hhdr_len = strlen(html_header);
 268   2            page_len = strlen(web_page);
 269   2            body_len = hhdr_len + page_len;
 270   2            
 271   2            // Free memory holding received message.  The message from the
 272   2            // browser can be 500+ bytes long so this is a significant 
 273   2            // chunk out of the available malloc space of 1500 bytes
 274   2            if (!resend) { rcve_buf_allocated = FALSE;}
 275   2      
 276   2            // Allocate memory for entire outgoing message including
 277   2            // 14 byte Ethernet + 20 byte IP + 20 byte TCP headers
 278   2            // Allow 1 byte for NULL char at the end
 279   2           // outbuf = (UCHAR xdata *)malloc(54 + body_len + 1);
 280   2           // if (outbuf == NULL)
 281   2            //{
 282   2              // return 0;
 283   2            //}
 284   2            outbuf = outbuf1;
 285   2            // Copy page data.  This moves data from flash into RAM.  It is
 286   2            // an undesirable process, but must get data into RAM to replace
 287   2            // tags 
 288   2                      memcpy(outbuf + 54, html_header, hhdr_len);
 289   2                      memcpy(outbuf + 54 + hhdr_len, web_page, page_len);
 290   2                              
 291   2              outbuf[54 + body_len] = 0;              // Append NULL 
 292   2         
 293   2            // Replace length tag with actual value
 294   2            itoa(page_len, text, 10);
 295   2                      replace_tag(outbuf + 54, "TAG:LEN1", text);
 296   2                      
 297   2                      // Replace CPU temperature tag with actual value
 298   2                      itoa(cpu_temperature/100, text, 10);
 299   2                      i=strlen(text);
 300   2                      text[i]='.';
 301   2                      i++;
 302   2                      itoa(cpu_temperature%100, text+i, 10);
 303   2                      replace_tag(outbuf + 54, "TAG:TMP1", text);
C51 COMPILER V8.08   HTTP                                                                  11/04/2008 18:45:34 PAGE 6   

 304   2      
 305   2                      itoa(air_temperature/1000, text, 10);
 306   2                      i=strlen(text);
 307   2                      text[i]='.';
 308   2                      i++;
 309   2                      itoa(air_temperature%1000, text+i, 10);
 310   2                      replace_tag(outbuf + 54, "TAG:TMP2", text);
 311   2      
 312   2                      // Replace CPU voltage tag with actual value X 100
 313   2                      // Insert decimal point between first and second digits
 314   2                      itoa(cpu_voltage/1000, text, 10);
 315   2                      i=strlen(text);
 316   2                      text[i]='.';
 317   2                      i++;
 318   2                      itoa(cpu_voltage%1000, text+i, 10);
 319   2                      replace_tag(outbuf + 54, "TAG:VOL1", text);
 320   2            
 321   2            // Insert the word CHECKED into the html so the browser will
 322   2                      // check the correct LED state indicator box 
 323   2            if (CONTROL_LED == OFF) replace_tag(outbuf + 54, "TAG:CHK1", "CHECKED");
 324   2            else replace_tag(outbuf + 54, "TAG:CHK2", "CHECKED");
 325   2            
 326   2            // Segment length = body_len + 20
 327   2            http_send(outbuf, body_len + 20, nr);
 328   2            conxn[nr].my_sequence += body_len;
 329   2         }
 330   1         else if (request == GET_JPEG)
 331   1         {
 332   2            // Ths browser has requested the jpeg image.  First figure out
 333   2            // sizes - cannot use sizeof() for jpeg here because it is in
 334   2            // another module.  Just directly specify length of it
 335   2            jhdr_len = strlen(jpeg_header);
 336   2            jpeg_len = 5705;//6194;
 337   2            body_len = jhdr_len + jpeg_len;
 338   2            
 339   2            // Free memory holding received message.  The message from the
 340   2            // browser can be 500+ bytes long so this is a significant 
 341   2            // chunk out of the available malloc space of 1500 bytes
 342   2            if (!resend) { rcve_buf_allocated = FALSE;}
 343   2      
 344   2            // First send the header and enough of the jpeg to make 1000 bytes.
 345   2            // The value of 1000 is arbitrary, but must be stay under 1500. 
 346   2            if (body_len < 1000) remaining = body_len; else remaining = 1000; 
 347   2      //      outbuf = (UCHAR xdata *)malloc(54 + remaining + 1);
 348   2            //if (outbuf == NULL)
 349   2            //{
 350   2              // return 0;
 351   2            //}
 352   2            outbuf=outbuf1;
 353   2            memcpy(outbuf + 54, jpeg_header, jhdr_len);
 354   2                      memcpy(outbuf + 54 + jhdr_len, photo1_jpeg, remaining - jhdr_len);
 355   2                        
 356   2            outbuf[54 + remaining] = 0;               // Append NULL
 357   2      
 358   2            // Replace jpeg length tag with actual value
 359   2            itoa(jpeg_len, text, 10);
 360   2                      replace_tag(outbuf + 54, "TAG:LEN2", text);
 361   2      
 362   2            http_send(outbuf, remaining + 20, nr);
 363   2            sent = remaining - jhdr_len;
 364   2            conxn[nr].my_sequence += remaining;
 365   2           
C51 COMPILER V8.08   HTTP                                                                  11/04/2008 18:45:34 PAGE 7   

 366   2            // Send the rest of the jpeg file in 1000 byte chunks.  This sends about
 367   2            // 6 segments of 1000 bytes back to back, but we should actually process
 368   2            // acks from the other end to make sure we are not sending more than the
 369   2            // other end can receive.  Most systems can handle 6K
 370   2            while (sent < jpeg_len)
 371   2            {
 372   3               remaining = jpeg_len - sent;
 373   3               if (remaining > 1000) remaining = 1000;
 374   3             //  outbuf = (UCHAR xdata *)malloc(54 + remaining + 1);
 375   3               outbuf=outbuf1;
 376   3                      // if (outbuf == NULL)
 377   3               //{
 378   3                //  return 0;
 379   3               //}
 380   3               
 381   3               memcpy(outbuf + 54, photo1_jpeg + sent, remaining);
 382   3                                 
 383   3               outbuf[54 + remaining] = 0;            // Append NULL
 384   3               http_send(outbuf, remaining + 20, nr);
 385   3               sent += remaining;
 386   3               conxn[nr].my_sequence += remaining;
 387   3            }
 388   2         }
 389   1         else
 390   1         {
 391   2            // The incoming HTTP message did not warrant a response
 392   2            return 0;
 393   2         }
 394   1         
 395   1         // Return number of bytes sent, not including TCP header
 396   1              return(body_len);
 397   1      }
 398          
 399          
 400          
 401          
 402          


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