mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Revamp the way that ethernet devices are found
Also add RADStar2 Ethernet support
This commit is contained in:
+2
-5
@@ -139,11 +139,8 @@ bool Device::open() {
|
||||
}
|
||||
|
||||
std::string currentSerial = getNeoDevice().serial;
|
||||
if(currentSerial == SERIAL_FIND_ON_OPEN) {
|
||||
strncpy(getWritableNeoDevice().serial, serial->deviceSerial.c_str(), sizeof(getNeoDevice().serial));
|
||||
getWritableNeoDevice().serial[sizeof(getWritableNeoDevice().serial) - 1] = '\0';
|
||||
} else if(currentSerial != serial->deviceSerial) {
|
||||
std::cout << "NeoDevice has serial " << getNeoDevice().serial << " but device has serial " << serial->deviceSerial.c_str() << "!" << std::endl;
|
||||
if(currentSerial != serial->deviceSerial) {
|
||||
std::cout << "Found device had serial " << getNeoDevice().serial << " but connected device has serial " << serial->deviceSerial.c_str() << "!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,12 @@ std::vector<std::shared_ptr<Device>> DeviceFinder::FindAll() {
|
||||
findResults.push_back(RADGalaxy::Find());
|
||||
#endif
|
||||
|
||||
#ifdef __RADSTAR2_H_
|
||||
findResults.push_back(RADStar2::Find());
|
||||
#ifdef __RADSTAR2ETH_H_
|
||||
findResults.push_back(RADStar2ETH::Find());
|
||||
#endif
|
||||
|
||||
#ifdef __RADSTAR2USB_H_
|
||||
findResults.push_back(RADStar2USB::Find());
|
||||
#endif
|
||||
|
||||
#ifdef __RADSUPERMOON_H_
|
||||
|
||||
@@ -17,8 +17,6 @@ namespace icsneo {
|
||||
|
||||
class Device {
|
||||
public:
|
||||
static constexpr const char* SERIAL_FIND_ON_OPEN = "xxxxxx";
|
||||
|
||||
Device(neodevice_t neodevice = { 0 }) {
|
||||
data = neodevice;
|
||||
data.device = this;
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace icsneo {
|
||||
class NeoVIFIRE2 : public Device {
|
||||
public:
|
||||
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::FIRE2;
|
||||
static constexpr const char* SERIAL_START = "CY";
|
||||
NeoVIFIRE2(neodevice_t neodevice) : Device(neodevice) {
|
||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||
}
|
||||
|
||||
@@ -23,21 +23,29 @@ public:
|
||||
|
||||
static std::vector<std::shared_ptr<Device>> Find() {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto neodevice : PCAP::FindByProduct(PRODUCT_ID)) {
|
||||
{ // Scope created so that we don't have two of the same device at once
|
||||
strncpy(neodevice.serial, SERIAL_FIND_ON_OPEN, sizeof(neodevice.serial));
|
||||
neodevice.serial[sizeof(neodevice.serial) - 1] = '\0';
|
||||
auto device = std::make_shared<NeoVIFIRE2ETH>(neodevice);
|
||||
if(!device->open()) // We will get the serial number on open
|
||||
continue; // If the open failed, we won't display the device as an option to connect to
|
||||
const char* serial = device->getNeoDevice().serial;
|
||||
if(serial[0] != 'C' || serial[1] != 'Y')
|
||||
continue; // The device is not a FIRE 2
|
||||
strncpy(neodevice.serial, device->getNeoDevice().serial, sizeof(neodevice.serial));
|
||||
neodevice.serial[sizeof(neodevice.serial) - 1] = '\0';
|
||||
|
||||
for(auto& foundDev : PCAP::FindAll()) {
|
||||
auto packetizer = std::make_shared<Packetizer>();
|
||||
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 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));
|
||||
break;
|
||||
}
|
||||
found.push_back(std::make_shared<NeoVIFIRE2ETH>(neodevice));
|
||||
}
|
||||
|
||||
return found;
|
||||
|
||||
@@ -10,10 +10,11 @@ namespace icsneo {
|
||||
class Plasion : public Device {
|
||||
public:
|
||||
Plasion(neodevice_t neodevice) : Device(neodevice) {
|
||||
auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
|
||||
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
|
||||
auto packetizer = std::make_shared<Packetizer>();
|
||||
auto decoder = std::make_shared<Decoder>();
|
||||
com = std::make_shared<MultiChannelCommunication>(transport, packetizer, decoder);
|
||||
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
|
||||
auto decoder = std::unique_ptr<Decoder>(new Decoder());
|
||||
com = std::make_shared<MultiChannelCommunication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,11 +14,18 @@ public:
|
||||
// Serial numbers start with RG
|
||||
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADGalaxy;
|
||||
static constexpr const uint16_t PRODUCT_ID = 0x0003;
|
||||
RADGalaxy(neodevice_t neodevice) : Device(neodevice) {
|
||||
auto transport = std::unique_ptr<ICommunication>(new PCAP(getWritableNeoDevice()));
|
||||
static constexpr const char* SERIAL_START = "RG";
|
||||
|
||||
static std::shared_ptr<Packetizer> MakePacketizer() {
|
||||
auto packetizer = std::make_shared<Packetizer>();
|
||||
packetizer->disableChecksum = true;
|
||||
packetizer->align16bit = false;
|
||||
return packetizer;
|
||||
}
|
||||
|
||||
RADGalaxy(neodevice_t neodevice) : Device(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));
|
||||
@@ -28,21 +35,29 @@ public:
|
||||
|
||||
static std::vector<std::shared_ptr<Device>> Find() {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto neodevice : PCAP::FindByProduct(PRODUCT_ID)) {
|
||||
{ // Scope created so that we don't have two of the same device at once
|
||||
strncpy(neodevice.serial, SERIAL_FIND_ON_OPEN, sizeof(neodevice.serial));
|
||||
neodevice.serial[sizeof(neodevice.serial) - 1] = '\0';
|
||||
auto device = std::make_shared<NeoVIFIRE2ETH>(neodevice);
|
||||
if(!device->open()) // We will get the serial number on open
|
||||
continue; // If the open failed, we won't display the device as an option to connect to
|
||||
const char* serial = device->getNeoDevice().serial;
|
||||
if(serial[0] != 'R' || serial[1] != 'G')
|
||||
continue; // The device is not a RADGalaxy
|
||||
strncpy(neodevice.serial, device->getNeoDevice().serial, sizeof(neodevice.serial));
|
||||
neodevice.serial[sizeof(neodevice.serial) - 1] = '\0';
|
||||
|
||||
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 RADGalaxy
|
||||
|
||||
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
|
||||
found.push_back(std::make_shared<RADGalaxy>(foundDev.device));
|
||||
break;
|
||||
}
|
||||
found.push_back(std::make_shared<RADGalaxy>(neodevice));
|
||||
}
|
||||
|
||||
return found;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user