Neaten Webserver project code.

pull/1469/head
Dean Camera 15 years ago
parent 431db89b00
commit d66f227cce

@ -51,7 +51,6 @@ char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
"Server: LUFA RNDIS\r\n"
"Connection: close\r\n\r\n";
/****************************************************************************************/
/** HTTP page to serve to the host when a HTTP request is made. This page is too long for a single response, thus it is automatically
* broken up into smaller blocks and sent as a series of packets each time the webserver application callback is run.
*/
@ -75,7 +74,17 @@ char PROGMEM HTTPPage[] =
" </body>"
"</html>";
void WebserverAppCallback(void)
/** Initialization function for the simple HTTP webserver. */
void WebserverApp_Init(void)
{
/* Listen on port 80 for HTTP connections from hosts */
uip_listen(HTONS(80));
}
/** uIP stack application callback for the simple HTTP webserver. This function must be called each time the
* TCP/IP stack needs a TCP packet to be processed.
*/
void WebserverApp_Callback(void)
{
char* AppDataPtr = (char*)uip_appdata;
uint16_t AppDataSize = 0;
@ -116,10 +125,12 @@ void WebserverAppCallback(void)
}
else if (BytesRemaining > MaxSegSize)
{
/* More bytes remaining to send than the maximum segment size, send next chunk */
AppDataSize = MaxSegSize;
}
else
{
/* Less bytes than the segment size remaining, send all remaining bytes in the one packet */
AppDataSize = BytesRemaining;
}

@ -45,6 +45,7 @@
#include <uip.h>
/* Function Prototypes: */
void WebserverAppCallback(void);
void WebserverApp_Init(void);
void WebserverApp_Callback(void);
#endif

@ -14,7 +14,7 @@
char* SendPos;
} uip_tcp_appstate_t;
#define UIP_APPCALL WebserverAppCallback
#define UIP_APPCALL WebserverApp_Callback
void UIP_APPCALL(void);
#endif /*__APPS_CONF_H__*/

@ -71,8 +71,6 @@ int main(void)
{
SetupHardware();
puts_P(PSTR(ESC_FG_CYAN "RNDIS Host Demo running.\r\n" ESC_FG_WHITE));
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;)
@ -88,7 +86,6 @@ int main(void)
if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
{
printf("Error Retrieving Configuration Descriptor.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
@ -97,7 +94,6 @@ int main(void)
if (RNDIS_Host_ConfigurePipes(&Ethernet_RNDIS_Interface,
ConfigDescriptorSize, ConfigDescriptorData) != RNDIS_ENUMERROR_NoError)
{
printf("Attached Device Not a Valid RNDIS Class Device.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
@ -105,7 +101,6 @@ int main(void)
if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
{
printf("Error Setting Device Configuration.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
@ -113,21 +108,15 @@ int main(void)
if (RNDIS_Host_InitializeDevice(&Ethernet_RNDIS_Interface) != HOST_SENDCONTROL_Successful)
{
printf("Error Initializing Device.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
printf("Device Max Transfer Size: %lu bytes.\r\n", Ethernet_RNDIS_Interface.State.DeviceMaxPacketSize);
uint32_t PacketFilter = (REMOTE_NDIS_PACKET_DIRECTED | REMOTE_NDIS_PACKET_BROADCAST);
if (RNDIS_Host_SetRNDISProperty(&Ethernet_RNDIS_Interface, OID_GEN_CURRENT_PACKET_FILTER,
&PacketFilter, sizeof(PacketFilter)) != HOST_SENDCONTROL_Successful)
{
printf("Error Setting Device Packet Filter.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
@ -137,22 +126,14 @@ int main(void)
if (RNDIS_Host_QueryRNDISProperty(&Ethernet_RNDIS_Interface, OID_802_3_CURRENT_ADDRESS,
&MACAddress, sizeof(MACAddress)) != HOST_SENDCONTROL_Successful)
{
printf("Error Getting MAC Address.\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
printf("MAC Address: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\r\n",
MACAddress.addr[0], MACAddress.addr[1], MACAddress.addr[2],
MACAddress.addr[3], MACAddress.addr[4], MACAddress.addr[5]);
uip_setethaddr(MACAddress);
LEDs_SetAllLEDs(LEDMASK_USB_READY);
printf("RNDIS Device Enumerated.\r\n");
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
@ -253,7 +234,6 @@ void SetupHardware(void)
clock_prescale_set(clock_div_1);
/* Hardware Initialization */
SerialStream_Init(9600, false);
LEDs_Init();
USB_Init();
@ -273,7 +253,7 @@ void SetupHardware(void)
uip_setdraddr(&GatewayIPAddress);
/* HTTP Webserver Initialization */
uip_listen(HTONS(80));
WebserverApp_Init();
}
/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and
@ -281,7 +261,6 @@ void SetupHardware(void)
*/
void EVENT_USB_Host_DeviceAttached(void)
{
puts_P(PSTR("Device Attached.\r\n"));
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
}
@ -290,7 +269,6 @@ void EVENT_USB_Host_DeviceAttached(void)
*/
void EVENT_USB_Host_DeviceUnattached(void)
{
puts_P(PSTR("\r\nDevice Unattached.\r\n"));
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
}
@ -307,9 +285,6 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{
USB_ShutDown();
printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"
" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
for(;;);
}
@ -319,10 +294,5 @@ void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)
{
printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"
" -- Error Code %d\r\n"
" -- Sub Error Code %d\r\n"
" -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}

@ -41,11 +41,9 @@
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <avr/power.h>
#include <stdio.h>
#include <LUFA/Version.h>
#include <LUFA/Drivers/Misc/TerminalCodes.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/USB/Class/RNDIS.h>

@ -123,8 +123,6 @@ LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
Lib/WebserverApp.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \

Loading…
Cancel
Save