|
| 1 | +/* |
| 2 | + * Software License Agreement (BSD License) |
| 3 | + * |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions |
| 7 | + * are met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * * Redistributions in binary form must reproduce the above |
| 12 | + * copyright notice, this list of conditions and the following |
| 13 | + * disclaimer in the documentation and/or other materials provided |
| 14 | + * with the distribution. |
| 15 | + * * Neither the name of Willow Garage, Inc. nor the names of its |
| 16 | + * contributors may be used to endorse or promote prducts derived |
| 17 | + * from this software without specific prior written permission. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 22 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 23 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 25 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 26 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 27 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 29 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | + * POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | + |
| 33 | +#ifndef ESP32HARDWARE_H |
| 34 | +#define ESP32HARDWARE_H |
| 35 | + |
| 36 | +#include <WiFi.h> |
| 37 | + |
| 38 | +class Esp32Hardware { |
| 39 | + public: |
| 40 | + Esp32Hardware() |
| 41 | + { |
| 42 | + } |
| 43 | + |
| 44 | + void setConnection(IPAddress &server, int port) { |
| 45 | + this->server = server; |
| 46 | + this->serverPort = port; |
| 47 | + } |
| 48 | + |
| 49 | + IPAddress getLocalIP() { |
| 50 | + return tcp.localIP(); |
| 51 | + } |
| 52 | + |
| 53 | + void init() { |
| 54 | + this->tcp.connect(this->server, this->serverPort); |
| 55 | + } |
| 56 | + |
| 57 | + int read() { |
| 58 | + if (this->tcp.connected()) { |
| 59 | + return tcp.read(); |
| 60 | + } else { |
| 61 | + this->tcp.connect(this->server, this->serverPort); |
| 62 | + } |
| 63 | + return -1; |
| 64 | + }; |
| 65 | + |
| 66 | + void write(const uint8_t* data, size_t length) { |
| 67 | + tcp.write(data, length); |
| 68 | + } |
| 69 | + |
| 70 | + unsigned long time() {return millis();} |
| 71 | + |
| 72 | + protected: |
| 73 | + WiFiClient tcp; |
| 74 | + IPAddress server; |
| 75 | + uint16_t serverPort = 11411; |
| 76 | +}; |
| 77 | + |
| 78 | +#endif // ESP8266HARDWARE_H |
0 commit comments