#ifndef __VALUECAN4INDUSTRIAL_ETH_H_ #define __VALUECAN4INDUSTRIAL_ETH_H_ #ifdef __cplusplus #include "icsneo/device/tree/valuecan4/valuecan4industrial.h" #include "icsneo/platform/pcap.h" #include namespace icsneo { class ValueCAN4IndustrialETH : public ValueCAN4Industrial { public: static constexpr const uint16_t ETH_PRODUCT_ID = 0x0012; static std::vector> Find(const std::vector& pcapDevices) { std::vector> found; for(auto& foundDev : pcapDevices) { auto fakedev = std::shared_ptr(new ValueCAN4IndustrialETH({})); 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->type != Message::Type::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 ValueCAN 4 Industrial auto device = foundDev.device; device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0'; found.push_back(std::shared_ptr(new ValueCAN4IndustrialETH(std::move(device)))); break; } } return found; } static const std::vector& GetSupportedNetworks() { static std::vector supportedNetworks = { Network::NetID::HSCAN, Network::NetID::HSCAN2, // No Network::NetID::Ethernet, since we're communicating over it instead }; return supportedNetworks; } bool currentDriverSupportsDFU() const override { return false; } protected: 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); } private: ValueCAN4IndustrialETH(neodevice_t neodevice) : ValueCAN4Industrial(neodevice) { initialize(); } }; } #endif // __cplusplus #endif