Program the control the fischertechnik robo interface or intelligent interface via tcp socket or via a java gui.

Dependencies:   mbed ConfigFile

Committer:
networker
Date:
Fri Dec 31 14:01:14 2010 +0000
Revision:
0:7f26f0680202
initial release: comprises ftlib (no usb), ft-over-ip socket server, and the http server (the html page and java jar I still have to publish somewhere)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
networker 0:7f26f0680202 1
networker 0:7f26f0680202 2 /*
networker 0:7f26f0680202 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
networker 0:7f26f0680202 4
networker 0:7f26f0680202 5 Permission is hereby granted, free of charge, to any person obtaining a copy
networker 0:7f26f0680202 6 of this software and associated documentation files (the "Software"), to deal
networker 0:7f26f0680202 7 in the Software without restriction, including without limitation the rights
networker 0:7f26f0680202 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
networker 0:7f26f0680202 9 copies of the Software, and to permit persons to whom the Software is
networker 0:7f26f0680202 10 furnished to do so, subject to the following conditions:
networker 0:7f26f0680202 11
networker 0:7f26f0680202 12 The above copyright notice and this permission notice shall be included in
networker 0:7f26f0680202 13 all copies or substantial portions of the Software.
networker 0:7f26f0680202 14
networker 0:7f26f0680202 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
networker 0:7f26f0680202 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
networker 0:7f26f0680202 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
networker 0:7f26f0680202 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
networker 0:7f26f0680202 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
networker 0:7f26f0680202 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
networker 0:7f26f0680202 21 THE SOFTWARE.
networker 0:7f26f0680202 22 */
networker 0:7f26f0680202 23
networker 0:7f26f0680202 24 /**
networker 0:7f26f0680202 25 HTTP Request Handler header file.
networker 0:7f26f0680202 26 */
networker 0:7f26f0680202 27
networker 0:7f26f0680202 28 #ifndef HTTP_REQUEST_HANDLER_H
networker 0:7f26f0680202 29 #define HTTP_REQUEST_HANDLER_H
networker 0:7f26f0680202 30
networker 0:7f26f0680202 31 #include "api/TCPSocket.h"
networker 0:7f26f0680202 32 //#include "HTTPServer.h"
networker 0:7f26f0680202 33
networker 0:7f26f0680202 34 #include "mbed.h"
networker 0:7f26f0680202 35 #include "core/netservice.h"
networker 0:7f26f0680202 36
networker 0:7f26f0680202 37 #include <string>
networker 0:7f26f0680202 38 using std::string;
networker 0:7f26f0680202 39
networker 0:7f26f0680202 40 #include <map>
networker 0:7f26f0680202 41 using std::map;
networker 0:7f26f0680202 42
networker 0:7f26f0680202 43 ///HTTP Server's generic request handler
networker 0:7f26f0680202 44 class HTTPRequestHandler : public NetService
networker 0:7f26f0680202 45 {
networker 0:7f26f0680202 46 public:
networker 0:7f26f0680202 47 ///Instantiated by the HTTP Server
networker 0:7f26f0680202 48 HTTPRequestHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
networker 0:7f26f0680202 49 virtual ~HTTPRequestHandler();
networker 0:7f26f0680202 50
networker 0:7f26f0680202 51 //protected:
networker 0:7f26f0680202 52 virtual void doGet() = 0;
networker 0:7f26f0680202 53 virtual void doPost() = 0;
networker 0:7f26f0680202 54 virtual void doHead() = 0;
networker 0:7f26f0680202 55
networker 0:7f26f0680202 56 virtual void onReadable() = 0; //Data has been read
networker 0:7f26f0680202 57 virtual void onWriteable() = 0; //Data has been written & buf is free
networker 0:7f26f0680202 58 virtual void onTimeout(); //Connection has timed out
networker 0:7f26f0680202 59 virtual void onClose() = 0; //Connection is closing
networker 0:7f26f0680202 60
networker 0:7f26f0680202 61 virtual void close(); //Close socket and destroy data
networker 0:7f26f0680202 62
networker 0:7f26f0680202 63 protected:
networker 0:7f26f0680202 64 map<string, string>& reqHeaders() /*const*/;
networker 0:7f26f0680202 65 string& path() /*const*/;
networker 0:7f26f0680202 66 int dataLen() const;
networker 0:7f26f0680202 67 int readData(char* buf, int len);
networker 0:7f26f0680202 68 string& rootPath() /*const*/;
networker 0:7f26f0680202 69
networker 0:7f26f0680202 70 void setErrCode(int errc);
networker 0:7f26f0680202 71 void setContentLen(int len);
networker 0:7f26f0680202 72
networker 0:7f26f0680202 73 map<string, string>& respHeaders();
networker 0:7f26f0680202 74 int writeData(const char* buf, int len);
networker 0:7f26f0680202 75
networker 0:7f26f0680202 76 void setTimeout(int ms);
networker 0:7f26f0680202 77 void resetTimeout();
networker 0:7f26f0680202 78
networker 0:7f26f0680202 79 private:
networker 0:7f26f0680202 80 void readHeaders(); //Called at instanciation
networker 0:7f26f0680202 81 void writeHeaders(); //Called at the first writeData call
networker 0:7f26f0680202 82 void onTCPSocketEvent(TCPSocketEvent e);
networker 0:7f26f0680202 83
networker 0:7f26f0680202 84 TCPSocket* m_pTCPSocket;
networker 0:7f26f0680202 85 map<string, string> m_reqHeaders;
networker 0:7f26f0680202 86 map<string, string> m_respHeaders;
networker 0:7f26f0680202 87 string m_rootPath;
networker 0:7f26f0680202 88 string m_path;
networker 0:7f26f0680202 89 int m_errc; //Response code
networker 0:7f26f0680202 90
networker 0:7f26f0680202 91 Timeout m_watchdog;
networker 0:7f26f0680202 92 int m_timeout;
networker 0:7f26f0680202 93
networker 0:7f26f0680202 94 bool m_closed;
networker 0:7f26f0680202 95 bool m_headersSent;
networker 0:7f26f0680202 96
networker 0:7f26f0680202 97 int readLine(char* str, int maxLen);
networker 0:7f26f0680202 98
networker 0:7f26f0680202 99 };
networker 0:7f26f0680202 100
networker 0:7f26f0680202 101 #endif