📄 http1.lst
字号:
221 1 // See if this is a GET message
222 1 else if (strstr(tcp_data, "GET") != NULL)
223 1 {
224 1 post_flg = FALSE;
225 1 if (strstr(tcp_data, "photo1") != NULL) request = GET_JPEG;
226 1 else if (strstr(tcp_data, "index") != NULL) request = GET_PAGE;
227 1 else if (strstr(tcp_data, "/ ") != NULL) request = GET_PAGE;
228 1 }
229 1
230 1 // If POST flag is "armed" then look for the "switch=" string
231 1 // and if found, turn the LED on or off according to whether
232 1 // the browser is sending a 1 or a 0.
233 1 if (post_flg)
234 1 {
235 1 ptr = strstr(tcp_data, "switch=");
236 1 if (ptr != NULL)
237 1 {
C51 COMPILER V7.09 HTTP1 06/28/2007 09:51:20 PAGE 5
238 1 // Move to space after equals sign
239 1 // Set control indicator accordingly
240 1 post_flg = FALSE;
241 1 request = POST_PAGE;
242 1 ptr += 7;
243 1 // if (*ptr == '1') {CONTROL_LED=0x0;}
244 1 // else if (*ptr == '0') {CONTROL_LED=0x1;}
245 1 // LightONOFF(CONTROL_LED);
246 1 // P36=!CONTROL_LED;
247 1 }
248 1 }
249 1
250 1 if ((request == GET_PAGE) || (request == POST_PAGE))
251 1 {
252 1 // Figure out sizes
253 1 //hhdr_len = strlen(html_header);
254 1 //page_len = strlen(web_page);
255 1 body_len = hhdr_len + page_len;
256 1
257 1 // Free memory holding received message. The message from the
258 1 // browser can be 500+ bytes long so this is a significant
259 1 // chunk out of the available malloc space of 1500 bytes
260 1 if (!resend) {free(inbuf); rcve_buf_allocated = FALSE;}
261 1
262 1 // Allocate memory for entire outgoing message including
263 1 // 14 byte Ethernet + 20 byte IP + 20 byte TCP headers
264 1 // Allow 1 byte for NULL char at the end
265 1 outbuf = (UCHAR *)malloc(54 + body_len + 1);
266 1 if (outbuf == NULL)
267 1 {
268 1 if (debug) serial_send("TCP: Oops, out of memory\r");
269 1 return 0;
270 1 }
271 1
272 1 // Copy page data. This moves data from flash into RAM. It is
273 1 // an undesirable process, but must get data into RAM to replace
274 1 // tags
275 1 //memcpy(outbuf + 54, html_header, hhdr_len);
276 1 //memcpy(outbuf + 54 + hhdr_len, web_page, page_len);
277 1
278 1 outbuf[54 + body_len] = 0; // Append NULL
279 1
280 1 // Replace length tag with actual value
281 1 itoa(page_len, text, 10);
282 1 replace_tag(outbuf + 54, "TAG:LEN1", text);
283 1
284 1 // Replace CPU temperature tag with actual value
285 1 //itoa(cpu_temperature/100, text, 10);
286 1 i=strlen(text);
287 1 text[i]='.';
288 1 i++;
289 1 //itoa(cpu_temperature%100, text+i, 10);
290 1 replace_tag(outbuf + 54, "TAG:TMP1", text);
291 1
292 1 // itoa(air_temperature/1000, text, 10);
293 1 i=strlen(text);
294 1 text[i]='.';
295 1 i++;
296 1 // itoa(air_temperature%1000, text+i, 10);
297 1 replace_tag(outbuf + 54, "TAG:TMP2", text);
298 1
299 1 // Replace CPU voltage tag with actual value X 100
C51 COMPILER V7.09 HTTP1 06/28/2007 09:51:20 PAGE 6
300 1 // Insert decimal point between first and second digits
301 1
302 1 i=strlen(text);
303 1 text[i]='.';
304 1 i++;
305 1 // itoa(cpu_voltage%1000, text+i, 10);
306 1 replace_tag(outbuf + 54, "TAG:VOL1", text);
307 1
308 1 // Insert the word CHECKED into the html so the browser will
309 1 // check the correct LED state indicator box
310 1 // if (CONTROL_LED == OFF) replace_tag(outbuf + 54, "TAG:CHK1", "CHECKED");
311 1 //else replace_tag(outbuf + 54, "TAG:CHK2", "CHECKED");
312 1
313 1 // Segment length = body_len + 20
314 1 http_send(outbuf, body_len + 20, nr);
315 1 conxn[nr].my_sequence += body_len;
316 1 }
317 1 else if (request == GET_JPEG)
318 1 {
319 1 // Ths browser has requested the jpeg image. First figure out
320 1 // sizes - cannot use sizeof() for jpeg here because it is in
321 1 // another module. Just directly specify length of it
322 1 //jhdr_len = strlen(jpeg_header);
323 1 jpeg_len = 5705;//6194;
324 1 body_len = jhdr_len + jpeg_len;
325 1
326 1 // Free memory holding received message. The message from the
327 1 // browser can be 500+ bytes long so this is a significant
328 1 // chunk out of the available malloc space of 1500 bytes
329 1 if (!resend) {free(inbuf); rcve_buf_allocated = FALSE;}
330 1
331 1 // First send the header and enough of the jpeg to make 1000 bytes.
332 1 // The value of 1000 is arbitrary, but must be stay under 1500.
333 1 if (body_len < 1000) remaining = body_len; else remaining = 1000;
334 1 outbuf = (UCHAR *)malloc(54 + remaining + 1);
335 1 if (outbuf == NULL)
336 1 {
337 1 // if (debug) serial_send("TCP: Oops, out of memory\r");
338 1 return 0;
339 1 }
340 1
341 1 //memcpy(outbuf + 54, jpeg_header, jhdr_len);
342 1 // memcpy(outbuf + 54 + jhdr_len, photo1_jpeg, remaining - jhdr_len);
343 1
344 1 outbuf[54 + remaining] = 0; // Append NULL
345 1
346 1 // Replace jpeg length tag with actual value
347 1 itoa(jpeg_len, text, 10);
348 1 replace_tag(outbuf + 54, "TAG:LEN2", text);
349 1
350 1 http_send(outbuf, remaining + 20, nr);
351 1 sent = remaining - jhdr_len;
352 1 conxn[nr].my_sequence += remaining;
353 1
354 1 // Send the rest of the jpeg file in 1000 byte chunks. This sends about
355 1 // 6 segments of 1000 bytes back to back, but we should actually process
356 1 // acks from the other end to make sure we are not sending more than the
357 1 // other end can receive. Most systems can handle 6K
358 1 while (sent < jpeg_len)
359 1 {
360 1 remaining = jpeg_len - sent;
361 1 if (remaining > 1000) remaining = 1000;
C51 COMPILER V7.09 HTTP1 06/28/2007 09:51:20 PAGE 7
362 1 outbuf = (UCHAR *)malloc(54 + remaining + 1);
363 1 if (outbuf == NULL)
364 1 {
365 1 // if (debug) serial_send("TCP: Oops, out of memory\r");
366 1 return 0;
367 1 }
368 1
369 1 //memcpy(outbuf + 54, photo1_jpeg + sent, remaining);
370 1
371 1 outbuf[54 + remaining] = 0; // Append NULL
372 1 http_send(outbuf, remaining + 20, nr);
373 1 sent += remaining;
374 1 conxn[nr].my_sequence += remaining;
375 1 }
376 1 }
377 1 else
378 1 {
379 1 // The incoming HTTP message did not warrant a response
380 1 // if (debug) serial_send("HTTP: No response sent\r");
381 1 */
382 1 if(data_len>0)
383 1 {
384 2 //printf(tcp_data);
385 2
386 2 jpeg_len = data_len;//6194;
387 2 body_len = jpeg_len;
388 2
389 2 // Free memory holding received message. The message from the
390 2 // browser can be 500+ bytes long so this is a significant
391 2 // chunk out of the available malloc space of 1500 bytes
392 2 if (!resend) {/*free(inbuf);*/ rcve_buf_allocated = FALSE;}
393 2
394 2 // First send the header and enough of the jpeg to make 1000 bytes.
395 2 // The value of 1000 is arbitrary, but must be stay under 1500.
396 2 /* if (body_len < 1000)
397 2 remaining = body_len;
398 2 else
399 2 remaining = 1000; */
400 2 outbuf = (UCHAR *)malloc(54 + data_len + 1);
401 2 if (outbuf == NULL)
402 2 {
403 3 // if (debug) serial_send("TCP: Oops, out of memory\r");
404 3 return 0;
405 3 }
406 2
407 2 memcpy(outbuf + 54, tcp_data, data_len);
408 2
409 2 http_send(outbuf, 20 + data_len, nr);
410 2
411 2 #ifdef __LITTLEENDIAN__
412 2
413 2 conxn[nr].my_sequence += data_len;
414 2 #endif
415 2 }
416 1 return 0;
417 1 // }
418 1
419 1 // Return number of bytes sent, not including TCP header
420 1 return(body_len);
421 1 }
*** WARNING C280 IN LINE 174 OF TCP\HTTP1.C: 'i': unreferenced local variable
*** WARNING C280 IN LINE 175 OF TCP\HTTP1.C: 'hhdr_len': unreferenced local variable
C51 COMPILER V7.09 HTTP1 06/28/2007 09:51:20 PAGE 8
*** WARNING C280 IN LINE 175 OF TCP\HTTP1.C: 'jhdr_len': unreferenced local variable
*** WARNING C280 IN LINE 175 OF TCP\HTTP1.C: 'page_len': unreferenced local variable
*** WARNING C280 IN LINE 176 OF TCP\HTTP1.C: 'sent': unreferenced local variable
*** WARNING C280 IN LINE 176 OF TCP\HTTP1.C: 'remaining': unreferenced local variable
*** WARNING C280 IN LINE 178 OF TCP\HTTP1.C: 'ptr': unreferenced local variable
*** WARNING C280 IN LINE 180 OF TCP\HTTP1.C: 'request': unreferenced local variable
*** WARNING C280 IN LINE 181 OF TCP\HTTP1.C: 'post_flg': unreferenced local variable
422
423
424
425
426
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1186 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 2 53
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 12 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -