00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #if (HTTP_USED == 1)
00056
00057
00058
00059 #include <stdio.h>
00060 #include <string.h>
00061
00062 #include "conf_eth.h"
00063
00064
00065 #include "FreeRTOS.h"
00066 #include "task.h"
00067 #include "semphr.h"
00068 #include "partest.h"
00069 #include "serial.h"
00070
00071
00072
00073 #include "portmacro.h"
00074
00075
00076 #include "lwip/api.h"
00077 #include "lwip/tcpip.h"
00078 #include "lwip/memp.h"
00079 #include "lwip/stats.h"
00080 #include "netif/loopif.h"
00081
00082
00083 #include "ethernet.h"
00084
00086 #define webMAX_PAGE_SIZE 512
00087
00089 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
00090
00092 #define webHTTP_PORT ( 80 )
00093
00095 #define webSHORT_DELAY ( 10 )
00096
00098 #define webHTML_START \
00099 "<html>\
00100 <head>\
00101 </head>\
00102 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\" bgcolor=\"#FFFFFF\" text=\"#2477E6\">\
00103 \r\nPage Hits = "
00104
00105 #define webHTML_END \
00106 "\r\n</pre>\
00107 \r\n</font></BODY>\
00108 </html>"
00109
00110 portCHAR cDynamicPage[ webMAX_PAGE_SIZE ];
00111 portCHAR cPageHits[ 11 ];
00112
00113
00115 static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon );
00116
00117
00124 portTASK_FUNCTION( vBasicWEBServer, pvParameters )
00125 {
00126 struct netconn *pxHTTPListener, *pxNewConnection;
00127
00128
00129 pxHTTPListener = netconn_new( NETCONN_TCP );
00130 netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
00131 netconn_listen( pxHTTPListener );
00132
00133
00134 for( ;; )
00135 {
00136
00137 pxNewConnection = netconn_accept(pxHTTPListener);
00138 vParTestSetLED(webCONN_LED, pdTRUE);
00139
00140 if(pxNewConnection != NULL)
00141 {
00142 prvweb_ParseHTMLRequest(pxNewConnection);
00143 }
00144
00145 vParTestSetLED(webCONN_LED, pdFALSE);
00146
00147 }
00148 }
00149
00150
00157 static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon )
00158 {
00159 struct netbuf *pxRxBuffer;
00160 portCHAR *pcRxString;
00161 unsigned portSHORT usLength;
00162 static unsigned portLONG ulPageHits = 0;
00163
00164
00165 pxRxBuffer = netconn_recv( pxNetCon );
00166
00167 if( pxRxBuffer != NULL )
00168 {
00169
00170 netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
00171
00172
00173 if(( NULL != pcRxString )
00174 && ( !strncmp( pcRxString, "GET", 3 ) ))
00175 {
00176
00177 ulPageHits++;
00178 sprintf( cPageHits, "%d", (int)ulPageHits );
00179
00180
00181 netconn_write( pxNetCon, webHTTP_OK, (u16_t) strlen( webHTTP_OK ), NETCONN_COPY );
00182
00183
00184 strcpy( cDynamicPage, webHTML_START );
00185
00186
00187 strcat( cDynamicPage, cPageHits );
00188 strcat( cDynamicPage, "<p><pre>Task State Priority Stack #<br>************************************************<br>" );
00189
00190
00191 vTaskList( ( signed portCHAR * ) cDynamicPage + strlen( cDynamicPage ) );
00192
00193
00194 strcat( cDynamicPage, webHTML_END );
00195
00196
00197 netconn_write( pxNetCon, cDynamicPage, (u16_t) strlen( cDynamicPage ), NETCONN_COPY );
00198 }
00199 netbuf_delete( pxRxBuffer );
00200 }
00201
00202 netconn_close( pxNetCon );
00203 netconn_delete( pxNetCon );
00204 }
00205
00206 #endif
00207