Compare commits
5 Commits
fa1394f611
...
67b4f2c966
| Author | SHA1 | Date |
|---|---|---|
|
|
67b4f2c966 | |
|
|
bb711ae7e2 | |
|
|
476b5ff35c | |
|
|
99792a0ee1 | |
|
|
0c9f1c5f3e |
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
using namespace icsneo;
|
||||
|
||||
APIEvent::APIEvent(Type type, APIEvent::Severity severity, const Device* device) : eventStruct({}) {
|
||||
this->device = device;
|
||||
if(device) {
|
||||
serial = device->getSerial();
|
||||
APIEvent::APIEvent(Type type, APIEvent::Severity severity, std::weak_ptr<Device> device) : eventStruct({}), device(device) {
|
||||
auto shared = device.lock();
|
||||
if(shared) {
|
||||
serial = shared->getSerial();
|
||||
eventStruct.serial[serial.copy(eventStruct.serial, sizeof(eventStruct.serial))] = '\0';
|
||||
}
|
||||
|
||||
|
|
@ -27,9 +27,10 @@ void APIEvent::downgradeFromError() noexcept {
|
|||
}
|
||||
|
||||
bool APIEvent::isForDevice(std::string filterSerial) const noexcept {
|
||||
if(!device || filterSerial.length() == 0)
|
||||
auto shared = device.lock();
|
||||
if(!shared || filterSerial.length() == 0)
|
||||
return false;
|
||||
return device->getSerial() == filterSerial;
|
||||
return shared->getSerial() == filterSerial;
|
||||
}
|
||||
|
||||
// API Errors
|
||||
|
|
@ -467,8 +468,9 @@ const char* APIEvent::DescriptionForType(Type type) {
|
|||
|
||||
std::string APIEvent::describe() const noexcept {
|
||||
std::stringstream ss;
|
||||
if(device)
|
||||
ss << *device; // Makes use of device.describe()
|
||||
auto shared = device.lock();
|
||||
if(shared)
|
||||
ss << *shared; // Makes use of device.describe()
|
||||
else
|
||||
ss << "API";
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ bool Packetizer::input(RingBuffer& bytes) {
|
|||
* end of the payload. The short packet length, for reference, only encompasses the length of the actual
|
||||
* payload, and not the header or checksum.
|
||||
*/
|
||||
if(packetLength < 6 || packetLength > 4000) {
|
||||
if(packetLength < 6 || packetLength > std::numeric_limits<uint16_t>::max()) {
|
||||
bytes.pop_front();
|
||||
EventManager::GetInstance().add(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
||||
state = ReadState::SearchForHeader;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ typedef struct {
|
|||
#include <chrono>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
|
|
@ -185,19 +186,25 @@ public:
|
|||
Error = 0x30
|
||||
};
|
||||
|
||||
APIEvent() : eventStruct({}), serial(), timepoint(), device(nullptr) {}
|
||||
APIEvent(APIEvent::Type event, APIEvent::Severity severity, const Device* device = nullptr);
|
||||
APIEvent() : eventStruct({}), serial(), timepoint() {}
|
||||
APIEvent(APIEvent::Type event, APIEvent::Severity severity, std::weak_ptr<Device> device = {});
|
||||
|
||||
const neoevent_t* getNeoEvent() const noexcept { return &eventStruct; }
|
||||
Type getType() const noexcept { return Type(eventStruct.eventNumber); }
|
||||
Severity getSeverity() const noexcept { return Severity(eventStruct.severity); }
|
||||
std::string getDescription() const noexcept { return std::string(eventStruct.description); }
|
||||
const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide event
|
||||
const Device* getDevice() const noexcept { // Will return nullptr if this is an API-wide event
|
||||
auto shared = device.lock();
|
||||
return (shared) ? shared.get() : nullptr;
|
||||
}
|
||||
EventTimePoint getTimestamp() const noexcept { return timepoint; }
|
||||
|
||||
void downgradeFromError() noexcept;
|
||||
|
||||
bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; }
|
||||
bool isForDevice(const Device* forDevice) const noexcept {
|
||||
auto shared = device.lock();
|
||||
return shared && (shared.get() == forDevice);
|
||||
}
|
||||
bool isForDevice(std::string serial) const noexcept;
|
||||
|
||||
// As opposed to getDescription, this will also add text such as "neoVI FIRE 2 CY2468 Error: " to fully describe the problem
|
||||
|
|
@ -213,7 +220,7 @@ private:
|
|||
neoevent_t eventStruct;
|
||||
std::string serial;
|
||||
EventTimePoint timepoint;
|
||||
const Device* device;
|
||||
std::weak_ptr<Device> device;
|
||||
|
||||
void init(APIEvent::Type event, APIEvent::Severity);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public:
|
|||
APIEvent getLastError();
|
||||
|
||||
void add(APIEvent event);
|
||||
void add(APIEvent::Type type, APIEvent::Severity severity, const Device* forDevice = nullptr) {
|
||||
void add(APIEvent::Type type, APIEvent::Severity severity, std::weak_ptr<Device> forDevice = {}) {
|
||||
add(APIEvent(type, severity, forDevice));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class DeviceExtension;
|
|||
|
||||
typedef uint64_t MemoryAddress;
|
||||
|
||||
class Device {
|
||||
class Device : public std::enable_shared_from_this<Device> {
|
||||
public:
|
||||
virtual ~Device();
|
||||
|
||||
|
|
@ -930,7 +930,7 @@ protected:
|
|||
|
||||
virtual device_eventhandler_t makeEventHandler() {
|
||||
return [this](APIEvent::Type type, APIEvent::Severity severity) {
|
||||
EventManager::GetInstance().add(type, severity, this);
|
||||
EventManager::GetInstance().add(type, severity, weak_from_this());
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ public:
|
|||
Network::NetID::LIN_06,
|
||||
Network::NetID::LIN_07,
|
||||
Network::NetID::LIN_08,
|
||||
|
||||
Network::NetID::MDIO_01,
|
||||
};
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ public:
|
|||
Network::NetID::FLEXRAY_02,
|
||||
Network::NetID::FLEXRAY_02A,
|
||||
Network::NetID::FLEXRAY_02B,
|
||||
|
||||
Network::NetID::MDIO_01,
|
||||
};
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ public:
|
|||
Network::NetID::AE_06,
|
||||
Network::NetID::AE_07,
|
||||
Network::NetID::AE_08,
|
||||
|
||||
Network::NetID::MDIO_01,
|
||||
};
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ public:
|
|||
Network::NetID::ETHERNET_02,
|
||||
|
||||
Network::NetID::LIN_01,
|
||||
Network::NetID::LIN_02
|
||||
Network::NetID::LIN_02,
|
||||
|
||||
Network::NetID::MDIO_01,
|
||||
};
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,8 +108,9 @@ void CDCACM::Find(std::vector<FoundDevice>& found) {
|
|||
releasers.emplace_back(parent);
|
||||
current = parent;
|
||||
// On old macOSes, IOUSBDevice is the type of the class we want
|
||||
// On newer macOSes, IOUSBDevice may further be subclassed as IOUSBHostDevice
|
||||
if(IOObjectConformsTo(parent, kIOUSBDeviceClassName)) {
|
||||
// On macOS 12+, IOUSBHostDevice is the main USB device class (separate hierarchy from IOUSBDevice)
|
||||
if(IOObjectConformsTo(parent, kIOUSBDeviceClassName) ||
|
||||
IOObjectConformsTo(parent, "IOUSBHostDevice")) {
|
||||
usb = parent;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue