From 4782e26bedf2e97817333334ec7876c3c272f7bc Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Tue, 13 Feb 2024 21:24:51 +0000 Subject: [PATCH] Device: Add isOnlineSupported() --- api/icsneoc/icsneoc.cpp | 9 +++++- api/icsneolegacy/icsneolegacy.cpp | 28 +++++++++++++++++-- include/icsneo/device/device.h | 2 ++ .../device/tree/radmoon2/radmoon2base.h | 2 ++ .../icsneo/device/tree/radmoon3/radmoon3.h | 2 ++ .../icsneo/device/tree/vividcan/vividcan.h | 2 ++ include/icsneo/icsneoc.h | 22 +++++++++++---- include/icsneo/icsneolegacy.h | 3 +- 8 files changed, 59 insertions(+), 11 deletions(-) diff --git a/api/icsneoc/icsneoc.cpp b/api/icsneoc/icsneoc.cpp index 5717750..a2b69f3 100644 --- a/api/icsneoc/icsneoc.cpp +++ b/api/icsneoc/icsneoc.cpp @@ -740,4 +740,11 @@ int icsneo_getDeviceStatus(const neodevice_t* device, void* status, size_t* size *size = rawMessage->data.size(); return true; -} \ No newline at end of file +} + +bool icsneo_isOnlineSupported(const neodevice_t* device) { + if(!icsneo_isValidNeoDevice(device)) + return false; + + return device->device->isOnlineSupported(); +} diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index e3d99ee..d36c63c 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -417,8 +417,19 @@ int LegacyDLLExport icsneoOpenNeoDevice(NeoDevice* pNeoDevice, void** hObject, u *hObject = device; if (!icsneo_openDevice(device)) return false; - - return icsneo_setPollingMessageLimit(device, 20000) && icsneo_enableMessagePolling(device) && icsneo_goOnline(device); + + if (icsneo_isOnlineSupported(device)) { + if (!icsneo_setPollingMessageLimit(device, 20000)) + return false; + + if (!icsneo_enableMessagePolling(device)) + return false; + + if (!icsneo_goOnline(device)) + return false; + } + + return true; } int LegacyDLLExport icsneoOpenDevice( @@ -447,7 +458,18 @@ int LegacyDLLExport icsneoOpenDevice( if(!icsneo_openDevice(device)) return false; - return icsneo_setPollingMessageLimit(device, 20000) && icsneo_enableMessagePolling(device) && icsneo_goOnline(device); + if (icsneo_isOnlineSupported(device)) { + if (!icsneo_setPollingMessageLimit(device, 20000)) + return false; + + if (!icsneo_enableMessagePolling(device)) + return false; + + if (!icsneo_goOnline(device)) + return false; + } + + return true; } int LegacyDLLExport icsneoClosePort(void* hObject, int* pNumberOfErrors) diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 64cff6c..2d80ee2 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -685,6 +685,8 @@ public: uint64_t pos, uint8_t* into, uint64_t amount, std::optional metadata = std::nullopt ); + virtual bool isOnlineSupported() const { return true; } + protected: bool online = false; int messagePollingCallbackID = 0; diff --git a/include/icsneo/device/tree/radmoon2/radmoon2base.h b/include/icsneo/device/tree/radmoon2/radmoon2base.h index 6488700..a7f8764 100644 --- a/include/icsneo/device/tree/radmoon2/radmoon2base.h +++ b/include/icsneo/device/tree/radmoon2/radmoon2base.h @@ -64,6 +64,8 @@ public: virtual uint8_t getPhyAddrOrPort() const = 0; + bool isOnlineSupported() const override { return false; } + protected: using Device::Device; diff --git a/include/icsneo/device/tree/radmoon3/radmoon3.h b/include/icsneo/device/tree/radmoon3/radmoon3.h index e56e3ad..225efe7 100644 --- a/include/icsneo/device/tree/radmoon3/radmoon3.h +++ b/include/icsneo/device/tree/radmoon3/radmoon3.h @@ -25,6 +25,8 @@ public: bool getEthPhyRegControlSupported() const override { return true; } + bool isOnlineSupported() const override { return false; } + protected: RADMoon3(neodevice_t neodevice, const driver_factory_t& makeDriver) : Device(neodevice) { initialize(makeDriver); diff --git a/include/icsneo/device/tree/vividcan/vividcan.h b/include/icsneo/device/tree/vividcan/vividcan.h index 7d1e50a..b155b31 100644 --- a/include/icsneo/device/tree/vividcan/vividcan.h +++ b/include/icsneo/device/tree/vividcan/vividcan.h @@ -27,6 +27,8 @@ public: return false; } + bool isOnlineSupported() const override { return false; } + protected: VividCAN(neodevice_t neodevice, const driver_factory_t& makeDriver) : Device(neodevice) { initialize(makeDriver); diff --git a/include/icsneo/icsneoc.h b/include/icsneo/icsneoc.h index 58da0f1..74ceaef 100644 --- a/include/icsneo/icsneoc.h +++ b/include/icsneo/icsneoc.h @@ -817,25 +817,33 @@ extern bool DLLExport icsneo_setTerminationFor(const neodevice_t* device, neonet * * This function populates the device status structures and sub members. */ -extern int icsneo_getDeviceStatus(const neodevice_t* device, void* status, size_t* size); +extern int DLLExport icsneo_getDeviceStatus(const neodevice_t* device, void* status, size_t* size); /** * \brief Get the real-time clock for the given device. - * \param[out] device A pointer to the neodevice_t structure specifying the device to read the RTC from. + * \param[in] device A pointer to the neodevice_t structure specifying the device to read the RTC from. * \param[out] output A pointer to a uint64_t where the RTC will be stored. This value is in seconds. * \returns True if the RTC was successfully retrieved. */ -extern bool icsneo_getRTC(const neodevice_t* device, uint64_t* output); +extern bool DLLExport icsneo_getRTC(const neodevice_t* device, uint64_t* output); /** * \brief Set the real-time clock for the given device. - * \param[out] device A pointer to the neodevice_t structure specifying the device to write the RTC to. + * \param[in] device A pointer to the neodevice_t structure specifying the device to write the RTC to. * \param[in] input A uint64_t object holding the RTC value. This value is in seconds. * \returns True if the RTC was successfully set. */ -extern bool icsneo_setRTC(const neodevice_t* device, uint64_t input); +extern bool DLLExport icsneo_setRTC(const neodevice_t* device, uint64_t input); + +/** + * \brief Check if the device supports the ability to go online + * \param[in] device A pointer to the neodevice_t structure specifying the device to operate on. + + * \returns True if the device supports the ability to go online +*/ +extern bool DLLExport icsneo_isOnlineSupported(const neodevice_t* device); #ifdef __cplusplus } // extern "C" @@ -1017,6 +1025,9 @@ fn_icsneo_getRTC icsneo_getRTC; typedef bool (*fn_icsneo_setRTC)(const neodevice_t* device, uint64_t input); fn_icsneo_setRTC icsneo_setRTC; +typedef bool(*fn_icsneo_isOnlineSupported)(const neodevice_t* device); +fn_icsneo_isOnlineSupported icsneo_isOnlineSupported; + #define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func) #define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3 void* icsneo_libraryHandle = NULL; @@ -1089,6 +1100,7 @@ int icsneo_init() { ICSNEO_IMPORTASSERT(icsneo_getDeviceStatus); ICSNEO_IMPORTASSERT(icsneo_getRTC); ICSNEO_IMPORTASSERT(icsneo_setRTC); + ICSNEO_IMPORTASSERT(icsneo_isOnlineSupported); icsneo_initialized = true; return 0; diff --git a/include/icsneo/icsneolegacy.h b/include/icsneo/icsneolegacy.h index e0cb8c3..973b7e2 100644 --- a/include/icsneo/icsneolegacy.h +++ b/include/icsneo/icsneolegacy.h @@ -24,10 +24,9 @@ extern "C" { extern int LegacyDLLExport icsneoFindDevices(NeoDeviceEx* pNeoDeviceEx, int* pNumDevices, unsigned int* DeviceTypes, unsigned int numDeviceTypes,POptionsFindNeoEx* pOptionsNeoEx, unsigned int* reserved); extern int LegacyDLLExport icsneoFindNeoDevices(unsigned long DeviceTypes, NeoDevice* pNeoDevice, int* pNumDevices); extern int LegacyDLLExport icsneoOpenNeoDevice(NeoDevice* pNeoDevice, void** hObject, unsigned char* bNetworkIDs, int bConfigRead, int bSyncToPC); -extern int LegacyDLLExport icsneoOpenDevice(NeoDeviceEx* pNeoDeviceEx, void** hObject, unsigned char* bNetworkIDs, int bConfigRead, int iOptions, OptionsOpenNeoEx* stOptionsOpenNeoEx, unsigned long reserved); +extern int LegacyDLLExport icsneoOpenDevice(NeoDeviceEx* pNeoDeviceEx, void** hObject, unsigned char* bNetworkIDs, int bConfigRead, int iOptions, OptionsOpenNeoEx* stOptionsOpenNeoEx, unsigned long reserved); extern int LegacyDLLExport icsneoClosePort(void* hObject, int* pNumberOfErrors); extern void LegacyDLLExport icsneoFreeObject(void* hObject); -extern int LegacyDLLExport icsneoOpenDevice(NeoDeviceEx* pNeoDeviceEx, void** hObject, unsigned char* bNetworkIDs, int bConfigRead, int iOptions, OptionsOpenNeoEx* stOptionsOpenNeoEx, unsigned long reserved); //Message Functions extern int LegacyDLLExport icsneoGetMessages(void* hObject, icsSpyMessage* pMsg, int* pNumberOfMessages, int* pNumberOfErrors);