Skip to content

Commit 96a5382

Browse files
committed
start adding definitions for Quirks
1 parent 150bd77 commit 96a5382

File tree

5 files changed

+199
-18
lines changed

5 files changed

+199
-18
lines changed

data/Quirks.xml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<QuirkData xmlns='https://github.com/OpenZWave/open-zwave'>
3+
<Quirk name="action">
4+
</Quirk>
5+
<Quirk name="base">
6+
</Quirk>
7+
<Quirk name="override_precision">
8+
</Quirk>
9+
<Quirk name="scenecount">
10+
</Quirk>
11+
<Quirk name="create_vars">
12+
<option name="true"/>
13+
<option name="false"/>
14+
</Quirk>
15+
<Quirk name="setasreport">
16+
<option name="true"/>
17+
<option name="false"/>
18+
</Quirk>
19+
<Quirk name="ignoreremapping">
20+
<option name="true"/>
21+
<option name="false"/>
22+
</Quirk>
23+
<Quirk name="getsupported">
24+
<option name="true"/>
25+
<option name="false"/>
26+
</Quirk>
27+
<Quirk name="classgetsupported">
28+
<option name="true"/>
29+
<option name="false"/>
30+
</Quirk>
31+
<Quirk name="coloridxbug">
32+
<option name="true"/>
33+
<option name="false"/>
34+
</Quirk>
35+
<Quirk name="forceUniqueEndpoints">
36+
<option name="true"/>
37+
<option name="false"/>
38+
</Quirk>
39+
<Quirk name="ForceInstances">
40+
<option name="true"/>
41+
<option name="false"/>
42+
</Quirk>
43+
<Quirk name="ignoreUnsolicitedMultiChnCapReport" CommandClass="96">
44+
<option name="true"/>
45+
<option name="false"/>
46+
<Help>Blahblah</Help>
47+
</Quirk>
48+
</QuirkData>

devicedb-lib/devicedb.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <QtWidgets>
1818

1919
#include "devicedb.hpp"
20-
20+
#include "devicequirks.h"
2121
#include "ui_devicedb.h"
2222

