Skip to content

Commit 7af5255

Browse files
committed
Fix compilation on API cores
Fixes #39
1 parent df69cda commit 7af5255

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/libmodbus/modbus-tcp.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# define SHUT_RDWR 2
2929
# define close closesocket
3030
#elif defined(ARDUINO)
31+
#include "Arduino.h"
3132
#ifndef DEBUG
3233
#define printf(...) {}
3334
#define fprintf(...) {}
@@ -738,7 +739,11 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
738739

739740

740741
#ifdef ARDUINO
742+
#ifdef __NEED_NAMESPACE__
743+
int modbus_tcp_accept(modbus_t *ctx, arduino::Client* client)
744+
#else
741745
int modbus_tcp_accept(modbus_t *ctx, Client* client)
746+
#endif
742747
#else
743748
int modbus_tcp_accept(modbus_t *ctx, int *s)
744749
#endif
@@ -913,7 +918,11 @@ const modbus_backend_t _modbus_tcp_pi_backend = {
913918
#endif
914919

915920
#ifdef ARDUINO
921+
#ifdef __NEED_NAMESPACE__
922+
modbus_t* modbus_new_tcp(arduino::Client* client, arduino::IPAddress ip_address, int port)
923+
#else
916924
modbus_t* modbus_new_tcp(Client* client, IPAddress ip_address, int port)
925+
#endif
917926
#else
918927
modbus_t* modbus_new_tcp(const char *ip, int port)
919928
#endif

src/libmodbus/modbus-tcp.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
// check if __has_include ArduinoAPI
1313
#if defined __has_include
1414
# if __has_include("api/ArduinoAPI.h")
15-
#define NEED_NAMESPACE
15+
#define __NEED_NAMESPACE__
1616
namespace arduino {
1717
# endif
1818
#endif
1919
class Client;
2020
class IPAddress;
2121
#endif
22+
#ifdef __NEED_NAMESPACE__
23+
}
24+
#endif
2225

2326
#include "modbus.h"
2427

@@ -53,9 +56,14 @@ MODBUS_BEGIN_DECLS
5356
#define MODBUS_TCP_MAX_ADU_LENGTH 260
5457

5558
#ifdef ARDUINO
59+
#ifdef __NEED_NAMESPACE__
60+
MODBUS_API modbus_t* modbus_new_tcp(arduino::Client* client, arduino::IPAddress ip_address, int port);
61+
MODBUS_API int modbus_tcp_accept(modbus_t *ctx, arduino::Client* client);
62+
#else
5663
MODBUS_API modbus_t* modbus_new_tcp(Client* client, IPAddress ip_address, int port);
57-
MODBUS_API int modbus_tcp_listen(modbus_t *ctx);
5864
MODBUS_API int modbus_tcp_accept(modbus_t *ctx, Client* client);
65+
#endif
66+
MODBUS_API int modbus_tcp_listen(modbus_t *ctx);
5967
#else
6068
MODBUS_API modbus_t* modbus_new_tcp(const char *ip_address, int port);
6169
MODBUS_API int modbus_tcp_listen(modbus_t *ctx, int nb_connection);
@@ -68,10 +76,4 @@ MODBUS_API int modbus_tcp_pi_accept(modbus_t *ctx, int *s);
6876

6977
MODBUS_END_DECLS
7078

71-
#ifdef NEED_NAMESPACE
72-
}
73-
#endif
74-
75-
#undef NEED_NAMESPACE
76-
7779
#endif /* MODBUS_TCP_H */

0 commit comments

Comments
 (0)