7#include <QJsonDocument>
10#include <QtCore/QVector>
19 :
_ctx(std::move(ctx))
29 QJsonArray viewModelsArray;
31 for (
const auto& p :
_props) {
32 json[p.first] = QJsonValue::fromVariant(p.second);
40 if (json.contains(propName))
41 _props[propName] = json[propName].toVariant();
50 std::vector<devConfigPair> ret;
52 if (c.length() == 0) {
57 auto&& propList = c.split(
";");
59 for (
auto& item : propList) {
61 bool res = getConfigPair(item, pair);
93#if QT_VERSION >= 0x050900
97 p->addItems(QCanBus::instance()->plugins());
109 disconnect(_prevConn);
112 const QList<QCanBusDeviceInfo> devices = QCanBus::instance()->availableDevices(
113 backend, &errorString);
116 for(
auto&& d : devices) {
117 list.append(d.name());
120 if (errorString.isEmpty()) {
124 cds_error(
"Failed to get interface for '{}' backend", backend.toStdString());
125 cds_error(
"{}", errorString.toStdString());
151 auto configStr = in.split(
"=");
153 if ((configStr.length() != 2) || (configStr[1].length() == 0)) {
154 cds_error(
"Config parameter parse error");
158 auto keyStr = configStr[0];
159 auto valStr = configStr[1];
161 QCanBusDevice::ConfigurationKey key;
165 if (keyStr ==
"RawFilterKey") {
168 }
else if (keyStr ==
"ErrorFilterKey") {
169 cds_error(
"ErrorFilterKey not supported");
171 }
else if (keyStr ==
"LoopbackKey") {
172 key = QCanBusDevice::LoopbackKey;
173 val = valStr.toUpper() ==
"TRUE";
174 }
else if (keyStr ==
"ReceiveOwnKey") {
175 key = QCanBusDevice::ReceiveOwnKey;
176 val = valStr.toUpper() ==
"TRUE";
177 }
else if (keyStr ==
"BitRateKey") {
178 key = QCanBusDevice::BitRateKey;
179 val = valStr.toUInt(&res);
180 }
else if (keyStr ==
"CanFdKey") {
181 key = QCanBusDevice::CanFdKey;
182 val = valStr.toUpper() ==
"TRUE";
183#if QT_VERSION >= 0x050900
184 }
else if (keyStr ==
"DataBitRateKey") {
185 key = QCanBusDevice::DataBitRateKey;
186 val = valStr.toUInt(&res);
188 }
else if (keyStr ==
"UserKey") {
189 key = QCanBusDevice::UserKey;
192 cds_error(
"Failed to convert '{}' to ConfigurationKey", keyStr.toStdString());
197 cds_debug(
"Key: {}({}), Val: {}", keyStr.toStdString(), key, val.toString().toStdString());
198 out = std::make_pair(key, val);
205 QMetaObject::Connection _prevConn;
The class provides abstraction layer for CAN BUS hardware.
Definition candevice.h:15
Definition candevice_p.h:13
CanDeviceCtx _ctx
Definition candevice_p.h:75
void backendChanged(const QString &backend)
std::pair< int, QVariant > devConfigPair
Definition candevice_p.h:46
std::vector< devConfigPair > getDevConfig()
Definition candevice_p.h:47
const QString _backendProperty
Definition candevice_p.h:82
bool _initialized
Definition candevice_p.h:78
const QString _configProperty
Definition candevice_p.h:84
const QString _interfaceProperty
Definition candevice_p.h:83
CanDeviceInterface & _canDevice
Definition candevice_p.h:77
QVector< QCanBusFrame > _sendQueue
Definition candevice_p.h:76
void saveSettings(QJsonObject &json)
Definition candevice_p.h:27
bool restoreConfiguration(const QJsonObject &json)
Definition candevice_p.h:36
CanDevicePrivate(CanDevice *q, CanDeviceCtx &&ctx=CanDeviceCtx(new CanDeviceQt()))
Definition candevice_p.h:18
bool _simStarted
Definition candevice_p.h:79
std::map< QString, QVariant > _props
Definition candevice_p.h:139
ComponentInterface::CustomEditFieldCbk cf
Definition candevice_p.h:87
const QString _nameProperty
Definition candevice_p.h:81
ComponentInterface::ComponentProperties _supportedProps
Definition candevice_p.h:90
Definition propertyfields.h:86
void currentTextChanged(const QString &text)
Context< CanDeviceInterface > CanDeviceCtx
Definition context.h:41
#define cds_debug(fmt,...)
Definition log.h:13
#define cds_error(fmt,...)
Definition log.h:21
Definition candeviceinterface.h:8
virtual void setParent(QObject *parent)=0
Definition candeviceqt.h:9
std::vector< ComponentProperty > ComponentProperties
Definition componentinterface.h:66
std::function< QWidget *(void)> CustomEditFieldCbk
Definition componentinterface.h:64
static constexpr const QString & propertyName(const ComponentProperty &p)
Definition componentinterface.h:69