From 2b443ad83d7d1ea57e6efbce945574dfde198a2f Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Thu, 27 Sep 2018 13:34:16 -0400 Subject: [PATCH] The icsneolegacy API finds devices correctly now --- api/icsneoc/icsneoc.cpp | 10 +++++----- api/icsneolegacy/icsneolegacy.cpp | 5 +++-- device/include/devicetype.h | 9 +++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/api/icsneoc/icsneoc.cpp b/api/icsneoc/icsneoc.cpp index fa7dd69..aa1ab2b 100644 --- a/api/icsneoc/icsneoc.cpp +++ b/api/icsneoc/icsneoc.cpp @@ -55,13 +55,13 @@ void icsneo_freeUnconnectedDevices() { bool icsneo_serialNumToString(uint32_t num, char* str, size_t* count) { auto result = Device::SerialNumToString(num); - if(*count <= result.length()) { + if(*count < result.length()) { *count = result.length() + 1; // This is how big of a buffer we need return false; } - strncpy(str, result.c_str(), *count); - str[*count - 1] = '\0'; - *count = result.length(); + + *count = result.copy(str, *count); + str[*count] = '\0'; return true; } @@ -208,6 +208,6 @@ bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLeng return false; *maxLength = device->device->getType().toString().copy(str, *maxLength); - str[*maxLength + 1] = '\0'; + str[*maxLength] = '\0'; return true; } \ No newline at end of file diff --git a/api/icsneolegacy/icsneolegacy.cpp b/api/icsneolegacy/icsneolegacy.cpp index e834746..e856a1a 100644 --- a/api/icsneolegacy/icsneolegacy.cpp +++ b/api/icsneolegacy/icsneolegacy.cpp @@ -6,11 +6,12 @@ static NeoDevice OldNeoDeviceFromNew(const neodevice_t* newnd) { NeoDevice oldnd = { 0 }; + oldnd.DeviceType = newnd->type; oldnd.SerialNumber = icsneo_serialStringToNum(newnd->serial); oldnd.NumberOfClients = 0; oldnd.MaxAllowedClients = 1; - static_assert(sizeof(neodevice_handle_t) <= sizeof(oldnd.Handle), "neodevice_handle_t size must be at least sizeof(int) for compatibility reasons"); - *(neodevice_handle_t*)(&oldnd.Handle) = newnd->handle; + static_assert(sizeof(neodevice_handle_t) == sizeof(oldnd.Handle), "neodevice_handle_t size must be sizeof(int) for compatibility reasons"); + oldnd.Handle = newnd->handle; return oldnd; } diff --git a/device/include/devicetype.h b/device/include/devicetype.h index 3faec14..6429a9d 100644 --- a/device/include/devicetype.h +++ b/device/include/devicetype.h @@ -1,18 +1,19 @@ #ifndef __DEVICETYPE_H_ #define __DEVICETYPE_H_ -typedef uint32_t devicetype_t; - // Hold the length of the longest name, so that C applications can allocate memory accordingly // Currently the longest is "Intrepid Ethernet Evaluation Board" #define DEVICE_TYPE_LONGEST_NAME (35 + 1) // Add 1 so that if someone forgets, they still have space for null terminator #ifndef __cplusplus #include +typedef uint32_t devicetype_t; #else #include #include +typedef uint32_t devicetype_t; + namespace icsneo { class DeviceType { @@ -147,8 +148,8 @@ public: DeviceType(DeviceType::Enum netid) { value = netid; } DeviceType::Enum getDeviceType() const { return value; } std::string toString() const { return GetDeviceTypeString(getDeviceType()); } - friend std::ostream& operator<<(std::ostream& os, const DeviceType& DeviceType) { - os << DeviceType.toString(); + friend std::ostream& operator<<(std::ostream& os, const DeviceType& type) { + os << type.toString().c_str(); return os; }