Skip to content

Commit 1ef344f

Browse files
committed
Fix compilation on ArduinoAPI cores
1 parent 5bf098b commit 1ef344f

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/libmodbus/modbus-rtu.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
* SPDX-License-Identifier: LGPL-2.1+
66
*/
77

8-
#include <stdio.h>
9-
#include <stdlib.h>
10-
#include <errno.h>
11-
#include <fcntl.h>
12-
#include <string.h>
13-
#ifndef _MSC_VER
14-
#include <unistd.h>
15-
#endif
16-
#include <assert.h>
17-
188
#ifdef ARDUINO
199
#include <ArduinoRS485.h>
2010

@@ -24,6 +14,16 @@
2414
#endif
2515
#endif
2616

17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
#include <errno.h>
20+
#include <fcntl.h>
21+
#include <string.h>
22+
#if !defined(_MSC_VER) && !defined(ARDUINO)
23+
#include <unistd.h>
24+
#endif
25+
#include <assert.h>
26+
2727
#include "modbus-private.h"
2828

2929
#include "modbus-rtu.h"

src/libmodbus/modbus-tcp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <stdlib.h>
1010
#include <string.h>
1111
#include <errno.h>
12-
#ifndef _MSC_VER
12+
#if !defined(_MSC_VER) && !defined(ARDUINO)
1313
#include <unistd.h>
1414
#endif
1515
#include <signal.h>

src/libmodbus/modbus-tcp.h

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
#define MODBUS_TCP_H
1010

1111
#ifdef ARDUINO
12+
// check if __has_include ArduinoAPI
13+
#if defined __has_include
14+
# if __has_include("api/ArduinoAPI.h")
15+
#define NEED_NAMESPACE
16+
namespace arduino {
17+
# endif
18+
#endif
1219
class Client;
1320
class IPAddress;
1421
#endif
@@ -61,4 +68,10 @@ MODBUS_API int modbus_tcp_pi_accept(modbus_t *ctx, int *s);
6168

6269
MODBUS_END_DECLS
6370

71+
#ifdef NEED_NAMESPACE
72+
}
73+
#endif
74+
75+
#undef NEED_NAMESPACE
76+
6477
#endif /* MODBUS_TCP_H */

0 commit comments

Comments
 (0)