91 lines
2.7 KiB
C++
91 lines
2.7 KiB
C++
#ifndef __NEOVIRED2_H_
|
|
#define __NEOVIRED2_H_
|
|
|
|
#include "icsneo/device/device.h"
|
|
#include "icsneo/device/devicetype.h"
|
|
#include "icsneo/platform/pcap.h"
|
|
#include "icsneo/device/tree/neovired2/neovired2settings.h"
|
|
|
|
namespace icsneo {
|
|
|
|
class NeoVIRED2 : public Device {
|
|
public:
|
|
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RED2;
|
|
static constexpr const char* SERIAL_START = "D2";
|
|
static constexpr const uint16_t PRODUCT_ID = 0x000E;
|
|
static std::vector<std::shared_ptr<Device>> Find(const std::vector<PCAP::PCAPFoundDevice>& pcapDevices) {
|
|
std::vector<std::shared_ptr<Device>> found;
|
|
|
|
for(auto& foundDev : pcapDevices) {
|
|
auto fakedev = std::shared_ptr<NeoVIRED2>(new NeoVIRED2({}));
|
|
for (auto& payload : foundDev.discoveryPackets)
|
|
fakedev->com->packetizer->input(payload);
|
|
for (auto& packet : fakedev->com->packetizer->output()) {
|
|
std::shared_ptr<Message> msg;
|
|
if (!fakedev->com->decoder->decode(msg, packet))
|
|
continue; // We failed to decode this packet
|
|
|
|
if(!msg || msg->type != Message::Type::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 RED 2
|
|
|
|
auto device = foundDev.device;
|
|
device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0';
|
|
found.emplace_back(new NeoVIRED2(std::move(device)));
|
|
break;
|
|
}
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
static const std::vector<Network>& GetSupportedNetworks() {
|
|
static std::vector<Network> supportedNetworks = {
|
|
Network::NetID::HSCAN,
|
|
Network::NetID::MSCAN,
|
|
Network::NetID::HSCAN2,
|
|
Network::NetID::HSCAN3,
|
|
Network::NetID::HSCAN4,
|
|
Network::NetID::HSCAN5,
|
|
Network::NetID::HSCAN6,
|
|
Network::NetID::HSCAN7,
|
|
|
|
Network::NetID::Ethernet,
|
|
|
|
Network::NetID::LIN,
|
|
Network::NetID::LIN2
|
|
};
|
|
return supportedNetworks;
|
|
}
|
|
|
|
protected:
|
|
NeoVIRED2(neodevice_t neodevice) : Device(neodevice) {
|
|
initialize<PCAP, NeoVIRED2Settings>();
|
|
getWritableNeoDevice().type = DEVICE_TYPE;
|
|
productId = PRODUCT_ID;
|
|
}
|
|
|
|
virtual void setupEncoder(Encoder& encoder) override {
|
|
Device::setupEncoder(encoder);
|
|
encoder.supportCANFD = true;
|
|
}
|
|
|
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
|
for(auto& netid : GetSupportedNetworks())
|
|
rxNetworks.emplace_back(netid);
|
|
}
|
|
|
|
// The supported TX networks are the same as the supported RX networks for this device
|
|
virtual void setupSupportedTXNetworks(std::vector<Network>& txNetworks) override { setupSupportedRXNetworks(txNetworks); }
|
|
};
|
|
|
|
}
|
|
|
|
#endif |