Detection for ValueCAN 4 models, as well as settings for each

pull/4/head
Paul Hollinsky 2018-10-19 13:43:36 -04:00
parent cb57f06564
commit 769c797a50
15 changed files with 425 additions and 19 deletions

View File

@ -55,8 +55,20 @@ std::vector<std::shared_ptr<Device>> DeviceFinder::FindAll() {
findResults.push_back(ValueCAN3::Find());
#endif
#ifdef __VALUECAN4_H_
findResults.push_back(ValueCAN4::Find());
#ifdef __VALUECAN4_1_H_
findResults.push_back(ValueCAN4_1::Find());
#endif
#ifdef __VALUECAN4_2_H_
findResults.push_back(ValueCAN4_2::Find());
#endif
#ifdef __VALUECAN4_2EL_H_
findResults.push_back(ValueCAN4_2EL::Find());
#endif
#ifdef __VALUECAN4_4_H_
findResults.push_back(ValueCAN4_4::Find());
#endif
#ifdef __VIVIDCAN_H_

View File

@ -0,0 +1,34 @@
#ifndef __VALUECAN4_1_H_
#define __VALUECAN4_1_H_
#include "device/valuecan4/include/valuecan4.h"
#include "device/valuecan4/settings/include/valuecan4-1settings.h"
#include <string>
namespace icsneo {
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());
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));
}
return found;
}
};
}
#endif

View File

@ -0,0 +1,34 @@
#ifndef __VALUECAN4_2_H_
#define __VALUECAN4_2_H_
#include "device/valuecan4/include/valuecan4.h"
#include "device/valuecan4/settings/include/valuecan4-2settings.h"
#include <string>
namespace icsneo {
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));
}
return found;
}
};
}
#endif

View File

@ -0,0 +1,34 @@
#ifndef __VALUECAN4_2EL_H_
#define __VALUECAN4_2EL_H_
#include "device/valuecan4/include/valuecan4.h"
#include "device/valuecan4/settings/include/valuecan4-2elsettings.h"
#include <string>
namespace icsneo {
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));
}
return found;
}
};
}
#endif

View File

@ -0,0 +1,34 @@
#ifndef __VALUECAN4_4_H_
#define __VALUECAN4_4_H_
#include "device/valuecan4/include/valuecan4.h"
#include "device/valuecan4/settings/include/valuecan4-4settings.h"
#include <string>
namespace icsneo {
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));
}
return found;
}
};
}
#endif

View File

@ -9,26 +9,18 @@ namespace icsneo {
class ValueCAN4 : public Device {
public:
// Serial numbers are V0 for 4-4, VE for 4-2EL, V2 for 4-2, and V1 for 4-1
static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::VCAN4_2; // TODO Split headers and determine the correct type
static constexpr const uint16_t PRODUCT_ID = 0x1101;
ValueCAN4(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<ValueCAN4>(neodevice));
return found;
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));
auto decoder = std::unique_ptr<Decoder>(new Decoder());
return std::make_shared<Communication>(std::move(transport), packetizer, std::move(encoder), std::move(decoder));
}
};

View File

@ -0,0 +1,21 @@
#ifndef __VALUECAN4_1_2_SETTINGS_H_
#define __VALUECAN4_1_2_SETTINGS_H_
#include "device/include/idevicesettings.h"
#include "device/valuecan4/settings/include/valuecan4settings.h"
#ifdef __cplusplus
namespace icsneo {
class ValueCAN4_1_2Settings : public IDeviceSettings {
public:
ValueCAN4_1_2Settings(std::shared_ptr<Communication> com) : IDeviceSettings(com, sizeof(valuecan4_1_2_settings_t)) {}
// We do not override getCANSettingsFor or getCANFDSettingsFor here because they will be device specific
};
}
#endif // __cplusplus
#endif

View File

