mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Drivers: Decouple from devices
This allows us to better implement alternative drivers for devices, such as for device sharing servers or talking to CoreMini processors within the same device.
This commit is contained in:
@@ -12,9 +12,9 @@ namespace icsneo {
|
||||
class RADStar2 : public Device {
|
||||
public:
|
||||
// Serial numbers start with RS
|
||||
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADStar2;
|
||||
static constexpr const uint16_t PRODUCT_ID = 0x0005;
|
||||
static constexpr const char* SERIAL_START = "RS";
|
||||
// USB PID is 0x0005, standard driver is FTDI
|
||||
// Ethernet MAC allocation is 0x05, standard driver is Raw
|
||||
ICSNEO_FINDABLE_DEVICE(RADStar2, DeviceType::RADStar2, "RS");
|
||||
|
||||
static const std::vector<Network>& GetSupportedNetworks() {
|
||||
static std::vector<Network> supportedNetworks = {
|
||||
@@ -30,6 +30,10 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
RADStar2(neodevice_t neodevice, const driver_factory_t& makeDriver) : Device(neodevice) {
|
||||
initialize<RADStar2Settings>(makeDriver);
|
||||
}
|
||||
|
||||
virtual void setupPacketizer(Packetizer& packetizer) override {
|
||||
Device::setupPacketizer(packetizer);
|
||||
packetizer.disableChecksum = true;
|
||||
@@ -46,18 +50,13 @@ protected:
|
||||
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
||||
}
|
||||
|
||||
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||
void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||
for(auto& netid : GetSupportedNetworks())
|
||||
rxNetworks.emplace_back(netid);
|
||||
}
|
||||
|
||||
// The supported TX networks are the same as the supported RX networks for this device
|
||||
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||
|
||||
RADStar2(neodevice_t neodevice) : Device(neodevice) {
|
||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||
productId = PRODUCT_ID;
|
||||
}
|
||||
void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#ifndef __RADSTAR2ETH_H_
|
||||
#define __RADSTAR2ETH_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/device/tree/radstar2/radstar2.h"
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/communication/message/serialnumbermessage.h"
|
||||
#include "icsneo/platform/pcap.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class RADStar2ETH : public RADStar2 {
|
||||
public:
|
||||
// Serial numbers start with RS
|
||||
static std::vector<std::shared_ptr<Device>> Find(const std::vector<PCAP::PCAPFoundDevice>& pcapDevices) {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto& foundDev : pcapDevices) {
|
||||
auto fakedev = std::shared_ptr<RADStar2ETH>(new RADStar2ETH({}));
|
||||
for(auto& payload : foundDev.discoveryPackets)
|
||||
fakedev->com->packetizer->input(payload);
|
||||
for(auto& packet : fakedev->com->packetizer->output()) {
|
||||
std::shared_ptr<Message> msg;
|
||||
if(!fakedev->com->decoder->decode(msg, packet))
|
||||
continue; // We failed to decode this packet
|
||||
|
||||
if(!msg || msg->type != Message::Type::Main51)
|
||||
continue; // Not a message we care about
|
||||
auto sn = std::dynamic_pointer_cast<SerialNumberMessage>(msg);
|
||||
if(!sn)
|
||||
continue; // Not a serial number message
|
||||
|
||||
if(sn->deviceSerial.length() < 2)
|
||||
continue;
|
||||
if(sn->deviceSerial.substr(0, 2) != SERIAL_START)
|
||||
continue; // Not a RADStar2
|
||||
|
||||
auto device = foundDev.device;
|
||||
device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0';
|
||||
found.push_back(std::make_shared<RADStar2ETH>(device));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) {
|
||||
initialize<PCAP, RADStar2Settings>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef __RADSTAR2USB_H_
|
||||
#define __RADSTAR2USB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/device/tree/radstar2/radstar2.h"
|
||||
#include "icsneo/platform/ftdi.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class RADStar2USB : public RADStar2 {
|
||||
public:
|
||||
// Serial numbers start with RS
|
||||
static std::vector<std::shared_ptr<Device>> Find() {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
|
||||
found.emplace_back(new RADStar2USB(neodevice));
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private:
|
||||
RADStar2USB(neodevice_t neodevice) : RADStar2(neodevice) {
|
||||
initialize<FTDI, RADStar2Settings>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user