ported HTTP-Server with W5500 Ethernet Shield
Dependencies: W5500Interface mbed-rpc mbed
Fork of HTTP-Server by
Revision 7:838d7ea07e18, committed 2013-07-17
- Comitter:
- feb11
- Date:
- Wed Jul 17 16:23:35 2013 +0000
- Parent:
- 6:d03e189ebbfe
- Child:
- 8:464abd184b7b
- Commit message:
- Improved error handling and added log
Changed in this revision
HTTPServer.cpp | Show annotated file Show diff for this revision Revisions of this file |
RequestHandler.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTTPServer.cpp Wed Jul 17 15:18:41 2013 +0000 +++ b/HTTPServer.cpp Wed Jul 17 16:23:35 2013 +0000 @@ -51,20 +51,25 @@ } else if(n != -1) { + printf("Received data\n"); buffer[n] = '\0'; handle_request(buffer); if(formatter != NULL) { + printf("Sending data..."); char *page = formatter->get_page(reply); do { c.send(page, strlen(page)+1); page = formatter->get_page(reply); }while(strlen(page)>0); + printf("done\n"); } else c.send(INVALID_FORMATTER, strlen(INVALID_FORMATTER)+1); } + else + printf("Error while receiving data\n"); } } }
--- a/RequestHandler.cpp Wed Jul 17 15:18:41 2013 +0000 +++ b/RequestHandler.cpp Wed Jul 17 16:23:35 2013 +0000 @@ -3,21 +3,29 @@ #include "RPCObjectManager.h" #include "RPCCommand.h" +const char* INVALID_CMD = "Invalid RPC command"; +const char* DELETE_ERROR = "You must send a DELETE request to remove an object "; +const char* CREATE_ERROR = "You must send a PUT request to create an object"; +const char* FUNC_CALL_ERROR = "You must send a GET request to call a function"; + void GetRequestHandler::handle(const RPCCommand& cmd, char *reply) { switch(cmd.get_type()) { case DELETE: - strcat(reply, "You must send a DELETE request to remove an object "); + printf("Error: %s\n", DELETE_ERROR); + strcat(reply, DELETE_ERROR); break; case FUNCTION_CALL: RPC::call(cmd.get_cmd(), reply); break; case CREATE: - strcat(reply, "You must send a PUT request to call a function"); + printf("Error: %s\n", CREATE_ERROR); + strcat(reply, CREATE_ERROR); break; default: - strcat(reply, "Invalid RPC command"); + printf("Error: %s\n", INVALID_CMD); + strcat(reply, INVALID_CMD); break; } } @@ -27,10 +35,12 @@ switch(cmd.get_type()) { case DELETE: - strcat(reply, "You must send a DELETE request to remove an object "); + printf("Error: %s\n", DELETE_ERROR); + strcat(reply, DELETE_ERROR); break; case FUNCTION_CALL: - strcat(reply, "You must send a GET request to call a function"); + printf("Error: %s\n", FUNC_CALL_ERROR); + strcat(reply, FUNC_CALL_ERROR); break; case CREATE: RPC::call(cmd.get_cmd(), reply); @@ -40,10 +50,14 @@ strcat(reply, " has been created"); } else + { + printf("Error while creating object\n"); strcat(reply, "Error while creating object."); + } break; default: - strcat(reply, "Invalid RPC command"); + printf("Error: %s\n", INVALID_CMD); + strcat(reply, INVALID_CMD); break; } } @@ -53,10 +67,12 @@ switch(cmd.get_type()) { case CREATE: - strcat(reply, "You must send a PUT request to remove an object "); + printf("Error: %s\n", CREATE_ERROR); + strcat(reply, CREATE_ERROR); break; case FUNCTION_CALL: - strcat(reply, "You must send a GET request to call a function"); + printf("Error: %s\n", FUNC_CALL_ERROR); + strcat(reply, FUNC_CALL_ERROR); break; case DELETE: RPC::call(cmd.get_cmd(), reply); @@ -65,7 +81,8 @@ strcat(reply, cmd.get_obj_name()); break; default: - strcat(reply, "Invalid RPC command"); + printf("Error: %s\n", INVALID_CMD); + strcat(reply, INVALID_CMD); break; } } @@ -84,7 +101,8 @@ getHandler.handle(cmd, reply); break; default : - strcat(reply, "Invalid RPC command"); + printf("Error: %s\n", INVALID_CMD); + strcat(reply, INVALID_CMD); break; } }