57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#ifndef __NEOVIFIRE2ETH_H_
|
|
#define __NEOVIFIRE2ETH_H_
|
|
|
|
#include "device/neovifire2/include/neovifire2.h"
|
|
#include "platform/include/pcap.h"
|
|
#include "device/neovifire2/include/neovifire2settings.h"
|
|
#include <memory>
|
|
|
|
namespace icsneo {
|
|
|
|
class NeoVIFIRE2ETH : public NeoVIFIRE2 {
|
|
public:
|
|
static constexpr const uint16_t PRODUCT_ID = 0x0004;
|
|
NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
|
|
auto transport = std::unique_ptr<ICommunication>(new PCAP(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));
|
|
settings = std::unique_ptr<IDeviceSettings>(new NeoVIFIRE2Settings(com));
|
|
productId = PRODUCT_ID;
|
|
}
|
|
|
|
static std::vector<std::shared_ptr<Device>> Find() {
|
|
std::vector<std::shared_ptr<Device>> found;
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
return found;
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif |