Device describe
parent
419fc2fc73
commit
95dce1c429
|
|
@ -269,3 +269,12 @@ bool icsneo_transmitMessages(const neodevice_t* device, const neomessage_t* mess
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
@ -67,6 +67,12 @@ bool Device::SerialStringIsNumeric(const std::string& serial) {
|
|||
return isdigit(serial[0]) && isdigit(serial[1]);
|
||||
}
|
||||
|
||||
std::string Device::describe() const {
|
||||
std::stringstream ss;
|
||||
ss << getType() << ' ' << getSerial();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Device::enableMessagePolling() {
|
||||
if(messagePollingCallbackID != 0) // We are already polling
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ public:
|
|||
std::string getSerial() const { return data.serial; }
|
||||
uint32_t getSerialNumber() const { return Device::SerialStringToNum(getSerial()); }
|
||||
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 close();
|
||||
|
|
|
|||
|
|
@ -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_describeDevice(const neodevice_t* device, char* str, size_t* maxLength);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#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);
|
||||
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_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3
|
||||
void* icsneo_libraryHandle = NULL;
|
||||
|
|
@ -176,6 +181,7 @@ int icsneo_init() {
|
|||
ICSNEO_IMPORTASSERT(icsneo_setBaudrate);
|
||||
ICSNEO_IMPORTASSERT(icsneo_transmit);
|
||||
ICSNEO_IMPORTASSERT(icsneo_transmitMessages);
|
||||
ICSNEO_IMPORTASSERT(icsneo_describeDevice);
|
||||
|
||||
icsneo_initialized = true;
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue