From f907d6759f812c2881c4f74b7dfbf7a88b0d9a70 Mon Sep 17 00:00:00 2001 From: Joseph Niksa Date: Thu, 25 May 2023 16:42:38 +0000 Subject: [PATCH] icsneolegacy: implemented getDeviceStatus in C and legacy -Added missing DLL asserts for getRTC() and setRTC() in icsneoc.h --- api/icsneoc/icsneoc.cpp | 27 ++++++++++ api/icsneolegacy/icsneolegacy.cpp | 12 +++++ include/icsneo/icsnVC40.h | 86 +++++++++++++++++++++++++++++++ include/icsneo/icsneoc.h | 23 +++++++++ include/icsneo/icsneolegacy.h | 4 +- platform/windows/icsneolegacy.def | 2 +- 6 files changed, 152 insertions(+), 2 deletions(-) diff --git a/api/icsneoc/icsneoc.cpp b/api/icsneoc/icsneoc.cpp index 2ee9d3e..5717750 100644 --- a/api/icsneoc/icsneoc.cpp +++ b/api/icsneoc/icsneoc.cpp @@ -714,3 +714,30 @@ bool icsneo_setRTC(const neodevice_t* device, uint64_t input) const std::chrono::system_clock::time_point time(duration); return device->device->setRTC(time); } + +int icsneo_getDeviceStatus(const neodevice_t* device, void* status, size_t* size) { + if(!icsneo_isValidNeoDevice(device)) + return false; + + if(status == nullptr || size == nullptr) + return false; + + std::shared_ptr msg = device->device->com->waitForMessageSync([&]() { + return device->device->com->sendCommand(Command::RequestStatusUpdate); + }, std::make_shared(Network::NetID::DeviceStatus), std::chrono::milliseconds(100)); + + if(!msg) // Did not receive a message + return false; + + auto rawMessage = std::static_pointer_cast(msg); + if(!rawMessage || (rawMessage->network.getNetID() != Network::NetID::DeviceStatus)) + return false; + + if(*size < rawMessage->data.size()) + return false; + + std::copy(rawMessage->data.begin(), rawMessage->data.end(), static_cast(status)); + *size = rawMessage->data.size(); + + return true; +} \ No newline at end of file diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index 6e8dd48..31935e6 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -912,6 +912,18 @@ int LegacyDLLExport icsneoStopSockServer(void* hObject) return false; } +int LegacyDLLExport icsneoGetDeviceStatus(void* hObject, icsDeviceStatus* deviceStatus, size_t* deviceStatusSize) +{ + if (!icsneoValidateHObject(hObject)) + return false; + neodevice_t* device = reinterpret_cast(hObject); + + if (deviceStatus == nullptr || deviceStatusSize == nullptr) + return false; + + return icsneo_getDeviceStatus(device, deviceStatus, deviceStatusSize); +} + //CoreMini Script functions int LegacyDLLExport icsneoScriptStart(void* hObject, int iLocation) { diff --git a/include/icsneo/icsnVC40.h b/include/icsneo/icsnVC40.h index 0527753..16e28e7 100644 --- a/include/icsneo/icsnVC40.h +++ b/include/icsneo/icsnVC40.h @@ -2416,24 +2416,110 @@ typedef struct _icsSpyMessageVSB m.NetworkID2 = X >> 8; \ } while (0) +#define RADJUPITER_NUM_PORTS 8 + +#pragma pack(push) +#pragma pack(1) +typedef struct _ethernetNetworkStatus_t +{ + uint16_t networkId; + uint8_t linkStatus; + uint8_t linkFullDuplex; + uint8_t linkSpeed; // see ethLinkSpeed + uint8_t linkMode; // for automotive networks - see opEthLinkMode +} ethernetNetworkStatus_t; +#pragma pack(pop) + typedef struct { uint8_t backupPowerGood; uint8_t backupPowerEnabled; uint8_t usbHostPowerEnabled; uint8_t ethernetActivationLineEnabled; + ethernetNetworkStatus_t ethernetStatus; } icsFire2DeviceStatus; typedef struct { uint8_t ethernetActivationLineEnabled; + ethernetNetworkStatus_t ethernetStatus; + uint8_t unused; +} icsFire2VnetDeviceStatus; + +typedef struct +{ + uint8_t ethernetActivationLineEnabled; + ethernetNetworkStatus_t ethernetStatus; + uint8_t unused; } icsVcan4DeviceStatus; +typedef struct +{ + uint8_t ethernetActivationLineEnabled; + ethernetNetworkStatus_t ethernetStatus; + uint8_t unused; +} icsFlexVnetzDeviceStatus; + +typedef struct +{ + uint8_t ethernetActivationLineEnabled; + ethernetNetworkStatus_t ethernetStatus[3]; + uint8_t ethernetActivationLineEnabled_2; +} icsFire3DeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus[4]; +} icsRadMoonDuoDeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus[RADJUPITER_NUM_PORTS-1]; +} icsRadJupiterDeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus; +} icsOBD2ProDeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus[4]; +} icsRadPlutoDeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus; +} icsVcan4IndustrialDeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus; +} icsRadEpsilonDeviceStatus; + +typedef struct +{ + ethernetNetworkStatus_t ethernetStatus; +} icsRadBMSDeviceStatus; + +#pragma pack(push) +#pragma pack(4) + typedef union { icsFire2DeviceStatus fire2Status; icsVcan4DeviceStatus vcan4Status; + icsFlexVnetzDeviceStatus flexVnetzStatus; + icsFire3DeviceStatus fire3Status; + icsRadMoonDuoDeviceStatus radMoonDuoStatus; + icsRadJupiterDeviceStatus jupiterStatus; + icsOBD2ProDeviceStatus obd2proStatus; + icsRadPlutoDeviceStatus plutoStatus; + icsVcan4IndustrialDeviceStatus vcan4indStatus; + icsRadBMSDeviceStatus radBMSStatus; } icsDeviceStatus; +#pragma pack(pop) + typedef struct { int8_t szName[128]; //Adaptor name - ASCII Null terminated diff --git a/include/icsneo/icsneoc.h b/include/icsneo/icsneoc.h index b6ca1be..58da0f1 100644 --- a/include/icsneo/icsneoc.h +++ b/include/icsneo/icsneoc.h @@ -808,6 +808,17 @@ extern bool DLLExport icsneo_isTerminationEnabledFor(const neodevice_t* device, */ extern bool DLLExport icsneo_setTerminationFor(const neodevice_t* device, neonetid_t netid, bool enabled); +/** + * \brief Return the device status structures for a specified device. + * \param[in] device A pointer to the neodevice_t structure specifying the device to operate on. + * \param[in] status A pointer to a device status structure for the current device. + * \param[in] size The size of the current device status structure in bytes. + * \returns True if the device status was successfully read. + * + * This function populates the device status structures and sub members. + */ +extern int 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. @@ -997,6 +1008,15 @@ fn_icsneo_isTerminationEnabledFor icsneo_isTerminationEnabledFor; typedef bool(*fn_icsneo_setTerminationFor)(const neodevice_t* device, neonetid_t netid, bool enabled); fn_icsneo_setTerminationFor icsneo_setTerminationFor; +typedef int (*fn_icsneo_getDeviceStatus)(const neodevice_t* device, void* status, size_t* size); +fn_icsneo_getDeviceStatus icsneo_getDeviceStatus; + +typedef bool (*fn_icsneo_getRTC)(const neodevice_t* device, uint64_t* output); +fn_icsneo_getRTC icsneo_getRTC; + +typedef bool (*fn_icsneo_setRTC)(const neodevice_t* device, uint64_t input); +fn_icsneo_setRTC icsneo_setRTC; + #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; @@ -1066,6 +1086,9 @@ int icsneo_init() { ICSNEO_IMPORTASSERT(icsneo_canTerminationBeEnabledFor); ICSNEO_IMPORTASSERT(icsneo_isTerminationEnabledFor); ICSNEO_IMPORTASSERT(icsneo_setTerminationFor); + ICSNEO_IMPORTASSERT(icsneo_getDeviceStatus); + ICSNEO_IMPORTASSERT(icsneo_getRTC); + ICSNEO_IMPORTASSERT(icsneo_setRTC); icsneo_initialized = true; return 0; diff --git a/include/icsneo/icsneolegacy.h b/include/icsneo/icsneolegacy.h index c0650d7..7e29fa7 100644 --- a/include/icsneo/icsneolegacy.h +++ b/include/icsneo/icsneolegacy.h @@ -90,6 +90,8 @@ extern unsigned int LegacyDLLExport icsneoGetCANControllerClockFrequency(void* h extern int LegacyDLLExport icsneoSetCANParameters(void* hObject,unsigned int baudRatePrescaler,unsigned int propagationTqs,unsigned int phase1Tqs,unsigned int phase2Tqs,unsigned int syncJumpWidthTqs,unsigned int optionBits,int lNetworkID); extern int LegacyDLLExport icsneoSetCANParametersPhilipsSJA1000(void* hObject,unsigned int btr0,unsigned int btr1,unsigned int optionBits,int lNetworkID); +extern int LegacyDLLExport icsneoGetDeviceStatus(void* hObject, icsDeviceStatus* deviceStatus, size_t* deviceStatusSize); + //Remote Device Functions extern int LegacyDLLExport icsneoOpenRemoteNeoDevice(const char* pIPAddress,NeoDevice* pNeoDevice,void** hObject,unsigned char* bNetworkIDs,int iOptions); extern int LegacyDLLExport icsneoFindRemoteNeoDevices(const char* pIPAddress, NeoDevice* pNeoDevice, int* pNumDevices); @@ -131,7 +133,7 @@ extern int LegacyDLLExport icsneoScriptGetScriptStatus(void* hObject, int* piSta extern int LegacyDLLExport icsneoScriptReadAppSignal(void* hObject, unsigned int iIndex, double*dValue); extern int LegacyDLLExport icsneoScriptWriteAppSignal(void* hObject, unsigned int iIndex, double dValue); -//Deprecated (but still suppored in the DLL) +//Deprecated (but still supported in the DLL) extern int LegacyDLLExport icsneoOpenPortEx(void* lPortNumber, int lPortType, int lDriverType, int lIPAddressMSB, int lIPAddressLSBOrBaudRate, int bConfigRead, unsigned char* bNetworkID, int* hObject); extern int LegacyDLLExport icsneoOpenPort(int lPortNumber, int lPortType, int lDriverType, unsigned char* bNetworkID, unsigned char* bSCPIDs, int* hObject); extern int LegacyDLLExport icsneoFindAllCOMDevices(int lDriverType, int lGetSerialNumbers, int lStopAtFirst, int lUSBCommOnly, int* p_lDeviceTypes, int* p_lComPorts, int* p_lSerialNumbers, int*lNumDevices); diff --git a/platform/windows/icsneolegacy.def b/platform/windows/icsneolegacy.def index 2c99eff..4a7f183 100644 --- a/platform/windows/icsneolegacy.def +++ b/platform/windows/icsneolegacy.def @@ -185,7 +185,7 @@ EXPORTS ; icsneoSetVividCANSettings @ 197 ; icsneoFindNeoDevicesNewStyle @ 198 - ; icsneoGetDeviceStatus @ 202 + icsneoGetDeviceStatus @ 202 icsneoFindDevices @ 203 icsneoOpenDevice @ 204