#ifndef __RADPLUTO_H_ #define __RADPLUTO_H_ #include "icsneo/device/device.h" #include "icsneo/device/devicetype.h" #include "icsneo/platform/pcap.h" #include "icsneo/communication/packetizer.h" #include "icsneo/communication/decoder.h" namespace icsneo { class RADPluto : public Device { public: // Serial numbers start with PL static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADPluto; static constexpr const uint16_t PRODUCT_ID = 0xffff; // Not yet set static constexpr const char* SERIAL_START = "PL"; static std::vector> Find() { std::vector> found; for(auto& foundDev : PCAP::FindAll()) { auto fakedev = std::shared_ptr(new RADPluto({})); for(auto& payload : foundDev.discoveryPackets) fakedev->com->packetizer->input(payload); for(auto& packet : fakedev->com->packetizer->output()) { std::shared_ptr msg; if(!fakedev->com->decoder->decode(msg, packet)) continue; // We failed to decode this packet if(!msg || msg->network.getNetID() != Network::NetID::Main51) continue; // Not a message we care about auto sn = std::dynamic_pointer_cast(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 RADPluto foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0'; found.emplace_back(new RADPluto(foundDev.device)); break; } } return found; } static const std::vector& GetSupportedNetworks() { static std::vector supportedNetworks = { Network::NetID::HSCAN, Network::NetID::HSCAN2, Network::NetID::LIN, Network::NetID::Ethernet, Network::NetID::OP_Ethernet1, Network::NetID::OP_Ethernet2, Network::NetID::OP_Ethernet3, Network::NetID::OP_Ethernet4 }; return supportedNetworks; } RADPluto(neodevice_t neodevice) : Device(neodevice) { initialize(); getWritableNeoDevice().type = DEVICE_TYPE; productId = PRODUCT_ID; } protected: void setupPacketizer(Packetizer& packetizer) override { Device::setupPacketizer(packetizer); packetizer.disableChecksum = true; packetizer.align16bit = false; } virtual void setupEncoder(Encoder& encoder) override { Device::setupEncoder(encoder); encoder.supportCANFD = true; } virtual void setupDecoder(Decoder& decoder) override { Device::setupDecoder(decoder); decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns } virtual void setupSupportedRXNetworks(std::vector& 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& txNetworks) override { setupSupportedRXNetworks(txNetworks); } }; } #endif