ssssss
CushionSock.h@0:01a2e92d2924, 2016-12-17 (annotated)
- Committer:
- 3116redtrain
- Date:
- Sat Dec 17 09:13:37 2016 +0000
- Revision:
- 0:01a2e92d2924
- Child:
- 1:e6addce35f93
first issue
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
3116redtrain | 0:01a2e92d2924 | 1 | #ifndef CUSHION_SOCK_H |
3116redtrain | 0:01a2e92d2924 | 2 | #define CUSHION_SOCK_H |
3116redtrain | 0:01a2e92d2924 | 3 | |
3116redtrain | 0:01a2e92d2924 | 4 | #include "mbed.h" |
3116redtrain | 0:01a2e92d2924 | 5 | #include "Websocket.h" |
3116redtrain | 0:01a2e92d2924 | 6 | #include "EthernetNetIf.h" |
3116redtrain | 0:01a2e92d2924 | 7 | #include "picojson.h" |
3116redtrain | 0:01a2e92d2924 | 8 | #include "MbedJSONValue.h" |
3116redtrain | 0:01a2e92d2924 | 9 | |
3116redtrain | 0:01a2e92d2924 | 10 | |
3116redtrain | 0:01a2e92d2924 | 11 | class CushionSock |
3116redtrain | 0:01a2e92d2924 | 12 | { |
3116redtrain | 0:01a2e92d2924 | 13 | public: |
3116redtrain | 0:01a2e92d2924 | 14 | int MESS_STOP; |
3116redtrain | 0:01a2e92d2924 | 15 | int MESS_START; |
3116redtrain | 0:01a2e92d2924 | 16 | int MESS_SIT; |
3116redtrain | 0:01a2e92d2924 | 17 | int MESS_FRUST; |
3116redtrain | 0:01a2e92d2924 | 18 | int MESS_TEST; |
3116redtrain | 0:01a2e92d2924 | 19 | |
3116redtrain | 0:01a2e92d2924 | 20 | /* |
3116redtrain | 0:01a2e92d2924 | 21 | Constructor |
3116redtrain | 0:01a2e92d2924 | 22 | @param hostAndport format : "hostname:port" |
3116redtrain | 0:01a2e92d2924 | 23 | */ |
3116redtrain | 0:01a2e92d2924 | 24 | CushionSock(char * hostAndPort); |
3116redtrain | 0:01a2e92d2924 | 25 | |
3116redtrain | 0:01a2e92d2924 | 26 | /* |
3116redtrain | 0:01a2e92d2924 | 27 | connect to server |
3116redtrain | 0:01a2e92d2924 | 28 | @return true if the connection is established, false otherwise |
3116redtrain | 0:01a2e92d2924 | 29 | */ |
3116redtrain | 0:01a2e92d2924 | 30 | bool connect(); |
3116redtrain | 0:01a2e92d2924 | 31 | |
3116redtrain | 0:01a2e92d2924 | 32 | /* |
3116redtrain | 0:01a2e92d2924 | 33 | send message to server |
3116redtrain | 0:01a2e92d2924 | 34 | @return the number of bytes sent |
3116redtrain | 0:01a2e92d2924 | 35 | @param type Message type(prease show and choose from line 14 to 17 in souece code) |
3116redtrain | 0:01a2e92d2924 | 36 | @param msg message payload |
3116redtrain | 0:01a2e92d2924 | 37 | */ |
3116redtrain | 0:01a2e92d2924 | 38 | int mess_send(int type, char * msg); |
3116redtrain | 0:01a2e92d2924 | 39 | |
3116redtrain | 0:01a2e92d2924 | 40 | /* |
3116redtrain | 0:01a2e92d2924 | 41 | Recieve message from server |
3116redtrain | 0:01a2e92d2924 | 42 | @return if recieved succsessful, Message type(prease show and choose from line 14 to 17 in souece code), otherwise returns -1. |
3116redtrain | 0:01a2e92d2924 | 43 | @param msg pointer to the message to be read. |
3116redtrain | 0:01a2e92d2924 | 44 | */ |
3116redtrain | 0:01a2e92d2924 | 45 | int mess_recv(char * msg); |
3116redtrain | 0:01a2e92d2924 | 46 | |
3116redtrain | 0:01a2e92d2924 | 47 | /* |
3116redtrain | 0:01a2e92d2924 | 48 | To see if there is a SocketIO connection active |
3116redtrain | 0:01a2e92d2924 | 49 | @return true if there is a connection active |
3116redtrain | 0:01a2e92d2924 | 50 | */ |
3116redtrain | 0:01a2e92d2924 | 51 | bool is_connected(); |
3116redtrain | 0:01a2e92d2924 | 52 | |
3116redtrain | 0:01a2e92d2924 | 53 | bool close(); |
3116redtrain | 0:01a2e92d2924 | 54 | |
3116redtrain | 0:01a2e92d2924 | 55 | private: |
3116redtrain | 0:01a2e92d2924 | 56 | EthernetNetIf *eth; |
3116redtrain | 0:01a2e92d2924 | 57 | Websocket *ws; |
3116redtrain | 0:01a2e92d2924 | 58 | |
3116redtrain | 0:01a2e92d2924 | 59 | std::map<int,string> type_name; |
3116redtrain | 0:01a2e92d2924 | 60 | std::map<string,int> name_type; |
3116redtrain | 0:01a2e92d2924 | 61 | }; |
3116redtrain | 0:01a2e92d2924 | 62 | #endif |