Compare commits

..

1 Commits

Author SHA1 Message Date
Gowtham Nanjukutty fa1394f611
Merge 0c9f1c5f3e into d42c51d772 2026-05-26 10:02:34 -04:00
9 changed files with 18 additions and 35 deletions

View File

@ -4,10 +4,10 @@
using namespace icsneo; using namespace icsneo;
APIEvent::APIEvent(Type type, APIEvent::Severity severity, std::weak_ptr<Device> device) : eventStruct({}), device(device) { APIEvent::APIEvent(Type type, APIEvent::Severity severity, const Device* device) : eventStruct({}) {
auto shared = device.lock(); this->device = device;
if(shared) { if(device) {
serial = shared->getSerial(); serial = device->getSerial();
eventStruct.serial[serial.copy(eventStruct.serial, sizeof(eventStruct.serial))] = '\0'; eventStruct.serial[serial.copy(eventStruct.serial, sizeof(eventStruct.serial))] = '\0';
} }
@ -27,10 +27,9 @@ void APIEvent::downgradeFromError() noexcept {
} }
bool APIEvent::isForDevice(std::string filterSerial) const noexcept { bool APIEvent::isForDevice(std::string filterSerial) const noexcept {
auto shared = device.lock(); if(!device || filterSerial.length() == 0)
if(!shared || filterSerial.length() == 0)
return false; return false;
return shared->getSerial() == filterSerial; return device->getSerial() == filterSerial;
} }
// API Errors // API Errors
@ -468,9 +467,8 @@ const char* APIEvent::DescriptionForType(Type type) {
std::string APIEvent::describe() const noexcept { std::string APIEvent::describe() const noexcept {
std::stringstream ss; std::stringstream ss;
auto shared = device.lock(); if(device)
if(shared) ss << *device; // Makes use of device.describe()
ss << *shared; // Makes use of device.describe()
else else
ss << "API"; ss << "API";

View File

@ -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 * end of the payload. The short packet length, for reference, only encompasses the length of the actual
* payload, and not the header or checksum. * payload, and not the header or checksum.
*/ */
if(packetLength < 6 || packetLength > std::numeric_limits<uint16_t>::max()) { if(packetLength < 6 || packetLength > 4000) {
bytes.pop_front(); bytes.pop_front();
EventManager::GetInstance().add(APIEvent::Type::FailedToRead, APIEvent::Severity::Error); EventManager::GetInstance().add(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
state = ReadState::SearchForHeader; state = ReadState::SearchForHeader;

View File

@ -19,7 +19,6 @@ typedef struct {
#include <chrono> #include <chrono>
#include <string> #include <string>
#include <ostream> #include <ostream>
#include <memory>
namespace icsneo { namespace icsneo {
@ -186,25 +185,19 @@ public:
Error = 0x30 Error = 0x30
}; };
APIEvent() : eventStruct({}), serial(), timepoint() {} APIEvent() : eventStruct({}), serial(), timepoint(), device(nullptr) {}
APIEvent(APIEvent::Type event, APIEvent::Severity severity, std::weak_ptr<Device> device = {}); APIEvent(APIEvent::Type event, APIEvent::Severity severity, const Device* device = nullptr);
const neoevent_t* getNeoEvent() const noexcept { return &eventStruct; } const neoevent_t* getNeoEvent() const noexcept { return &eventStruct; }
Type getType() const noexcept { return Type(eventStruct.eventNumber); } Type getType() const noexcept { return Type(eventStruct.eventNumber); }
Severity getSeverity() const noexcept { return Severity(eventStruct.severity); } Severity getSeverity() const noexcept { return Severity(eventStruct.severity); }
std::string getDescription() const noexcept { return std::string(eventStruct.description); } std::string getDescription() const noexcept { return std::string(eventStruct.description); }
const Device* getDevice() const noexcept { // Will return nullptr if this is an API-wide event const Device* getDevice() const noexcept { return device; } // 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; } EventTimePoint getTimestamp() const noexcept { return timepoint; }
void downgradeFromError() noexcept; void downgradeFromError() noexcept;
bool isForDevice(const Device* forDevice) const noexcept { bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; }
auto shared = device.lock();
return shared && (shared.get() == forDevice);
}
bool isForDevice(std::string serial) const noexcept; 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 // As opposed to getDescription, this will also add text such as "neoVI FIRE 2 CY2468 Error: " to fully describe the problem
@ -220,7 +213,7 @@ private:
neoevent_t eventStruct; neoevent_t eventStruct;
std::string serial; std::string serial;
EventTimePoint timepoint; EventTimePoint timepoint;
std::weak_ptr<Device> device; const Device* device;
void init(APIEvent::Type event, APIEvent::Severity); void init(APIEvent::Type event, APIEvent::Severity);
}; };

View File

@ -56,7 +56,7 @@ public:
APIEvent getLastError(); APIEvent getLastError();
void add(APIEvent event); void add(APIEvent event);
void add(APIEvent::Type type, APIEvent::Severity severity, std::weak_ptr<Device> forDevice = {}) { void add(APIEvent::Type type, APIEvent::Severity severity, const Device* forDevice = nullptr) {
add(APIEvent(type, severity, forDevice)); add(APIEvent(type, severity, forDevice));
} }

View File

@ -87,7 +87,7 @@ class DeviceExtension;
typedef uint64_t MemoryAddress; typedef uint64_t MemoryAddress;
class Device : public std::enable_shared_from_this<Device> { class Device {
public: public:
virtual ~Device(); virtual ~Device();
@ -930,7 +930,7 @@ protected:
virtual device_eventhandler_t makeEventHandler() { virtual device_eventhandler_t makeEventHandler() {
return [this](APIEvent::Type type, APIEvent::Severity severity) { return [this](APIEvent::Type type, APIEvent::Severity severity) {
EventManager::GetInstance().add(type, severity, weak_from_this()); EventManager::GetInstance().add(type, severity, this);
}; };
} }

View File

@ -46,8 +46,6 @@ public:
Network::NetID::LIN_06, Network::NetID::LIN_06,
Network::NetID::LIN_07, Network::NetID::LIN_07,
Network::NetID::LIN_08, Network::NetID::LIN_08,
Network::NetID::MDIO_01,
}; };
return supportedNetworks; return supportedNetworks;
} }

View File

@ -49,8 +49,6 @@ public:
Network::NetID::FLEXRAY_02, Network::NetID::FLEXRAY_02,
Network::NetID::FLEXRAY_02A, Network::NetID::FLEXRAY_02A,
Network::NetID::FLEXRAY_02B, Network::NetID::FLEXRAY_02B,
Network::NetID::MDIO_01,
}; };
return supportedNetworks; return supportedNetworks;
} }

View File

@ -53,8 +53,6 @@ public:
Network::NetID::AE_06, Network::NetID::AE_06,
Network::NetID::AE_07, Network::NetID::AE_07,
Network::NetID::AE_08, Network::NetID::AE_08,
Network::NetID::MDIO_01,
}; };
return supportedNetworks; return supportedNetworks;
} }

View File

@ -30,9 +30,7 @@ public:
Network::NetID::ETHERNET_02, Network::NetID::ETHERNET_02,
Network::NetID::LIN_01, Network::NetID::LIN_01,
Network::NetID::LIN_02, Network::NetID::LIN_02
Network::NetID::MDIO_01,
}; };
return supportedNetworks; return supportedNetworks;
} }