reuse discovered pcap interfaces in DeviceFinder::FindAll()

This commit is contained in:
Jeffrey Quesnelle
2020-05-11 16:17:56 -04:00
parent 99879c9021
commit d2019c24df
7 changed files with 24 additions and 16 deletions
@@ -23,7 +23,7 @@ public:
virtual void handleMessage(const std::shared_ptr<Message>&) {}
// Return true to continue transmitting, success should be written to if false is returned
virtual bool transmitHook(const std::shared_ptr<Message>& message, bool& success) { return true; }
virtual bool transmitHook(const std::shared_ptr<Message>& message, bool& success) { (void)message; (void)success; return true; }
protected:
Device& device;
@@ -11,10 +11,10 @@ namespace icsneo {
class NeoVIFIRE2ETH : public NeoVIFIRE2 {
public:
static constexpr const uint16_t PRODUCT_ID = 0x0004;
static std::vector<std::shared_ptr<Device>> Find() {
static std::vector<std::shared_ptr<Device>> Find(const std::vector<PCAP::PCAPFoundDevice>& pcapDevices) {
std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) {
for(auto& foundDev : pcapDevices) {
auto fakedev = std::shared_ptr<NeoVIFIRE2ETH>(new NeoVIFIRE2ETH({}));
for (auto& payload : foundDev.discoveryPackets)
fakedev->com->packetizer->input(payload);
@@ -34,8 +34,9 @@ public:
if(sn->deviceSerial.substr(0, 2) != SERIAL_START)
continue; // Not a FIRE 2
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
found.push_back(std::make_shared<NeoVIFIRE2ETH>(foundDev.device));
auto device = foundDev.device;
device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0';
found.push_back(std::make_shared<NeoVIFIRE2ETH>(std::move(device)));
break;
}
}
@@ -15,10 +15,10 @@ public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADGalaxy;
static constexpr const uint16_t PRODUCT_ID = 0x0003;
static constexpr const char* SERIAL_START = "RG";
static std::vector<std::shared_ptr<Device>> Find() {
static std::vector<std::shared_ptr<Device>> Find(const std::vector<PCAP::PCAPFoundDevice>& pcapDevices) {
std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) {
for(auto& foundDev : pcapDevices) {
auto fakedev = std::shared_ptr<RADGalaxy>(new RADGalaxy({}));
for(auto& payload : foundDev.discoveryPackets)
fakedev->com->packetizer->input(payload);
@@ -38,8 +38,9 @@ public:
if(sn->deviceSerial.substr(0, 2) != SERIAL_START)
continue; // Not a RADGalaxy
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
found.emplace_back(new RADGalaxy(foundDev.device));
auto device = foundDev.device;
device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0';
found.emplace_back(new RADGalaxy(std::move(device)));
break;
}
}
@@ -3,7 +3,6 @@
#include "icsneo/device/device.h"
#include "icsneo/device/devicetype.h"
#include "icsneo/platform/pcap.h"
#include "icsneo/communication/packetizer.h"
#include "icsneo/communication/decoder.h"
@@ -11,10 +11,10 @@ namespace icsneo {
class RADStar2ETH : public RADStar2 {
public:
// Serial numbers start with RS
static std::vector<std::shared_ptr<Device>> Find() {
static std::vector<std::shared_ptr<Device>> Find(const std::vector<PCAP::PCAPFoundDevice>& pcapDevices) {
std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) {
for(auto& foundDev : pcapDevices) {
auto fakedev = std::shared_ptr<RADStar2ETH>(new RADStar2ETH({}));
for(auto& payload : foundDev.discoveryPackets)
fakedev->com->packetizer->input(payload);
@@ -34,7 +34,8 @@ public:
if(sn->deviceSerial.substr(0, 2) != SERIAL_START)
continue; // Not a RADStar2
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
auto device = foundDev.device;
device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0';
found.push_back(std::make_shared<RADStar2ETH>(foundDev.device));
break;
}