Program the control the fischertechnik robo interface or intelligent interface via tcp socket or via a java gui.
ftserver.h@1:2c9d412ad471, 2011-05-04 (annotated)
- Committer:
- networker
- Date:
- Wed May 04 15:42:13 2011 +0000
- Revision:
- 1:2c9d412ad471
- Parent:
- 0:7f26f0680202
first publication (mbed challenge submission)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
networker | 0:7f26f0680202 | 1 | #ifndef FTSERVER_H |
networker | 0:7f26f0680202 | 2 | #define FTSERVER_H |
networker | 0:7f26f0680202 | 3 | #include <list> |
networker | 0:7f26f0680202 | 4 | using namespace std; |
networker | 1:2c9d412ad471 | 5 | |
networker | 0:7f26f0680202 | 6 | void handleMessage(char[7]); |
networker | 0:7f26f0680202 | 7 | class connection; |
networker | 0:7f26f0680202 | 8 | |
networker | 0:7f26f0680202 | 9 | class ftServer { |
networker | 0:7f26f0680202 | 10 | list<connection*> queue; |
networker | 0:7f26f0680202 | 11 | TCPSocket listeningSock; |
networker | 0:7f26f0680202 | 12 | TCPSocketErr err; |
networker | 0:7f26f0680202 | 13 | char msg[7]; |
networker | 0:7f26f0680202 | 14 | char *text; |
networker | 0:7f26f0680202 | 15 | char textlen, index; |
networker | 0:7f26f0680202 | 16 | bool isMsg; |
networker | 0:7f26f0680202 | 17 | protected: |
networker | 0:7f26f0680202 | 18 | void onTCPEvent(TCPSocketEvent ev); |
networker | 0:7f26f0680202 | 19 | char* render(); |
networker | 0:7f26f0680202 | 20 | public: |
networker | 0:7f26f0680202 | 21 | ftServer(IpAddr host, unsigned short port); |
networker | 0:7f26f0680202 | 22 | bool startServer(); |
networker | 0:7f26f0680202 | 23 | // void pollServer(); |
networker | 0:7f26f0680202 | 24 | void errorMsg(); |
networker | 0:7f26f0680202 | 25 | bool readStream(TCPSocket *pConnectedSock); |
networker | 0:7f26f0680202 | 26 | bool writeStream(char *); |
networker | 0:7f26f0680202 | 27 | bool writeStream(SMESSAGE*); |
networker | 0:7f26f0680202 | 28 | void remove(connection* c); |
networker | 0:7f26f0680202 | 29 | void handleMessage() { |
networker | 0:7f26f0680202 | 30 | ::handleMessage(msg); //change this to a function pointer |
networker | 0:7f26f0680202 | 31 | } |
networker | 0:7f26f0680202 | 32 | int clients() { return queue.size();} |
networker | 0:7f26f0680202 | 33 | }; |
networker | 0:7f26f0680202 | 34 | |
networker | 0:7f26f0680202 | 35 | class connection { |
networker | 0:7f26f0680202 | 36 | TCPSocket * pConnectedSock; |
networker | 0:7f26f0680202 | 37 | Host client; |
networker | 0:7f26f0680202 | 38 | ftServer *server; |
networker | 0:7f26f0680202 | 39 | void onConnectedTCPSocketEvent(TCPSocketEvent ev); |
networker | 0:7f26f0680202 | 40 | public: |
networker | 0:7f26f0680202 | 41 | connection(ftServer *svr, Host h, TCPSocket *s): server(svr), client(h), pConnectedSock(s) { |
networker | 0:7f26f0680202 | 42 | pConnectedSock->setOnEvent(this, &connection::onConnectedTCPSocketEvent); //Setup the new socket events |
networker | 0:7f26f0680202 | 43 | char str[80]; |
networker | 0:7f26f0680202 | 44 | sprintf(str, "Message from Server: Connection OK. Client nr %d", server->clients()); |
networker | 0:7f26f0680202 | 45 | writeStream(str); |
networker | 0:7f26f0680202 | 46 | //should also send the present state of the inputs, ne clean way to access the ft-interface |
networker | 0:7f26f0680202 | 47 | } |
networker | 0:7f26f0680202 | 48 | ~connection() { |
networker | 0:7f26f0680202 | 49 | pConnectedSock->close();//close and destroy the socket created by 'accept' |
networker | 0:7f26f0680202 | 50 | } |
networker | 0:7f26f0680202 | 51 | bool writeStream(char *); |
networker | 0:7f26f0680202 | 52 | bool writeStream(SMESSAGE*); |
networker | 0:7f26f0680202 | 53 | const TCPSocket* socket() const { |
networker | 0:7f26f0680202 | 54 | return pConnectedSock; |
networker | 0:7f26f0680202 | 55 | } |
networker | 0:7f26f0680202 | 56 | }; |
networker | 0:7f26f0680202 | 57 | |
networker | 0:7f26f0680202 | 58 | #endif |