@ -0,0 +1,29 @@
#ifndef __VALUECAN4_1_SETTINGS_H_
#define __VALUECAN4_1_SETTINGS_H_
#include "device/valuecan4/settings/include/valuecan4-1-2settings.h"
#ifdef __cplusplus
namespace icsneo {
class ValueCAN4_1Settings : public ValueCAN4_1_2Settings {
public:
ValueCAN4_1Settings(std::shared_ptr<Communication> com) : ValueCAN4_1_2Settings(com) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
auto cfg = getStructurePointer<valuecan4_1_2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
return &(cfg->can1);
default:
return nullptr;
}
}
// CANFD_SETTINGS* getCANFDSettingsFor(Network net) override { return nullptr; }
};
}
#endif // __cplusplus
#endif

View File

@ -0,0 +1,36 @@
#ifndef __VALUECAN4_2EL_SETTINGS_H_
#define __VALUECAN4_2EL_SETTINGS_H_
#include "device/include/idevicesettings.h"
#include "device/valuecan4/settings/include/valuecan4-4-2elsettings.h"
#ifdef __cplusplus
namespace icsneo {
class ValueCAN4_2ELSettings : public ValueCAN4_4_2ELSettings {
public:
ValueCAN4_2ELSettings(std::shared_ptr<Communication> com) : ValueCAN4_4_2ELSettings(com) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
return &(cfg->can1);
case Network::NetID::HSCAN2:
return &(cfg->can2);
case Network::NetID::HSCAN3:
return &(cfg->can3);
case Network::NetID::HSCAN4:
return &(cfg->can4);
default:
return nullptr;
}
}
// CANFD_SETTINGS* getCANFDSettingsFor(Network net) override { return nullptr; }
};
}
#endif // __cplusplus
#endif

View File

@ -0,0 +1,31 @@
#ifndef __VALUECAN4_2_SETTINGS_H_
#define __VALUECAN4_2_SETTINGS_H_
#include "device/valuecan4/settings/include/valuecan4-1-2settings.h"
#ifdef __cplusplus
namespace icsneo {
class ValueCAN4_2Settings : public ValueCAN4_1_2Settings {
public:
ValueCAN4_2Settings(std::shared_ptr<Communication> com) : ValueCAN4_1_2Settings(com) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
auto cfg = getStructurePointer<valuecan4_1_2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
return &(cfg->can1);
case Network::NetID::HSCAN2:
return &(cfg->can2);
default:
return nullptr;
}
}
// CANFD_SETTINGS* getCANFDSettingsFor(Network net) override { return nullptr; }
};
}
#endif // __cplusplus
#endif

View File

@ -0,0 +1,21 @@
#ifndef __VALUECAN4_4_2EL_SETTINGS_H_
#define __VALUECAN4_4_2EL_SETTINGS_H_
#include "device/include/idevicesettings.h"
#include "device/valuecan4/settings/include/valuecan4settings.h"
#ifdef __cplusplus
namespace icsneo {
class ValueCAN4_4_2ELSettings : public IDeviceSettings {
public:
ValueCAN4_4_2ELSettings(std::shared_ptr<Communication> com) : IDeviceSettings(com, sizeof(valuecan4_4_2el_settings_t)) {}
// We do not override getCANSettingsFor, getCANFDSettingsFor, or getEthernetSettingsFor here because they will be device specific
};
}
#endif // __cplusplus
#endif

View File

@ -0,0 +1,36 @@
#ifndef __VALUECAN4_4_SETTINGS_H_
#define __VALUECAN4_4_SETTINGS_H_
#include "device/include/idevicesettings.h"
#include "device/valuecan4/settings/include/valuecan4-4-2elsettings.h"
#ifdef __cplusplus
namespace icsneo {
class ValueCAN4_4Settings : public ValueCAN4_4_2ELSettings {
public:
ValueCAN4_4Settings(std::shared_ptr<Communication> com) : ValueCAN4_4_2ELSettings(com) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
return &(cfg->can1);
case Network::NetID::HSCAN2:
return &(cfg->can2);
case Network::NetID::HSCAN3:
return &(cfg->can3);
case Network::NetID::HSCAN4:
return &(cfg->can4);
default:
return nullptr;
}
}
// CANFD_SETTINGS* getCANFDSettingsFor(Network net) override { return nullptr; }
};
}
#endif // __cplusplus
#endif

