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) {
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;
}

View File

@ -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;
}

View File

@ -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 <stdint.h>
typedef uint32_t devicetype_t;
#else
#include <ostream>
#include <cstdint>
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;
}