2323
DeviceDB::DeviceDB(QWidget *parent) :
@@ -27,6 +27,7 @@ DeviceDB::DeviceDB(QWidget *parent) :
2727
m_Path("config/")
2828
{
2929
ui->setupUi(this);
30+
qDebug() << DeviceQuirks::GetInstance().isReady();
3031
this->ui->saveBtn->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
3132
this->ui->saveBtn->button(QDialogButtonBox::Save)->setEnabled(false);
3233
deviceTree = new DeviceDBXMLReader(this);

devicedb-lib/devicequirks.cpp

+112
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,118 @@
11
#include "devicequirks.h"
2+
#include <QFile>
3+
#include <QDebug>
4+
#include <QMessageBox>
5+
#include <QDir>
6+
7+
8+
bool parseNumberList(QString str, QList<uint8_t> &list) {
9+
size_t pos = 0;
10+
size_t start = 0;
11+
bool parsing = true;
12+
while( parsing )
13+
{
14+
std::string ccStr;
15+
16+
pos = str.toStdString().find_first_of( ",", start );
17+
if( std::string::npos == pos )
18+
{
19+
ccStr = str.toStdString().substr( start );
20+
parsing = false;
21+
}
22+
else
23+
{
24+
ccStr = str.toStdString().substr( start, pos-start );
25+
start = pos + 1;
26+
}
27+
QString result = QString::fromStdString(ccStr);
28+
list.push_back(result.toInt());
29+
}
30+
return true;
31+
}
232

333
DeviceQuirks::DeviceQuirks(QObject *parent) : QObject(parent)
434
{
35+
QString errorStr;
36+
int errorLine;
37+
int errorColumn;
38+
39+
qDebug() << QDir(".").absolutePath();
40+
QFile mfxml("Quirks.xml");
41+
if (!mfxml.open(QFile::ReadOnly | QFile::Text)) {
42+
QMessageBox::warning(nullptr, tr("QXmlStream Quirks"),
43+
tr("Cannot read file %1:\n%2.")
44+
.arg(mfxml.fileName())
45+
.arg(mfxml.errorString()));
46+
this->setReady(false);
47+
return;
48+
}
49+
if (!domDocument.setContent(&mfxml, false,&errorStr, &errorLine, &errorColumn)) {
50+
QMessageBox::information(nullptr, tr("Quirks Database"), tr("Parse Error at line %1, column %2:\n%3")
51+
.arg(errorLine)
52+
.arg(errorColumn)
53+
.arg(errorStr));
54+
return;
55+
}
56+
57+
QDomElement root = domDocument.documentElement();
58+
if (root.tagName() != "QuirkData") {
59+
QMessageBox::information(nullptr, tr("Quirks Database"),
60+
tr("The file is not an Quirk file."));
61+
return;
62+
}
63+
64+
QDomElement child = root.firstChildElement("Quirk");
65+
while (!child.isNull()) {
66+
QString name = child.attribute("name");
67+
QuirksEntry *entry = new QuirksEntry();
68+
if (child.hasAttribute("CommandClass"))
69+
parseNumberList(child.attribute("CommandClass"), entry->CommandClasses);
70+
if (child.hasChildNodes()) {
71+
QDomNode options = child.firstChild();
72+
while (!options.isNull()) {
73+
if (options.nodeName().toUpper() == "OPTION")
74+
entry->options.push_back(options.toElement().attribute("name"));
75+
else if (options.nodeName().toUpper() == "HELP")
76+
entry->Help = options.firstChild().toText().data();
77+
options = options.nextSibling();
78+
}
79+
}
80+
this->m_quirks.insert(name, entry);
81+
child = child.nextSiblingElement();
82+
}
83+
84+
mfxml.close();
85+
this->setReady(true);
86+
this->dump();
87+
}
588

89+
DeviceQuirks &DeviceQuirks::GetInstance() {
90+
static DeviceQuirks instance;
91+
return instance;
692
}
93+
94+
void DeviceQuirks::setReady(bool ready) {
95+
this->m_Ready = ready;
96+
}
97+
bool DeviceQuirks::isReady() const {
98+
return this->m_Ready;
99+
}
100+
101+
void DeviceQuirks::dump() {
102+
QHash<QString, QuirksEntry*>::iterator it;
103+
for (it = this->m_quirks.begin(); it != this->m_quirks.end(); ++it) {
104+
qDebug() << it.key();
105+
qDebug() << "\tOptions:";
106+
for (int i = 0; i < it.value()->options.count(); ++i)
107+
qDebug() << "\t\t" << it.value()->options.at(i);
108+
qDebug() << "\tCommandClasses:";
109+
for (int i = 0; i < it.value()->CommandClasses.count(); ++i)
110+
qDebug() << "\t\t" << it.value()->CommandClasses.at(i);
111+
qDebug() << "\tHelp:";
112+
qDebug() << "\t\t" << it.value()->Help;
113+
}
114+
}
115+
116+
117+
118+

devicedb-lib/devicequirks.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,33 @@
22
#define DEVICEQUIRKS_H
33

44
#include <QObject>
5+
#include <QDomDocument>
6+
#include <QHash>
57

68
class DeviceQuirks : public QObject
79
{
810
Q_OBJECT
911
public:
10-
explicit DeviceQuirks(QObject *parent = 0);
12+
static DeviceQuirks &GetInstance();
13+
bool isReady() const;
14+
void dump();
15+
private:
16+
struct QuirksEntry {
17+
QList<QString> options;
18+
QList<uint8_t> CommandClasses;
19+
QString Help;
20+
};
1121

22+
explicit DeviceQuirks(QObject *parent = 0);
23+
void setReady(bool ready);
1224
signals:
1325

1426
public slots:
27+
28+
private:
29+
QDomDocument domDocument;
30+
bool m_Ready;
31+
QHash<QString, QuirksEntry*> m_quirks;
1532
};
1633

17-
#endif // DEVICEQUIRKS_H
34+
#endif // DEVICEQUIRKS_H

ozwadmin-main/mainwindow.ui

+18-15
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
<rect>
4545
<x>0</x>
4646
<y>0</y>
47-
<width>605</width>
48-
<height>516</height>
47+
<width>573</width>
48+
<height>468</height>
4949
</rect>
5050
</property>
5151
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -289,8 +289,8 @@
289289
<rect>
290290
<x>0</x>
291291
<y>0</y>
292-
<width>605</width>
293-
<height>461</height>
292+
<width>573</width>
293+
<height>428</height>
294294
</rect>
295295
</property>
296296
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -610,8 +610,8 @@
610610
<rect>
611611
<x>0</x>
612612
<y>0</y>
613-
<width>618</width>
614-
<height>303</height>
613+
<width>588</width>
614+
<height>276</height>
615615
</rect>
616616
</property>
617617
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -625,8 +625,8 @@
625625
<rect>
626626
<x>0</x>
627627
<y>0</y>
628-
<width>600</width>
629-
<height>217</height>
628+
<width>564</width>
629+
<height>184</height>
630630
</rect>
631631
</property>
632632
<attribute name="label">
@@ -643,8 +643,8 @@
643643
<rect>
644644
<x>0</x>
645645
<y>0</y>
646-
<width>600</width>
647-
<height>183</height>
646+
<width>102</width>
647+
<height>102</height>
648648
</rect>
649649
</property>
650650
<attribute name="label">
@@ -679,8 +679,8 @@
679679
<rect>
680680
<x>0</x>
681681
<y>0</y>
682-
<width>618</width>
683-
<height>303</height>
682+
<width>588</width>
683+
<height>276</height>
684684
</rect>
685685
</property>
686686
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -717,8 +717,8 @@
717717
<rect>
718718
<x>0</x>
719719
<y>0</y>
720-
<width>618</width>
721-
<height>303</height>
720+
<width>588</width>
721+
<height>276</height>
722722
</rect>
723723
</property>
724724
<layout class="QVBoxLayout" name="verticalLayout_9">
@@ -757,7 +757,7 @@
757757
<x>0</x>
758758
<y>0</y>
759759
<width>660</width>
760-
<height>28</height>
760+
<height>22</height>
761761
</rect>
762762
</property>
763763
<widget class="QMenu" name="menuFile">
@@ -790,6 +790,9 @@
790790
<attribute name="toolBarBreak">
791791
<bool>false</bool>
792792
</attribute>
793+
<addaction name="actionOpen_Serial_Port"/>
794+
<addaction name="actionOpen_Log_Window"/>
795+
<addaction name="actionDevice_Database"/>
793796
</widget>
794797
<widget class="QStatusBar" name="statusBar"/>
795798
<action name="actionOpen_Serial_Port">

0 commit comments

Comments
 (0)