View File

@ -0,0 +1,86 @@
#ifndef __VALUECAN4_SETTINGS_H_
#define __VALUECAN4_SETTINGS_H_
#include <stdint.h>
#include "device/include/idevicesettings.h"
#ifdef __cplusplus
namespace icsneo {
#endif
// This is where the actual settings structures for all the ValueCAN 4 line live
// ValueCAN 4-1 and 4-2 share a structure, and 4-4 shares with 4-2EL
#pragma pack(push, 2)
typedef struct {
/* Performance Test */
uint16_t perf_en;
CAN_SETTINGS can1;
CANFD_SETTINGS canfd1;
CAN_SETTINGS can2;
CANFD_SETTINGS canfd2;
uint64_t network_enables;
uint64_t termination_enables;
uint32_t pwr_man_timeout;
uint16_t pwr_man_enable;
uint16_t network_enabled_on_boot;
/* ISO15765-2 Transport Layer */
int16_t iso15765_separation_time_offset;
STextAPISettings text_api;
struct
{
uint32_t disableUsbCheckOnBoot : 1;
uint32_t enableLatencyTest : 1;
uint32_t reserved : 30;
} flags;
} valuecan4_1_2_settings_t, valuecan4_1_settings_t, valuecan4_2_settings_t;
typedef struct {
uint16_t perf_en;
CAN_SETTINGS can1;
CANFD_SETTINGS canfd1;
CAN_SETTINGS can2;
CANFD_SETTINGS canfd2;
CAN_SETTINGS can3;
CANFD_SETTINGS canfd3;
CAN_SETTINGS can4;
CANFD_SETTINGS canfd4;
uint16_t network_enables;
uint16_t network_enables_2;
LIN_SETTINGS lin1;
uint16_t network_enabled_on_boot;
int16_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 network_enables_3;
STextAPISettings text_api;
uint64_t termination_enables;
ETHERNET_SETTINGS ethernet;
struct
{
uint32_t enableLatencyTest : 1;
uint32_t enablePcEthernetComm : 1;
uint32_t reserved : 30;
} flags;
uint16_t pwr_man_enable;
uint16_t pwr_man_timeout;
} valuecan4_4_2el_settings_t, valuecan4_4_settings_t, valuecan4_2el_settings_t;
#pragma pack(pop)
#ifdef __cplusplus
} // End of namespace
#endif // __cplusplus
#endif

View File

@ -13,7 +13,10 @@
#include "device/radstar2/include/radstar2usb.h"
#include "device/radsupermoon/include/radsupermoon.h"
#include "device/valuecan3/include/valuecan3.h"
#include "device/valuecan4/include/valuecan4.h"
#include "device/valuecan4/include/valuecan4-1.h"
#include "device/valuecan4/include/valuecan4-2.h"
#include "device/valuecan4/include/valuecan4-2el.h"
#include "device/valuecan4/include/valuecan4-4.h"
#include "device/vividcan/include/vividcan.h"
#endif

View File

@ -13,7 +13,10 @@
#include "device/radstar2/include/radstar2usb.h"
#include "device/radsupermoon/include/radsupermoon.h"
#include "device/valuecan3/include/valuecan3.h"
#include "device/valuecan4/include/valuecan4.h"
#include "device/valuecan4/include/valuecan4-1.h"
#include "device/valuecan4/include/valuecan4-2.h"
#include "device/valuecan4/include/valuecan4-2el.h"
#include "device/valuecan4/include/valuecan4-4.h"
#include "device/vividcan/include/vividcan.h"
#endif