diff --git a/api/icsneocpp/error.cpp b/api/icsneocpp/error.cpp index cb870f2..87bd4bb 100644 --- a/api/icsneocpp/error.cpp +++ b/api/icsneocpp/error.cpp @@ -17,11 +17,11 @@ APIError::APIError(ErrorType error, const Device* forDevice) : errorStruct({}) { } void APIError::init(ErrorType error) { - timepoint = std::chrono::high_resolution_clock::now(); + timepoint = ErrorClock::now(); errorStruct.description = DescriptionForType(error); errorStruct.errorNumber = (uint32_t)error; errorStruct.severity = (uint8_t)SeverityForType(error); - errorStruct.timestamp = std::chrono::high_resolution_clock::to_time_t(timepoint); + errorStruct.timestamp = ErrorClock::to_time_t(timepoint); } std::string APIError::describe() const noexcept { @@ -35,10 +35,10 @@ std::string APIError::describe() const noexcept { return ss.str(); } -bool APIError::isForDevice(std::string serial) const noexcept { - if(!device || serial.length() == 0) +bool APIError::isForDevice(std::string filterSerial) const noexcept { + if(!device || filterSerial.length() == 0) return false; - return device->getSerial() == serial; + return device->getSerial() == filterSerial; } // API Errors diff --git a/include/icsneo/api/error.h b/include/icsneo/api/error.h index 1620e9e..5d5dd3e 100644 --- a/include/icsneo/api/error.h +++ b/include/icsneo/api/error.h @@ -26,6 +26,9 @@ class Device; class APIError { public: + typedef std::chrono::system_clock ErrorClock; + typedef std::chrono::time_point ErrorTimePoint; + enum ErrorType : uint32_t { Any = 0, // Used for filtering, should not appear in data @@ -73,7 +76,7 @@ public: Severity getSeverity() const noexcept { return Severity(errorStruct.severity); } std::string getDescription() const noexcept { return std::string(errorStruct.description); } const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide error - std::chrono::time_point getTimestamp() const noexcept { return timepoint; } + ErrorTimePoint getTimestamp() const noexcept { return timepoint; } bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; } bool isForDevice(std::string serial) const noexcept; @@ -91,7 +94,7 @@ public: private: neoerror_t errorStruct; std::string serial; - std::chrono::time_point timepoint; + ErrorTimePoint timepoint; const Device* device; void init(ErrorType error); diff --git a/include/icsneo/api/errormanager.h b/include/icsneo/api/errormanager.h index eb4b43e..525387c 100644 --- a/include/icsneo/api/errormanager.h +++ b/include/icsneo/api/errormanager.h @@ -26,9 +26,9 @@ public: get(ret, filter, max); return ret; } - void get(std::vector& errors, ErrorFilter filter, size_t max = 0) { get(errors, max, filter); } - void get(std::vector& errors, size_t max = 0, ErrorFilter filter = ErrorFilter()); - bool getLastError(APIError& error, ErrorFilter filter = ErrorFilter()); + void get(std::vector& outErrors, ErrorFilter filter, size_t max = 0) { get(outErrors, max, filter); } + void get(std::vector& outErrors, size_t max = 0, ErrorFilter filter = ErrorFilter()); + bool getLastError(APIError& outErrors, ErrorFilter filter = ErrorFilter()); void add(APIError error) { std::lock_guard lk(mutex); diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 466a3f1..5681748 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -103,29 +103,29 @@ protected: template std::unique_ptr makeTransport() { return std::unique_ptr(new Transport(err, getWritableNeoDevice())); } - virtual void setupTransport(ICommunication* transport) {} + virtual void setupTransport(ICommunication* stransport) { (void)stransport; } virtual std::shared_ptr makePacketizer() { return std::make_shared(err); } - virtual void setupPacketizer(Packetizer* packetizer) {} + virtual void setupPacketizer(Packetizer* spacketizer) { (void)spacketizer; } virtual std::unique_ptr makeEncoder(std::shared_ptr p) { return std::unique_ptr(new Encoder(err, p)); } - virtual void setupEncoder(Encoder* encoder) {} + virtual void setupEncoder(Encoder* sencoder) { (void)sencoder; } virtual std::unique_ptr makeDecoder() { return std::unique_ptr(new Decoder(err)); } - virtual void setupDecoder(Decoder* decoder) {} + virtual void setupDecoder(Decoder* sdecoder) { (void)sdecoder; } virtual std::shared_ptr makeCommunication( std::unique_ptr t, std::shared_ptr p, std::unique_ptr e, std::unique_ptr d) { return std::make_shared(err, std::move(t), p, std::move(e), std::move(d)); } - virtual void setupCommunication(Communication* com) {} + virtual void setupCommunication(Communication* scom) { (void)scom; } template std::unique_ptr makeSettings(std::shared_ptr com) { return std::unique_ptr(new Settings(com)); } - virtual void setupSettings(IDeviceSettings* settings) {} + virtual void setupSettings(IDeviceSettings* ssettings) { (void)ssettings; } // END Initialization Functions void handleInternalMessage(std::shared_ptr message); diff --git a/include/icsneo/device/neovifire2/neovifire2eth.h b/include/icsneo/device/neovifire2/neovifire2eth.h index 3cabb84..13fcb89 100644 --- a/include/icsneo/device/neovifire2/neovifire2eth.h +++ b/include/icsneo/device/neovifire2/neovifire2eth.h @@ -15,13 +15,12 @@ public: std::vector> found; for(auto& foundDev : PCAP::FindAll()) { - auto packetizer = std::make_shared(); - auto decoder = std::unique_ptr(new Decoder()); - for(auto& payload : foundDev.discoveryPackets) - packetizer->input(payload); - for(auto& packet : packetizer->output()) { + auto fakedev = std::shared_ptr(new NeoVIFIRE2ETH({})); + for (auto& payload : foundDev.discoveryPackets) + fakedev->com->packetizer->input(payload); + for (auto& packet : fakedev->com->packetizer->output()) { std::shared_ptr msg; - if(!decoder->decode(msg, packet)) + if (!fakedev->com->decoder->decode(msg, packet)) continue; // We failed to decode this packet if(!msg || msg->network.getNetID() != Network::NetID::Main51) @@ -44,17 +43,16 @@ public: return found; } -protected: - virtual void setupSettings(IDeviceSettings* settings) { - // TODO Check firmware version, old firmwares will reset Ethernet settings on settings send - settings->readonly = true; - } - -private: NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) { initialize(); productId = PRODUCT_ID; } + +protected: + virtual void setupSettings(IDeviceSettings* ssettings) { + // TODO Check firmware version, old firmwares will reset Ethernet settings on settings send + ssettings->readonly = true; + } }; } diff --git a/include/icsneo/device/radgalaxy/radgalaxy.h b/include/icsneo/device/radgalaxy/radgalaxy.h index f8b5b97..b6f7719 100644 --- a/include/icsneo/device/radgalaxy/radgalaxy.h +++ b/include/icsneo/device/radgalaxy/radgalaxy.h @@ -47,18 +47,17 @@ public: return found; } -protected: - void setupPacketizer(Packetizer* packetizer) override { - packetizer->disableChecksum = true; - packetizer->align16bit = false; - } - -private: RADGalaxy(neodevice_t neodevice) : Device(neodevice) { initialize(); getWritableNeoDevice().type = DEVICE_TYPE; productId = PRODUCT_ID; } + +protected: + void setupPacketizer(Packetizer* packetizer) override { + packetizer->disableChecksum = true; + packetizer->align16bit = false; + } }; } diff --git a/include/icsneo/device/radstar2/radstar2eth.h b/include/icsneo/device/radstar2/radstar2eth.h index 62a17c6..8821aed 100644 --- a/include/icsneo/device/radstar2/radstar2eth.h +++ b/include/icsneo/device/radstar2/radstar2eth.h @@ -43,7 +43,6 @@ public: return found; } -private: RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) { initialize(); } diff --git a/include/icsneo/platform/windows/pcap.h b/include/icsneo/platform/windows/pcap.h index 1d9bca8..137b5ba 100644 --- a/include/icsneo/platform/windows/pcap.h +++ b/include/icsneo/platform/windows/pcap.h @@ -27,6 +27,7 @@ public: bool close(); private: PCAPDLL pcap; + device_errorhandler_t err; char errbuf[PCAP_ERRBUF_SIZE] = { 0 }; neodevice_t& device; uint8_t deviceMAC[6]; diff --git a/platform/windows/vcp.cpp b/platform/windows/vcp.cpp index 6ebc279..7f6f416 100644 --- a/platform/windows/vcp.cpp +++ b/platform/windows/vcp.cpp @@ -270,7 +270,6 @@ void VCP::readTask() { case WAIT: { auto ret = WaitForSingleObject(overlappedRead.hEvent, 100); if(ret == WAIT_OBJECT_0) { - auto err = GetLastError(); if(GetOverlappedResult(handle, &overlappedRead, &bytesRead, FALSE)) { readQueue.enqueue_bulk(readbuf, bytesRead); state = LAUNCH; @@ -300,8 +299,8 @@ void VCP::writeTask() { if(WriteFile(handle, writeOp.bytes.data(), (DWORD)writeOp.bytes.size(), nullptr, &overlappedWrite)) continue; - auto err = GetLastError(); - if(err == ERROR_IO_PENDING) { + auto winerr = GetLastError(); + if(winerr == ERROR_IO_PENDING) { state = WAIT; } else