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:
Paul Hollinsky
2022-03-27 14:30:31 -04:00
parent 0ff12300f3
commit 781fc2c034
66 changed files with 780 additions and 1566 deletions
+6 -4
View File
@@ -11,14 +11,16 @@ namespace icsneo {
class RADMars : public Device {
public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADMars;
static constexpr const char* SERIAL_START = "GL";
// Serial numbers start with GL (previously, RAD-Gigalog)
// USB PID is 0x1203, standard driver is FTDI3
// Ethernet MAC allocation is 0x0A, standard driver is Raw
ICSNEO_FINDABLE_DEVICE(RADMars, DeviceType::RADMars, "GL");
size_t getEthernetActivationLineCount() const override { return 1; }
protected:
RADMars(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
RADMars(neodevice_t neodevice, const driver_factory_t& makeDriver) : Device(neodevice) {
initialize<RADMarsSettings>(makeDriver);
}
void setupPacketizer(Packetizer& packetizer) override {
@@ -1,58 +0,0 @@
#ifndef __RADMARS_ETH_H_
#define __RADMARS_ETH_H_
#ifdef __cplusplus
#include "icsneo/device/tree/radmars/radmars.h"
#include "icsneo/platform/pcap.h"
namespace icsneo {
class RADMarsETH : public RADMars {
public:
static constexpr const uint16_t PRODUCT_ID = 0x000A;
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<RADMarsETH>(new RADMarsETH({}));
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 RAD-Mars
auto device = foundDev.device;
device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0';
found.push_back(std::shared_ptr<RADMarsETH>(new RADMarsETH(std::move(device))));
break;
}
}
return found;
}
private:
RADMarsETH(neodevice_t neodevice) : RADMars(neodevice) {
initialize<PCAP, RADMarsSettings>();
productId = PRODUCT_ID;
}
};
}
#endif // __cplusplus
#endif
@@ -1,34 +0,0 @@
#ifndef __RADMARS_USB_H_
#define __RADMARS_USB_H_
#ifdef __cplusplus
#include "icsneo/device/tree/radmars/radmars.h"
#include "icsneo/platform/ftdi3.h"
namespace icsneo {
class RADMarsUSB : public RADMars {
public:
static constexpr const uint16_t PRODUCT_ID = 0x1203;
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI3::FindByProduct(PRODUCT_ID))
found.emplace_back(new RADMarsUSB(neodevice)); // Creation of the shared_ptr
return found;
}
private:
RADMarsUSB(neodevice_t neodevice) : RADMars(neodevice) {
initialize<FTDI3, RADMarsSettings>();
productId = PRODUCT_ID;
}
};
}
#endif // __cplusplus
#endif