mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Device component initialization done more intelligently
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user