Revamp the way that ethernet devices are found

Also add RADStar2 Ethernet support
This commit is contained in:
Paul Hollinsky
2018-10-08 16:32:51 -04:00
parent 466d35c68b
commit 7d821b9745
13 changed files with 207 additions and 116 deletions
+1 -14
View File
@@ -3,7 +3,6 @@
#include "device/include/device.h"
#include "device/include/devicetype.h"
#include "platform/include/ftdi.h"
namespace icsneo {
@@ -12,23 +11,11 @@ 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";
RADStar2(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder);
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<RADStar2>(neodevice));
return found;
}
};
}
+62
View File
@@ -0,0 +1,62 @@
#ifndef __RADSTAR2ETH_H_
#define __RADSTAR2ETH_H_
#include "device/radstar2/include/radstar2.h"
#include "communication/include/network.h"
#include "communication/message/include/serialnumbermessage.h"
#include "platform/include/pcap.h"
namespace icsneo {
class RADStar2ETH : public RADStar2 {
public:
static std::shared_ptr<Packetizer> MakePacketizer() {
auto packetizer = std::make_shared<Packetizer>();
packetizer->disableChecksum = true;
packetizer->align16bit = false;
return packetizer;
}
// Serial numbers start with RS
RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new PCAP(getWritableNeoDevice()));
auto packetizer = MakePacketizer();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) {
auto packetizer = MakePacketizer();
auto decoder = std::unique_ptr<Decoder>(new Decoder());
for(auto& payload : foundDev.discoveryPackets)
packetizer->input(payload);
for(auto& packet : packetizer->output()) {
auto msg = decoder->decodePacket(packet);
if(!msg || msg->network.getNetID() != Network::NetID::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
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
found.push_back(std::make_shared<RADStar2ETH>(foundDev.device));
break;
}
}
return found;
}
};
}
#endif
+32
View File
@@ -0,0 +1,32 @@
#ifndef __RADSTAR2USB_H_
#define __RADSTAR2USB_H_
#include "device/radstar2/include/radstar2.h"
#include "platform/include/ftdi.h"
namespace icsneo {
class RADStar2USB : public RADStar2 {
public:
// Serial numbers start with RS
RADStar2USB(neodevice_t neodevice) : RADStar2(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<RADStar2USB>(neodevice));
return found;
}
};
}
#endif