[144] | 1 | /*
|
---|
| 2 | Copyright (C) 2015 Embedded and Real-Time Systems Laboratory
|
---|
| 3 | Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 4 |
|
---|
| 5 | This library is free software; you can redistribute it and/or
|
---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
---|
| 7 | License as published by the Free Software Foundation; either
|
---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 9 | This library is distributed in the hope that it will be useful,
|
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 12 | Lesser General Public License for more details.
|
---|
| 13 | You should have received a copy of the GNU Lesser General Public
|
---|
| 14 | License along with this library; if not, write to the Free Software
|
---|
| 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 16 | */
|
---|
| 17 |
|
---|
| 18 | #ifndef _CLIENT_ESP8366_H_
|
---|
| 19 | #define _CLIENT_ESP8366_H_
|
---|
[184] | 20 |
|
---|
[144] | 21 | #include "ESP8266.h"
|
---|
| 22 |
|
---|
| 23 | class ESP8266Client: public Client, public ESP8266 {
|
---|
| 24 | public:
|
---|
[180] | 25 | ESP8266Client(void) {
|
---|
| 26 | pbuffer = &rx_buffer[0];
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[144] | 29 | /*
|
---|
| 30 | * @retval 0 : faild
|
---|
| 31 | * @retval 1 : success
|
---|
| 32 | */
|
---|
| 33 | int connect(IPAddress ip, uint16_t port) {
|
---|
| 34 | String ip_str;
|
---|
[180] | 35 | ip_str.concat(ip[0]); ip_str.concat(".");
|
---|
| 36 | ip_str.concat(ip[1]); ip_str.concat(".");
|
---|
| 37 | ip_str.concat(ip[2]); ip_str.concat(".");
|
---|
[144] | 38 | ip_str.concat(ip[3]);
|
---|
[180] | 39 | return (createTCP(ip_str, port))? 1 : 0;
|
---|
[144] | 40 | };
|
---|
| 41 |
|
---|
| 42 | int connect(const char *host, uint16_t port) {
|
---|
| 43 | String ip_str(host);
|
---|
[180] | 44 | return (createTCP(ip_str, port))? 1 : 0;
|
---|
[144] | 45 | };
|
---|
| 46 |
|
---|
| 47 | size_t write(uint8_t data) {
|
---|
| 48 | if(send(&data, 1)){
|
---|
| 49 | return 1;
|
---|
[180] | 50 | }
|
---|
| 51 | return 0;
|
---|
[144] | 52 | };
|
---|
[180] | 53 |
|
---|
[144] | 54 | size_t write(const uint8_t *buf, size_t size){
|
---|
| 55 | if(send(buf, size)){
|
---|
| 56 | return size;
|
---|
| 57 | }
|
---|
[180] | 58 | return 0;
|
---|
[144] | 59 | };
|
---|
[180] | 60 |
|
---|
[169] | 61 | int available(){
|
---|
[180] | 62 | return isDataAvailable();
|
---|
[169] | 63 | };
|
---|
[180] | 64 |
|
---|
[144] | 65 | int read(){
|
---|
[180] | 66 | uint8_t data;
|
---|
| 67 | if(recv(&data, 1) == 1) {
|
---|
| 68 | return data;
|
---|
[144] | 69 | }
|
---|
[180] | 70 | return (int)-1;
|
---|
[144] | 71 | };
|
---|
[180] | 72 |
|
---|
| 73 | int read(uint8_t *buf, size_t size){
|
---|
| 74 | return recv(buf, size);
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | int peek(){
|
---|
| 78 | return pbuffer->peek();
|
---|
| 79 | };
|
---|
| 80 |
|
---|
[144] | 81 | void flush(){};
|
---|
| 82 | void stop(){releaseTCP();};
|
---|
[180] | 83 | uint8_t connected(){return (isConnected())? 1 : 0;};
|
---|
| 84 | operator bool(){return isConnected();};
|
---|
[144] | 85 | private:
|
---|
[180] | 86 | ESP8266_RingBuffer *pbuffer;
|
---|
[144] | 87 | };
|
---|
| 88 |
|
---|
| 89 | #endif /* _CLIENT_ESP8366_H_ */
|
---|