source: rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/Client_ESP8266.h@ 187

Last change on this file since 187 was 187, checked in by ertl-honda, 8 years ago

管理場所の変更

File size: 2.5 KB
Line 
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_
20
21#include "ESP8266.h"
22
23class ESP8266Client: public Client, public ESP8266 {
24 public:
25 ESP8266Client(void) {
26 pbuffer = &rx_buffer[0];
27 }
28
29 /*
30 * @retval 0 : faild
31 * @retval 1 : success
32 */
33 int connect(IPAddress ip, uint16_t port) {
34 String ip_str;
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(".");
38 ip_str.concat(ip[3]);
39 return (createTCP(ip_str, port))? 1 : 0;
40 };
41
42 int connect(const char *host, uint16_t port) {
43 String ip_str(host);
44 return (createTCP(ip_str, port))? 1 : 0;
45 };
46
47 size_t write(uint8_t data) {
48 if(send(&data, 1)){
49 return 1;
50 }
51 return 0;
52 };
53
54 size_t write(const uint8_t *buf, size_t size){
55 if(send(buf, size)){
56 return size;
57 }
58 return 0;
59 };
60
61 int available(){
62 return isDataAvailable();
63 };
64
65 int read(){
66 uint8_t data;
67 if(recv(&data, 1) == 1) {
68 return data;
69 }
70 return (int)-1;
71 };
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
81 void flush(){};
82 void stop(){releaseTCP();};
83 uint8_t connected(){return (isConnected())? 1 : 0;};
84 operator bool(){return isConnected();};
85 private:
86 ESP8266_RingBuffer *pbuffer;
87};
88
89#endif /* _CLIENT_ESP8366_H_ */
Note: See TracBrowser for help on using the repository browser.