diff --git a/device/device.cpp b/device/device.cpp index 54365ff..7361baf 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -168,6 +168,14 @@ bool Device::open() { return false; } + if(!afterCommunicationOpen()) { + // Very unlikely, at the time of writing this only fails if rawWrite does. + // If you're looking for this error, you're probably looking for if(!serial) below. + report(APIEvent::Type::NoSerialNumber, APIEvent::Severity::Error); // Communication could not be established with the device. Perhaps it is not powered with 12 volts? + com->close(); + return false; + } + auto serial = com->getSerialNumberSync(); int i = 0; while(!serial) { diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 0e4fe64..5195884 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -166,6 +166,10 @@ protected: virtual void setupExtensions() {} void addExtension(std::shared_ptr&& extension); + + // Hook for devices such as FIRE which need to inject traffic before RequestSerialNumber + // Return false to bail + virtual bool afterCommunicationOpen() { return true; } template std::shared_ptr getExtension() const { diff --git a/include/icsneo/device/tree/neovifire/neovifire.h b/include/icsneo/device/tree/neovifire/neovifire.h index f055c3a..23df356 100644 --- a/include/icsneo/device/tree/neovifire/neovifire.h +++ b/include/icsneo/device/tree/neovifire/neovifire.h @@ -45,18 +45,12 @@ public: Bootloader = 'B' }; - bool open() override { - if(!com) - return false; - - if(!com->open()) + bool afterCommunicationOpen() override { + if(!Device::afterCommunicationOpen()) // Doesn't do anything right now but just in case it gets added to later return false; // Enter mode is only needed on very old FIRE devices (white board), will be ignored by newer devices - if(!enterMode(Mode::Application)) - return false; - - return Device::open(); + return enterMode(Mode::Application); } bool enterMode(Mode mode) {