Skip to content
Browse files

Fixing build issues

- Fixing build errors when compiling the included sketches
- Fixing build conflict with the Ethernet library
  • Loading branch information...
1 parent 841647c commit 2bf3f8f9be52589369118a73d194d66e2728ecb4 @asynclabs committed Jul 15, 2009
Showing with 88 additions and 81 deletions.
  1. +41 −38 WiServer.cpp
  2. +24 −24 WiServer.h
  3. +1 −1 WiShield.cpp
  4. +2 −2 apps-conf.h
  5. +1 −1 config.h
  6. +1 −1 network.c
  7. +12 −9 server.h
  8. +1 −1 stack.c
  9. +1 −0 webserver.h
  10. +4 −4 types.h → witypes.h
View
79 WiServer.cpp
@@ -42,11 +42,12 @@ extern "C" {
#include "g2100.h"
#include "uip.h"
#include "server.h"
+ #include "global-conf.h"
void stack_init(void);
void stack_process(void);
}
-
+#ifdef APP_WISERVER
#define CR 13
#define LF 10
@@ -218,7 +219,7 @@ void send() {
Serial.print(len);
Serial.println(" bytes");
}
-
+
#ifdef DEBUG
Serial.print(app->ackedCount);
Serial.print(" - ");
@@ -239,12 +240,12 @@ void send() {
/*
* Processes a line of data in an HTTP request. This function looks
- * for GET and saves a copy of the URL in the current connection's
- * server request. It also sets the request's isValid flag if the
+ * for GET and saves a copy of the URL in the current connection's
+ * server request. It also sets the request's isValid flag if the
* URL has been saved and an empty line is found.
*/
boolean processLine(char* data, int len) {
-
+
// Check for a valid GET line
if ((uip_conn->appstate.request == NULL) && (strncmp(data, "GET /", 4) == 0)) {
// URL starts at the '/'
@@ -266,33 +267,33 @@ boolean processLine(char* data, int len) {
}
// No space, not valid
}
-
+
return (len == 0);
}
/*
* Processes a packet of data that supposedly contains an HTTP request
* This function looks for CR/LF (or just LF) and calls processLine
- * with each line of data found.
+ * with each line of data found.
*/
boolean processPacket(char* data, int len) {
-
+
// Address after the last byte of data
char* end = data + len;
// Start of current line
char* start = data;
-
+
// Scan through the bytes in the packet looking for a Line Feed character
while (data < end) {
if (*data == LF) {
// Determine the length of the line excluding the Line Feed
int lineLength = data - start;
-
+
if (*(data - 1) == CR) {
lineLength--;
}
-
+
*(start + lineLength) = 0;
// Process the line
if (processLine(start, lineLength)) {
@@ -362,40 +363,40 @@ boolean Server::clientIsLocal() {
* Handles high-level server communications
*/
void server_task_impl() {
-
+
// Get the connection's app state
uip_tcp_appstate_t *app = &(uip_conn->appstate);
-
+
if (uip_connected()) {
-
+
if (verbose) {
- Serial.println("Server connected");
+ Serial.println("Server connected");
}
-
+
// Initialize the server request data
app->ackedCount = 0;
app->request = NULL;
}
-
+
if (uip_newdata()) {
setRXPin(HIGH);
// Process the received packet and check if a valid GET request had been received
if (processPacket((char*)uip_appdata, uip_datalen()) && app->request) {
if (verbose) {
- Serial.print("Processing request for ");
+ Serial.print("Processing request for ");
Serial.println((char*)app->request);
}
sendPage();
}
}
-
-
+
+
// Did we get an ack for the last packet?
if (uip_acked()) {
// Record the bytes that were successfully sent
app->ackedCount += app->sentCount;
app->sentCount = 0;
-
+
// Check if we're done or need to send more content for this
// request
if (app->ackedCount == (int)app->cursor) {
@@ -406,21 +407,21 @@ void server_task_impl() {
sendPage();
}
}
-
+
// Check if we need to retransmit
if (uip_rexmit()) {
// Send the same data again (same ackedCount value)
sendPage();
}
-
+
if (uip_aborted() || uip_closed() || uip_timedout()) {
// Check if a URL was stored for this connection
if (app->request != NULL) {
if (verbose) {
- Serial.println("Server connection closed");
+ Serial.println("Server connection closed");
}
-
+
// Free RAM and clear the pointer
free(app->request);
app->request = NULL;
@@ -467,7 +468,7 @@ void sendRequest() {
app->cursor = 0;
// Indicates if this is a POST request (instead of a GET)
- // Main difference is that POST requests have a body and a
+ // Main difference is that POST requests have a body and a
// callback function to generate said body
bool isPost = req->body != NULL;
@@ -488,11 +489,11 @@ void sendRequest() {
// User agent (WiServer, of course!)
WiServer.println_P(userAgent);
-
+
if (isPost) {
// Since a post has a body after the blank header line, it has to include
// an accurate content length so that the server knows when it has received
- // all of the body data.
+ // all of the body data.
char* lengthFieldPos; // Cursor position where the content length place holder starts
char* contentStart; // Start of the body
char* contentEnd; // End of the body
@@ -510,12 +511,12 @@ void sendRequest() {
// Body starts here
contentStart = app->cursor;
-
+
// Print the body preamble if the request has one
if (req->bodyPreamble) {
WiServer.print(req->bodyPreamble);
}
-
+
// Have the sketch provide the body for the POST
req->body();
@@ -528,7 +529,7 @@ void sendRequest() {
// Put the cursor back at the end of the body so that all of the data gets sent
app->cursor = contentEnd;
-
+
} else {
// Blank line to indicate end of GET header
WiServer.println();
@@ -561,15 +562,15 @@ void client_task_impl() {
// Record the bytes that were successfully sent
app->ackedCount += app->sentCount;
app->sentCount = 0;
-
+
// Check if we're done or need to send more content for this
// request
if (app->ackedCount != (int)app->cursor) {
// Generate the post again to send the next packet of data
sendRequest();
}
}
-
+
if (uip_rexmit()) {
sendRequest();
}
@@ -597,12 +598,12 @@ void client_task_impl() {
Serial.print("Ended connection with ");
Serial.println(req->hostName);
}
-
+
if (req->returnFunc) {
// Call the sketch's callback function with 0 bytes to indicate End Of Data
req->returnFunc((char*)uip_appdata, 0);
}
- // Remove the request from the connection
+ // Remove the request from the connection
app->request = NULL;
// Request is no longer active
req->active = false;
@@ -648,7 +649,7 @@ void Server::server_task() {
// Run the stack state machine
stack_process();
-
+
// Run the driver
zg_drv_process();
@@ -657,13 +658,13 @@ void Server::server_task() {
if (queue) {
// Attempt to connect to the server
struct uip_conn *conn = uip_connect(&(queue->ipAddr), queue->port);
-
+
if (conn != NULL) {
#ifdef DEBUG
Serial.print("Got connection for ");
Serial.println(queue->hostName);
#endif // DEBUG
-
+
// Attach the request object to its connection
conn->appstate.request = queue;
// Move the head of the queue to the next request in the queue
@@ -677,3 +678,5 @@ void Server::server_task() {
// Single instance of the server
Server WiServer;
+
+#endif /* APP_WISERVER */
View
48 WiServer.h
@@ -30,7 +30,7 @@
plus added various enhancements such as
multi-pass transmission, local client
checks, activity LED support, etc.
-
+
Mark A. Patel 06/22/2009 Revised client API
@@ -40,7 +40,7 @@
#define WISERVER_H_
extern "C" {
- #include "types.h"
+ #include "witypes.h"
#include "server.h"
#include "config.h"
#include "uip.h"
@@ -72,45 +72,45 @@ typedef void (*bodyFunction)();
/*
* Class that encapsulates an HTTP GET request
*/
-class GETrequest
+class GETrequest
{
public:
-
+
/*
* Creates a new GETrequest with the provided IP, port, host name and URL
*/
GETrequest(uint8* ipAddr, int port, char* hostName, char* URL);
-
+
/*
- * Submits the request and prevents further changes to the request until it has been
+ * Submits the request and prevents further changes to the request until it has been
* processed.
*/
void submit();
-
+
/*
* Sets the function that should be called with data returned by the server.
*/
void setReturnFunc(returnFunction func);
-
+
/*
* Sets the authorization string for the request. Calls to this method will be ignored if the request
* has been submitted and is still being processed by WiServer.
*/
void setAuth(char* auth);
-
+
/*
* Checks if this request is currently being processed by the WiServer (i.e. it is awaiting a connection
- * or is currently connected and communicating with the server). If it is, any calls that attempt
+ * or is currently connected and communicating with the server). If it is, any calls that attempt
* to change the properties of the request will be ignored.
*/
boolean isActive();
-
+
/*
* Sets the URL for the request. Calls to this method will be ignored if the request
* has been submitted and is currently being processed by WiServer.
*/
- void setURL(char* URL);
-
+ void setURL(char* URL);
+
// Server IP address (network byte order)
uip_ipaddr_t ipAddr;
// Server port number
@@ -122,7 +122,7 @@ class GETrequest
// Authorization string (may be NULL)
char* auth;
// Return value callback function (may be NULL)
- returnFunction returnFunc;
+ returnFunction returnFunc;
// Indicates if the request is currently active (i.e. has a connection)
boolean active;
// Body data callback function (may be NULL)
@@ -140,14 +140,14 @@ class GETrequest
class POSTrequest : public GETrequest
{
public:
-
+
/*
* Creates a new POSTrequest with the provided IP, port, host name, URL and body function.
*/
POSTrequest(uint8* ipAddr, int port, char* hostName, char* URL, bodyFunction body);
-
+
void setBodyFunc(bodyFunction body);
-
+
};
@@ -157,13 +157,13 @@ class POSTrequest : public GETrequest
class TWEETrequest : public POSTrequest
{
public:
-
+
/*
* Creates a new TWEETrequest with the provided auth string and message function.
* The body function will be called to provide the contents of the message; the
* 'status=' prefix is automatically inserted before the message.
*/
- TWEETrequest(char* auth, bodyFunction message);
+ TWEETrequest(char* auth, bodyFunction message);
};
#endif // ENABLE_CLIENT_MODE
@@ -178,15 +178,15 @@ class Server: public Print
*
* @param pageServerFunc name of the sketch's page serving function
*/
- void init(pageServingFunction function);
-
+ void init(pageServingFunction function);
+
/*
* Enables or disables verbose mode. If verbose mode is true, then WiServer
* will output log info via the Serial class. Verbose mode is disabled by
* default, but is automatically enabled if DEBUG is defined
*/
void enableVerboseMode(boolean enable);
-
+
/**
* The server task method (must be called in the main loop to run the WiServer)
*/
@@ -214,10 +214,10 @@ class Server: public Print
/**
* Prints a time value in the form HH:MM:SS. The time value is in milliseconds.
- *
+ *
*/
void printTime(long t);
-
+
/**
* Indicates if a page is currently being sent, and that a subsequent call to the page
* serving function may occur to request more data or to retransmit data that was lost
View
2 WiShield.cpp
@@ -34,7 +34,7 @@
*****************************************************************************/
extern "C" {
- #include "types.h"
+ #include "witypes.h"
#include "global-conf.h"
#include "network.h"
#include "g2100.h"
View
4 apps-conf.h
@@ -36,10 +36,10 @@
#define __APPS_CONF_H__
//Here we include the header file for the application(s) we use in our project.
-#define APP_WEBSERVER
+//#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
-//#define APP_WISERVER
+#define APP_WISERVER
#ifdef APP_WEBSERVER
#include "webserver.h"
View
2 config.h
@@ -36,7 +36,7 @@
#ifndef CONFIG_H_
#define CONFIG_H_
-#include "types.h"
+#include "witypes.h"
extern U8 local_ip[];
extern U8 gateway_ip[];
View
2 network.c
@@ -36,7 +36,7 @@
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
-#include "types.h"
+#include "witypes.h"
#include "g2100.h"
void network_init(void)
View
21 server.h
@@ -1,31 +1,31 @@
/******************************************************************************
-
+
Filename: server.h
Description: Private header file for WiServer
-
+
******************************************************************************
-
+
Copyright(c) 2009 Mark A. Patel All rights reserved.
-
+
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
-
+
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
-
+
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
+
Contact Information:
-
+
Author Date Comment
---------------------------------------------------------------
Mark A. Patel 06/10/2009 Initial version
-
+
*****************************************************************************/
#ifndef __SERVER_H__
@@ -34,6 +34,8 @@
#include <avr/pgmspace.h>
#include <uip-conf.h>
+#ifdef APP_WISERVER
+
// Enables client mode (i.e. for sending Tweets and HTTP POST or GET requests)
// Comment out this #define if client mode isn't required
// (it'll save a bunch of code size and a bit of RAM too!)
@@ -62,5 +64,6 @@ struct conn_state {
typedef struct conn_state uip_tcp_appstate_t;
+#endif /* APP_WISERVER */
#endif //__SERVER_H__
View
2 stack.c
@@ -40,7 +40,7 @@
#include "global-conf.h"
#include "uip_arp.h"
#include "network.h"
-#include "types.h"
+#include "witypes.h"
#include "config.h"
#include "g2100.h"
#include "spi.h"
View
1 webserver.h
@@ -34,6 +34,7 @@
#ifndef __WEBSERVER_H__
#define __WEBSERVER_H__
+
#include "psock.h"
typedef struct webserver_state {
View
8 types.h → witypes.h
@@ -1,7 +1,7 @@
/******************************************************************************
- Filename: types.h
+ Filename: witypes.h
Description: Data types
******************************************************************************
@@ -33,8 +33,8 @@
*****************************************************************************/
-#ifndef TYPES_H_
-#define TYPES_H_
+#ifndef WITYPES_H_
+#define WITYPES_H_
#include <avr/pgmspace.h>
@@ -69,4 +69,4 @@ typedef unsigned long U32;
typedef uint8_t boolean;
-#endif /* TYPES_H_ */
+#endif /* WITYPES_H_ */

0 comments on commit 2bf3f8f

Please sign in to comment.
Something went wrong with that request. Please try again.