Finished adding error checking
parent
255e1e2b90
commit
b7288edd9a
|
|
@ -87,6 +87,11 @@ uint32_t icsneo_serialStringToNum(const char* str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_isValidNeoDevice(const neodevice_t* device) {
|
bool icsneo_isValidNeoDevice(const neodevice_t* device) {
|
||||||
|
// return false on nullptr
|
||||||
|
if(!device) {
|
||||||
|
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// If this neodevice_t was returned by a previous search, it will no longer be valid (as the underlying icsneo::Device is freed)
|
// If this neodevice_t was returned by a previous search, it will no longer be valid (as the underlying icsneo::Device is freed)
|
||||||
for(auto& dev : connectedDevices) {
|
for(auto& dev : connectedDevices) {
|
||||||
if(dev.get() == device->device)
|
if(dev.get() == device->device)
|
||||||
|
|
@ -96,14 +101,14 @@ bool icsneo_isValidNeoDevice(const neodevice_t* device) {
|
||||||
if(dev.get() == device->device)
|
if(dev.get() == device->device)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_openDevice(const neodevice_t* device) {
|
bool icsneo_openDevice(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(!device->device->open())
|
if(!device->device->open())
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -123,10 +128,8 @@ bool icsneo_openDevice(const neodevice_t* device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_closeDevice(const neodevice_t* device) {
|
bool icsneo_closeDevice(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(!device->device->close())
|
if(!device->device->close())
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -144,65 +147,51 @@ bool icsneo_closeDevice(const neodevice_t* device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_isOpen(const neodevice_t* device) {
|
bool icsneo_isOpen(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->isOpen();
|
return device->device->isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_goOnline(const neodevice_t* device) {
|
bool icsneo_goOnline(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->goOnline();
|
return device->device->goOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_goOffline(const neodevice_t* device) {
|
bool icsneo_goOffline(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->goOffline();
|
return device->device->goOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_isOnline(const neodevice_t* device) {
|
bool icsneo_isOnline(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->isOnline();
|
return device->device->isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_enableMessagePolling(const neodevice_t* device) {
|
bool icsneo_enableMessagePolling(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
device->device->enableMessagePolling();
|
device->device->enableMessagePolling();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_disableMessagePolling(const neodevice_t* device) {
|
bool icsneo_disableMessagePolling(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->disableMessagePolling();
|
return device->device->disableMessagePolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_getMessages(const neodevice_t* device, neomessage_t* messages, size_t* items, uint64_t timeout) {
|
bool icsneo_getMessages(const neodevice_t* device, neomessage_t* messages, size_t* items, uint64_t timeout) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(items == nullptr) {
|
if(items == nullptr) {
|
||||||
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
||||||
|
|
@ -233,19 +222,15 @@ bool icsneo_getMessages(const neodevice_t* device, neomessage_t* messages, size_
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t icsneo_getPollingMessageLimit(const neodevice_t* device) {
|
size_t icsneo_getPollingMessageLimit(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->getPollingMessageLimit();
|
return device->device->getPollingMessageLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_setPollingMessageLimit(const neodevice_t* device, size_t newLimit) {
|
bool icsneo_setPollingMessageLimit(const neodevice_t* device, size_t newLimit) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
device->device->setPollingMessageLimit(newLimit);
|
device->device->setPollingMessageLimit(newLimit);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -258,10 +243,8 @@ bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLeng
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
std::string output = device->device->getType().toString();
|
std::string output = device->device->getType().toString();
|
||||||
|
|
||||||
|
|
@ -303,55 +286,43 @@ bool icsneo_getProductNameForType(devicetype_t type, char* str, size_t* maxLengt
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_settingsRefresh(const neodevice_t* device) {
|
bool icsneo_settingsRefresh(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->refresh();
|
return device->device->settings->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_settingsApply(const neodevice_t* device) {
|
bool icsneo_settingsApply(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->apply();
|
return device->device->settings->apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_settingsApplyTemporary(const neodevice_t* device) {
|
bool icsneo_settingsApplyTemporary(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->apply(true);
|
return device->device->settings->apply(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_settingsApplyDefaults(const neodevice_t* device) {
|
bool icsneo_settingsApplyDefaults(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->applyDefaults();
|
return device->device->settings->applyDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_settingsApplyDefaultsTemporary(const neodevice_t* device) {
|
bool icsneo_settingsApplyDefaultsTemporary(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->applyDefaults(true);
|
return device->device->settings->applyDefaults(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t icsneo_settingsReadStructure(const neodevice_t* device, void* structure, size_t structureSize) {
|
size_t icsneo_settingsReadStructure(const neodevice_t* device, void* structure, size_t structureSize) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
size_t readSize = device->device->settings->getSize();
|
size_t readSize = device->device->settings->getSize();
|
||||||
if(structure == nullptr) // Structure size request
|
if(structure == nullptr) // Structure size request
|
||||||
|
|
@ -379,10 +350,8 @@ size_t icsneo_settingsReadStructure(const neodevice_t* device, void* structure,
|
||||||
|
|
||||||
// Not exported
|
// Not exported
|
||||||
static bool icsneo_settingsWriteStructure(const neodevice_t* device, const void* structure, size_t structureSize) {
|
static bool icsneo_settingsWriteStructure(const neodevice_t* device, const void* structure, size_t structureSize) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(structure == nullptr) {
|
if(structure == nullptr) {
|
||||||
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
||||||
|
|
@ -418,46 +387,36 @@ bool icsneo_settingsApplyStructureTemporary(const neodevice_t* device, const voi
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t icsneo_getBaudrate(const neodevice_t* device, uint16_t netid) {
|
int64_t icsneo_getBaudrate(const neodevice_t* device, uint16_t netid) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->getBaudrateFor(netid);
|
return device->device->settings->getBaudrateFor(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_setBaudrate(const neodevice_t* device, uint16_t netid, int64_t newBaudrate) {
|
bool icsneo_setBaudrate(const neodevice_t* device, uint16_t netid, int64_t newBaudrate) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->setBaudrateFor(netid, newBaudrate);
|
return device->device->settings->setBaudrateFor(netid, newBaudrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t icsneo_getFDBaudrate(const neodevice_t* device, uint16_t netid) {
|
int64_t icsneo_getFDBaudrate(const neodevice_t* device, uint16_t netid) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->getFDBaudrateFor(netid);
|
return device->device->settings->getFDBaudrateFor(netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_setFDBaudrate(const neodevice_t* device, uint16_t netid, int64_t newBaudrate) {
|
bool icsneo_setFDBaudrate(const neodevice_t* device, uint16_t netid, int64_t newBaudrate) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->settings->setFDBaudrateFor(netid, newBaudrate);
|
return device->device->settings->setFDBaudrateFor(netid, newBaudrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_transmit(const neodevice_t* device, const neomessage_t* message) {
|
bool icsneo_transmit(const neodevice_t* device, const neomessage_t* message) {
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return device->device->transmit(CreateMessageFromNeoMessage(message));
|
return device->device->transmit(CreateMessageFromNeoMessage(message));
|
||||||
}
|
}
|
||||||
|
|
@ -479,10 +438,8 @@ bool icsneo_describeDevice(const neodevice_t* device, char* str, size_t* maxLeng
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
std::string output = device->device->describe();
|
std::string output = device->device->describe();
|
||||||
|
|
||||||
|
|
@ -519,10 +476,8 @@ bool icsneo_getErrors(neoerror_t* errors, size_t* size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_getDeviceErrors(const neodevice_t* device, neoerror_t* errors, size_t* size) {
|
bool icsneo_getDeviceErrors(const neodevice_t* device, neoerror_t* errors, size_t* size) {
|
||||||
if(device != nullptr && !icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(size == nullptr) {
|
if(size == nullptr) {
|
||||||
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
||||||
|
|
@ -563,10 +518,8 @@ void icsneo_discardAllErrors(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void icsneo_discardDeviceErrors(const neodevice_t* device) {
|
void icsneo_discardDeviceErrors(const neodevice_t* device) {
|
||||||
if(device != nullptr && !icsneo_isValidNeoDevice(device)) {
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if(device == nullptr)
|
if(device == nullptr)
|
||||||
icsneo::DiscardErrors(nullptr); // Discard errors not associated with a device
|
icsneo::DiscardErrors(nullptr); // Discard errors not associated with a device
|
||||||
|
|
@ -608,14 +561,11 @@ bool icsneo_getSupportedDevices(devicetype_t* devices, size_t* count) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool DLLExport icsneo_getTimestampResolution(const neodevice_t* device, uint16_t* resolution)
|
extern bool DLLExport icsneo_getTimestampResolution(const neodevice_t* device, uint16_t* resolution) {
|
||||||
{
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
if (!icsneo_isValidNeoDevice(device)) {
|
|
||||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (resolution == nullptr) {
|
if(resolution == nullptr) {
|
||||||
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ static constexpr const char* ERROR_PACKET_CHECKSUM_ERROR = "There was a checksum
|
||||||
static constexpr const char* ERROR_TRANSMIT_BUFFER_FULL = "The transmit buffer is full and the device is set to non-blocking.";
|
static constexpr const char* ERROR_TRANSMIT_BUFFER_FULL = "The transmit buffer is full and the device is set to non-blocking.";
|
||||||
static constexpr const char* ERROR_PCAP_COULD_NOT_START = "The PCAP driver could not be started. Ethernet devices will not be found.";
|
static constexpr const char* ERROR_PCAP_COULD_NOT_START = "The PCAP driver could not be started. Ethernet devices will not be found.";
|
||||||
static constexpr const char* ERROR_PCAP_COULD_NOT_FIND_DEVICES = "The PCAP driver failed to find devices. Ethernet devices will not be found.";
|
static constexpr const char* ERROR_PCAP_COULD_NOT_FIND_DEVICES = "The PCAP driver failed to find devices. Ethernet devices will not be found.";
|
||||||
|
static constexpr const char* ERROR_PACKET_DECODING = "The packet could not be decoded.";
|
||||||
|
|
||||||
static constexpr const char* ERROR_TOO_MANY_ERRORS = "Too many errors have occurred. The list has been truncated.";
|
static constexpr const char* ERROR_TOO_MANY_ERRORS = "Too many errors have occurred. The list has been truncated.";
|
||||||
static constexpr const char* ERROR_UNKNOWN = "An unknown internal error occurred.";
|
static constexpr const char* ERROR_UNKNOWN = "An unknown internal error occurred.";
|
||||||
|
|
@ -183,6 +184,8 @@ const char* APIError::DescriptionForType(ErrorType type) {
|
||||||
return ERROR_PCAP_COULD_NOT_START;
|
return ERROR_PCAP_COULD_NOT_START;
|
||||||
case PCAPCouldNotFindDevices:
|
case PCAPCouldNotFindDevices:
|
||||||
return ERROR_PCAP_COULD_NOT_FIND_DEVICES;
|
return ERROR_PCAP_COULD_NOT_FIND_DEVICES;
|
||||||
|
case PacketDecodingError:
|
||||||
|
return ERROR_PACKET_DECODING;
|
||||||
|
|
||||||
// Other Errors
|
// Other Errors
|
||||||
case TooManyErrors:
|
case TooManyErrors:
|
||||||
|
|
@ -248,6 +251,7 @@ APIError::Severity APIError::SeverityForType(ErrorType type) {
|
||||||
case DriverFailedToClose:
|
case DriverFailedToClose:
|
||||||
case PacketChecksumError:
|
case PacketChecksumError:
|
||||||
case TransmitBufferFull:
|
case TransmitBufferFull:
|
||||||
|
case PacketDecodingError:
|
||||||
// Other Errors
|
// Other Errors
|
||||||
case TooManyErrors:
|
case TooManyErrors:
|
||||||
case Unknown:
|
case Unknown:
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,10 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||||
switch(packet->network.getType()) {
|
switch(packet->network.getType()) {
|
||||||
case Network::Type::Ethernet:
|
case Network::Type::Ethernet:
|
||||||
result = HardwareEthernetPacket::DecodeToMessage(packet->data);
|
result = HardwareEthernetPacket::DecodeToMessage(packet->data);
|
||||||
if(!result)
|
if(!result) {
|
||||||
|
err(APIError::PacketDecodingError);
|
||||||
return false; // A nullptr was returned, the packet was not long enough to decode
|
return false; // A nullptr was returned, the packet was not long enough to decode
|
||||||
|
}
|
||||||
|
|
||||||
// Timestamps are in (resolution) ns increments since 1/1/2007 GMT 00:00:00.0000
|
// Timestamps are in (resolution) ns increments since 1/1/2007 GMT 00:00:00.0000
|
||||||
// The resolution depends on the device
|
// The resolution depends on the device
|
||||||
|
|
@ -33,13 +35,16 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||||
case Network::Type::CAN:
|
case Network::Type::CAN:
|
||||||
case Network::Type::SWCAN:
|
case Network::Type::SWCAN:
|
||||||
case Network::Type::LSFTCAN: {
|
case Network::Type::LSFTCAN: {
|
||||||
if(packet->data.size() < 24)
|
if(packet->data.size() < 24) {
|
||||||
|
err(APIError::PacketDecodingError);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
result = HardwareCANPacket::DecodeToMessage(packet->data);
|
result = HardwareCANPacket::DecodeToMessage(packet->data);
|
||||||
if(!result)
|
if(!result) {
|
||||||
|
err(APIError::PacketDecodingError);
|
||||||
return false; // A nullptr was returned, the packet was malformed
|
return false; // A nullptr was returned, the packet was malformed
|
||||||
|
}
|
||||||
// Timestamps are in (resolution) ns increments since 1/1/2007 GMT 00:00:00.0000
|
// Timestamps are in (resolution) ns increments since 1/1/2007 GMT 00:00:00.0000
|
||||||
// The resolution depends on the device
|
// The resolution depends on the device
|
||||||
result->timestamp *= timestampResolution;
|
result->timestamp *= timestampResolution;
|
||||||
|
|
@ -49,8 +54,10 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||||
case Network::Type::Internal: {
|
case Network::Type::Internal: {
|
||||||
switch(packet->network.getNetID()) {
|
switch(packet->network.getNetID()) {
|
||||||
case Network::NetID::Reset_Status: {
|
case Network::NetID::Reset_Status: {
|
||||||
if(packet->data.size() < sizeof(HardwareResetStatusPacket))
|
if(packet->data.size() < sizeof(HardwareResetStatusPacket)) {
|
||||||
|
err(APIError::PacketDecodingError);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
HardwareResetStatusPacket* data = (HardwareResetStatusPacket*)packet->data.data();
|
HardwareResetStatusPacket* data = (HardwareResetStatusPacket*)packet->data.data();
|
||||||
auto msg = std::make_shared<ResetStatusMessage>();
|
auto msg = std::make_shared<ResetStatusMessage>();
|
||||||
|
|
@ -111,7 +118,7 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||||
/* So-called "old format" messages are a "new style, long format" wrapper around the old short messages.
|
/* So-called "old format" messages are a "new style, long format" wrapper around the old short messages.
|
||||||
* They consist of a 16-bit LE length first, then the 8-bit length and netid combo byte, then the payload
|
* They consist of a 16-bit LE length first, then the 8-bit length and netid combo byte, then the payload
|
||||||
* with no checksum. The upper-nibble length of the combo byte should be ignored completely, using the
|
* with no checksum. The upper-nibble length of the combo byte should be ignored completely, using the
|
||||||
* length from the first two bytes in it's place. Ideally, we never actually send the oldformat messages
|
* length from the first two bytes in its place. Ideally, we never actually send the oldformat messages
|
||||||
* out to the rest of the application as they can recursively get decoded to another message type here.
|
* out to the rest of the application as they can recursively get decoded to another message type here.
|
||||||
* Feed the result back into the decoder in case we do something special with the resultant netid.
|
* Feed the result back into the decoder in case we do something special with the resultant netid.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,10 @@ bool ICommunication::readWait(std::vector<uint8_t>& bytes, std::chrono::millisec
|
||||||
|
|
||||||
bytes.resize(actuallyRead);
|
bytes.resize(actuallyRead);
|
||||||
|
|
||||||
return actuallyRead > 0;
|
bool ret = actuallyRead > 0;
|
||||||
|
if(!ret)
|
||||||
|
err(APIError::FailedToRead);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ICommunication::write(const std::vector<uint8_t>& bytes) {
|
bool ICommunication::write(const std::vector<uint8_t>& bytes) {
|
||||||
|
|
@ -46,9 +49,8 @@ bool ICommunication::write(const std::vector<uint8_t>& bytes) {
|
||||||
|
|
||||||
if(writeBlocks) {
|
if(writeBlocks) {
|
||||||
std::unique_lock<std::mutex> lk(writeMutex);
|
std::unique_lock<std::mutex> lk(writeMutex);
|
||||||
if(writeQueue.size_approx() > writeQueueSize) {
|
if(writeQueue.size_approx() > writeQueueSize)
|
||||||
writeCV.wait(lk);
|
writeCV.wait(lk);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if(writeQueue.size_approx() > writeQueueSize) {
|
if(writeQueue.size_approx() > writeQueueSize) {
|
||||||
err(APIError::TransmitBufferFull);
|
err(APIError::TransmitBufferFull);
|
||||||
|
|
@ -57,8 +59,8 @@ bool ICommunication::write(const std::vector<uint8_t>& bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = writeQueue.enqueue(WriteOperation(bytes));
|
bool ret = writeQueue.enqueue(WriteOperation(bytes));
|
||||||
if(!ret) {
|
if(!ret)
|
||||||
err(APIError::Unknown);
|
err(APIError::Unknown);
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +204,9 @@ bool Device::close() {
|
||||||
|
|
||||||
internalHandlerCallbackID = 0;
|
internalHandlerCallbackID = 0;
|
||||||
|
|
||||||
goOffline();
|
if(isOnline())
|
||||||
|
goOffline();
|
||||||
|
|
||||||
return com->close();
|
return com->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ public:
|
||||||
TransmitBufferFull = 0x3005,
|
TransmitBufferFull = 0x3005,
|
||||||
PCAPCouldNotStart = 0x3102,
|
PCAPCouldNotStart = 0x3102,
|
||||||
PCAPCouldNotFindDevices = 0x3103,
|
PCAPCouldNotFindDevices = 0x3103,
|
||||||
|
PacketDecodingError = 0x3104,
|
||||||
|
|
||||||
TooManyErrors = 0xFFFFFFFE,
|
TooManyErrors = 0xFFFFFFFE,
|
||||||
Unknown = 0xFFFFFFFF
|
Unknown = 0xFFFFFFFF
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue