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
+31 -16
View File
@@ -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;