Settings: add APIs for LIN configuration
Add getter/setter APIs for LIN configuration: - baudrate - master resistor ON/OFF - mode (SLEEP, SLOW, NORMAL, FAST)pull/58/head
parent
02f1b4592e
commit
86ecfa7b5b
|
|
@ -116,6 +116,8 @@ static constexpr const char* A2B_MESSAGE_INCOMPLETE_FRAME = "At least one of the
|
||||||
static constexpr const char* COREMINI_UPLOAD_VERSION_MISMATCH = "The version of the coremini engine on the device and the script uploaded are not the same.";
|
static constexpr const char* COREMINI_UPLOAD_VERSION_MISMATCH = "The version of the coremini engine on the device and the script uploaded are not the same.";
|
||||||
static constexpr const char* DISK_NOT_CONNECTED = "The program tried to access a disk that is not connected.";
|
static constexpr const char* DISK_NOT_CONNECTED = "The program tried to access a disk that is not connected.";
|
||||||
static constexpr const char* UNEXPECTED_RESPONSE = "Received an unexpected or invalid response from the device.";
|
static constexpr const char* UNEXPECTED_RESPONSE = "Received an unexpected or invalid response from the device.";
|
||||||
|
static constexpr const char* LIN_SETTINGS_NOT_AVAILABLE = "LIN settings are not available for this device.";
|
||||||
|
static constexpr const char* MODE_NOT_FOUND = "The mode was not found.";
|
||||||
|
|
||||||
// Transport Errors
|
// Transport Errors
|
||||||
static constexpr const char* FAILED_TO_READ = "A read operation failed.";
|
static constexpr const char* FAILED_TO_READ = "A read operation failed.";
|
||||||
|
|
@ -302,6 +304,10 @@ const char* APIEvent::DescriptionForType(Type type) {
|
||||||
return DISK_NOT_CONNECTED;
|
return DISK_NOT_CONNECTED;
|
||||||
case Type::UnexpectedResponse:
|
case Type::UnexpectedResponse:
|
||||||
return UNEXPECTED_RESPONSE;
|
return UNEXPECTED_RESPONSE;
|
||||||
|
case Type::LINSettingsNotAvailable:
|
||||||
|
return LIN_SETTINGS_NOT_AVAILABLE;
|
||||||
|
case Type::ModeNotFound:
|
||||||
|
return MODE_NOT_FOUND;
|
||||||
// Transport Errors
|
// Transport Errors
|
||||||
case Type::FailedToRead:
|
case Type::FailedToRead:
|
||||||
return FAILED_TO_READ;
|
return FAILED_TO_READ;
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,37 @@ int64_t IDeviceSettings::GetBaudrateValueForEnum(CANBaudrate enumValue) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IDeviceSettings::ValidateLINBaudrate(int64_t baudrate) {
|
||||||
|
switch(baudrate) {
|
||||||
|
case 4800:
|
||||||
|
// fallthrough
|
||||||
|
case 9600:
|
||||||
|
// fallthrough
|
||||||
|
case 10400:
|
||||||
|
// fallthrough
|
||||||
|
case 10417:
|
||||||
|
// fallthrough
|
||||||
|
case 10504:
|
||||||
|
// fallthrough
|
||||||
|
case 10593:
|
||||||
|
// fallthrough
|
||||||
|
case 10684:
|
||||||
|
// fallthrough
|
||||||
|
case 10776:
|
||||||
|
// fallthrough
|
||||||
|
case 10870:
|
||||||
|
// fallthrough
|
||||||
|
case 10965:
|
||||||
|
// fallthrough
|
||||||
|
case 11062:
|
||||||
|
// fallthrough
|
||||||
|
case 19200:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool IDeviceSettings::refresh(bool ignoreChecksum) {
|
bool IDeviceSettings::refresh(bool ignoreChecksum) {
|
||||||
if(disabled) {
|
if(disabled) {
|
||||||
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
|
@ -414,6 +445,15 @@ int64_t IDeviceSettings::getBaudrateFor(Network net) const {
|
||||||
}
|
}
|
||||||
return baudrate;
|
return baudrate;
|
||||||
}
|
}
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg->Baudrate;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -493,6 +533,21 @@ bool IDeviceSettings::setBaudrateFor(Network net, int64_t baudrate) {
|
||||||
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
|
cfg->SetBaudrate = AUTO; // Device will use the baudrate value to set the TQ values
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid = ValidateLINBaudrate(baudrate);
|
||||||
|
if(!valid) {
|
||||||
|
report(APIEvent::Type::BaudrateNotFound, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cfg->Baudrate = baudrate;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -704,6 +759,186 @@ bool IDeviceSettings::setTerminationFor(Network net, bool enabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<bool> IDeviceSettings::isMasterResistorEnabledFor(Network net) const {
|
||||||
|
if(!settingsLoaded) {
|
||||||
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(disabled) {
|
||||||
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(net.getType()) {
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (cfg->MasterResistor != RESISTOR_OFF);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IDeviceSettings::setMasterResistorFor(Network net, bool resistor_on) {
|
||||||
|
if(disabled) {
|
||||||
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!settingsLoaded) {
|
||||||
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(readonly) {
|
||||||
|
report(APIEvent::Type::SettingsReadOnly, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(net.getType()) {
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg->MasterResistor = resistor_on ? RESISTOR_ON : RESISTOR_OFF;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<enum LINMode> IDeviceSettings::getLINModeFor(Network net) const {
|
||||||
|
if(!settingsLoaded) {
|
||||||
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(disabled) {
|
||||||
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(net.getType()) {
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (enum LINMode)cfg->Mode;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IDeviceSettings::setLINModeFor(Network net, enum LINMode mode) {
|
||||||
|
if(disabled) {
|
||||||
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!settingsLoaded) {
|
||||||
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(readonly) {
|
||||||
|
report(APIEvent::Type::SettingsReadOnly, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(net.getType()) {
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg->Mode = (uint8_t)mode;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<uint8_t> IDeviceSettings::getLINMasterSlaveIntervalFor(Network net) const {
|
||||||
|
if(!settingsLoaded) {
|
||||||
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(disabled) {
|
||||||
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(net.getType()) {
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
const LIN_SETTINGS* cfg = getLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg->numBitsDelay;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IDeviceSettings::setLINMasterSlaveIntervalFor(Network net, uint8_t bits) {
|
||||||
|
if(disabled) {
|
||||||
|
report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!settingsLoaded) {
|
||||||
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(readonly) {
|
||||||
|
report(APIEvent::Type::SettingsReadOnly, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(net.getType()) {
|
||||||
|
case Network::Type::LIN: {
|
||||||
|
LIN_SETTINGS* cfg = getMutableLINSettingsFor(net);
|
||||||
|
if(cfg == nullptr) {
|
||||||
|
report(APIEvent::Type::LINSettingsNotAvailable, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg->numBitsDelay = bits;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
report(APIEvent::Type::UnexpectedNetworkType, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T> bool IDeviceSettings::applyStructure(const T& newStructure) {
|
template<typename T> bool IDeviceSettings::applyStructure(const T& newStructure) {
|
||||||
if(!settingsLoaded) {
|
if(!settingsLoaded) {
|
||||||
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error);
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,8 @@ public:
|
||||||
LiveDataEncoderError = 0x2050,
|
LiveDataEncoderError = 0x2050,
|
||||||
LiveDataDecoderError = 0x2051,
|
LiveDataDecoderError = 0x2051,
|
||||||
LiveDataNotSupported = 0x2052,
|
LiveDataNotSupported = 0x2052,
|
||||||
|
LINSettingsNotAvailable = 0x2053,
|
||||||
|
ModeNotFound = 0x2054,
|
||||||
|
|
||||||
// Transport Events
|
// Transport Events
|
||||||
FailedToRead = 0x3000,
|
FailedToRead = 0x3000,
|
||||||
|
|
|
||||||
|
|
@ -544,7 +544,7 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Mode in LIN_SETTINGS */
|
/* Mode in LIN_SETTINGS */
|
||||||
enum
|
enum LINMode
|
||||||
{
|
{
|
||||||
SLEEP_MODE,
|
SLEEP_MODE,
|
||||||
SLOW_MODE,
|
SLOW_MODE,
|
||||||
|
|
@ -643,6 +643,7 @@ public:
|
||||||
static std::optional<uint16_t> CalculateGSChecksum(const std::vector<uint8_t>& settings, std::optional<size_t> knownSize = std::nullopt);
|
static std::optional<uint16_t> CalculateGSChecksum(const std::vector<uint8_t>& settings, std::optional<size_t> knownSize = std::nullopt);
|
||||||
static CANBaudrate GetEnumValueForBaudrate(int64_t baudrate);
|
static CANBaudrate GetEnumValueForBaudrate(int64_t baudrate);
|
||||||
static int64_t GetBaudrateValueForEnum(CANBaudrate enumValue);
|
static int64_t GetBaudrateValueForEnum(CANBaudrate enumValue);
|
||||||
|
static bool ValidateLINBaudrate(int64_t baudrate);
|
||||||
|
|
||||||
IDeviceSettings(std::shared_ptr<Communication> com, size_t size) : com(com), report(com->report), structSize(size) {}
|
IDeviceSettings(std::shared_ptr<Communication> com, size_t size) : com(com), report(com->report), structSize(size) {}
|
||||||
virtual ~IDeviceSettings() {}
|
virtual ~IDeviceSettings() {}
|
||||||
|
|
@ -700,6 +701,16 @@ public:
|
||||||
return reinterpret_cast<SWCAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
|
return reinterpret_cast<SWCAN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const LIN_SETTINGS* getLINSettingsFor(Network net) const { (void)net; return nullptr; }
|
||||||
|
LIN_SETTINGS* getMutableLINSettingsFor(Network net) {
|
||||||
|
if(disabled || readonly)
|
||||||
|
return nullptr;
|
||||||
|
const uint8_t* offset = (const uint8_t*)getLINSettingsFor(net);
|
||||||
|
if(offset == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
return reinterpret_cast<LIN_SETTINGS*>((void*)(settings.data() + (offset - settingsInDeviceRAM.data())));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some devices have groupings of networks, where software
|
* Some devices have groupings of networks, where software
|
||||||
* switchable termination can only be applied to one network
|
* switchable termination can only be applied to one network
|
||||||
|
|
@ -753,6 +764,53 @@ public:
|
||||||
*/
|
*/
|
||||||
bool setTerminationFor(Network net, bool enabled);
|
bool setTerminationFor(Network net, bool enabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether software switchable master resistor is currently
|
||||||
|
* enabled for a given network in the currently active device settings.
|
||||||
|
*
|
||||||
|
* Returns true if the call was successful, otherwise an error
|
||||||
|
* will have been reported in icsneo::getLastError().
|
||||||
|
*/
|
||||||
|
std::optional<bool> isMasterResistorEnabledFor(Network net) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable software switchable master resistor for a given
|
||||||
|
* network.
|
||||||
|
*
|
||||||
|
* Returns true if the call was successful, otherwise an error
|
||||||
|
* will have been reported in icsneo::getLastError().
|
||||||
|
*/
|
||||||
|
bool setMasterResistorFor(Network net, bool resistor_on);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get LIN mode for a given network in the currently active device
|
||||||
|
* settings.
|
||||||
|
*/
|
||||||
|
std::optional<enum LINMode> getLINModeFor(Network net) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set LIN mode for a given network.
|
||||||
|
*
|
||||||
|
* Returns true if the call was successful, otherwise an error
|
||||||
|
* will have been reported in icsneo::getLastError().
|
||||||
|
*/
|
||||||
|
bool setLINModeFor(Network net, enum LINMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of bit delays between Master ID and first Slave byte for
|
||||||
|
* a given network in the currently active device settings.
|
||||||
|
*/
|
||||||
|
std::optional<uint8_t> getLINMasterSlaveIntervalFor(Network net) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set number of bit delays between Master ID and first Slave byte for
|
||||||
|
* a given network
|
||||||
|
*
|
||||||
|
* Returns true if the call was successful, otherwise an error
|
||||||
|
* will have been reported in icsneo::getLastError().
|
||||||
|
*/
|
||||||
|
bool setLINMasterSlaveIntervalFor(Network net, uint8_t bits);
|
||||||
|
|
||||||
const void* getRawStructurePointer() const { return settingsInDeviceRAM.data(); }
|
const void* getRawStructurePointer() const { return settingsInDeviceRAM.data(); }
|
||||||
void* getMutableRawStructurePointer() { return settings.data(); }
|
void* getMutableRawStructurePointer() { return settings.data(); }
|
||||||
template<typename T> const T* getStructurePointer() const { return reinterpret_cast<const T*>(getRawStructurePointer()); }
|
template<typename T> const T* getStructurePointer() const { return reinterpret_cast<const T*>(getRawStructurePointer()); }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue