diff --git a/device/devicefinder.cpp b/device/devicefinder.cpp index ba6ffa5..e636cc0 100644 --- a/device/devicefinder.cpp +++ b/device/devicefinder.cpp @@ -19,6 +19,10 @@ static std::vector supportedDevices = { NeoOBD2SIM::DEVICE_TYPE, #endif + #ifdef __NEOVIRED2_H_ + NeoVIRED2::DEVICE_TYPE, + #endif + #ifdef __NEOVIFIRE_H_ NeoVIFIRE::DEVICE_TYPE, #endif @@ -153,6 +157,10 @@ std::vector> DeviceFinder::FindAll() { findResults.push_back(NeoVIFIRE2USB::Find()); #endif + #ifdef __NEOVIRED2_H_ + findResults.push_back(NeoVIRED2::Find(pcapDevices)); + #endif + #ifdef __NEOVIION_H_ findResults.push_back(NeoVIION::Find()); #endif diff --git a/include/icsneo/device/devicetype.h b/include/icsneo/device/devicetype.h index b6011ff..a46391b 100644 --- a/include/icsneo/device/devicetype.h +++ b/include/icsneo/device/devicetype.h @@ -42,6 +42,7 @@ public: RADJupiter = (0x00000011), VCAN4_IND = (0x00000012), RADGigastar = (0x00000013), + RED2 = (0x00000014), EtherBADGE = (0x00000016), RED = (0x00000040), ECU = (0x00000080), @@ -119,6 +120,8 @@ public: return "ValueCAN 4 Industrial"; case RADGigastar: return "RAD-Gigastar"; + case RED2: + return "neoVI RED 2"; case EtherBADGE: return "EtherBADGE"; case RED: @@ -210,6 +213,7 @@ private: #define ICSNEO_DEVICETYPE_RADJUPITER ((devicetype_t)0x00000011) #define ICSNEO_DEVICETYPE_VCAN4_IND ((devicetype_t)0x00000012) #define ICSNEO_DEVICETYPE_RADGIGASTAR ((devicetype_t)0x00000013) +#define ICSNEO_DEVICETYPE_RED2 ((devicetype_t)0x00000014) #define ICSNEO_DEVICETYPE_ETHERBADGE ((devicetype_t)0x00000016) #define ICSNEO_DEVICETYPE_RED ((devicetype_t)0x00000040) #define ICSNEO_DEVICETYPE_ECU ((devicetype_t)0x00000080) diff --git a/include/icsneo/device/tree/neovired2/neovired2.h b/include/icsneo/device/tree/neovired2/neovired2.h new file mode 100644 index 0000000..93cc464 --- /dev/null +++ b/include/icsneo/device/tree/neovired2/neovired2.h @@ -0,0 +1,91 @@ +#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> Find(const std::vector& pcapDevices) { + std::vector> found; + + for(auto& foundDev : pcapDevices) { + auto fakedev = std::shared_ptr(new NeoVIRED2({})); + 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 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& GetSupportedNetworks() { + static std::vector 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(); + getWritableNeoDevice().type = DEVICE_TYPE; + productId = PRODUCT_ID; + } + + virtual void setupEncoder(Encoder& encoder) override { + Device::setupEncoder(encoder); + encoder.supportCANFD = true; + } + + 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 \ No newline at end of file diff --git a/include/icsneo/device/tree/neovired2/neovired2settings.h b/include/icsneo/device/tree/neovired2/neovired2settings.h new file mode 100644 index 0000000..416d54d --- /dev/null +++ b/include/icsneo/device/tree/neovired2/neovired2settings.h @@ -0,0 +1,178 @@ +#ifndef __NEOVIRED2SETTINGS_H_ +#define __NEOVIRED2SETTINGS_H_ + +#include +#include "icsneo/device/idevicesettings.h" + +#ifdef __cplusplus + +namespace icsneo { + +#endif + +#pragma pack(push, 2) +typedef struct { + uint16_t perf_en; + uint16_t network_enabled_on_boot; + uint16_t misc_io_on_report_events; + uint16_t pwr_man_enable; + int16_t iso15765_separation_time_offset; + uint16_t slaveVnetA; + uint32_t reserved; + uint64_t termination_enables; + union { + uint64_t word; + struct + { + uint16_t network_enables; + uint16_t network_enables_2; + uint16_t network_enables_3; + }; + } network_enables; + uint32_t pwr_man_timeout; + CAN_SETTINGS can1; + CANFD_SETTINGS canfd1; + CAN_SETTINGS can2; + CANFD_SETTINGS canfd2; + CAN_SETTINGS can3; + CANFD_SETTINGS canfd3; + CAN_SETTINGS can4; + CANFD_SETTINGS canfd4; + CAN_SETTINGS can5; + CANFD_SETTINGS canfd5; + CAN_SETTINGS can6; + CANFD_SETTINGS canfd6; + CAN_SETTINGS can7; + CANFD_SETTINGS canfd7; + CAN_SETTINGS can8; + CANFD_SETTINGS canfd8; + LIN_SETTINGS lin1; + LIN_SETTINGS lin2; + ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_1; + uint16_t iso_parity_1; + uint16_t iso_msg_termination_1; + ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_2; + uint16_t iso_parity_2; + uint16_t iso_msg_termination_2; + ETHERNET_SETTINGS ethernet; + TIMESYNC_ICSHARDWARE_SETTINGS timeSync; + STextAPISettings text_api; + struct + { + uint32_t disableUsbCheckOnBoot : 1; + uint32_t enableLatencyTest : 1; + uint32_t busMessagesToAndroid : 1; + uint32_t enablePcEthernetComm : 1; + uint32_t enableDefaultLogger : 1; + uint32_t enableDefaultUpload : 1; + uint32_t reserved : 26; + } flags; + DISK_SETTINGS disk; + uint16_t misc_io_report_period; + uint16_t ain_threshold; + uint16_t misc_io_analog_enable; + uint16_t digitalIoThresholdTicks; + uint16_t digitalIoThresholdEnable; + uint16_t misc_io_initial_ddr; + uint16_t misc_io_initial_latch; + ETHERNET_SETTINGS2 ethernet2; +} neovired2_settings_t; + +typedef struct { + uint8_t backupPowerGood; + uint8_t backupPowerEnabled; + uint8_t usbHostPowerEnabled; + uint8_t ethernetActivationLineEnabled; + EthernetNetworkStatus ethernetStatus; +} neovired2_status_t; +#pragma pack(pop) + +#ifdef __cplusplus + +#include + +class NeoVIRED2Settings : public IDeviceSettings { +public: + NeoVIRED2Settings(std::shared_ptr com) : IDeviceSettings(com, sizeof(neovired2_settings_t)) {} + const CAN_SETTINGS* getCANSettingsFor(Network net) const override { + auto cfg = getStructurePointer(); + if(cfg == nullptr) + return nullptr; + switch(net.getNetID()) { + case Network::NetID::HSCAN: + return &(cfg->can1); + case Network::NetID::MSCAN: + return &(cfg->can2); + case Network::NetID::HSCAN2: + return &(cfg->can3); + case Network::NetID::HSCAN3: + return &(cfg->can4); + case Network::NetID::HSCAN4: + return &(cfg->can5); + case Network::NetID::HSCAN5: + return &(cfg->can6); + case Network::NetID::HSCAN6: + return &(cfg->can7); + case Network::NetID::HSCAN7: + return &(cfg->can8); + default: + return nullptr; + } + } + const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const override { + auto cfg = getStructurePointer(); + if(cfg == nullptr) + return nullptr; + switch(net.getNetID()) { + case Network::NetID::HSCAN: + return &(cfg->canfd1); + case Network::NetID::MSCAN: + return &(cfg->canfd2); + case Network::NetID::HSCAN2: + return &(cfg->canfd3); + case Network::NetID::HSCAN3: + return &(cfg->canfd4); + case Network::NetID::HSCAN4: + return &(cfg->canfd5); + case Network::NetID::HSCAN5: + return &(cfg->canfd6); + case Network::NetID::HSCAN6: + return &(cfg->canfd7); + case Network::NetID::HSCAN7: + return &(cfg->canfd8); + default: + return nullptr; + } + } + + virtual std::vector getTerminationGroups() const override { + return { + { + Network(Network::NetID::HSCAN), + Network(Network::NetID::HSCAN3), + Network(Network::NetID::HSCAN5), + Network(Network::NetID::HSCAN7) + }, + { + Network(Network::NetID::MSCAN), + Network(Network::NetID::HSCAN2), + Network(Network::NetID::HSCAN4), + Network(Network::NetID::HSCAN6) + } + }; + } + +protected: + ICSNEO_UNALIGNED(const uint64_t*) getTerminationEnables() const override { + auto cfg = getStructurePointer(); + if(cfg == nullptr) + return nullptr; + return &cfg->termination_enables; + } +}; + +} + +#endif // __cplusplus + +#endif \ No newline at end of file diff --git a/include/icsneo/platform/posix/devices.h b/include/icsneo/platform/posix/devices.h index 90149d4..49b9cf0 100644 --- a/include/icsneo/platform/posix/devices.h +++ b/include/icsneo/platform/posix/devices.h @@ -7,6 +7,7 @@ #include "icsneo/device/tree/neovifire/neovifire.h" #include "icsneo/device/tree/neovifire2/neovifire2eth.h" #include "icsneo/device/tree/neovifire2/neovifire2usb.h" +#include "icsneo/device/tree/neovired2/neovired2.h" #include "icsneo/device/tree/plasion/neoviion.h" #include "icsneo/device/tree/plasion/neoviplasma.h" #include "icsneo/device/tree/radgalaxy/radgalaxy.h" diff --git a/include/icsneo/platform/windows/devices.h b/include/icsneo/platform/windows/devices.h index 2c7b882..f9008dd 100644 --- a/include/icsneo/platform/windows/devices.h +++ b/include/icsneo/platform/windows/devices.h @@ -7,6 +7,7 @@ #include "icsneo/device/tree/neovifire/neovifire.h" #include "icsneo/device/tree/neovifire2/neovifire2eth.h" #include "icsneo/device/tree/neovifire2/neovifire2usb.h" +#include "icsneo/device/tree/neovired2/neovired2.h" #include "icsneo/device/tree/plasion/neoviion.h" #include "icsneo/device/tree/plasion/neoviplasma.h" #include "icsneo/device/tree/radgalaxy/radgalaxy.h"