【4个文本框】 #include <avr/pgmspace.h> #include <stdio.h> #include <string.h> #include "uip/uip.h"
const char html_0[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Length: "; const char html_1[] PROGMEM = "\r\nKeep-Alive: timeout=5, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\n\r\n";
const char html_2[] PROGMEM = "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>AVR Page</title>\n</head>\n\n<body>\n<form id=\"form1\" name=\"form1\" method=\"post\">\nThis is a page from a server just made of AVR MCU.<br>\n<label for=\"textfield\">PINA: </label><input name=\"textfield\" type=\"text\" id=\"textfield\" value=\"0x"; const char html_3[] PROGMEM = "\"><br>\n<label for=\"textfield2\">PINB: </label><input name=\"textfield2\" type=\"text\" id=\"textfield2\" value=\"0x"; const char html_4[] PROGMEM = "\"><br>\n<label for=\"textfield3\">PINC: </label><input name=\"textfield3\" type=\"text\" id=\"textfield3\" value=\"0x"; const char html_5[] PROGMEM = "\"><br>\n<label for=\"textfield4\">PIND: </label><input name=\"textfield4\" type=\"text\" id=\"textfield4\" value=\"0x"; const char html_6[] PROGMEM = "\"><br>\n<input type=\"submit\" value=\"Submit\">\n</form>\n</body>\n</html>\n";
void send_current_str(void) { uint8_t len = strlen(uip_conn->appstate.buf + uip_conn->appstate.bufptr); uip_send(uip_conn->appstate.buf + uip_conn->appstate.bufptr, len); uip_conn->appstate.bufptr += len + 1; }
void uip_appcall(void) { if (uip_connected()) { uip_conn->appstate.step = 0; uip_conn->appstate.bufptr = 1 + sprintf_P(uip_conn->appstate.buf, PSTR("%02x"), PINA); uip_conn->appstate.bufptr += 1 + sprintf_P(uip_conn->appstate.buf + uip_conn->appstate.bufptr, PSTR("%02x"), PINB); uip_conn->appstate.bufptr += 1 + sprintf_P(uip_conn->appstate.buf + uip_conn->appstate.bufptr, PSTR("%02x"), PINC); uip_conn->appstate.bufptr += 1 + sprintf_P(uip_conn->appstate.buf + uip_conn->appstate.bufptr, PSTR("%02x"), PIND);
sprintf_P(uip_conn->appstate.len_s, PSTR("%d"), strlen_P(html_2) + strlen_P(html_3) + strlen_P(html_4) + strlen_P(html_5) + strlen_P(html_6) + uip_conn->appstate.bufptr - 4); uip_conn->appstate.bufptr = 0; }
if (uip_acked() || uip_newdata() || uip_rexmit()) { switch (uip_conn->appstate.step) { case 0: uip_send_P(html_0); break; case 1: uip_send(uip_conn->appstate.len_s, strlen(uip_conn->appstate.len_s)); break; case 2: uip_send_P(html_1); break; case 3: uip_send_P(html_2); break; case 4: case 6: case 8: case 10: send_current_str(); break; case 5: uip_send_P(html_3); break; case 7: uip_send_P(html_4); break; case 9: uip_send_P(html_5); break; case 11: uip_send_P(html_6); break; default: uip_close(); }
if (!uip_rexmit() && !uip_closed()) uip_conn->appstate.step++; } }
|