00001 00028 #include <compiler.h> 00029 #include "board.h" 00030 #include "gpio.h" 00031 #include "adc.h" 00032 00033 #include "lwip/stats.h" 00034 #include "lwip/init.h" 00035 #include "lwip/netif.h" 00036 00037 #include "fsdata_file.h" 00038 #include "util.h" 00039 #include "wl_util.h" 00040 #include "hdwireless_gif.h" 00041 00042 00046 static char* 00047 get_adc(void) 00048 { 00049 volatile avr32_adc_t *adc = &AVR32_ADC; 00050 static char buf[8]; 00051 signed short val; 00052 adc_start(adc); 00053 val = adc_get_value(adc, 0); 00054 00055 sniprintf(buf, sizeof(buf), "%d", val); 00056 return buf; 00057 } 00058 00059 00063 static char* 00064 get_tx(void) 00065 { 00066 static char buf[8]; 00067 sniprintf(buf, sizeof(buf), "%d", lwip_stats.link.xmit); 00068 return buf; 00069 } 00070 00071 00075 static char* 00076 get_rx(void) 00077 { 00078 static char buf[8]; 00079 sniprintf(buf, sizeof(buf), "%d", lwip_stats.link.recv); 00080 return buf; 00081 } 00082 00083 00087 static int 00088 html_add_row(char* buf, int len, char* name, const char* data) 00089 { 00090 return sniprintf(buf, len, "<tr><td>%s: </td><td><b>%s</b></td></tr>", 00091 name, data); 00092 } 00093 00094 00098 static int 00099 html_add_button(char* buf, int len, char* id, char* value) 00100 { 00101 return sniprintf(buf, len, "<input type=\"submit\" name=\"%s\" " 00102 "value=\"%s\"/>  ", 00103 id, value); 00104 } 00105 00106 00110 void 00111 document_image_gif_cb(const char** buf, int* len) 00112 { 00113 *buf = hdwireless_gif; 00114 *len = sizeof(hdwireless_gif); 00115 } 00116 00117 00121 void 00122 document_404_html_cb(const char** buf, int* len) 00123 { 00124 static const char *rsp = 00125 "HTTP/1.0 404 File not found\n" 00126 "Server: lwIP\n" 00127 "Content-type: text/html\n\n" 00128 "<html>" 00129 "<head><title>802.11 WiFi on Atmel UC3A3256</title></head>" 00130 "<body bgcolor=\"white\" text=\"black\">" 00131 "<table width=\"100%\">" 00132 "<tr valign=\"top\"><td width=\"80\">" 00133 "<a href=\"http://www.atmel.com/\"><img src=\"image.gif\"" 00134 "border=\"0\" alt=\"logo\" title=\"logo\"></a>" 00135 "</td><td width=\"500\">" 00136 "<h2>802.11 WiFi on Atmel UC3A3256</h2>" 00137 "<h3>404 - Page not found</h3>" 00138 "<p>" 00139 "Sorry, the page you are requesting was not found on this" 00140 "server." 00141 "</p></td><td> </td></tr></table></body></html>"; 00142 00143 *buf = rsp; 00144 *len = strlen(rsp); 00145 } 00146 00147 00151 void 00152 document_index_html_cb(const char** buf, int* len) 00153 { 00154 static char rsp[1500]; 00155 int pos = 0; 00156 00157 pos += sniprintf(rsp + pos, sizeof(rsp) - pos, 00158 "HTTP/1.0 200 OK\n" 00159 "Server: lwIP\n" 00160 "Content-type: text/html\n\n" 00161 "<html>" 00162 "<head><title>802.11bg WiFi on Atmel UC3%s</title>" 00163 "</head>" 00164 "</html>" 00165 "<body bgcolor=\"white\" text=\"black\">" 00166 "<table width=\"100%%\">" 00167 "<tr valign=\"top\"><td width=\"80\">" 00168 "<a href=\"index.html\">" 00169 "<img src=\"image.gif\" border=\"0\" alt=\"logo\"" 00170 "title=\"logo\"></a>" 00171 "</td>" 00172 "<td width=\"500\">" 00173 "<h2>802.11bg WiFi on Atmel UC3%s</h2>" 00174 "<p>" 00175 "The web page you are watching was served by Atmel " 00176 "UC3%s, using the H&D Wireless 802.11bg Wi-Fi SIP " 00177 "solution. The web server is running on top of the " 00178 "lightweight TCP/IP stack, " 00179 "<a href=\"http://www.sics.se/~adam/lwip/\">lwIP</a>." 00180 "</p><hr><table>", 00181 #if BOARD == EVK1104 00182 "A3256", "A3256", "A3256"); 00183 #elif BOARD == EVK1105 || BOARD == EVK1100 00184 "A0512", "A0512", "A0512"); 00185 #elif BOARD == EVK1101 00186 "B0256", "B0256", "B0256"); 00187 #else 00188 #error 00189 #endif 00190 00191 00192 pos += html_add_row(rsp + pos, sizeof(rsp) - pos, 00193 "IP Address", ip2str(netif_default->ip_addr)); 00194 pos += html_add_row(rsp + pos, sizeof(rsp) - pos, 00195 "MAC Address", mac2str(netif_default->hwaddr)); 00196 pos += html_add_row(rsp + pos, sizeof(rsp) - pos, 00197 "TX packets", get_tx()); 00198 pos += html_add_row(rsp + pos, sizeof(rsp) - pos, 00199 "RX packets", get_rx()); 00200 pos += html_add_row(rsp + pos, sizeof(rsp) - pos, 00201 #if BOARD == EVK1104 || BOARD == EVK1101 00202 "Light sensor ADC value", 00203 #elif BOARD == EVK1105 || BOARD == EVK1100 00204 "ADC value", 00205 #else 00206 #error 00207 #endif 00208 get_adc()); 00209 00210 pos += sniprintf(rsp + pos, sizeof(rsp) - pos, 00211 "<tr><td><form method=\"get\">" 00212 "<input type=\"submit\" value=\"Refresh\"/>" 00213 "</form></td></tr>"); 00214 00215 00216 pos += sniprintf(rsp + pos, sizeof(rsp) - pos, 00217 "</table><br>"); 00218 pos += sniprintf(rsp + pos, sizeof(rsp) - pos, "<form id=\"form\"" 00219 "name=\"form\" method=\"get\" action=\"index.html\">" 00220 "<fieldset style=\"width: 300;\">" 00221 "<legend>LED control</legend>"); 00222 pos += html_add_button(rsp + pos, sizeof(rsp) - pos, "toggle", "LED0"); 00223 pos += html_add_button(rsp + pos, sizeof(rsp) - pos, "toggle", "LED1"); 00224 pos += html_add_button(rsp + pos, sizeof(rsp) - pos, "toggle", "LED2"); 00225 pos += html_add_button(rsp + pos, sizeof(rsp) - pos, "toggle", "LED3"); 00226 pos += sniprintf(rsp + pos, sizeof(rsp) - pos, "</fieldset></form>"); 00227 00228 pos += sniprintf(rsp + pos, sizeof(rsp) - pos, "</td>" 00229 "<td> </td></tr></table></body></html>"); 00230 00231 *buf = rsp; 00232 *len = pos; 00233 } 00234 00235 00239 void 00240 query_led0_cb(const char** buf, int* len) 00241 { 00242 document_index_html_cb(buf, len); 00243 LED_Toggle(LED0); 00244 } 00245 00246 00250 void 00251 query_led1_cb(const char** buf, int* len) 00252 { 00253 document_index_html_cb(buf, len); 00254 LED_Toggle(LED1); 00255 } 00256 00257 00261 void 00262 query_led2_cb(const char** buf, int* len) 00263 { 00264 document_index_html_cb(buf, len); 00265 LED_Toggle(LED2); 00266 } 00267 00268 00272 void 00273 query_led3_cb(const char** buf, int* len) 00274 { 00275 document_index_html_cb(buf, len); 00276 LED_Toggle(LED3); 00277 } 00278 00279 00280 const struct fsdata_file file_led3 = { 00281 "/index.html?toggle=LED3", 00282 query_led3_cb, 00283 NULL 00284 }; 00285 00286 const struct fsdata_file file_led2 = { 00287 "/index.html?toggle=LED2", 00288 query_led2_cb, 00289 &file_led3, 00290 }; 00291 00292 const struct fsdata_file file_led1 = { 00293 "/index.html?toggle=LED1", 00294 query_led1_cb, 00295 &file_led2, 00296 }; 00297 00298 const struct fsdata_file file_led0 = { 00299 "/index.html?toggle=LED0", 00300 query_led0_cb, 00301 &file_led1, 00302 }; 00303 00304 const struct fsdata_file file_image_gif = { 00305 "/image.gif", 00306 document_image_gif_cb, 00307 &file_led0, 00308 }; 00309 00310 const struct fsdata_file file_404_html = { 00311 "/404.html", 00312 document_404_html_cb, 00313 &file_image_gif, 00314 }; 00315 00316 const struct fsdata_file file_index_html = { 00317 "/index.html", 00318 document_index_html_cb, 00319 &file_404_html, 00320 }; 00321 00322 #define FS_ROOT &file_index_html