Device describe

pull/4/head
Paul Hollinsky 2018-10-24 12:51:04 -04:00
parent 419fc2fc73
commit 95dce1c429
4 changed files with 219 additions and 193 deletions

View File

@ -269,3 +269,12 @@ bool icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* mess
} }
return true; return true;
} }
bool icsneo_describeDevice(const neodevice_t* device, char* str, size_t* maxLength) {
if(!icsneo_isValidNeoDevice(device))
return false;
*maxLength = device->device->describe().copy(str, *maxLength);
str[*maxLength] = '\0';
return true;
}

View File

@ -67,6 +67,12 @@ bool Device::SerialStringIsNumeric(const std::string& serial) {
return isdigit(serial[0]) && isdigit(serial[1]); return isdigit(serial[0]) && isdigit(serial[1]);
} }
std::string Device::describe() const {
std::stringstream ss;
ss << getType() << ' ' << getSerial();
return ss.str();
}
void Device::enableMessagePolling() { void Device::enableMessagePolling() {
if(messagePollingCallbackID != 0) // We are already polling if(messagePollingCallbackID != 0) // We are already polling
return; return;

View File

@ -37,6 +37,11 @@ public:
std::string getSerial() const { return data.serial; } std::string getSerial() const { return data.serial; }
uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); } uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); }
const neodevice_t& getNeoDevice() const { return data; } const neodevice_t& getNeoDevice() const { return data; }
std::string describe() const;
friend std::ostream& operator<<(std::ostream& os, const Device& device) {
os << device.describe();
return os;
}
virtual bool open(); virtual bool open();
virtual bool close(); virtual bool close();

View File

@ -60,6 +60,8 @@ extern bool DLLExport icsneo_transmit(const neodevice_t* device, const neomessag
extern bool DLLExport icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* messages, size_t count); extern bool DLLExport icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* messages, size_t count);
extern bool DLLExport icsneo_describeDevice(const neodevice_t* device, char* str, size_t* maxLength);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
@ -138,6 +140,9 @@ fn_icsneo_transmit icsneo_transmit;
typedef bool(*fn_icsneo_transmitMessages)(const neodevice_t* device, const neomessage_t* messages, size_t count); typedef bool(*fn_icsneo_transmitMessages)(const neodevice_t* device, const neomessage_t* messages, size_t count);
fn_icsneo_transmitMessages icsneo_transmitMessages; fn_icsneo_transmitMessages icsneo_transmitMessages;
typedef bool(*fn_icsneo_describeDevice)(const neodevice_t* device, char* str, size_t* maxLength);
fn_icsneo_describeDevice icsneo_describeDevice;
#define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func) #define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func)
#define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3 #define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3
void* icsneo_libraryHandle = NULL; void* icsneo_libraryHandle = NULL;
@ -176,6 +181,7 @@ int icsneo_init() {
ICSNEO_IMPORTASSERT(icsneo_setBaudrate); ICSNEO_IMPORTASSERT(icsneo_setBaudrate);
ICSNEO_IMPORTASSERT(icsneo_transmit); ICSNEO_IMPORTASSERT(icsneo_transmit);
ICSNEO_IMPORTASSERT(icsneo_transmitMessages); ICSNEO_IMPORTASSERT(icsneo_transmitMessages);
ICSNEO_IMPORTASSERT(icsneo_describeDevice);
icsneo_initialized = true; icsneo_initialized = true;
return 0; return 0;