Skip to content

Commit 9ead2cf

Browse files
authored
Merge pull request #11 from fanhuafeng/master
Add Esp32 support
2 parents 94ff775 + 2f32e2a commit 9ead2cf

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

src/Esp32Hardware.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

src/ros.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737

3838
#include "ros/node_handle.h"
3939
#include "ArduinoHardware.h"
40-
#include <avr/pgmspace.h>
40+
//#include <avr/pgmspace.h>
4141
#if defined(ESP8266)
4242
#include "Esp8266Hardware.h"
4343
#endif
44+
#if defined(ESP32)
45+
#include "Esp32Hardware.h"
46+
#endif
4447
#if defined(MKR1000)
4548
#include "MKR1000Hardware.h"
4649
#endif

0 commit comments

Comments
 (0)