mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Begin work on FlexRay support
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#ifndef __RADSTAR2_H_
|
||||
#define __RADSTAR2_H_
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/devicetype.h"
|
||||
#include "icsneo/device/tree/radstar2/radstar2settings.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class RADStar2 : public Device {
|
||||
public:
|
||||
// Serial numbers start with RS
|
||||
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADStar2;
|
||||
static constexpr const uint16_t PRODUCT_ID = 0x0005;
|
||||
static constexpr const char* SERIAL_START = "RS";
|
||||
|
||||
static const std::vector<Network>& GetSupportedNetworks() {
|
||||
static std::vector<Network> supportedNetworks = {
|
||||
Network::NetID::HSCAN,
|
||||
Network::NetID::MSCAN,
|
||||
|
||||
Network::NetID::LIN,
|
||||
|
||||
Network::NetID::OP_Ethernet1,
|
||||
Network::NetID::OP_Ethernet2
|
||||
};
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual 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<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); }
|
||||
|
||||
RADStar2(neodevice_t neodevice) : Device(neodevice) {
|
||||
getWritableNeoDevice().type = DEVICE_TYPE;
|
||||
productId = PRODUCT_ID;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef __RADSTAR2ETH_H_
|
||||
#define __RADSTAR2ETH_H_
|
||||
|
||||
#include "icsneo/device/tree/radstar2/radstar2.h"
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/communication/message/serialnumbermessage.h"
|
||||
#include "icsneo/platform/pcap.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class RADStar2ETH : public RADStar2 {
|
||||
public:
|
||||
// Serial numbers start with RS
|
||||
static std::vector<std::shared_ptr<Device>> Find() {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto& foundDev : PCAP::FindAll()) {
|
||||
auto fakedev = std::shared_ptr<RADStar2ETH>(new RADStar2ETH({}));
|
||||
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->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 RADStar2
|
||||
|
||||
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
|
||||
found.push_back(std::make_shared<RADStar2ETH>(foundDev.device));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) {
|
||||
initialize<PCAP, RADStar2Settings>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef __RADSTAR2SETTINGS_H_
|
||||
#define __RADSTAR2SETTINGS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "icsneo/device/idevicesettings.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 2)
|
||||
typedef struct {
|
||||
uint16_t perf_en;
|
||||
|
||||
OP_ETH_GENERAL_SETTINGS opEthGen;
|
||||
OP_ETH_SETTINGS opEth1;
|
||||
OP_ETH_SETTINGS opEth2;
|
||||
|
||||
CAN_SETTINGS can1;
|
||||
CANFD_SETTINGS canfd1;
|
||||
CAN_SETTINGS can2;
|
||||
CANFD_SETTINGS canfd2;
|
||||
|
||||
uint16_t network_enables;
|
||||
uint16_t network_enables_2;
|
||||
|
||||
LIN_SETTINGS lin1;
|
||||
uint16_t misc_io_initial_ddr;
|
||||
uint16_t misc_io_initial_latch;
|
||||
uint16_t misc_io_report_period;
|
||||
uint16_t misc_io_on_report_events;
|
||||
uint16_t misc_io_analog_enable;
|
||||
uint16_t ain_sample_period;
|
||||
uint16_t ain_threshold;
|
||||
|
||||
uint32_t pwr_man_timeout;
|
||||
uint16_t pwr_man_enable;
|
||||
|
||||
uint16_t network_enabled_on_boot;
|
||||
|
||||
uint16_t iso15765_separation_time_offset;
|
||||
|
||||
uint16_t iso_9141_kwp_enable_reserved;
|
||||
ISO9141_KEYWORD2000_SETTINGS iso9141_kwp_settings_1;
|
||||
uint16_t iso_parity_1;
|
||||
|
||||
uint16_t iso_msg_termination_1;
|
||||
|
||||
uint16_t idle_wakeup_network_enables_1;
|
||||
uint16_t idle_wakeup_network_enables_2;
|
||||
|
||||
uint16_t network_enables_3;
|
||||
uint16_t idle_wakeup_network_enables_3;
|
||||
|
||||
uint16_t can_switch_mode;
|
||||
STextAPISettings text_api;
|
||||
uint16_t pc_com_mode;
|
||||
TIMESYNC_ICSHARDWARE_SETTINGS timeSyncSettings;
|
||||
uint16_t hwComLatencyTestEn;
|
||||
} radstar2_settings_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class RADStar2Settings : public IDeviceSettings {
|
||||
public:
|
||||
RADStar2Settings(std::shared_ptr<Communication> com) : IDeviceSettings(com, sizeof(radstar2_settings_t)) {
|
||||
disableGSChecksumming = true;
|
||||
}
|
||||
|
||||
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
|
||||
auto cfg = getStructurePointer<radstar2_settings_t>();
|
||||
if(cfg == nullptr)
|
||||
return nullptr;
|
||||
switch(net.getNetID()) {
|
||||
case Network::NetID::HSCAN:
|
||||
return &(cfg->can1);
|
||||
case Network::NetID::MSCAN:
|
||||
return &(cfg->can2);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const override {
|
||||
auto cfg = getStructurePointer<radstar2_settings_t>();
|
||||
if(cfg == nullptr)
|
||||
return nullptr;
|
||||
switch(net.getNetID()) {
|
||||
case Network::NetID::HSCAN:
|
||||
return &(cfg->canfd1);
|
||||
case Network::NetID::MSCAN:
|
||||
return &(cfg->canfd2);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef __RADSTAR2USB_H_
|
||||
#define __RADSTAR2USB_H_
|
||||
|
||||
#include "icsneo/device/tree/radstar2/radstar2.h"
|
||||
#include "icsneo/platform/ftdi.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class RADStar2USB : public RADStar2 {
|
||||
public:
|
||||
// Serial numbers start with RS
|
||||
static std::vector<std::shared_ptr<Device>> Find() {
|
||||
std::vector<std::shared_ptr<Device>> found;
|
||||
|
||||
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
|
||||
found.emplace_back(new RADStar2USB(neodevice));
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private:
|
||||
RADStar2USB(neodevice_t neodevice) : RADStar2(neodevice) {
|
||||
initialize<FTDI, RADStar2Settings>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user