Device component initialization done more intelligently

This commit is contained in:
Paul Hollinsky
2018-10-26 19:28:09 -04:00
parent 7e6282a7ad
commit a331a2afa8
24 changed files with 255 additions and 213 deletions
+39 -7
View File
@@ -6,6 +6,7 @@
#include <cstring>
#include "icsneo/device/neodevice.h"
#include "icsneo/device/idevicesettings.h"
#include "icsneo/device/nullsettings.h"
#include "icsneo/device/devicetype.h"
#include "icsneo/communication/communication.h"
#include "icsneo/communication/packetizer.h"
@@ -18,11 +19,6 @@ namespace icsneo {
class Device {
public:
Device(neodevice_t neodevice = { 0 }) {
data = neodevice;
data.device = this;
settings = std::unique_ptr<IDeviceSettings>(new IDeviceSettings(nullptr));
}
virtual ~Device() {
disableMessagePolling();
close();
@@ -67,8 +63,6 @@ public:
bool transmit(std::shared_ptr<Message> message);
bool transmit(std::vector<std::shared_ptr<Message>> messages);
void handleInternalMessage(std::shared_ptr<Message> message);
std::unique_ptr<IDeviceSettings> settings;
protected:
@@ -78,6 +72,44 @@ protected:
int internalHandlerCallbackID = 0;
std::shared_ptr<Communication> com;
// START Initialization Functions
Device(neodevice_t neodevice = { 0 }) {
data = neodevice;
data.device = this;
}
template<typename Transport, typename Settings = NullSettings>
void initialize();
template<typename Transport>
std::unique_ptr<ICommunication> makeTransport() { return std::unique_ptr<ICommunication>(new Transport(getWritableNeoDevice())); }
virtual void setupTransport(ICommunication* transport) {}
virtual std::shared_ptr<Packetizer> makePacketizer() { return std::make_shared<Packetizer>(); }
virtual void setupPacketizer(Packetizer* packetizer) {}
virtual std::unique_ptr<Encoder> makeEncoder(std::shared_ptr<Packetizer> p) { return std::unique_ptr<Encoder>(new Encoder(p)); }
virtual void setupEncoder(Encoder* encoder) {}
virtual std::unique_ptr<Decoder> makeDecoder() { return std::unique_ptr<Decoder>(new Decoder()); }
virtual void setupDecoder(Decoder* decoder) {}
virtual std::shared_ptr<Communication> makeCommunication(
std::unique_ptr<ICommunication> t,
std::shared_ptr<Packetizer> p,
std::unique_ptr<Encoder> e,
std::unique_ptr<Decoder> d) { return std::make_shared<Communication>(std::move(t), p, std::move(e), std::move(d)); }
virtual void setupCommunication(Communication* com) {}
template<typename Settings>
std::unique_ptr<IDeviceSettings> makeSettings(std::shared_ptr<Communication> com) {
return std::unique_ptr<IDeviceSettings>(new Settings(com));
}
virtual void setupSettings(IDeviceSettings* settings) {}
// END Initialization Functions
void handleInternalMessage(std::shared_ptr<Message> message);
neodevice_t& getWritableNeoDevice() { return data; }
private:
+8 -11
View File
@@ -12,24 +12,21 @@ public:
// Serial numbers are NP****
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::OBD2_PRO;
static constexpr const uint16_t PRODUCT_ID = 0x1103;
NeoOBD2PRO(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new STM32(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<NeoOBD2PRO>(neodevice));
found.emplace_back(new NeoOBD2PRO(neodevice));
return found;
}
private:
NeoOBD2PRO(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
+8 -11
View File
@@ -12,24 +12,21 @@ public:
// Serial numbers are OS****
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::OBD2_SIM;
static constexpr const uint16_t PRODUCT_ID = 0x1100;
NeoOBD2SIM(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new STM32(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<NeoOBD2SIM>(neodevice));
found.emplace_back(new NeoOBD2SIM(neodevice));
return found;
}
private:
NeoOBD2SIM(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
+13 -17
View File
@@ -12,15 +12,13 @@ class NeoVIFIRE : public Device {
public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::FIRE;
static constexpr const uint16_t PRODUCT_ID = 0x0701;
NeoVIFIRE(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
settings = std::unique_ptr<IDeviceSettings>(new NeoVIFIRESettings(com));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
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 NeoVIFIRE(neodevice)); // Creation of the shared_ptr
return found;
}
enum class Mode : char {
@@ -28,7 +26,7 @@ public:
Bootloader = 'B'
};
bool open() {
bool open() override {
if(!com)
return false;
@@ -53,13 +51,11 @@ public:
return true;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<NeoVIFIRE>(neodevice));
return found;
private:
NeoVIFIRE(neodevice_t neodevice) : Device(neodevice) {
initialize<FTDI, NeoVIFIRESettings>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
@@ -11,17 +11,15 @@ class NeoVIFIRE2 : public Device {
public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::FIRE2;
static constexpr const char* SERIAL_START = "CY";
protected:
NeoVIFIRE2(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
}
protected:
static std::shared_ptr<Communication> MakeCommunication(std::unique_ptr<ICommunication> transport) {
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
virtual void setupEncoder(Encoder* encoder) override {
Device::setupEncoder(encoder);
encoder->supportCANFD = true;
auto decoder = std::unique_ptr<Decoder>(new Decoder());
return std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
};
@@ -11,13 +11,6 @@ namespace icsneo {
class NeoVIFIRE2ETH : public NeoVIFIRE2 {
public:
static constexpr const uint16_t PRODUCT_ID = 0x0004;
NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
com = MakeCommunication(std::unique_ptr<ICommunication>(new PCAP(getWritableNeoDevice())));
settings = std::unique_ptr<IDeviceSettings>(new NeoVIFIRE2Settings(com));
settings->readonly = true;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
@@ -50,6 +43,18 @@ public:
return found;
}
protected:
virtual void setupSettings(IDeviceSettings* settings) {
// TODO Check firmware version, old firmwares will reset Ethernet settings on settings send
settings->readonly = true;
}
private:
NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
initialize<PCAP, NeoVIFIRE2Settings>();
productId = PRODUCT_ID;
}
};
}
@@ -10,20 +10,20 @@ namespace icsneo {
class NeoVIFIRE2USB : public NeoVIFIRE2 {
public:
static constexpr const uint16_t PRODUCT_ID = 0x1000;
NeoVIFIRE2USB(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
com = MakeCommunication(std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice())));
settings = std::unique_ptr<IDeviceSettings>(new NeoVIFIRE2Settings(com));
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<NeoVIFIRE2USB>(neodevice));
found.emplace_back(new NeoVIFIRE2USB(neodevice)); // Creation of the shared_ptr
return found;
}
private:
NeoVIFIRE2USB(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
initialize<FTDI, NeoVIFIRE2Settings>();
productId = PRODUCT_ID;
}
};
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef __NULL_SETTINGS_H_
#define __NULL_SETTINGS_H_
#include "icsneo/device/idevicesettings.h"
#include "icsneo/communication/communication.h"
#include <memory>
namespace icsneo {
class NullSettings : public IDeviceSettings {
public:
// Calls the base constructor with "createInoperableSettings"
NullSettings(std::shared_ptr<Communication> com = std::shared_ptr<Communication>()) : IDeviceSettings(nullptr) { (void)com; }
};
}
#endif
+8 -6
View File
@@ -11,19 +11,21 @@ class NeoVIION : public Plasion {
public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::ION;
static constexpr const uint16_t PRODUCT_ID = 0x0901;
NeoVIION(neodevice_t neodevice) : Plasion(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<NeoVIION>(neodevice));
found.emplace_back(new NeoVIION(neodevice));
return found;
}
private:
NeoVIION(neodevice_t neodevice) : Plasion(neodevice) {
initialize<FTDI>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
+8 -6
View File
@@ -11,19 +11,21 @@ class NeoVIPLASMA : public Plasion {
public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::PLASMA;
static constexpr const uint16_t PRODUCT_ID = 0x0801;
NeoVIPLASMA(neodevice_t neodevice) : Plasion(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<NeoVIPLASMA>(neodevice));
found.emplace_back(new NeoVIPLASMA(neodevice));
return found;
}
private:
NeoVIPLASMA(neodevice_t neodevice) : Plasion(neodevice) {
initialize<FTDI>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
+9 -7
View File
@@ -8,14 +8,16 @@
namespace icsneo {
class Plasion : public Device {
protected:
virtual std::shared_ptr<Communication> makeCommunication(
std::unique_ptr<ICommunication> transport,
std::shared_ptr<Packetizer> packetizer,
std::unique_ptr<Encoder> encoder,
std::unique_ptr<Decoder> decoder
) override { return std::make_shared<MultiChannelCommunication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder)); }
public:
Plasion(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<MultiChannelCommunication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
Plasion(neodevice_t neodevice) : Device(neodevice) {}
};
}
+18 -24
View File
@@ -15,35 +15,16 @@ public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADGalaxy;
static constexpr const uint16_t PRODUCT_ID = 0x0003;
static constexpr const char* SERIAL_START = "RG";
static std::shared_ptr<Packetizer> MakePacketizer() {
auto packetizer = std::make_shared<Packetizer>();
packetizer->disableChecksum = true;
packetizer->align16bit = false;
return packetizer;
}
RADGalaxy(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new PCAP(getWritableNeoDevice()));
auto packetizer = MakePacketizer();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) {
auto packetizer = MakePacketizer();
auto decoder = std::unique_ptr<Decoder>(new Decoder());
auto fakedev = std::shared_ptr<RADGalaxy>(new RADGalaxy({}));
for(auto& payload : foundDev.discoveryPackets)
packetizer->input(payload);
for(auto& packet : packetizer->output()) {
fakedev->com->packetizer->input(payload);
for(auto& packet : fakedev->com->packetizer->output()) {
std::shared_ptr<Message> msg;
if(!decoder->decode(msg, packet))
if(!fakedev->com->decoder->decode(msg, packet))
continue; // We failed to decode this packet
if(!msg || msg->network.getNetID() != Network::NetID::Main51)
@@ -58,13 +39,26 @@ public:
continue; // Not a RADGalaxy
foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0';
found.push_back(std::make_shared<RADGalaxy>(foundDev.device));
found.emplace_back(new RADGalaxy(foundDev.device));
break;
}
}
return found;
}
protected:
void setupPacketizer(Packetizer* packetizer) override {
packetizer->disableChecksum = true;
packetizer->align16bit = false;
}
private:
RADGalaxy(neodevice_t neodevice) : Device(neodevice) {
initialize<PCAP>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
@@ -12,6 +12,13 @@ public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADStar2;
static constexpr const uint16_t PRODUCT_ID = 0x0005;
static constexpr const char* SERIAL_START = "RS";
protected:
virtual void setupPacketizer(Packetizer* packetizer) override {
packetizer->disableChecksum = true;
packetizer->align16bit = false;
}
RADStar2(neodevice_t neodevice) : Device(neodevice) {
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
+9 -20
View File
@@ -10,33 +10,17 @@ namespace icsneo {
class RADStar2ETH : public RADStar2 {
public:
static std::shared_ptr<Packetizer> MakePacketizer() {
auto packetizer = std::make_shared<Packetizer>();
packetizer->disableChecksum = true;
packetizer->align16bit = false;
return packetizer;
}
// Serial numbers start with RS
RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new PCAP(getWritableNeoDevice()));
auto packetizer = MakePacketizer();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto& foundDev : PCAP::FindAll()) {
auto packetizer = MakePacketizer();
auto decoder = std::unique_ptr<Decoder>(new Decoder());
auto fakedev = std::shared_ptr<RADStar2ETH>(new RADStar2ETH({}));
for(auto& payload : foundDev.discoveryPackets)
packetizer->input(payload);
for(auto& packet : packetizer->output()) {
fakedev->com->packetizer->input(payload);
for(auto& packet : fakedev->com->packetizer->output()) {
std::shared_ptr<Message> msg;
if(!decoder->decode(msg, packet))
if(!fakedev->com->decoder->decode(msg, packet))
continue; // We failed to decode this packet
if(!msg || msg->network.getNetID() != Network::NetID::Main51)
@@ -58,6 +42,11 @@ public:
return found;
}
private:
RADStar2ETH(neodevice_t neodevice) : RADStar2(neodevice) {
initialize<PCAP>();
}
};
}
+6 -9
View File
@@ -9,22 +9,19 @@ namespace icsneo {
class RADStar2USB : public RADStar2 {
public:
// Serial numbers start with RS
RADStar2USB(neodevice_t neodevice) : RADStar2(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<RADStar2USB>(neodevice));
found.emplace_back(new RADStar2USB(neodevice));
return found;
}
private:
RADStar2USB(neodevice_t neodevice) : RADStar2(neodevice) {
initialize<FTDI>();
}
};
}
@@ -9,28 +9,24 @@ namespace icsneo {
class RADSupermoon : public Device {
public:
// Serial numbers start with VV
// RSM does not connect at all yet (needs FTDI D3xx driver, not the 2xx compatible one)
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADSupermoon;
static constexpr const uint16_t PRODUCT_ID = 0x1201;
RADSupermoon(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
// RSM does not connect at all yet (needs FTDI D3xx driver, not the 2xx compatible one)
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<RADSupermoon>(neodevice));
found.emplace_back(new RADSupermoon(neodevice));
return found;
}
private:
RADSupermoon(neodevice_t neodevice) : Device(neodevice) {
initialize<FTDI>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
+8 -11
View File
@@ -11,24 +11,21 @@ class ValueCAN3 : public Device {
public:
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN3;
static constexpr const uint16_t PRODUCT_ID = 0x0601;
ValueCAN3(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new FTDI(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : FTDI::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<ValueCAN3>(neodevice));
found.emplace_back(new ValueCAN3(neodevice));
return found;
}
private:
ValueCAN3(neodevice_t neodevice) : Device(neodevice) {
initialize<FTDI>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}
+12 -8
View File
@@ -11,23 +11,27 @@ class ValueCAN4_1 : public ValueCAN4 {
public:
// Serial numbers start with V1 for 4-1
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_1;
ValueCAN4_1(neodevice_t neodevice) : ValueCAN4(neodevice) {
com = MakeCommunication(getWritableNeoDevice());
com->encoder->supportCANFD = false; // VCAN 4-1 does not support CAN FD
settings = std::unique_ptr<IDeviceSettings>(new ValueCAN4_1Settings(com));
getWritableNeoDevice().type = DEVICE_TYPE;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == "V1")
found.push_back(std::make_shared<ValueCAN4_1>(neodevice));
found.emplace_back(new ValueCAN4_1(neodevice));
}
return found;
}
protected:
void setupEncoder(Encoder* encoder) override {
encoder->supportCANFD = false; // VCAN 4-1 does not support CAN FD
}
private:
ValueCAN4_1(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_1Settings>();
getWritableNeoDevice().type = DEVICE_TYPE;
}
};
}
@@ -11,22 +11,22 @@ class ValueCAN4_2 : public ValueCAN4 {
public:
// Serial numbers start with V2 for 4-2
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_2;
ValueCAN4_2(neodevice_t neodevice) : ValueCAN4(neodevice) {
com = MakeCommunication(getWritableNeoDevice());
settings = std::unique_ptr<IDeviceSettings>(new ValueCAN4_2Settings(com));
getWritableNeoDevice().type = DEVICE_TYPE;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == "V2")
found.push_back(std::make_shared<ValueCAN4_2>(neodevice));
found.emplace_back(new ValueCAN4_2(neodevice));
}
return found;
}
private:
ValueCAN4_2(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_2Settings>();
getWritableNeoDevice().type = DEVICE_TYPE;
}
};
}
@@ -11,22 +11,22 @@ class ValueCAN4_2EL : public ValueCAN4 {
public:
// Serial numbers start with VE for 4-2EL
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_2EL;
ValueCAN4_2EL(neodevice_t neodevice) : ValueCAN4(neodevice) {
com = MakeCommunication(getWritableNeoDevice());
settings = std::unique_ptr<IDeviceSettings>(new ValueCAN4_2ELSettings(com));
getWritableNeoDevice().type = DEVICE_TYPE;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == "VE")
found.push_back(std::make_shared<ValueCAN4_2EL>(neodevice));
found.emplace_back(new ValueCAN4_2EL(neodevice));
}
return found;
}
private:
ValueCAN4_2EL(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_2ELSettings>();
getWritableNeoDevice().type = DEVICE_TYPE;
}
};
}
@@ -11,22 +11,22 @@ class ValueCAN4_4 : public ValueCAN4 {
public:
// Serial numbers start with V4 for 4-4
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_4;
ValueCAN4_4(neodevice_t neodevice) : ValueCAN4(neodevice) {
com = MakeCommunication(getWritableNeoDevice());
settings = std::unique_ptr<IDeviceSettings>(new ValueCAN4_4Settings(com));
getWritableNeoDevice().type = DEVICE_TYPE;
}
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID)) {
if(std::string(neodevice.serial).substr(0, 2) == "V4")
found.push_back(std::make_shared<ValueCAN4_4>(neodevice));
found.emplace_back(new ValueCAN4_4(neodevice));
}
return found;
}
private:
ValueCAN4_4(neodevice_t neodevice) : ValueCAN4(neodevice) {
initialize<STM32, ValueCAN4_4Settings>();
getWritableNeoDevice().type = DEVICE_TYPE;
}
};
}
+5 -9
View File
@@ -10,18 +10,14 @@ namespace icsneo {
class ValueCAN4 : public Device {
public:
static constexpr const uint16_t PRODUCT_ID = 0x1101;
ValueCAN4(neodevice_t neodevice) : Device(neodevice) {
productId = PRODUCT_ID;
}
protected:
static std::shared_ptr<Communication> MakeCommunication(neodevice_t& nd) {
auto transport = std::unique_ptr<ICommunication>(new STM32(nd));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
virtual void setupEncoder(Encoder* encoder) override {
encoder->supportCANFD = true;
auto decoder = std::unique_ptr<Decoder>(new Decoder());
return std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
ValueCAN4(neodevice_t neodevice) : Device(neodevice) {
productId = PRODUCT_ID;
}
};
+10 -13
View File
@@ -12,26 +12,23 @@ public:
// Serial numbers start with VV
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VividCAN;
static constexpr const uint16_t PRODUCT_ID = 0x1102;
VividCAN(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::unique_ptr<ICommunication>(new STM32(getWritableNeoDevice()));
auto packetizer = std::make_shared<Packetizer>();
auto encoder = std::unique_ptr<Encoder>(new Encoder(packetizer));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
com = std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
bool goOnline() { return false; }
static std::vector<std::shared_ptr<Device>> Find() {
std::vector<std::shared_ptr<Device>> found;
for(auto neodevice : STM32::FindByProduct(PRODUCT_ID))
found.push_back(std::make_shared<VividCAN>(neodevice));
found.emplace_back(new VividCAN(neodevice));
return found;
}
bool goOnline() override { return false; }
private:
VividCAN(neodevice_t neodevice) : Device(neodevice) {
initialize<STM32>();
getWritableNeoDevice().type = DEVICE_TYPE;
productId = PRODUCT_ID;
}
};
}