diff --git a/AdsLib/AdsLib.h b/AdsLib/AdsLib.h index a9ecb732..43b1e536 100644 --- a/AdsLib/AdsLib.h +++ b/AdsLib/AdsLib.h @@ -13,6 +13,9 @@ #include "Sockets.h" +#ifdef BHF_ADS_EXPORT_C +extern "C" { +#endif /** * Reads data synchronously from an ADS server. * @param[in] port port number of an Ads port that had previously been opened with AdsPortOpenEx(). @@ -185,6 +188,10 @@ long GetRemoteAddress(const std::string &remote, AmsNetId &netId); } } -#define AdsAddRoute bhf::ads::AddLocalRoute -#define AdsDelRoute bhf::ads::DelLocalRoute -#define AdsSetLocalAddress bhf::ads::SetLocalAddress +long AdsAddRoute(AmsNetId netId, const char* ipAddr); +void AdsDelRoute(AmsNetId netId); +void AdsSetLocalAddress(AmsNetId netId); + +#ifdef BHF_ADS_EXPORT_C +} +#endif diff --git a/AdsLib/standalone/AdsDef.h b/AdsLib/standalone/AdsDef.h index 76507176..3c84b396 100644 --- a/AdsLib/standalone/AdsDef.h +++ b/AdsLib/standalone/AdsDef.h @@ -407,12 +407,24 @@ struct AdsNotificationAttrib { * @brief This structure is also passed to the callback function. */ struct AdsNotificationHeader { +/* Original TwinCAT SDK headers have + * uint32_t | uint64_t | uint32_t + * We use the same order when compiled as a shared library to allow + * consumers to dynamically link against us or the upstream TwinCAT. + */ +#ifdef BHF_ADS_USE_TWINCAT_ORDER + /** Handle for the notification. Is specified when the notification is defined. */ + uint32_t hNotification; + + /** Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). */ + uint64_t nTimeStamp; +#else /** Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). */ uint64_t nTimeStamp; /** Handle for the notification. Is specified when the notification is defined. */ uint32_t hNotification; - +#endif /** Number of bytes transferred. */ uint32_t cbSampleSize; }; diff --git a/AdsLib/standalone/AdsLib.cpp b/AdsLib/standalone/AdsLib.cpp index 6f80f4c9..0bb84d40 100644 --- a/AdsLib/standalone/AdsLib.cpp +++ b/AdsLib/standalone/AdsLib.cpp @@ -6,6 +6,9 @@ #include "AdsLib.h" #include "AmsRouter.h" +#ifdef BHF_ADS_EXPORT_C +extern "C" { +#endif static AmsRouter &GetRouter() { static AmsRouter router; @@ -286,3 +289,18 @@ long AdsSyncSetTimeoutEx(long port, uint32_t timeout) ASSERT_PORT(port); return GetRouter().SetTimeout((uint16_t)port, timeout); } + +long AdsAddRoute(AmsNetId netId, const char* ipAddr) { + return bhf::ads::AddLocalRoute(netId, ipAddr); +} + +void AdsDelRoute(AmsNetId netId) { + bhf::ads::DelLocalRoute(netId); +} + +void AdsSetLocalAddress(AmsNetId netId) { + bhf::ads::SetLocalAddress(netId); +} +#ifdef BHF_ADS_EXPORT_C +} +#endif diff --git a/AdsLib/standalone/AdsLib.h b/AdsLib/standalone/AdsLib.h index 76e8aa4e..1f05af9a 100644 --- a/AdsLib/standalone/AdsLib.h +++ b/AdsLib/standalone/AdsLib.h @@ -6,6 +6,9 @@ #include "AdsDef.h" +#ifdef BHF_ADS_EXPORT_C +extern "C" { +#endif /** * The connection (communication port) to the message router is * closed. The port to be closed must previously have been opened via @@ -38,3 +41,6 @@ long AdsGetLocalAddressEx(long port, AmsAddr *pAddr); * @return [ADS Return Code](https://infosys.beckhoff.com/content/1031/tcadscommon/html/ads_returncodes.htm?id=1666172286265530469) */ long AdsSyncSetTimeoutEx(long port, uint32_t timeout); +#ifdef BHF_ADS_EXPORT_C +} +#endif diff --git a/meson.build b/meson.build index d3677d84..e44f1897 100644 --- a/meson.build +++ b/meson.build @@ -95,7 +95,18 @@ adslib = static_library('AdsLib', install: true, ) -install_libs = [ adslib ] +adslib_so = shared_library('adslib', + [common_files, router_files], + cpp_args: [ + '-DBHF_ADS_EXPORT_C', + '-DBHF_ADS_USE_TWINCAT_ORDER', + ], + include_directories: inc, + install: true, + dependencies: libs, +) + +install_libs = [ adslib, adslib_so ] adslib_dep = declare_dependency( include_directories : inc,