Added the ability to get the baudrate for networks

This commit is contained in:
Paul Hollinsky
2018-12-10 14:57:43 -05:00
parent b12e7dad97
commit 3488e36f2a
11 changed files with 221 additions and 77 deletions
+21 -9
View File
@@ -13,7 +13,7 @@ enum
};
/* Baudrate in CAN_SETTINGS/CANFD_SETTINGS */
enum
enum CANBaudrate
{
BPS20,
BPS33,
@@ -282,6 +282,8 @@ class IDeviceSettings {
public:
static constexpr uint16_t GS_VERSION = 5;
static uint16_t CalculateGSChecksum(const std::vector<uint8_t>& settings);
static CANBaudrate GetEnumValueForBaudrate(int64_t baudrate);
static int64_t GetBaudrateValueForEnum(CANBaudrate enumValue);
IDeviceSettings(std::shared_ptr<Communication> com, size_t size) : com(com), err(com->err), structSize(size) {}
virtual ~IDeviceSettings() {}
@@ -293,19 +295,29 @@ public:
bool apply(bool temporary = false);
bool applyDefaults(bool temporary = false);
virtual bool setBaudrateFor(Network net, uint32_t baudrate);
virtual bool setFDBaudrateFor(Network net, uint32_t baudrate);
virtual int64_t getBaudrateFor(Network net) const;
virtual bool setBaudrateFor(Network net, int64_t baudrate);
virtual CAN_SETTINGS* getCANSettingsFor(Network net) { (void)net; return nullptr; }
virtual CANFD_SETTINGS* getCANFDSettingsFor(Network net) { (void)net; return nullptr; }
virtual int64_t getFDBaudrateFor(Network net) const;
virtual bool setFDBaudrateFor(Network net, int64_t baudrate);
virtual const CAN_SETTINGS* getCANSettingsFor(Network net) const { (void)net; return nullptr; }
CAN_SETTINGS* getCANSettingsFor(Network net) {
return const_cast<CAN_SETTINGS*>(static_cast<const IDeviceSettings*>(this)->getCANSettingsFor(net));
}
virtual const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const { (void)net; return nullptr; }
CANFD_SETTINGS* getCANFDSettingsFor(Network net) {
return const_cast<CANFD_SETTINGS*>(static_cast<const IDeviceSettings*>(this)->getCANFDSettingsFor(net));
}
const void* getRawStructurePointer() const { return settings.data(); }
void* getRawStructurePointer() { return settings.data(); }
template<typename T> T* getStructurePointer() { return static_cast<T*>((void*)settings.data()); }
template<typename T> T getStructureCopy() { return *getStructurePointer<T>(); }
template<typename T> const T* getStructurePointer() const { return static_cast<const T*>(getRawStructurePointer()); }
template<typename T> T* getStructurePointer() { return static_cast<T*>(getRawStructurePointer()); }
template<typename T> T getStructureCopy() const { return *getStructurePointer<T>(); }
template<typename T> bool setStructure(const T& newStructure);
uint8_t getEnumValueForBaudrate(uint32_t baudrate);
bool disabled = false;
bool readonly = false;
protected:
@@ -100,7 +100,7 @@ typedef struct {
class NeoVIFIRESettings : public IDeviceSettings {
public:
NeoVIFIRESettings(std::shared_ptr<Communication> com) : IDeviceSettings(com, sizeof(neovifire_settings_t)) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<neovifire_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -114,7 +114,7 @@ typedef struct {
class NeoVIFIRE2Settings : public IDeviceSettings {
public:
NeoVIFIRE2Settings(std::shared_ptr<Communication> com) : IDeviceSettings(com, sizeof(neovifire2_settings_t)) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<neovifire2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -137,7 +137,7 @@ public:
return nullptr;
}
}
CANFD_SETTINGS* getCANFDSettingsFor(Network net) override {
const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const override {
auto cfg = getStructurePointer<neovifire2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -36,7 +36,7 @@ typedef struct {
class ValueCAN3Settings : public IDeviceSettings {
public:
ValueCAN3Settings(std::shared_ptr<Communication> com) : IDeviceSettings(com, sizeof(valuecan3_settings_t)) {}
CAN_SETTINGS* getCANSettingsFor(Network net) override {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan3_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -10,7 +10,7 @@ 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 {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_1_2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -11,7 +11,7 @@ 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 {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -22,7 +22,7 @@ public:
return nullptr;
}
}
CANFD_SETTINGS* getCANFDSettingsFor(Network net) override {
const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -10,7 +10,7 @@ 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 {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_1_2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -21,7 +21,7 @@ public:
return nullptr;
}
}
CANFD_SETTINGS* getCANFDSettingsFor(Network net) override {
const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_1_2_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -11,7 +11,7 @@ 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 {
const CAN_SETTINGS* getCANSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
@@ -26,7 +26,7 @@ public:
return nullptr;
}
}
CANFD_SETTINGS* getCANFDSettingsFor(Network net) override {
const CANFD_SETTINGS* getCANFDSettingsFor(Network net) const override {
auto cfg = getStructurePointer<valuecan4_4_2el_settings_t>();
switch(net.getNetID()) {
case Network::NetID::HSCAN:
+35 -4
View File
@@ -357,6 +357,17 @@ extern bool DLLExport icsneo_settingsApplyDefaults(const neodevice_t* device);
*/
extern bool DLLExport icsneo_settingsApplyDefaultsTemporary(const neodevice_t* device);
/**
* \brief Get the network baudrate for a specified device.
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
* \param[in] netid The network for which the baudrate should be retrieved.
* \returns The value in baud with no multipliers. (i.e. 500k becomes 500000) A negative value is returned if an error occurs.
*
* In the case of CAN, this function gets the standard CAN baudrate.
* See icsneo_getFDBaudrate() to get the baudrate for (the baudrate-switched portion of) CAN FD.
*/
extern int64_t DLLExport icsneo_getBaudrate(const neodevice_t* device, uint16_t netid);
/**
* \brief Set the network baudrate for a specified device.
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
@@ -369,7 +380,17 @@ extern bool DLLExport icsneo_settingsApplyDefaultsTemporary(const neodevice_t* d
*
* Call icsneo_settingsApply() or similar to make the changes active on the device.
*/
extern bool DLLExport icsneo_setBaudrate(const neodevice_t* device, uint16_t netid, uint32_t newBaudrate);
extern bool DLLExport icsneo_setBaudrate(const neodevice_t* device, uint16_t netid, int64_t newBaudrate);
/**
* \brief Get the CAN FD baudrate for a specified device.
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
* \param[in] netid The network for which the baudrate should be retrieved.
* \returns The value in baud with no multipliers. (i.e. 500k becomes 500000) A negative value is returned if an error occurs.
*
* See icsneo_getBaudrate() to get the baudrate for the non baudrate-switched portion of CAN FD, classical CAN 2.0, and other network types.
*/
extern int64_t DLLExport icsneo_getFDBaudrate(const neodevice_t* device, uint16_t netid);
/**
* \brief Set the CAN FD baudrate for a specified device.
@@ -378,9 +399,11 @@ extern bool DLLExport icsneo_setBaudrate(const neodevice_t* device, uint16_t net
* \param[in] newBaudrate The requested baudrate, with no multipliers. (i.e. 2Mbaud CAN FD should be represented as 2000000)
* \returns True if the baudrate could be set.
*
* See icsneo_setBaudrate() to set the baudrate for the non baudrate-switched portion of CAN FD, classical CAN 2.0, and other network types.
*
* Call icsneo_settingsApply() or similar to make the changes active on the device.
*/
extern bool DLLExport icsneo_setFDBaudrate(const neodevice_t* device, uint16_t netid, uint32_t newBaudrate);
extern bool DLLExport icsneo_setFDBaudrate(const neodevice_t* device, uint16_t netid, int64_t newBaudrate);
/**
* \brief Transmit a single message.
@@ -626,10 +649,16 @@ fn_icsneo_settingsApplyDefaults icsneo_settingsApplyDefaults;
typedef bool(*fn_icsneo_settingsApplyDefaultsTemporary)(const neodevice_t* device);
fn_icsneo_settingsApplyDefaultsTemporary icsneo_settingsApplyDefaultsTemporary;
typedef bool(*fn_icsneo_setBaudrate)(const neodevice_t* device, uint16_t netid, uint32_t newBaudrate);
typedef int64_t(*fn_icsneo_getBaudrate)(const neodevice_t* device, uint16_t netid);
fn_icsneo_getBaudrate icsneo_getBaudrate;
typedef bool(*fn_icsneo_setBaudrate)(const neodevice_t* device, uint16_t netid, int64_t newBaudrate);
fn_icsneo_setBaudrate icsneo_setBaudrate;
typedef bool(*fn_icsneo_setFDBaudrate)(const neodevice_t* device, uint16_t netid, uint32_t newBaudrate);
typedef int64_t(*fn_icsneo_getFDBaudrate)(const neodevice_t* device, uint16_t netid);
fn_icsneo_getFDBaudrate icsneo_getFDBaudrate;
typedef bool(*fn_icsneo_setFDBaudrate)(const neodevice_t* device, uint16_t netid, int64_t newBaudrate);
fn_icsneo_setFDBaudrate icsneo_setFDBaudrate;
typedef bool(*fn_icsneo_transmit)(const neodevice_t* device, const neomessage_t* message);
@@ -700,7 +729,9 @@ int icsneo_init() {
ICSNEO_IMPORTASSERT(icsneo_settingsApplyTemporary);
ICSNEO_IMPORTASSERT(icsneo_settingsApplyDefaults);
ICSNEO_IMPORTASSERT(icsneo_settingsApplyDefaultsTemporary);
ICSNEO_IMPORTASSERT(icsneo_getBaudrate);
ICSNEO_IMPORTASSERT(icsneo_setBaudrate);
ICSNEO_IMPORTASSERT(icsneo_getFDBaudrate);
ICSNEO_IMPORTASSERT(icsneo_setFDBaudrate);
ICSNEO_IMPORTASSERT(icsneo_transmit);
ICSNEO_IMPORTASSERT(icsneo_transmitMessages);