diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dc5b95..7e42fd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,7 @@ set(COMMON_SRC communication/packetizer.cpp communication/multichannelcommunication.cpp communication/communication.cpp - communication/icommunication.cpp + communication/driver.cpp device/extensions/flexray/extension.cpp device/extensions/flexray/controller.cpp device/idevicesettings.cpp diff --git a/communication/communication.cpp b/communication/communication.cpp index 65b1a70..52819b9 100644 --- a/communication/communication.cpp +++ b/communication/communication.cpp @@ -24,7 +24,7 @@ bool Communication::open() { } spawnThreads(); - return impl->open(); + return driver->open(); } void Communication::spawnThreads() { @@ -46,11 +46,11 @@ bool Communication::close() { joinThreads(); - return impl->close(); + return driver->close(); } bool Communication::isOpen() { - return impl->isOpen(); + return driver->isOpen(); } bool Communication::sendPacket(std::vector& bytes) { @@ -174,7 +174,7 @@ void Communication::readTask() { while(!closing) { readBytes.clear(); - if(impl->readWait(readBytes)) { + if(driver->readWait(readBytes)) { if(packetizer->input(readBytes)) { for(const auto& packet : packetizer->output()) { std::shared_ptr msg; diff --git a/communication/icommunication.cpp b/communication/driver.cpp similarity index 81% rename from communication/icommunication.cpp rename to communication/driver.cpp index 9b1680a..0a050c2 100644 --- a/communication/icommunication.cpp +++ b/communication/driver.cpp @@ -1,8 +1,8 @@ -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" using namespace icsneo; -bool ICommunication::read(std::vector& bytes, size_t limit) { +bool Driver::read(std::vector& bytes, size_t limit) { // A limit of zero indicates no limit if(limit == 0) limit = (size_t)-1; @@ -21,7 +21,7 @@ bool ICommunication::read(std::vector& bytes, size_t limit) { return true; } -bool ICommunication::readWait(std::vector& bytes, std::chrono::milliseconds timeout, size_t limit) { +bool Driver::readWait(std::vector& bytes, std::chrono::milliseconds timeout, size_t limit) { // A limit of zero indicates no limit if(limit == 0) limit = (size_t)-1; @@ -38,7 +38,7 @@ bool ICommunication::readWait(std::vector& bytes, std::chrono::millisec return actuallyRead > 0; } -bool ICommunication::write(const std::vector& bytes) { +bool Driver::write(const std::vector& bytes) { if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); return false; diff --git a/communication/multichannelcommunication.cpp b/communication/multichannelcommunication.cpp index c3758b0..033030a 100644 --- a/communication/multichannelcommunication.cpp +++ b/communication/multichannelcommunication.cpp @@ -41,7 +41,7 @@ void MultiChannelCommunication::hidReadTask() { while(!closing) { if(readMore) { readBytes.clear(); - if(impl->readWait(readBytes)) { + if(driver->readWait(readBytes)) { readMore = false; usbReadFifo.insert(usbReadFifo.end(), std::make_move_iterator(readBytes.begin()), std::make_move_iterator(readBytes.end())); } diff --git a/include/icsneo/communication/communication.h b/include/icsneo/communication/communication.h index 47b04c0..071c376 100644 --- a/include/icsneo/communication/communication.h +++ b/include/icsneo/communication/communication.h @@ -1,7 +1,7 @@ #ifndef __COMMUNICATION_H_ #define __COMMUNICATION_H_ -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/communication/command.h" #include "icsneo/communication/network.h" #include "icsneo/communication/packet.h" @@ -24,10 +24,10 @@ class Communication { public: Communication( device_eventhandler_t report, - std::unique_ptr&& com, + std::unique_ptr&& driver, std::function()> makeConfiguredPacketizer, std::unique_ptr&& e, - std::unique_ptr&& md) : makeConfiguredPacketizer(makeConfiguredPacketizer), encoder(std::move(e)), decoder(std::move(md)), report(report), impl(std::move(com)) { + std::unique_ptr&& md) : makeConfiguredPacketizer(makeConfiguredPacketizer), encoder(std::move(e)), decoder(std::move(md)), report(report), driver(std::move(driver)) { packetizer = makeConfiguredPacketizer(); } virtual ~Communication() { close(); } @@ -37,10 +37,10 @@ public: bool isOpen(); virtual void spawnThreads(); virtual void joinThreads(); - bool rawWrite(const std::vector& bytes) { return impl->write(bytes); } + bool rawWrite(const std::vector& bytes) { return driver->write(bytes); } virtual bool sendPacket(std::vector& bytes); - void setWriteBlocks(bool blocks) { impl->writeBlocks = blocks; } + void setWriteBlocks(bool blocks) { driver->writeBlocks = blocks; } virtual bool sendCommand(Command cmd, bool boolean) { return sendCommand(cmd, std::vector({ (uint8_t)boolean })); } virtual bool sendCommand(Command cmd, std::vector arguments = {}); @@ -68,7 +68,7 @@ public: device_eventhandler_t report; protected: - std::unique_ptr impl; + std::unique_ptr driver; static int messageCallbackIDCounter; std::mutex messageCallbacksLock; std::map messageCallbacks; diff --git a/include/icsneo/communication/icommunication.h b/include/icsneo/communication/driver.h similarity index 84% rename from include/icsneo/communication/icommunication.h rename to include/icsneo/communication/driver.h index b6aeaf7..747ffc3 100644 --- a/include/icsneo/communication/icommunication.h +++ b/include/icsneo/communication/driver.h @@ -1,5 +1,5 @@ -#ifndef __ICOMMUNICATION_H_ -#define __ICOMMUNICATION_H_ +#ifndef __DRIVER_H_ +#define __DRIVER_H_ #include #include @@ -12,10 +12,10 @@ namespace icsneo { -class ICommunication { +class Driver { public: - ICommunication(const device_eventhandler_t& handler) : report(handler) {} - virtual ~ICommunication() {} + Driver(const device_eventhandler_t& handler) : report(handler) {} + virtual ~Driver() {} virtual bool open() = 0; virtual bool isOpen() = 0; virtual bool close() = 0; diff --git a/include/icsneo/communication/multichannelcommunication.h b/include/icsneo/communication/multichannelcommunication.h index 8342cc4..479f913 100644 --- a/include/icsneo/communication/multichannelcommunication.h +++ b/include/icsneo/communication/multichannelcommunication.h @@ -2,7 +2,7 @@ #define __MULTICHANNELCOMMUNICATION_H_ #include "icsneo/communication/communication.h" -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/communication/command.h" #include "icsneo/communication/encoder.h" #include "icsneo/third-party/readerwriterqueue/readerwriterqueue.h" @@ -13,7 +13,7 @@ class MultiChannelCommunication : public Communication { public: MultiChannelCommunication( device_eventhandler_t err, - std::unique_ptr com, + std::unique_ptr com, std::function()> makeConfiguredPacketizer, std::unique_ptr e, std::unique_ptr md) : Communication(err, std::move(com), makeConfiguredPacketizer, std::move(e), std::move(md)) {} diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 94e1bfc..0e4fe64 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -106,16 +106,16 @@ protected: data.device = this; } - template + template void initialize() { report = makeEventHandler(); - auto transport = makeTransport(); - setupTransport(*transport); + auto driver = makeDriver(); + setupDriver(*driver); auto encoder = makeEncoder(); setupEncoder(*encoder); auto decoder = makeDecoder(); setupDecoder(*decoder); - com = makeCommunication(std::move(transport), std::bind(&Device::makeConfiguredPacketizer, this), std::move(encoder), std::move(decoder)); + com = makeCommunication(std::move(driver), std::bind(&Device::makeConfiguredPacketizer, this), std::move(encoder), std::move(decoder)); setupCommunication(*com); settings = makeSettings(com); setupSettings(*settings); @@ -130,9 +130,9 @@ protected: }; } - template - std::unique_ptr makeTransport() { return std::unique_ptr(new Transport(report, getWritableNeoDevice())); } - virtual void setupTransport(ICommunication&) {} + template + std::unique_ptr makeDriver() { return std::unique_ptr(new Driver(report, getWritableNeoDevice())); } + virtual void setupDriver(Driver&) {} virtual std::unique_ptr makePacketizer() { return std::unique_ptr(new Packetizer(report)); } virtual void setupPacketizer(Packetizer&) {} @@ -149,7 +149,7 @@ protected: virtual void setupDecoder(Decoder&) {} virtual std::shared_ptr makeCommunication( - std::unique_ptr t, + std::unique_ptr t, std::function()> makeConfiguredPacketizer, std::unique_ptr e, std::unique_ptr d) { return std::make_shared(report, std::move(t), makeConfiguredPacketizer, std::move(e), std::move(d)); } diff --git a/include/icsneo/device/tree/plasion/plasion.h b/include/icsneo/device/tree/plasion/plasion.h index 0525093..bb0da77 100644 --- a/include/icsneo/device/tree/plasion/plasion.h +++ b/include/icsneo/device/tree/plasion/plasion.h @@ -11,7 +11,7 @@ namespace icsneo { class Plasion : public Device { protected: virtual std::shared_ptr makeCommunication( - std::unique_ptr transport, + std::unique_ptr transport, std::function()> makeConfiguredPacketizer, std::unique_ptr encoder, std::unique_ptr decoder diff --git a/include/icsneo/platform/posix/ftdi.h b/include/icsneo/platform/posix/ftdi.h index 7fe99f7..180d2f1 100644 --- a/include/icsneo/platform/posix/ftdi.h +++ b/include/icsneo/platform/posix/ftdi.h @@ -6,13 +6,13 @@ #include #include #include "icsneo/device/neodevice.h" -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/third-party/concurrentqueue/blockingconcurrentqueue.h" #include "icsneo/api/eventmanager.h" namespace icsneo { -class FTDI : public ICommunication { +class FTDI : public Driver { public: static std::vector FindByProduct(int product); diff --git a/include/icsneo/platform/posix/pcap.h b/include/icsneo/platform/posix/pcap.h index 0bf3ed3..b6853cc 100644 --- a/include/icsneo/platform/posix/pcap.h +++ b/include/icsneo/platform/posix/pcap.h @@ -2,14 +2,14 @@ #define __PCAP_POSIX_H_ #include "icsneo/device/neodevice.h" -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/api/eventmanager.h" #include #include namespace icsneo { -class PCAP : public ICommunication { +class PCAP : public Driver { public: class PCAPFoundDevice { public: diff --git a/include/icsneo/platform/posix/stm32.h b/include/icsneo/platform/posix/stm32.h index 0690283..e8df59e 100644 --- a/include/icsneo/platform/posix/stm32.h +++ b/include/icsneo/platform/posix/stm32.h @@ -1,7 +1,7 @@ #ifndef __STM32_POSIX_H_ #define __STM32_POSIX_H_ -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/device/neodevice.h" #include "icsneo/api/eventmanager.h" #include @@ -9,7 +9,7 @@ namespace icsneo { -class STM32 : public ICommunication { +class STM32 : public Driver { public: /* * Note: This is a driver for all devices which use CDC_ACM @@ -21,7 +21,7 @@ public: * in stm32linux.cpp and stm32darwin.cpp respectively * Other POSIX systems (BSDs, QNX, etc) will need bespoke code written in the future */ - STM32(const device_eventhandler_t& err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) {} + STM32(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) {} static std::vector FindByProduct(int product); bool open(); diff --git a/include/icsneo/platform/windows/pcap.h b/include/icsneo/platform/windows/pcap.h index 66de9f3..8b3b862 100644 --- a/include/icsneo/platform/windows/pcap.h +++ b/include/icsneo/platform/windows/pcap.h @@ -3,13 +3,13 @@ #include "icsneo/platform/windows/internal/pcapdll.h" #include "icsneo/device/neodevice.h" -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/api/eventmanager.h" #include namespace icsneo { -class PCAP : public ICommunication { +class PCAP : public Driver { public: class PCAPFoundDevice { public: diff --git a/include/icsneo/platform/windows/vcp.h b/include/icsneo/platform/windows/vcp.h index 7a909e3..1df8749 100644 --- a/include/icsneo/platform/windows/vcp.h +++ b/include/icsneo/platform/windows/vcp.h @@ -8,19 +8,19 @@ #include #include #include "icsneo/device/neodevice.h" -#include "icsneo/communication/icommunication.h" +#include "icsneo/communication/driver.h" #include "icsneo/api/eventmanager.h" namespace icsneo { // Virtual COM Port Communication -class VCP : public ICommunication { +class VCP : public Driver { public: static std::vector FindByProduct(int product, std::vector driverName); static bool IsHandleValid(neodevice_handle_t handle); typedef void(*fn_boolCallback)(bool success); - VCP(const device_eventhandler_t& err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) { + VCP(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) { overlappedRead.hEvent = INVALID_HANDLE_VALUE; overlappedWrite.hEvent = INVALID_HANDLE_VALUE; overlappedWait.hEvent = INVALID_HANDLE_VALUE; diff --git a/platform/posix/ftdi.cpp b/platform/posix/ftdi.cpp index 5f29fd6..bc65e4f 100644 --- a/platform/posix/ftdi.cpp +++ b/platform/posix/ftdi.cpp @@ -39,7 +39,7 @@ std::vector FTDI::FindByProduct(int product) { return found; } -FTDI::FTDI(const device_eventhandler_t& err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) { +FTDI::FTDI(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) { openable = strlen(forDevice.serial) > 0 && device.handle >= 0 && device.handle < (neodevice_handle_t)handles.size(); } diff --git a/platform/posix/pcap.cpp b/platform/posix/pcap.cpp index 9773ff8..ebb680c 100644 --- a/platform/posix/pcap.cpp +++ b/platform/posix/pcap.cpp @@ -173,7 +173,7 @@ bool PCAP::IsHandleValid(neodevice_handle_t handle) { return (netifIndex < knownInterfaces.size()); } -PCAP::PCAP(device_eventhandler_t err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) { +PCAP::PCAP(device_eventhandler_t err, neodevice_t& forDevice) : Driver(err), device(forDevice) { if(IsHandleValid(device.handle)) { interface = knownInterfaces[(device.handle >> 24) & 0xFF]; interface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case. diff --git a/platform/windows/pcap.cpp b/platform/windows/pcap.cpp index de613cf..98789ab 100644 --- a/platform/windows/pcap.cpp +++ b/platform/windows/pcap.cpp @@ -177,7 +177,7 @@ bool PCAP::IsHandleValid(neodevice_handle_t handle) { return (netifIndex < knownInterfaces.size()); } -PCAP::PCAP(const device_eventhandler_t& err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) { +PCAP::PCAP(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) { if(IsHandleValid(device.handle)) { interface = knownInterfaces[(device.handle >> 24) & 0xFF]; interface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case.