/* Copyright (C) 2015 Embedded and Real-Time Systems Laboratory Graduate School of Information Science, Nagoya Univ., JAPAN This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _CLIENT_ESP8366_H_ #define _CLIENT_ESP8366_H_ #include "Print.h" #include "Stream.h" #include "IPAddress.h" #include "ESP8266.h" class ESP8266Client: public Client, public ESP8266 { public: ESP8266Client(void) { pbuffer = &rx_buffer[0]; } /* * @retval 0 : faild * @retval 1 : success */ int connect(IPAddress ip, uint16_t port) { String ip_str; ip_str.concat(ip[0]); ip_str.concat("."); ip_str.concat(ip[1]); ip_str.concat("."); ip_str.concat(ip[2]); ip_str.concat("."); ip_str.concat(ip[3]); return (createTCP(ip_str, port))? 1 : 0; }; int connect(const char *host, uint16_t port) { String ip_str(host); return (createTCP(ip_str, port))? 1 : 0; }; size_t write(uint8_t data) { if(send(&data, 1)){ return 1; } return 0; }; size_t write(const uint8_t *buf, size_t size){ if(send(buf, size)){ return size; } return 0; }; int available(){ return isDataAvailable(); }; int read(){ uint8_t data; if(recv(&data, 1) == 1) { return data; } return (int)-1; }; int read(uint8_t *buf, size_t size){ return recv(buf, size); }; int peek(){ return pbuffer->peek(); }; void flush(){}; void stop(){releaseTCP();}; uint8_t connected(){return (isConnected())? 1 : 0;}; operator bool(){return isConnected();}; private: ESP8266_RingBuffer *pbuffer; }; #endif /* _CLIENT_ESP8366_H_ */