mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Refactor ICommunication/Transport => Driver
This commit is contained in:
@@ -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<ICommunication>&& com,
|
||||
std::unique_ptr<Driver>&& driver,
|
||||
std::function<std::unique_ptr<Packetizer>()> makeConfiguredPacketizer,
|
||||
std::unique_ptr<Encoder>&& e,
|
||||
std::unique_ptr<Decoder>&& md) : makeConfiguredPacketizer(makeConfiguredPacketizer), encoder(std::move(e)), decoder(std::move(md)), report(report), impl(std::move(com)) {
|
||||
std::unique_ptr<Decoder>&& 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<uint8_t>& bytes) { return impl->write(bytes); }
|
||||
bool rawWrite(const std::vector<uint8_t>& bytes) { return driver->write(bytes); }
|
||||
virtual bool sendPacket(std::vector<uint8_t>& 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>({ (uint8_t)boolean })); }
|
||||
virtual bool sendCommand(Command cmd, std::vector<uint8_t> arguments = {});
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
device_eventhandler_t report;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<ICommunication> impl;
|
||||
std::unique_ptr<Driver> driver;
|
||||
static int messageCallbackIDCounter;
|
||||
std::mutex messageCallbacksLock;
|
||||
std::map<int, MessageCallback> messageCallbacks;
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
#ifndef __ICOMMUNICATION_H_
|
||||
#define __ICOMMUNICATION_H_
|
||||
#ifndef __DRIVER_H_
|
||||
#define __DRIVER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
@@ -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;
|
||||
@@ -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<ICommunication> com,
|
||||
std::unique_ptr<Driver> com,
|
||||
std::function<std::unique_ptr<Packetizer>()> makeConfiguredPacketizer,
|
||||
std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> md) : Communication(err, std::move(com), makeConfiguredPacketizer, std::move(e), std::move(md)) {}
|
||||
|
||||
@@ -106,16 +106,16 @@ protected:
|
||||
data.device = this;
|
||||
}
|
||||
|
||||
template<typename Transport, typename Settings = NullSettings>
|
||||
template<typename Driver, typename Settings = NullSettings>
|
||||
void initialize() {
|
||||
report = makeEventHandler();
|
||||
auto transport = makeTransport<Transport>();
|
||||
setupTransport(*transport);
|
||||
auto driver = makeDriver<Driver>();
|
||||
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<Settings>(com);
|
||||
setupSettings(*settings);
|
||||
@@ -130,9 +130,9 @@ protected:
|
||||
};
|
||||
}
|
||||
|
||||
template<typename Transport>
|
||||
std::unique_ptr<ICommunication> makeTransport() { return std::unique_ptr<ICommunication>(new Transport(report, getWritableNeoDevice())); }
|
||||
virtual void setupTransport(ICommunication&) {}
|
||||
template<typename Driver>
|
||||
std::unique_ptr<Driver> makeDriver() { return std::unique_ptr<Driver>(new Driver(report, getWritableNeoDevice())); }
|
||||
virtual void setupDriver(Driver&) {}
|
||||
|
||||
virtual std::unique_ptr<Packetizer> makePacketizer() { return std::unique_ptr<Packetizer>(new Packetizer(report)); }
|
||||
virtual void setupPacketizer(Packetizer&) {}
|
||||
@@ -149,7 +149,7 @@ protected:
|
||||
virtual void setupDecoder(Decoder&) {}
|
||||
|
||||
virtual std::shared_ptr<Communication> makeCommunication(
|
||||
std::unique_ptr<ICommunication> t,
|
||||
std::unique_ptr<Driver> t,
|
||||
std::function<std::unique_ptr<Packetizer>()> makeConfiguredPacketizer,
|
||||
std::unique_ptr<Encoder> e,
|
||||
std::unique_ptr<Decoder> d) { return std::make_shared<Communication>(report, std::move(t), makeConfiguredPacketizer, std::move(e), std::move(d)); }
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace icsneo {
|
||||
class Plasion : public Device {
|
||||
protected:
|
||||
virtual std::shared_ptr<Communication> makeCommunication(
|
||||
std::unique_ptr<ICommunication> transport,
|
||||
std::unique_ptr<Driver> transport,
|
||||
std::function<std::unique_ptr<Packetizer>()> makeConfiguredPacketizer,
|
||||
std::unique_ptr<Encoder> encoder,
|
||||
std::unique_ptr<Decoder> decoder
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include <string>
|
||||
#include <ftdi.h>
|
||||
#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<neodevice_t> FindByProduct(int product);
|
||||
|
||||
|
||||
@@ -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 <string>
|
||||
#include <pcap.h>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class PCAP : public ICommunication {
|
||||
class PCAP : public Driver {
|
||||
public:
|
||||
class PCAPFoundDevice {
|
||||
public:
|
||||
|
||||
@@ -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 <chrono>
|
||||
@@ -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<neodevice_t> FindByProduct(int product);
|
||||
|
||||
bool open();
|
||||
|
||||
@@ -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 <string>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class PCAP : public ICommunication {
|
||||
class PCAP : public Driver {
|
||||
public:
|
||||
class PCAPFoundDevice {
|
||||
public:
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
#include <chrono>
|
||||
#include <Windows.h>
|
||||
#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<neodevice_t> FindByProduct(int product, std::vector<std::wstring> 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;
|
||||
|
||||
Reference in New Issue
Block a user