start adding definitions for Quirks

This commit is contained in:
Justin Hammond 2017-05-05 23:46:44 +08:00
parent 150bd77368
commit 96a538236d
5 changed files with 199 additions and 18 deletions

48
data/Quirks.xml Normal file
View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<QuirkData xmlns='https://github.com/OpenZWave/open-zwave'>
<Quirk name="action">
</Quirk>
<Quirk name="base">
</Quirk>
<Quirk name="override_precision">
</Quirk>
<Quirk name="scenecount">
</Quirk>
<Quirk name="create_vars">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="setasreport">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="ignoreremapping">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="getsupported">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="classgetsupported">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="coloridxbug">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="forceUniqueEndpoints">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="ForceInstances">
<option name="true"/>
<option name="false"/>
</Quirk>
<Quirk name="ignoreUnsolicitedMultiChnCapReport" CommandClass="96">
<option name="true"/>
<option name="false"/>
<Help>Blahblah</Help>
</Quirk>
</QuirkData>

View file

@ -17,7 +17,7 @@
#include <QtWidgets> #include <QtWidgets>
#include "devicedb.hpp" #include "devicedb.hpp"
#include "devicequirks.h"
#include "ui_devicedb.h" #include "ui_devicedb.h"
DeviceDB::DeviceDB(QWidget *parent) : DeviceDB::DeviceDB(QWidget *parent) :
@ -27,6 +27,7 @@ DeviceDB::DeviceDB(QWidget *parent) :
m_Path("config/") m_Path("config/")
{ {
ui->setupUi(this); ui->setupUi(this);
qDebug() << DeviceQuirks::GetInstance().isReady();
this->ui->saveBtn->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel); this->ui->saveBtn->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
this->ui->saveBtn->button(QDialogButtonBox::Save)->setEnabled(false); this->ui->saveBtn->button(QDialogButtonBox::Save)->setEnabled(false);
deviceTree = new DeviceDBXMLReader(this); deviceTree = new DeviceDBXMLReader(this);

View file

@ -1,6 +1,118 @@
#include "devicequirks.h" #include "devicequirks.h"
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include <QDir>
bool parseNumberList(QString str, QList<uint8_t> &list) {
size_t pos = 0;
size_t start = 0;
bool parsing = true;
while( parsing )
{
std::string ccStr;
pos = str.toStdString().find_first_of( ",", start );
if( std::string::npos == pos )
{
ccStr = str.toStdString().substr( start );
parsing = false;
}
else
{
ccStr = str.toStdString().substr( start, pos-start );
start = pos + 1;
}
QString result = QString::fromStdString(ccStr);
list.push_back(result.toInt());
}
return true;
}
DeviceQuirks::DeviceQuirks(QObject *parent) : QObject(parent) DeviceQuirks::DeviceQuirks(QObject *parent) : QObject(parent)
{ {
QString errorStr;
int errorLine;
int errorColumn;
qDebug() << QDir(".").absolutePath();
QFile mfxml("Quirks.xml");
if (!mfxml.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(nullptr, tr("QXmlStream Quirks"),
tr("Cannot read file %1:\n%2.")
.arg(mfxml.fileName())
.arg(mfxml.errorString()));
this->setReady(false);
return;
}
if (!domDocument.setContent(&mfxml, false,&errorStr, &errorLine, &errorColumn)) {
QMessageBox::information(nullptr, tr("Quirks Database"), tr("Parse Error at line %1, column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr));
return;
}
QDomElement root = domDocument.documentElement();
if (root.tagName() != "QuirkData") {
QMessageBox::information(nullptr, tr("Quirks Database"),
tr("The file is not an Quirk file."));
return;
}
QDomElement child = root.firstChildElement("Quirk");
while (!child.isNull()) {
QString name = child.attribute("name");
QuirksEntry *entry = new QuirksEntry();
if (child.hasAttribute("CommandClass"))
parseNumberList(child.attribute("CommandClass"), entry->CommandClasses);
if (child.hasChildNodes()) {
QDomNode options = child.firstChild();
while (!options.isNull()) {
if (options.nodeName().toUpper() == "OPTION")
entry->options.push_back(options.toElement().attribute("name"));
else if (options.nodeName().toUpper() == "HELP")
entry->Help = options.firstChild().toText().data();
options = options.nextSibling();
}
}
this->m_quirks.insert(name, entry);
child = child.nextSiblingElement();
}
mfxml.close();
this->setReady(true);
this->dump();
} }
DeviceQuirks &DeviceQuirks::GetInstance() {
static DeviceQuirks instance;
return instance;
}
void DeviceQuirks::setReady(bool ready) {
this->m_Ready = ready;
}
bool DeviceQuirks::isReady() const {
return this->m_Ready;
}
void DeviceQuirks::dump() {
QHash<QString, QuirksEntry*>::iterator it;
for (it = this->m_quirks.begin(); it != this->m_quirks.end(); ++it) {
qDebug() << it.key();
qDebug() << "\tOptions:";
for (int i = 0; i < it.value()->options.count(); ++i)
qDebug() << "\t\t" << it.value()->options.at(i);
qDebug() << "\tCommandClasses:";
for (int i = 0; i < it.value()->CommandClasses.count(); ++i)
qDebug() << "\t\t" << it.value()->CommandClasses.at(i);
qDebug() << "\tHelp:";
qDebug() << "\t\t" << it.value()->Help;
}
}

View file

@ -2,16 +2,33 @@
#define DEVICEQUIRKS_H #define DEVICEQUIRKS_H
#include <QObject> #include <QObject>
#include <QDomDocument>
#include <QHash>
class DeviceQuirks : public QObject class DeviceQuirks : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DeviceQuirks(QObject *parent = 0); static DeviceQuirks &GetInstance();
bool isReady() const;
void dump();
private:
struct QuirksEntry {
QList<QString> options;
QList<uint8_t> CommandClasses;
QString Help;
};
explicit DeviceQuirks(QObject *parent = 0);
void setReady(bool ready);
signals: signals:
public slots: public slots:
private:
QDomDocument domDocument;
bool m_Ready;
QHash<QString, QuirksEntry*> m_quirks;
}; };
#endif // DEVICEQUIRKS_H #endif // DEVICEQUIRKS_H

View file

@ -44,8 +44,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>605</width> <width>573</width>
<height>516</height> <height>468</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -289,8 +289,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>605</width> <width>573</width>
<height>461</height> <height>428</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
@ -610,8 +610,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>618</width> <width>588</width>
<height>303</height> <height>276</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_12"> <layout class="QVBoxLayout" name="verticalLayout_12">
@ -625,8 +625,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>564</width>
<height>217</height> <height>184</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -643,8 +643,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>102</width>
<height>183</height> <height>102</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -679,8 +679,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>618</width> <width>588</width>
<height>303</height> <height>276</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_7">
@ -717,8 +717,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>618</width> <width>588</width>
<height>303</height> <height>276</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
@ -757,7 +757,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>660</width> <width>660</width>
<height>28</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -790,6 +790,9 @@
<attribute name="toolBarBreak"> <attribute name="toolBarBreak">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionOpen_Serial_Port"/>
<addaction name="actionOpen_Log_Window"/>
<addaction name="actionDevice_Database"/>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<action name="actionOpen_Serial_Port"> <action name="actionOpen_Serial_Port">