Skip to content

Commit 154ab16

Browse files
authored
Add configurable Arduino Serial (#6)
* Update Signed-off-by: Pablo Garrido <[email protected]> * Update Signed-off-by: Pablo Garrido <[email protected]> * Update Signed-off-by: Pablo Garrido <[email protected]>
1 parent 03033a8 commit 154ab16

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

ci/src/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
4242

4343
void setup() {
4444

45-
#if defined(MICRO_ROS_TRANSPORT_SERIAL)
46-
set_microros_serial_transports();
47-
#elif defined(MICRO_ROS_TRANSPORT_NATIVE_ETHERNET)
45+
#if defined(MICRO_ROS_TRANSPORT_ARDUINO_SERIAL)
46+
Serial.begin(115200);
47+
set_microros_serial_transports(Serial);
48+
#elif defined(MICRO_ROS_TRANSPORT_ARDUINO_NATIVE_ETHERNET)
4849
byte local_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF };
4950
IPAddress local_ip(192, 168, 1, 177);
5051
IPAddress agent_ip(192, 168, 1, 113);
5152
size_t agent_port = 8888;
5253

5354
set_microros_native_ethernet_transports(local_mac, local_ip, agent_ip, agent_port);
54-
#elif defined(MICRO_ROS_TRANSPORT_WIFI)
55+
#elif defined(MICRO_ROS_TRANSPORT_ARDUINO_WIFI)
5556
IPAddress agent_ip(192, 168, 1, 113);
5657
size_t agent_port = 8888;
5758

extra_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
env['_CPPDEFFLAGS'] += ' -I{}/platform_code/{}/{} '.format(main_path, framework, microros_transport)
107107

108108
# Add micro-ROS defines to user application
109-
global_env['_CPPDEFFLAGS'] += ' -DMICRO_ROS_TRANSPORT_{} '.format(microros_transport.upper())
109+
global_env['_CPPDEFFLAGS'] += ' -DMICRO_ROS_TRANSPORT_{}_{} '.format(framework.upper(), microros_transport.upper())
110110
global_env['_CPPDEFFLAGS'] += ' -DMICRO_ROS_DISTRO_ '.format(microros_distro.upper())
111111

112112
# Add platformio library for Arduino framework

platform_code/arduino/serial/micro_ros_transport.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,36 @@
33
#include <stdbool.h>
44
#include <sys/time.h>
55

6+
#include <uxr/client/profile/transport/custom/custom_transport.h>
7+
68
extern "C" {
79

810
bool platformio_transport_open(struct uxrCustomTransport * transport)
911
{
10-
Serial.begin(115200);
1112
return true;
1213
}
1314

1415
bool platformio_transport_close(struct uxrCustomTransport * transport)
1516
{
16-
Serial.end();
1717
return true;
1818
}
1919

2020
size_t platformio_transport_write(struct uxrCustomTransport * transport, uint8_t *buf, size_t len, uint8_t *errcode)
2121
{
2222
(void)errcode;
23-
size_t sent = Serial.write(buf, len);
23+
24+
Stream * stream = (Stream *) transport->args;
25+
size_t sent = stream->write(buf, len);
2426
return sent;
2527
}
2628

2729
size_t platformio_transport_read(struct uxrCustomTransport * transport, uint8_t *buf, size_t len, int timeout, uint8_t *errcode)
2830
{
2931
(void)errcode;
30-
Serial.setTimeout(timeout);
31-
return Serial.readBytes((char *)buf, len);
32+
33+
Stream * stream = (Stream *) transport->args;
34+
stream->setTimeout(timeout);
35+
return stream->readBytes((char *)buf, len);
3236
}
3337

3438
}

platform_code/arduino/serial/micro_ros_transport.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
static inline void set_microros_serial_transports(){
1+
#include <Stream.h>
2+
3+
static inline void set_microros_serial_transports(Stream & stream){
24
rmw_uros_set_custom_transport(
35
true,
4-
NULL,
6+
&stream,
57
platformio_transport_open,
68
platformio_transport_close,
79
platformio_transport_write,

0 commit comments

Comments
 (0)