Skip to content

Commit

Permalink
Add STITZ
Browse files Browse the repository at this point in the history
  • Loading branch information
j7eich committed May 2, 2020
1 parent a29e431 commit a85fbbe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions QtStsPlugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ void QtSts::Plugin::requestHeat()
m_core->requestHeat();
}

void QtSts::Plugin::requestStitz()
{
m_core->requestStitz();
}

void QtSts::Plugin::on_readyRead()
{
const QByteArray buffer(m_socket->readAll());
Expand Down
2 changes: 2 additions & 0 deletions QtStsPlugin/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ namespace QtSts {
void requestSimTime();
void requestSignalBoxInfo();
void requestHeat();
void requestStitz();

Q_SIGNALS:
void signalConnected(bool connected);
void statusMessageReceived(int code, const QString& text);
void timeReceived(int offset, int rtt);
void signalBoxInfoReceived(int simbuild, int aid, const QString& name);
void heatReceived(int heat);
void stitzReceived(int allgemein, int region);
void dataFromSts(const QByteArray& data);
void dataToSts(const QByteArray& data);

Expand Down
29 changes: 29 additions & 0 deletions QtStsPlugin/PluginCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace QtSts {
static const QString stsSENDER(QStringLiteral("sender"));
static const QString stsSIMZEIT(QStringLiteral("simzeit"));
static const QString stsSTATUS(QStringLiteral("status"));
static const QString stsSTITZ(QStringLiteral("stitz"));

static constexpr int stsSTATUS_NOT_REGISTERED = 300;
static constexpr int stsSTATUS_REGISTERED_OK = 220;
Expand All @@ -52,6 +53,9 @@ QtSts::PluginCore::PluginCore(const QString& pluginName,
, m_timeoffset(0)
, m_signalBoxId(0)
, m_simbuild(0)
, m_heat(0)
, m_stitzAllgemein(0)
, m_stitzRegion(0)
{
}

Expand Down Expand Up @@ -81,6 +85,11 @@ void QtSts::PluginCore::requestHeat()
sendSimpleCommand(stsHITZE);
}

void QtSts::PluginCore::requestStitz()
{
sendSimpleCommand(stsSTITZ);
}

void QtSts::PluginCore::receivedFromSts(const QByteArray& data)
{
m_xmlReader->addData(data);
Expand Down Expand Up @@ -111,6 +120,9 @@ void QtSts::PluginCore::receivedFromSts(const QByteArray& data)
m_timeoffset = 0;
m_signalBoxId = 0;
m_simbuild = 0;
m_heat = 0;
m_stitzAllgemein = 0;
m_stitzRegion = 0;
m_signalBoxName.clear();
break;
case QXmlStreamReader::Invalid:
Expand Down Expand Up @@ -153,6 +165,10 @@ void QtSts::PluginCore::handleStartElement()
{
parseHeat(attributes);
}
else if (nameIs(stsSTITZ))
{
parseStitz(attributes);
}
}

void QtSts::PluginCore::handleCharacters()
Expand Down Expand Up @@ -202,6 +218,10 @@ void QtSts::PluginCore::handleEndElement()
{
Q_EMIT heatReceived(m_heat);
}
else if (nameIs(stsSTITZ))
{
Q_EMIT stitzReceived(m_stitzAllgemein, m_stitzRegion);
}
}

void QtSts::PluginCore::sendRegister()
Expand Down Expand Up @@ -272,3 +292,12 @@ void QtSts::PluginCore::parseHeat(const QXmlStreamAttributes& attributes)
m_heat = rHeat.toInt();
}
}

void QtSts::PluginCore::parseStitz(const QXmlStreamAttributes& attributes)
{
const QStringRef rRegion = attributes.value(QStringLiteral("region"));
const QStringRef rAllgemein = attributes.value(QStringLiteral("allgemein"));

m_stitzAllgemein = rAllgemein.toInt();
m_stitzRegion = rRegion.toInt();
}
8 changes: 8 additions & 0 deletions QtStsPlugin/PluginCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ namespace QtSts {
constexpr int simbuild() const { return m_simbuild; }
constexpr int signalBoxId() const { return m_signalBoxId; }
const QString& signalBoxName() const { return m_signalBoxName; }
constexpr int heat() const { return m_heat; }
constexpr int stitzAllgemein() const { return m_stitzAllgemein; }
constexpr int stitzRegion() const { return m_stitzRegion; }

public Q_SLOTS:
void requestSimTime();
void requestSignalBoxInfo();
void requestHeat();
void requestStitz();
void receivedFromSts(const QByteArray& data);

Q_SIGNALS:
Expand All @@ -60,6 +64,7 @@ namespace QtSts {
void timeReceived(int offset, int rtt);
void signalBoxInfoReceived(int simbuild, int aid, const QString& name);
void heatReceived(int heat);
void stitzReceived(int allgemein, int region);

private:
void handleStartElement();
Expand All @@ -70,6 +75,7 @@ namespace QtSts {
void parseSimTime(const QXmlStreamAttributes& attributes);
void parseSignalBoxInfo(const QXmlStreamAttributes& attributes);
void parseHeat(const QXmlStreamAttributes& attributes);
void parseStitz(const QXmlStreamAttributes& attributes);

std::unique_ptr<QXmlStreamReader> m_xmlReader;
QString m_pluginName;
Expand All @@ -85,6 +91,8 @@ namespace QtSts {
int m_signalBoxId;
int m_simbuild;
int m_heat;
int m_stitzAllgemein;
int m_stitzRegion;
};

}

0 comments on commit a85fbbe

Please sign in to comment.