The icsneolegacy API finds devices correctly now

pull/4/head
Paul Hollinsky 2018-09-27 13:34:16 -04:00
parent 06b7181492
commit 2b443ad83d
3 changed files with 13 additions and 11 deletions

View File

@ -55,13 +55,13 @@ void icsneo_freeUnconnectedDevices() {
bool icsneo_serialNumToString(uint32_t num, char* str, size_t* count) { bool icsneo_serialNumToString(uint32_t num, char* str, size_t* count) {
auto result = Device::SerialNumToString(num); 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 *count = result.length() + 1; // This is how big of a buffer we need
return false; return false;
} }
strncpy(str, result.c_str(), *count);
str[*count - 1] = '\0'; *count = result.copy(str, *count);
*count = result.length(); str[*count] = '\0';
return true; return true;
} }
@ -208,6 +208,6 @@ bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLeng
return false; return false;
*maxLength = device->device->getType().toString().copy(str, *maxLength); *maxLength = device->device->getType().toString().copy(str, *maxLength);
str[*maxLength + 1] = '\0'; str[*maxLength] = '\0';
return true; return true;
} }

View File

@ -6,11 +6,12 @@
static NeoDevice OldNeoDeviceFromNew(const neodevice_t* newnd) { static NeoDevice OldNeoDeviceFromNew(const neodevice_t* newnd) {
NeoDevice oldnd = { 0 }; NeoDevice oldnd = { 0 };
oldnd.DeviceType = newnd->type;
oldnd.SerialNumber = icsneo_serialStringToNum(newnd->serial); oldnd.SerialNumber = icsneo_serialStringToNum(newnd->serial);
oldnd.NumberOfClients = 0; oldnd.NumberOfClients = 0;
oldnd.MaxAllowedClients = 1; 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"); static_assert(sizeof(neodevice_handle_t) == sizeof(oldnd.Handle), "neodevice_handle_t size must be sizeof(int) for compatibility reasons");
*(neodevice_handle_t*)(&oldnd.Handle) = newnd->handle; oldnd.Handle = newnd->handle;
return oldnd; return oldnd;
} }

View File

@ -1,18 +1,19 @@
#ifndef __DEVICETYPE_H_ #ifndef __DEVICETYPE_H_
#define __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 // Hold the length of the longest name, so that C applications can allocate memory accordingly
// Currently the longest is "Intrepid Ethernet Evaluation Board" // 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 #define DEVICE_TYPE_LONGEST_NAME (35 + 1) // Add 1 so that if someone forgets, they still have space for null terminator
#ifndef __cplusplus #ifndef __cplusplus
#include <stdint.h> #include <stdint.h>
typedef uint32_t devicetype_t;
#else #else
#include <ostream> #include <ostream>
#include <cstdint> #include <cstdint>
typedef uint32_t devicetype_t;
namespace icsneo { namespace icsneo {
class DeviceType { class DeviceType {
@ -147,8 +148,8 @@ public:
DeviceType(DeviceType::Enum netid) { value = netid; } DeviceType(DeviceType::Enum netid) { value = netid; }
DeviceType::Enum getDeviceType() const { return value; } DeviceType::Enum getDeviceType() const { return value; }
std::string toString() const { return GetDeviceTypeString(getDeviceType()); } std::string toString() const { return GetDeviceTypeString(getDeviceType()); }
friend std::ostream& operator<<(std::ostream& os, const DeviceType& DeviceType) { friend std::ostream& operator<<(std::ostream& os, const DeviceType& type) {
os << DeviceType.toString(); os << type.toString().c_str();
return os; return os;
} }