Reinserts original comments
This commit is contained in:
112 files changed
+7113
-5131
No files matched your search
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
//
|
||||
// Implementation of the Class AppComponent
|
||||
// **************************************************************************
|
||||
|
||||
#include "AppComponent.hpp"
|
||||
|
||||
@@ -84,5 +84,5 @@ IAppComponent *AppComponent::getChild(const QString &a_name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace N_AppComponent
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
//
|
||||
// Implementation of the Class AppComponent
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
//
|
||||
// Implementation of the Class IAppComponent
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
|
||||
// Check alle 30 Sekunden
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx_tetra.props", false);
|
||||
|
||||
NGL::INGLLogger &logger(NGL::NGLLoggerBootstrap::getNGLRootLogger());
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
|
||||
|
||||
/**
|
||||
* Tetra-Interface für Lasttest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#include "tetra_if.h"
|
||||
#include <utility>
|
||||
|
||||
@@ -48,7 +52,7 @@ void TetraIF::start()
|
||||
|
||||
void TetraIF::listenMode(const QStringList &args)
|
||||
{
|
||||
|
||||
// take input and write them to and output directory
|
||||
if (args.count() > 1)
|
||||
usage();
|
||||
m_outputDir = QCoreApplication::applicationDirPath();
|
||||
@@ -177,7 +181,7 @@ void TetraIF::onReadyRead()
|
||||
do
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Got " << m_socket->bytesAvailable() << " bytes from socket";
|
||||
|
||||
// read the 4-byte frame-header for find out the length of whole telegram
|
||||
N_CoPrtCnv::CoPrtCnvRadioTelegram::PrtCnvRadioGwHeader header;
|
||||
if (m_socket->bytesAvailable() < int(sizeof(header)))
|
||||
return;
|
||||
@@ -234,24 +238,24 @@ void TetraIF::handleReceivedTelegram(const QByteArray &data)
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
||||
// response to register indication
|
||||
case N_CoPrtCnv::CoPrtCnvRadioTelegram::e_RegisterRsp:
|
||||
handleRegisterRsp(data.at(5));
|
||||
handleRegisterRsp(data.at(5)); // registration status
|
||||
break;
|
||||
|
||||
|
||||
// payload telegram
|
||||
case N_CoPrtCnv::CoPrtCnvRadioTelegram::e_DataIndReq:
|
||||
handleDataIndReq(data);
|
||||
break;
|
||||
|
||||
|
||||
// ack-telegram - not handled here
|
||||
case N_CoPrtCnv::CoPrtCnvRadioTelegram::e_ReportIndReq:
|
||||
|
||||
// handleReportIndReq(data);
|
||||
break;
|
||||
|
||||
|
||||
// air-interface-load-telegram - not handled here
|
||||
case N_CoPrtCnv::CoPrtCnvRadioTelegram::e_AirInterfaceLoadReq:
|
||||
|
||||
// handleAirInterfaceLoadReq(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -297,7 +301,7 @@ void TetraIF::handleRegisterRsp(const uint8_t a_registrationStatus)
|
||||
|
||||
void TetraIF::dumpData(const QByteArray &data)
|
||||
{
|
||||
|
||||
// im Listen-Mode -> Ausgabe in Directory
|
||||
if (m_outputDir.isEmpty())
|
||||
return;
|
||||
const qint64 msecs = QDateTime::currentMSecsSinceEpoch();
|
||||
@@ -332,7 +336,7 @@ void TetraIF::dumpData(const QByteArray &data)
|
||||
<< " for writing - error: "
|
||||
<< f.errorString();
|
||||
}
|
||||
|
||||
// 27 Bytes Header entfernen
|
||||
f.write(&data.data()[27], data.size() - 27);
|
||||
f.close();
|
||||
}
|
||||
@@ -341,7 +345,7 @@ void TetraIF::dumpData(const QByteArray &data)
|
||||
void TetraIF::onSendData()
|
||||
{
|
||||
++m_secondFragment;
|
||||
|
||||
// we're called every 10ms
|
||||
if (m_secondFragment == 100)
|
||||
{
|
||||
m_secondFragment = 0;
|
||||
@@ -358,7 +362,7 @@ void TetraIF::onSendData()
|
||||
{
|
||||
for (unsigned short dest_issi : std::as_const(m_issiList))
|
||||
{
|
||||
|
||||
// GEF_BESTAETIGUNG -> Dummy, gets overridden by setPayloadDataComplete()
|
||||
m_data[0] = s_randomChar++;
|
||||
N_CoPrtCnv::CoPrtCnvRadioTelegram tele(GEF_BESTAETIGUNG, m_data.size(), dest_issi);
|
||||
tele.setPayloadDataComplete(m_data);
|
||||
@@ -383,7 +387,7 @@ void TetraIF::onSendData()
|
||||
void TetraIF::parseISSIs(const QStringList &issiList)
|
||||
{
|
||||
m_issiList.clear();
|
||||
|
||||
// broadcast
|
||||
if (issiList.count() == 0)
|
||||
{
|
||||
m_issiList += 0;
|
||||
@@ -430,7 +434,7 @@ void TetraIF::handleDataIndReq(const QByteArray &data)
|
||||
break;
|
||||
}
|
||||
|
||||
delete radioTelegram;
|
||||
delete radioTelegram; // this deletes also a_data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,7 +442,7 @@ void TetraIF::handleLoginTelegram(N_CoPrtCnv::CoPrtCnvRadioTelegram *a_loginTele
|
||||
{
|
||||
uint16_t identity = a_loginTelegram->getIdentity();
|
||||
uint32_t issi = a_loginTelegram->getSrcISSI();
|
||||
|
||||
// is it a login request?
|
||||
if (N_CoPrtCnv::CoPrtCnvRadioTelegram::e_LoginRequest == (a_loginTelegram->getPayloadDataUInt8(2) & N_CoPrtCnv::CoPrtCnvRadioTelegram::e_LoginStatusMask))
|
||||
{
|
||||
bool sent = sendLoginResponse(issi);
|
||||
@@ -456,33 +460,33 @@ bool TetraIF::sendLoginResponse(const uint32_t a_ISSI)
|
||||
++m_SendCounter;
|
||||
N_CoPrtCnv::CoPrtCnvRadioTelegram *a_telegram = new N_CoPrtCnv::CoPrtCnvRadioTelegram(GEF_BESTAETIGUNG, 20, a_ISSI);
|
||||
a_telegram->setZaehler(m_SendCounter);
|
||||
|
||||
// set our ISSI
|
||||
a_telegram->setDestISSI(a_ISSI);
|
||||
a_telegram->setSrcISSI(2);
|
||||
gef_telegramm_id_et telId = a_telegram->isNormalTelegram() ? a_telegram->getTelID() : GEF_BESTAETIGUNG;
|
||||
|
||||
|
||||
// send telegram to radio
|
||||
INFO_LOG(m_logger) << "Send telegram to radio: telId=" << telId << " wcounter=" << a_telegram->zaehler() << " size= 28";
|
||||
|
||||
|
||||
|
||||
// Protokoll-Byte wird hier mit als Datenbyte missbraucht...
|
||||
a_telegram->setProtocolIdentifier(N_CoPrtCnv::CoPrtCnvRadioTelegram::e_TDSMessageWithoutSDS_TL);
|
||||
a_telegram->setPayloadData(0x01);
|
||||
a_telegram->setPayloadData(0x04);
|
||||
|
||||
a_telegram->getData()[22] = 0x0d;
|
||||
// Bitanzahl anpassen
|
||||
a_telegram->getData()[22] = 0x0d; // Warum 13 (bzw. 21) ??
|
||||
|
||||
char *data = a_telegram->getData();
|
||||
|
||||
|
||||
data[02] = 0x18;
|
||||
|
||||
// Header - complete Payload in Bytes
|
||||
data[02] = 0x18; // 24 Bytes
|
||||
// Len in Bits
|
||||
data[22] = 0x0d;
|
||||
data[23] = 0x00;
|
||||
|
||||
// Len in Bytes
|
||||
data[24] = 0x02;
|
||||
data[25] = 0x00;
|
||||
|
||||
// Data
|
||||
data[13] = 0x00;
|
||||
data[26] = 0x01;
|
||||
data[27] = 0x40;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
|
||||
|
||||
/**
|
||||
* Tetra-Interface für Lasttest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#pragma once
|
||||
#include <QtCore/QObject>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
|
||||
@@ -22,10 +22,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
m_files.clear();
|
||||
|
||||
|
||||
|
||||
|
||||
//m_logfile.~QString();
|
||||
//delete m_logfileList;
|
||||
// m_logZeiten.~QString();
|
||||
//delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::changeEvent(QEvent *e)
|
||||
@@ -43,10 +43,10 @@ void MainWindow::changeEvent(QEvent *e)
|
||||
|
||||
void MainWindow::init()
|
||||
{
|
||||
|
||||
//Connect Signals & Slots
|
||||
connect(ui->pushButtonOrdnerFinden, &QPushButton::clicked, this, &MainWindow::slot_findFolder);
|
||||
connect(ui->pushButtonAnalysieren, &QPushButton::clicked, this, &MainWindow::slot_analysieren);
|
||||
|
||||
//m_logfileList = new QList<LogfileInfo>();
|
||||
ui->progressBar->setValue(0);
|
||||
ui->labelResult->setText(QString());
|
||||
QIntValidator intVal;
|
||||
@@ -57,9 +57,16 @@ void MainWindow::init()
|
||||
|
||||
void MainWindow::slot_findFolder()
|
||||
{
|
||||
|
||||
|
||||
|
||||
//hier liegt der fehler???, der erst beim zweiten mal ausführen des Dateibrowsers in erscheinung tritt
|
||||
/*QFileDialog dial(this);
|
||||
dial.setFileMode(QFileDialog::Directory);
|
||||
dial.setViewMode(QFileDialog::List);
|
||||
QStringList files;
|
||||
if (dial.exec())
|
||||
files = dial.selectedFiles();
|
||||
QString name = files.at(0);
|
||||
//testblabla
|
||||
*/
|
||||
QString name = QFileDialog::getExistingDirectory(this, tr("Choose folder"), QDir::homePath(), QFileDialog::DontResolveSymlinks);
|
||||
ui->lineEditOrdner->setText(name);
|
||||
ui->labelResult->setText(QString());
|
||||
@@ -74,7 +81,7 @@ void MainWindow::slot_analysieren()
|
||||
ISSI = QLatin1String("1");
|
||||
m_logfileList.clear();
|
||||
|
||||
|
||||
//alle DAteien in dem Ordner finden
|
||||
QDir folder(ui->lineEditOrdner->text());
|
||||
m_files = folder.entryList();
|
||||
folder.~QDir();
|
||||
@@ -83,7 +90,7 @@ void MainWindow::slot_analysieren()
|
||||
const QString issitext = ISSI + QLatin1String("-1");
|
||||
for (int i = 0; i < m_files.count(); i++)
|
||||
{
|
||||
|
||||
//Dateinamen entfernen, die keine Payload-Logs sind
|
||||
QString name = m_files[i];
|
||||
if (name.contains(paytext))
|
||||
{
|
||||
@@ -136,7 +143,7 @@ void MainWindow::readFiles()
|
||||
QFile file(filename);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
|
||||
//Datei auslesen
|
||||
QByteArray ar = file.read(150);
|
||||
file.close();
|
||||
if (ar.size() > 36)
|
||||
@@ -144,21 +151,21 @@ void MainWindow::readFiles()
|
||||
QString issi = getISSI(ar);
|
||||
QByteArray bytes = ar;
|
||||
|
||||
|
||||
//Laufende Nummer
|
||||
bytes.remove(0, 34);
|
||||
bytes.remove(2, 150);
|
||||
uint nr = bytes[0] & 255;
|
||||
nr *= 256;
|
||||
nr += bytes[1] & 255;
|
||||
|
||||
|
||||
//BytesNr 34+35
|
||||
//Sendezeit
|
||||
bytes = ar;
|
||||
bytes.remove(0, 30);
|
||||
bytes.remove(4, 150);
|
||||
|
||||
const QByteArray test = bytes.toHex();
|
||||
qint64 zeit = test.toLongLong(nullptr, 16);
|
||||
|
||||
//Byte 30-33
|
||||
const QDateTime timeStart(QDateTime::fromMSecsSinceEpoch(zeit * 1000));
|
||||
|
||||
writeToLogfile(issi, timeStart, getTimestamp(m_files[j]), m_files[j], nr);
|
||||
@@ -172,7 +179,7 @@ void MainWindow::readFiles()
|
||||
val *= (j + 1);
|
||||
val += 20;
|
||||
ui->progressBar->setValue(int(val));
|
||||
|
||||
// ui->progressBar->repaint();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -273,7 +280,7 @@ QDateTime MainWindow::getTimestamp(const QString &filename) const
|
||||
|
||||
QString MainWindow::getISSI(QByteArray ar)
|
||||
{
|
||||
|
||||
//wird nur für die "2-timestamp"-Dateien verwendet
|
||||
ar.remove(0, 5);
|
||||
ar.remove(4, 200);
|
||||
QByteArray issi = ar.toHex();
|
||||
@@ -310,7 +317,7 @@ QString MainWindow::getISSI(QByteArray ar)
|
||||
int MainWindow::auswerten()
|
||||
{
|
||||
|
||||
|
||||
//Logfile vorbereiten
|
||||
QFile f(m_logfile);
|
||||
if (!f.open(QIODevice::Append | QIODevice::Text))
|
||||
return -1;
|
||||
@@ -319,7 +326,7 @@ int MainWindow::auswerten()
|
||||
issis.reserve(100);
|
||||
for (int i = 0; i < m_logfileList.count(); i++)
|
||||
{
|
||||
|
||||
//Unterschiedliche Issis finden
|
||||
issis += m_logfileList.at(i).issi;
|
||||
}
|
||||
ui->progressBar->setValue(94);
|
||||
@@ -329,7 +336,7 @@ int MainWindow::auswerten()
|
||||
int i = 0;
|
||||
for (const QString &issi : std::as_const(issis))
|
||||
{
|
||||
|
||||
//für jede Issi die Nummern in timestampMap einlesen --> geordnet nach Zeitstempel
|
||||
numList.clear();
|
||||
for (int j = 0; j < m_logfileList.count(); j++)
|
||||
{
|
||||
@@ -344,7 +351,7 @@ int MainWindow::auswerten()
|
||||
f.write(text);
|
||||
|
||||
fehlcount += fehlendeNumsEintragen(numList, f);
|
||||
|
||||
// delete numList;
|
||||
|
||||
double val = 5;
|
||||
val /= issis.count();
|
||||
@@ -360,7 +367,7 @@ int MainWindow::auswerten()
|
||||
|
||||
int MainWindow::fehlendeNumsEintragen(const QVector<uint> &numList, QFile &f)
|
||||
{
|
||||
|
||||
//schreibt die fehlenden Nummern in das Logfile und die GUI
|
||||
QVector<uint> fehlendeNums = getFehlendeNums(numList);
|
||||
QByteArray text = QByteArray::number(fehlendeNums.count());
|
||||
text += " lost messages\n";
|
||||
@@ -370,7 +377,7 @@ int MainWindow::fehlendeNumsEintragen(const QVector<uint> &numList, QFile &f)
|
||||
text += QByteArray::number(fehlendeNums.at(j));
|
||||
text += ", ";
|
||||
}
|
||||
|
||||
// delete fehlendeNums;
|
||||
text += ")\n";
|
||||
|
||||
f.write(text);
|
||||
@@ -380,13 +387,13 @@ int MainWindow::fehlendeNumsEintragen(const QVector<uint> &numList, QFile &f)
|
||||
|
||||
QVector<uint> MainWindow::getFehlendeNums(const QVector<uint> &numsDurchgang)
|
||||
{
|
||||
|
||||
//ermittelt die fehlenden Nummern pro Durchgang
|
||||
uint count = numsDurchgang.count();
|
||||
uint maxnum = 0;
|
||||
uint minnum = 999999;
|
||||
for (uint k = 0; k < count; k++)
|
||||
{
|
||||
|
||||
//höchste und niedrigste Num finden
|
||||
if (numsDurchgang.at(k) > maxnum)
|
||||
maxnum = numsDurchgang.at(k);
|
||||
if (numsDurchgang.at(k) < minnum)
|
||||
@@ -396,7 +403,7 @@ QVector<uint> MainWindow::getFehlendeNums(const QVector<uint> &numsDurchgang)
|
||||
QVector<uint> fehlendeNum;
|
||||
for (uint z = minnum; z <= maxnum; z++)
|
||||
{
|
||||
|
||||
//liste nach fehlenden werten durchsuchen
|
||||
bool vorhanden = false;
|
||||
for (uint j = 0; j < count; j++)
|
||||
{
|
||||
@@ -425,5 +432,5 @@ void MainWindow::writeLogZeiten(const QDateTime &beginn, const QDateTime &end, c
|
||||
file.write(msg.toUtf8());
|
||||
file.close();
|
||||
|
||||
|
||||
//delete end;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
const QDateTime ×tamp,
|
||||
const QString &filename,
|
||||
uint lfdNr);
|
||||
QString getISSI(QByteArray ar);
|
||||
QString getISSI(QByteArray ar);//Für alte TPUS
|
||||
int auswerten();
|
||||
QVector<uint> getFehlendeNums(const QVector<uint> &numsDurchgang);
|
||||
int fehlendeNumsEintragen(const QVector<uint> &numList, QFile &file);
|
||||
@@ -66,4 +66,4 @@ private slots:
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif // MAINWINDOW_H
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvApplication
|
||||
// **************************************************************************
|
||||
|
||||
#include "PrtCnvApplication.hpp"
|
||||
#include "PrtCnvThreadStarter.hpp"
|
||||
@@ -65,9 +65,9 @@ PrtCnvApplication::~PrtCnvApplication()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Synchronisation of threads before create().
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::waitForCreate(const E_ThreadId a_threadId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Wait for others until we can create " << threadIdToString(a_threadId);
|
||||
@@ -111,9 +111,9 @@ void PrtCnvApplication::waitForCreate(const E_ThreadId a_threadId)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Synchronisation of threads before init().
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::waitForInit(E_ThreadId a_threadId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Wait for others until we can initialize " << threadIdToString(a_threadId);
|
||||
@@ -152,9 +152,9 @@ void PrtCnvApplication::waitForInit(E_ThreadId a_threadId)
|
||||
INFO_LOG(m_logger) << "Now we can initialize " << threadIdToString(a_threadId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Synchronisation of threads before start().
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::waitForStart(E_ThreadId a_threadId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Wait for others until we can start " << threadIdToString(a_threadId);
|
||||
@@ -209,17 +209,17 @@ void PrtCnvApplication::waitForStart(E_ThreadId a_threadId)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Synchronisation of threads before execution of thread.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::waitForExec(E_ThreadId a_threadId)
|
||||
{
|
||||
setStarted(a_threadId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Starts the main-application
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::startApp()
|
||||
{
|
||||
createApplication();
|
||||
@@ -258,9 +258,9 @@ void PrtCnvApplication::setConfigFile(const QString &configFile)
|
||||
m_ConfigFileName = configFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Creates the childs
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvApplication::createApplication()
|
||||
{
|
||||
setName(QStringLiteral("Common"));
|
||||
@@ -283,12 +283,12 @@ int32_t PrtCnvApplication::createApplication()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Starts the childs and then the main application
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvApplication::start()
|
||||
{
|
||||
|
||||
// start and create threads
|
||||
for (const auto &ti : m_threadInfo)
|
||||
ti.thread->start();
|
||||
|
||||
@@ -298,9 +298,9 @@ int32_t PrtCnvApplication::start()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the desired thread-starter
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnv::PrtCnvThreadStarter *PrtCnvApplication::getThreadStarter(const E_ThreadId a_threadId)
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -334,7 +334,7 @@ void PrtCnvApplication::logWlsTelegram(const TrainingAreaBase::TetraIcd::Trainin
|
||||
t->writeWlsTelegramLog(tele, bIsSend, 0);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvApplication::isConstructed(const E_ThreadId a_threadId) const
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -343,7 +343,7 @@ bool PrtCnvApplication::isConstructed(const E_ThreadId a_threadId) const
|
||||
return m_threadInfo[a_threadId].isConstructed;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::setConstructed(const E_ThreadId a_threadId)
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -352,7 +352,7 @@ void PrtCnvApplication::setConstructed(const E_ThreadId a_threadId)
|
||||
m_threadInfo[a_threadId].isConstructed = true;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvApplication::isInitialized(const E_ThreadId a_threadId) const
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -361,7 +361,7 @@ bool PrtCnvApplication::isInitialized(const E_ThreadId a_threadId) const
|
||||
return m_threadInfo[a_threadId].isInitialized;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::setInitialized(const E_ThreadId a_threadId)
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -370,7 +370,7 @@ void PrtCnvApplication::setInitialized(const E_ThreadId a_threadId)
|
||||
m_threadInfo[a_threadId].isInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvApplication::isCreated(const E_ThreadId a_threadId) const
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -379,7 +379,7 @@ bool PrtCnvApplication::isCreated(const E_ThreadId a_threadId) const
|
||||
return m_threadInfo[a_threadId].isCreated;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::setCreated(const E_ThreadId a_threadId)
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -388,7 +388,7 @@ void PrtCnvApplication::setCreated(const E_ThreadId a_threadId)
|
||||
m_threadInfo[a_threadId].isCreated = true;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvApplication::isStarted(const E_ThreadId a_threadId) const
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -397,7 +397,7 @@ bool PrtCnvApplication::isStarted(const E_ThreadId a_threadId) const
|
||||
return m_threadInfo[a_threadId].isStarted;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvApplication::setStarted(const E_ThreadId a_threadId)
|
||||
{
|
||||
if (a_threadId < e_Central || a_threadId >= e_ThreadIdMax)
|
||||
@@ -406,4 +406,4 @@ void PrtCnvApplication::setStarted(const E_ThreadId a_threadId)
|
||||
m_threadInfo[a_threadId].isStarted = true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvApplication
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -23,20 +23,32 @@
|
||||
#include "prtcnvlib_export.h"
|
||||
#include <TrainingAreaBase/training_area_telegrams.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Here are all project specific classes of protocol-converter implemented.
|
||||
*/
|
||||
namespace PrtCnv
|
||||
{
|
||||
class PrtCnvThreadStarter;
|
||||
|
||||
|
||||
/**
|
||||
* The main-application of protocol-converter. It is responsible for starting and
|
||||
* controlling the threads of this application.
|
||||
*
|
||||
* @author alois.wismer
|
||||
* @version 1.0
|
||||
* @created 23-Jun-2009 17:48:47
|
||||
*/
|
||||
class PRTCNVLIB_EXPORT PrtCnvApplication : public QObject, public N_AppComponent::AppComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This enum will be used to unique identify the threads
|
||||
*
|
||||
* @author alois.wismer
|
||||
* @version 1.0
|
||||
* @created 19-Jan-2010 17:09:00
|
||||
*/
|
||||
enum E_ThreadId
|
||||
{
|
||||
e_Central,
|
||||
@@ -50,8 +62,9 @@ namespace PrtCnv
|
||||
PrtCnvApplication();
|
||||
~PrtCnvApplication();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Starts the main-application
|
||||
*/
|
||||
void startApp();
|
||||
void shutdownApp();
|
||||
static void setCleanDb(bool bCleanDb);
|
||||
@@ -59,33 +72,51 @@ namespace PrtCnv
|
||||
int exerciseId() const { return m_exerciseId; }
|
||||
void setConfigFile(const QString &configFile);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Starts the childs and then the main application
|
||||
*/
|
||||
int32_t start() override;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Synchronisation of threads before init().
|
||||
*
|
||||
* @param a_threadId id of the calling thread
|
||||
*/
|
||||
void waitForInit(E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Synchronisation of threads before start().
|
||||
*
|
||||
* @param a_threadId id of the calling thread
|
||||
*/
|
||||
void waitForStart(E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Synchronisation of threads before create().
|
||||
*
|
||||
* @param a_threadId Id of the calling thread
|
||||
*/
|
||||
void waitForCreate(const E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Synchronisation of threads before execution of thread.
|
||||
*
|
||||
* @param a_threadId id of the calling thread
|
||||
*/
|
||||
void waitForExec(E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the desired thread-starter
|
||||
*
|
||||
* @param a_threadId Id of the desired thread-started (corresponding thread has
|
||||
* the same id)
|
||||
*/
|
||||
PrtCnvThreadStarter* getThreadStarter(const E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the database connection parameter when used as library
|
||||
*/
|
||||
void setDatabaseConnectionParams(const QString &driver,
|
||||
const QString &hostName,
|
||||
const QString &database,
|
||||
@@ -108,45 +139,59 @@ signals:
|
||||
void outgoingBroadcastTelegramsRequest(int equipmentNumber, int broadcastIndex, int resetCounter);
|
||||
void warehouseMessageFromPtrCnv(const QByteArray &jsonData);
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Creates the childs
|
||||
*/
|
||||
int32_t createApplication();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true when the specified thread is
|
||||
* already constructed
|
||||
*/
|
||||
bool isConstructed(const E_ThreadId a_threadId) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The specifed thread is now constructed
|
||||
*/
|
||||
void setConstructed(const E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true when the specified thread is
|
||||
* already initialized
|
||||
*/
|
||||
bool isInitialized(const E_ThreadId a_threadId) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The specifed thread is now initialized
|
||||
*/
|
||||
void setInitialized(const E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true when the specified thread is
|
||||
* already created
|
||||
*/
|
||||
bool isCreated(const E_ThreadId a_threadId) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The specifed thread is now created
|
||||
*/
|
||||
void setCreated(const E_ThreadId a_threadId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true when the specified thread is
|
||||
* already started
|
||||
*/
|
||||
bool isStarted(const E_ThreadId a_threadId) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The specifed thread is now started
|
||||
*/
|
||||
void setStarted(const E_ThreadId a_threadId);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Used to get configuration-parameter
|
||||
*/
|
||||
NGL::Settings *m_Config;
|
||||
|
||||
struct ThreadInfo
|
||||
@@ -157,11 +202,13 @@ protected:
|
||||
bool isInitialized = false;
|
||||
bool isStarted = false;
|
||||
} m_threadInfo[e_ThreadIdMax];
|
||||
|
||||
|
||||
/**
|
||||
* The name of the config-file
|
||||
*/
|
||||
QString m_ConfigFileName;
|
||||
|
||||
|
||||
/**
|
||||
* The exerciseId (or zero if not set)
|
||||
*/
|
||||
int m_exerciseId;
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -39,15 +39,27 @@ namespace PrtCnv
|
||||
{
|
||||
class PrtCnvDbThread;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class is responsible for handling all the broadcast stuff. This includes:
|
||||
* - sending the broadcast 3 times
|
||||
* - sending Broadcast-Nachforderungen to TNE
|
||||
* - store and manage the broadcast-list
|
||||
* - measure the Broadcast-Nachforderung-statistic
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 30-Apr-2010 11:21:05
|
||||
*/
|
||||
class PrtCnvBroadcastMgr final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The different states the broadcast-manager can be.
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 30-Apr-2010 11:21:05
|
||||
*/
|
||||
enum E_State
|
||||
{
|
||||
e_ST_UNDEFINED,
|
||||
@@ -57,74 +69,124 @@ public:
|
||||
|
||||
PrtCnvBroadcastMgr();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns true when the telegram should be sent to central
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
*/
|
||||
bool handleRadioTelegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates all subcomponents
|
||||
*/
|
||||
int32_t create(NGL::Settings *settings);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the variables.
|
||||
*/
|
||||
int32_t init();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the next normal broadcast to send.
|
||||
* a_doDelete is true, when the caller has to delete the telegram when no longer
|
||||
* using it.
|
||||
* Use the same a_actualTime in one tick-loop.
|
||||
*
|
||||
* @param a_beginSearchWithBroadcastIndex
|
||||
* @param a_actualTime
|
||||
* @param a_doDelete true if telegram must be deleted after using it
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getNextBroadcastTelegramToSend(const uint16_t a_beginSearchWithBroadcastIndex,
|
||||
const time_t a_currentTime);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* sets the DbThread used for get the stored broadcast-telegrams
|
||||
*
|
||||
* @param a_dbThread
|
||||
*/
|
||||
void setDbThread(PrtCnvDbThread *a_dbThread);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the broadcast-manager. If a_deleteTelegrams is true, all stored
|
||||
* telegrams and maps will be deleted.
|
||||
*
|
||||
* @param a_deleteTelegrams
|
||||
*/
|
||||
void cleanAndInit(const bool a_deleteTelegrams);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes all Nop out of broadcast-list and numerates the broadcast-index of kept
|
||||
* broadcast-telegrams new.
|
||||
*
|
||||
* @param a_doRestore
|
||||
*/
|
||||
void handleOverrunOfBroadcastCounter(const bool a_doRestore = false);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the next broadcast to send for nachforderungen
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getNextNachforderungTelegramToSend();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* dumps important values, only for debugging
|
||||
*/
|
||||
void dump();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Restores data after crash for seamless proceeding of work.
|
||||
*/
|
||||
void restoreAfterCrash();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the actual broadcast-index for normal broadcasts.
|
||||
*/
|
||||
uint16_t getBroadcastIndex() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the broadcastindex for the next broadcast
|
||||
*/
|
||||
uint16_t getNextBroadcastIndex();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds the telegram a_broadcastOnlyTelegram (which must have set already the
|
||||
* broadcast-index) to the broadcast-map. The telegram will be attached to an
|
||||
* already existing broadcast-telegram with same broadcast-index in the map,
|
||||
* otherwise it will be marked as broadcast-only.
|
||||
* If the there is already an broadcast-only-telegram attached, nothing will be
|
||||
* done.
|
||||
*
|
||||
* @param a_broadcastOnlyTelegram
|
||||
*/
|
||||
void addBroadcastOnlyTelegramToMap(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_broadcastOnlyTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Increments the tick-counter of broadcast-manager and informs the broadcast-
|
||||
* manager about the traffic-load.
|
||||
*
|
||||
* @param a_isHighLoad
|
||||
* @param a_isFullLoad
|
||||
*/
|
||||
void incTickAndSetTrafficLoad(const bool a_isHighLoad, const bool a_isFullLoad);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given id is in m_deactivatedAesMine2bcIndex/m_deactivatedDusMine2bcIndex/m_deactivatedFuncAreaMine2bcIndex
|
||||
*
|
||||
* @brief isEffectSimulationIdDeactivated
|
||||
* @param effectsimulationId
|
||||
* @return
|
||||
*/
|
||||
bool isEffectSimulationIdDeactivated(const uint16_t effectsimulationId) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds the TNE to the nachforderungs-list
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
*/
|
||||
void handleNachforderungBroadcastTelegram(int identity, int broadcastIndex, int resetCounter);
|
||||
|
||||
protected:
|
||||
@@ -136,99 +198,166 @@ protected:
|
||||
EquipNoBcIndex() = default;
|
||||
EquipNoBcIndex(int e, int b) : equipNo(e), bcIndex(b) {}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Map of TNE, that sent a NachforderungBroadcast-Telegram.
|
||||
* Key: identity of TNE; Value: broadcast-counter
|
||||
*/
|
||||
std::vector<EquipNoBcIndex> m_claimerArray;
|
||||
|
||||
|
||||
/**
|
||||
* Time (in SendGap-ticks) spent for collection NachforderungeBroadcast, before
|
||||
* sending broadcasts begins
|
||||
* This value will be used for normal load.
|
||||
*/
|
||||
uint16_t m_ClaimWindow;
|
||||
|
||||
|
||||
/**
|
||||
* the factor for widening claim-window before sending broadcasts when we have
|
||||
* high load traffic
|
||||
*/
|
||||
uint16_t m_HighLoadFactor;
|
||||
|
||||
|
||||
/**
|
||||
* the number of TPUs needed for sending the broadcasts as broadcast instead
|
||||
* directed
|
||||
*/
|
||||
uint16_t m_BroadcastLimit;
|
||||
|
||||
|
||||
/**
|
||||
* Used to get configuration-parameter.
|
||||
*/
|
||||
NGL::Settings *m_Config;
|
||||
|
||||
|
||||
/**
|
||||
* Actual time (in SendGap-ticks) spent for collection NachforderungeBroadcast,
|
||||
* before sending broadcasts begins. This value changes depending on downlink-load.
|
||||
*/
|
||||
uint16_t m_ActClaimWindow;
|
||||
|
||||
|
||||
/**
|
||||
* The state of broadcast-manager.
|
||||
*/
|
||||
PrtCnvBroadcastMgr::E_State m_State;
|
||||
uint16_t m_TickCounter;
|
||||
|
||||
|
||||
/**
|
||||
* The actual broadcast-index for sending nachforderungen
|
||||
*/
|
||||
PrtCnvDbThread *m_DbThread;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* sorted by broadcast-index
|
||||
*/
|
||||
std::map<uint16_t, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_BroadcastMap;
|
||||
|
||||
std::vector<std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_broadcastTelegamsToSend;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains all telegrams which must only be stored once for nachforderungen
|
||||
*/
|
||||
std::map<gef_telegramm_id_et, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_LastTelegramMap;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains all wirkfeld-telegrams which must be stored for nachforderungen
|
||||
* ordered by wirkfeldkennung.
|
||||
*/
|
||||
std::multimap<uint16_t, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_WirkfeldTelegramMapByKennung;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains all wirkfeld-telegrams which must be stored for nachforderungen
|
||||
* ordered by expiration-time.
|
||||
*/
|
||||
std::multimap<time_t, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_WirkfeldTelegramMapByTime;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains all funktionsraum-telegrams which must be stored for nachforderungen
|
||||
* ordered by funktionsraumkennung.
|
||||
*/
|
||||
std::map<uint16_t, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_FunktionsraumTelegramMap;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains all technik-funktionsraum-telegrams which must be stored for nachforderungen
|
||||
* ordered by funktionsraumkennung.
|
||||
*/
|
||||
std::map<uint16_t, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>> m_TechnikFunktionsraumTelegramMap;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The actual broadcast-index for normal broadcast
|
||||
*/
|
||||
uint16_t m_BroadcastIndex;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* True if send-traffic is on full-load => no nachforderungen will be sent
|
||||
*/
|
||||
bool m_IsFullLoad;
|
||||
|
||||
|
||||
/**
|
||||
* The highest broadcast-index of 3rd time sent broadcast-telegram (for optimize
|
||||
* by time)
|
||||
*/
|
||||
uint16_t m_FinishedBroadcastIndex;
|
||||
|
||||
|
||||
/**
|
||||
* The broadcast-index of the 1st broadcast-telegram which has been sent 1 time
|
||||
* only (for optimize by time)
|
||||
*/
|
||||
uint16_t m_FirstBroadcastIndexOfBc1;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* adds the radio-telegram to the broadcast-map, or generates the sammeltelegramme
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
*/
|
||||
void addToBroadcastMap(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the Nachforderungs-telegram with this broadcast-index from the
|
||||
* broadcast-map with sammeltelegrams. If the telegram with a_broadcastIndex does
|
||||
* not exist, a NOP-telegram will be returned, which must be consumed immediately
|
||||
* and must never be deleted.
|
||||
* The parameter a_broadcastIndex will be updated to the value of found telegram.
|
||||
* ATTENTION: the returned a_broadcastIndex could be different from the value
|
||||
* returned by getBroadcastIndex(), for example in NOP-telegrams
|
||||
* getBroadcastIndex() returns the Anfang, but a_broadcastIndex will be the Ende.
|
||||
*
|
||||
* @param a_broadcastIndex
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getNachforderungsTelegram(int curBcIndex, int startBcIndex, int &nextBcIndex);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* searches the kennung within sammeltelegram.
|
||||
* returns -1 when kennung not found
|
||||
*
|
||||
* @param a_sammelTelegram
|
||||
* @param a_kennung
|
||||
*/
|
||||
int getSammeltelegramIndex(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_sammelTelegram,
|
||||
const uint16_t a_kennung) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Moves a_radioTelegram to a_newBroadcastIndex in broadcast-map.
|
||||
* If a_radioTelegram has an attached broadcast-only-telegram, the broadcastOnly-
|
||||
* telegram will be detached and kept on the old broadcast-index position.
|
||||
* If a_attachTelegram in not NULL, this telegram will be attached to
|
||||
* a_radioTelegram.
|
||||
*
|
||||
* @param a_radioTelegram The radio-telegram to be moved
|
||||
* @param a_newBroadcastIndex The new broadcast-index
|
||||
* @param a_attachTelegram The telegram to be attached
|
||||
*/
|
||||
void moveTelegramInBroadcastMap(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram,
|
||||
const uint16_t a_newBroadcastIndex,
|
||||
const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_attachTelegram = {});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the telegram a_radioTelegram from the broadcast-map. If the
|
||||
* a_radioTelegram has an attached telegram, the attached telegram will be
|
||||
* detached and added to broadcast-map as broadcast-only telegram.
|
||||
* If the telegram is an attached BC-only-telegram, it will be detached.
|
||||
* The telegram itself will be deleted when a_doDeleteTelegram is true.
|
||||
* ATTENTION: iterators to m_BroadcastMap could be invalid after calling this
|
||||
* function
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
* @param a_doDeleteTelegram
|
||||
*/
|
||||
void removeFromBroadcastMap(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram);
|
||||
void removeFromBroadcastMapFunc(const std::function<bool(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &)> &pred);
|
||||
void removeDusMineDeactivationFromBroadcastMap(int dusMineId);
|
||||
@@ -242,25 +371,25 @@ protected:
|
||||
|
||||
bool removeFromDeactivatedAesArea(int aesAreaId);
|
||||
bool addToDeactivatedAesArea(int aesAreaId, int bcIndex);
|
||||
|
||||
// QHash<mineId, broadcastIndexDeactivated>
|
||||
QHash<int, int> m_deactivatedAesArea2bcIndex;
|
||||
|
||||
// QMap<broadcastIndexDeactivated, mineId>, keep sorted!
|
||||
QMap<int, int> m_deactivatedBcIndex2AesArea;
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>createAccuTeleDeactivatedAesAreas(int curBcIndex, int startBcIndex) const;
|
||||
|
||||
bool removeFromDeactivatedFuncArea(int aesAreaId);
|
||||
bool addToDeactivatedFuncArea(int aesAreaId, int bcIndex);
|
||||
|
||||
// QHash<mineId, broadcastIndexDeactivated>
|
||||
QHash<int, int> m_deactivatedFuncArea2bcIndex;
|
||||
|
||||
// QHash<broadcastIndexDeactivated, mineId>, keep sorted!
|
||||
QMap<int, int> m_deactivatedBcIndex2FuncArea;
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>createAccuTeleDeactivatedFuncAreas(int curBcIndex, int startBcIndex) const;
|
||||
|
||||
bool removeFromDeactivatedDusMine(int dusMineId);
|
||||
bool addToDeactivatedDusMine(int dusMineId, int bcIndex);
|
||||
|
||||
// QHash<mineId, broadcastIndexDeactivated>
|
||||
QHash<int, int> m_deactivatedDusMine2bcIndex;
|
||||
|
||||
// QHash<broadcastIndexDeactivated, mineId>, keep sorted!
|
||||
QMap<int, int> m_deactivatedBcIndex2DusMine;
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> createAccuTeleDeactivatedDusMines(int curBcIndex, int startBcIndex) const;
|
||||
|
||||
@@ -269,80 +398,165 @@ protected:
|
||||
QSet<int> m_activatedDusMines;
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> createAccuTeleActivatedDusMines(int curBcIndex);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the kennung from the sammeltelegram.
|
||||
* If the sammeltelegram is empty after remove of kennung, it will be taken out of
|
||||
* broadcast-map (but not deleted) and a_sammelTelRemoved will be true. A attached
|
||||
* braodcast-only-telegram will be deattached and inserted into broadcast-map.
|
||||
* Returns true if kennung was successful removed, otherwise the kennung was not
|
||||
* found within sammeltelegram
|
||||
*
|
||||
* @param a_sammelTelegram
|
||||
* @param a_kennung
|
||||
* @param a_anzahlPos
|
||||
* @param a_anzahlSize
|
||||
* @param a_sammelTelRemoved
|
||||
*/
|
||||
bool removeFromSammeltelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_sammelTelegram,
|
||||
const uint16_t a_kennung,
|
||||
const uint16_t a_anzahlPos,
|
||||
const uint8_t a_anzahlSize,
|
||||
bool &a_sammelTelRemoved);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* used for telegrams that must only exists once in BC-list
|
||||
*
|
||||
* @param a_newRadioTelegram
|
||||
*/
|
||||
void replaceLastTelegramAndAddAtEnd(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_newRadioTelegram);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Small helper to dump all wf-ids from a sammeltelegramm
|
||||
*/
|
||||
std::string dumpSammeldeaktivierung(const N_CoPrtCnv::CoPrtCnvRadioTelegram *sammelTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the braodcast-telegrams from Db, which were sent 1st time and adds them to
|
||||
* the maps. Expired telegrams will be removed.
|
||||
*
|
||||
* @param a_doRestore
|
||||
*/
|
||||
void getAllFinishedBroadcastsFromDb(const bool a_doRestore = false);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Takes expired wirkfeld-telegrams out of maps.
|
||||
*/
|
||||
void removeExpiredTelegrams();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the wirkfeld-telegrams with this kennung from the by time and by
|
||||
* kennung maps.
|
||||
* Replace this telegrams with Nop in BC-list.
|
||||
* Finally the telegram will be deleted.
|
||||
*
|
||||
* @param a_kennung
|
||||
*/
|
||||
void removeWirkfeldTelegrams(const uint16_t a_kennung);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* adds the wirkfeld-telegram to the by time and by kennung maps
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
* @param a_wirkfeldKennung
|
||||
* @param a_telId
|
||||
* @param a_minenKennung
|
||||
*/
|
||||
void addWirkfeldTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram,
|
||||
const uint16_t a_wirkfeldKennung, const gef_telegramm_id_et a_telId = GEF_BESTAETIGUNG,
|
||||
const uint16_t a_minenKennung = 0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deactivates the mine in the corresponding "WirkfeldstatusMinensperre"-telegram
|
||||
* and moves the "WirkfeldstatusMinensperre"-telegram to the position of
|
||||
* "DeactiviereEinzelmine"-telegram.
|
||||
* Returns true if the "WirkfeldstatusMinensperre"-telegram was already sent 3
|
||||
* times as normal broadcast.
|
||||
*
|
||||
* @param a_wirkfeldKennung
|
||||
* @param a_minenKennung
|
||||
* @param a_broadcastIndex
|
||||
*/
|
||||
bool deactivateEinzelmineFromMinensperre(const uint16_t a_wirkfeldKennung, const uint16_t a_minenKennung, const uint16_t a_broadcastIndex);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a NOP-telegramm filled with the desired values.
|
||||
*
|
||||
* @param a_from
|
||||
* @param a_to
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getNopTelegram(const uint16_t a_from, const uint16_t a_to);
|
||||
|
||||
|
||||
/**
|
||||
* Removes the telegram a_radioTelegram from all maps (broadcast-, wirkfeld-,
|
||||
* funktionsraum- and lastTelegram-map).
|
||||
* If the telegram is a attached BC-only-telegram, it will be detached.
|
||||
* The telegram itself will be deleted when a_doDeleteTelegram is true.
|
||||
* ATTENTION: iterators to all maps could be invalid after calling this function
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
* @param a_doDeleteTelegram
|
||||
*/
|
||||
void removeFromAllMaps(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Detaches an existing radio-telegram and adds it to the broadcast-map
|
||||
*
|
||||
* @param a_radioTelegram The telegram which could contain an attached telegram
|
||||
*/
|
||||
void detachTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the telegram with a_funktionsraumKennung from funktionsraum-map and
|
||||
* from the broadcast-map.
|
||||
* If the telegram is a attached BC-only-telegram, it will be detached.
|
||||
* The telegram itself will be deleted.
|
||||
* ATTENTION: iterators to m_FunktionsraumTelegramMap could be invalid after
|
||||
* calling this function
|
||||
*
|
||||
* @param a_funktionsraumKennung
|
||||
*/
|
||||
void removeFromFunktionsAndBroadcastMaps(const uint16_t a_funktionsraumKennung);
|
||||
void removeFromTechnikFunktionsAndBroadcastMaps(const uint16_t a_funktionsraumKennung);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the telegram where wirkfeldTelegramMapByKennungIterator points to from
|
||||
* wirkfeld-maps and from the broadcast-map.
|
||||
* If the telegram is a attached BC-only-telegram, it will be detached.
|
||||
* The telegram itself will be deleted.
|
||||
* ATTENTION: iterators to m_WirkfeldTelegramMapByKennung and
|
||||
* m_WirkfeldTelegramMapByTime could be invalid after calling this function
|
||||
*
|
||||
* @param a_wirkfeldTelegramMapByKennungIterator
|
||||
*/
|
||||
void removeFromWirkfeldAndBroadcastMaps(const std::multimap<uint16_t, std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>>::iterator &a_wirkfeldTelegramMapByKennungIterator);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles the REAKTIVIERUNG_DUS_MINE-telegram for normal-broadcasts and
|
||||
* nachforderungen.
|
||||
*
|
||||
* @param a_radioTelegram The GEF_REAKTIVIERUNG_DUS_MINE-telegram
|
||||
*/
|
||||
void reactivateDusMine(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles the DEAKTIVIERUNG_EINZELMINE-telegram for normal-broadcasts and
|
||||
* nachforderungen. This includes deactivation of mines from minen-sperre and DUS-
|
||||
* mines.
|
||||
*
|
||||
* @param a_radioTelegram The GEF_REAKTIVIERUNG_DUS_MINE-telegram
|
||||
*/
|
||||
void deactivateSingleMine(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepares values for start sending nachforderungen
|
||||
*/
|
||||
void prepareForSendNachforderungen();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the next nachforderung to send and prepares collecting window if no
|
||||
* more nachforderungen are to be sent
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> evaluateNextNachforderungToSend();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvCentralThread
|
||||
// **************************************************************************
|
||||
|
||||
#include "PrtCnvCentralThread.hpp"
|
||||
#include "PrtCnvRadioThread.hpp"
|
||||
@@ -35,7 +35,7 @@
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvCentralThread::PrtCnvCentralThread(PrtCnv::PrtCnvThreadStarter* a_parent)
|
||||
: PrtCnvThread(a_parent, "PrtCnvCentralThread")
|
||||
, m_webSocket(nullptr)
|
||||
@@ -66,9 +66,9 @@ PrtCnvCentralThread::~PrtCnvCentralThread()
|
||||
destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Creates all subcomponents and connects signals to slots
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvCentralThread::create(NGL::Settings *settings)
|
||||
{
|
||||
PrtCnvThread::create(settings);
|
||||
@@ -115,9 +115,9 @@ int32_t PrtCnvCentralThread::create(NGL::Settings *settings)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Deallocates subcomponents.
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvCentralThread::destroy()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Destroy";
|
||||
@@ -129,9 +129,9 @@ int32_t PrtCnvCentralThread::destroy()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Initializes the variables.
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvCentralThread::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Init";
|
||||
@@ -143,7 +143,7 @@ int32_t PrtCnvCentralThread::init()
|
||||
m_sendAckTimer->setInterval(m_Config->getInteger(getName(), QStringLiteral("AckTimeout"), 900));
|
||||
|
||||
m_VirtualTeilnehmerId = m_Config->getInteger(QStringLiteral("Common"), QStringLiteral("VirtualIdPrtCnv"), 90);
|
||||
m_maxEqID = m_Config->getInteger(QStringLiteral("Common"), QStringLiteral("MaxEqID"), 50000);
|
||||
m_maxEqID = m_Config->getInteger(QStringLiteral("Common"), QStringLiteral("MaxEqID"), 50000); //or max unsigned short 65535
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -155,9 +155,9 @@ int32_t PrtCnvCentralThread::deinit()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Starts the thread and connects to TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvCentralThread::start()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start";
|
||||
@@ -176,9 +176,9 @@ int32_t PrtCnvCentralThread::start()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Stops the thread
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvCentralThread::stop()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Stop";
|
||||
@@ -188,31 +188,31 @@ int32_t PrtCnvCentralThread::stop()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// see base-class
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::connected()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Central-Socket connected m_Socket=" << m_webSocket;
|
||||
m_SendCounter = 0;
|
||||
m_SendCounter = 0; // we reset this counter after every connect to 0 => next telegram to send has counter 1 (preincrement)
|
||||
m_LastSendCounter = 0;
|
||||
m_ReceiveCounter = 0;
|
||||
m_ReceiveCounter = 0; // send 0 until we get a telegram, we reset this counter after every connect to 0 => the next telegram from central must be 1
|
||||
m_ReceiveAckCounter = 0;
|
||||
m_aliveTimer->start();
|
||||
if (m_bRadioThreadInitDone)
|
||||
m_sendAckTimer->start();
|
||||
m_State = PrtCnvSocketThread::e_WORKING;
|
||||
emit checkSendToCentral();
|
||||
emit checkSendToCentral(); // start sending telegrams for central still in list (reconnection)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// see base-class
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::disconnected()
|
||||
{
|
||||
INFO_LOG(m_logger) << "disconnected m_Socket=" << m_webSocket;
|
||||
|
||||
|
||||
// for the case central is disconnecting, we have to disconnect also, otherwise
|
||||
// we could send rubish (still resisting in buffers) after a reconnection
|
||||
if (PrtCnvSocketThread::e_WORKING == m_State && m_webSocket)
|
||||
m_webSocket->close();
|
||||
|
||||
@@ -233,10 +233,10 @@ void PrtCnvCentralThread::disconnected()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Stores that radio-thread has stopped. Cleans the Db and
|
||||
// reinitializes when central-thread has also stopped.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::radioStopped()
|
||||
{
|
||||
m_RadioStopped = true;
|
||||
@@ -245,25 +245,25 @@ void PrtCnvCentralThread::radioStopped()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Calls clean of radio-thread and Db-thread and initializes
|
||||
// the variables for rework.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::cleanAndReinit()
|
||||
{
|
||||
INFO_LOG(m_logger) << "cleanAndReinit";
|
||||
emit cleanRadio();
|
||||
|
||||
// reinit mit sicherung und löschung der datenbestände
|
||||
m_ReceiveAckCounter = 0;
|
||||
m_DbThread->cleanAndInit();
|
||||
m_DoCleanup = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Starts radio-thread and itself for proceeding work after
|
||||
// cleaning the Db.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::radioCleant()
|
||||
{
|
||||
if (!m_DoCleanup)
|
||||
@@ -280,16 +280,16 @@ void PrtCnvCentralThread::radioCleant()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// see base-class
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::onTextMessageReceived(const QString &msg)
|
||||
{
|
||||
|
||||
// eat all pending readyReadyRead
|
||||
if (m_DoCleanup)
|
||||
return;
|
||||
if (PrtCnvSocketThread::e_WORKING != m_State)
|
||||
return;
|
||||
return; // do nothing when we are not in working state
|
||||
onDirectTextMessageReceived(msg.toUtf8());
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ void PrtCnvCentralThread::onDirectTextMessageReceived(const QByteArray &baJson)
|
||||
try
|
||||
{
|
||||
if (baJson.isEmpty())
|
||||
throw std::exception();
|
||||
throw std::exception(); // FIXME: use own exception
|
||||
const QJsonObject obj = QJsonDocument::fromJson(baJson).object();
|
||||
|
||||
const QJsonValue typeId = obj.value(QStringLiteral("typeId"));
|
||||
@@ -311,16 +311,16 @@ void PrtCnvCentralThread::onDirectTextMessageReceived(const QByteArray &baJson)
|
||||
|
||||
m_aliveTimer->start();
|
||||
|
||||
|
||||
// which kind of telegram is it?
|
||||
if (telegram.telegramId() == TrainingAreaBase::TetraIcd::BESTAETIGUNG)
|
||||
{
|
||||
|
||||
// it is an ack-telegram
|
||||
handleAck(&telegram);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Received telegram '" << baJson << "'";
|
||||
|
||||
// a payload-telegram
|
||||
handleTelegram(&telegram);
|
||||
}
|
||||
}
|
||||
@@ -328,7 +328,7 @@ void PrtCnvCentralThread::onDirectTextMessageReceived(const QByteArray &baJson)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "JSon conversion error happenend. Error:"
|
||||
<< e.what() << ", msg: " << baJson;
|
||||
|
||||
// inform central about the failure
|
||||
TrainingAreaBase::TetraIcd::CtaDataError tele;
|
||||
tele.header.equipmentNumber = m_VirtualTeilnehmerId;
|
||||
tele.header.timeStamp = time(nullptr) * 1000LL;
|
||||
@@ -339,21 +339,21 @@ void PrtCnvCentralThread::onDirectTextMessageReceived(const QByteArray &baJson)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::stateChanged(QAbstractSocket::SocketState newState)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Websocket changed to state " << newState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Stores a telegram to be sent to radio in volatile radio-
|
||||
// list and permanent in DB.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram)
|
||||
{
|
||||
|
||||
|
||||
|
||||
// => check with receive-counter if we lost a telegram or we get a telegram twice.
|
||||
// => in this cases neither store the telegram nor send an ack (just ignore and read the next telegram)
|
||||
// => the receive-counter will be hold on the last correct received telegram
|
||||
DEBUG_LOG(m_logger) << "Receive Central-Telegram with telId=" << a_telegram->telegramId()
|
||||
<< "; rcounter=" << a_telegram->counter();
|
||||
if (checkAndUpdateReceiveCounter(a_telegram->counter()))
|
||||
@@ -383,7 +383,7 @@ void PrtCnvCentralThread::handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_
|
||||
case AreaEffectSimulationType::GasPipeDetonation:
|
||||
case AreaEffectSimulationType::SpecialArea:
|
||||
case AreaEffectSimulationType::Unknown:
|
||||
Q_ASSERT(false);
|
||||
Q_ASSERT(false); // should not happen but who knows
|
||||
break;
|
||||
case AreaEffectSimulationType::BeStillWarning:
|
||||
case AreaEffectSimulationType::DangerZoneExplosion:
|
||||
@@ -400,7 +400,7 @@ void PrtCnvCentralThread::handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_
|
||||
bool bSomethingChanged = false;
|
||||
for (int i = 0; i < msms.mineCount; ++i)
|
||||
{
|
||||
if (!LtsUtils::BitArray::testBit(msms.mineState, i))
|
||||
if (!LtsUtils::BitArray::testBit(msms.mineState, i)) // 0 = triggered
|
||||
{
|
||||
INFO_LOG(m_logger) << "Testing bit " << i << " ... not set = triggered";
|
||||
if (!oldTriggeredMines.contains(i))
|
||||
@@ -419,7 +419,7 @@ void PrtCnvCentralThread::handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_
|
||||
return;
|
||||
}
|
||||
INFO_LOG(m_logger) << "MineState telegram contains new informations... " << msms.aesDdsId;
|
||||
oldTriggeredMines = newTriggeredMines;
|
||||
oldTriggeredMines = newTriggeredMines; // update in m_alreadyTriggeredMines[]
|
||||
}
|
||||
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram>
|
||||
@@ -427,7 +427,7 @@ void PrtCnvCentralThread::handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_
|
||||
if (radioTelegram)
|
||||
{
|
||||
if (radioTelegram->getIdentity() <= m_maxEqID) {
|
||||
|
||||
// save data in persistent database
|
||||
m_DbThread->storeRadioTelegram(radioTelegram, a_telegram->counter());
|
||||
} else {
|
||||
WARNING_LOG(m_logger) << "Central telegram with telId=" << a_telegram->telegramId()
|
||||
@@ -445,20 +445,20 @@ void PrtCnvCentralThread::handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_
|
||||
emit checkSendToRadio();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// The counter will be set to a_startCounter if a_maxCounter
|
||||
// is reached
|
||||
// returns true if receive-counter is ok
|
||||
// returns false if a telegram is repeated or lost
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvCentralThread::checkAndUpdateReceiveCounter(const int32_t a_counter)
|
||||
{
|
||||
TRACE_LOG(m_logger) << "checkAndUpdateReceiveCounter: " << a_counter << ", " << m_ReceiveCounter;
|
||||
|
||||
// check for wrap
|
||||
if (std::numeric_limits<int32_t>::max() == ++m_ReceiveCounter)
|
||||
m_ReceiveCounter = 0;
|
||||
|
||||
|
||||
// has the counter the expected value?
|
||||
if (m_ReceiveCounter != a_counter)
|
||||
{
|
||||
if (m_ReceiveCounter > a_counter)
|
||||
@@ -473,30 +473,43 @@ bool PrtCnvCentralThread::checkAndUpdateReceiveCounter(const int32_t a_counter)
|
||||
}
|
||||
#if 0
|
||||
m_ReceiveCounter--;
|
||||
return false;
|
||||
return false; // failure
|
||||
#else
|
||||
m_ReceiveCounter = a_counter;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
return true; // all ok
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to send periodically an ack to central
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::timeoutTick()
|
||||
{
|
||||
|
||||
//NOTICE_LOG(m_logger) << "timeoutTick, " << m_DoCleanup << ", " << m_State;
|
||||
if (m_DoCleanup)
|
||||
return;
|
||||
return; // eat all pending timeouts
|
||||
if (PrtCnvSocketThread::e_WORKING != m_State)
|
||||
return;
|
||||
return; // do nothing when we are not in working state
|
||||
|
||||
/*
|
||||
// Das bringt nur noch mehr Traffic wenn zskskp die gesendeten Daten
|
||||
// nicht schnell genug abarbeiten kann - deshalb ersteinmal auskommentiert
|
||||
|
||||
// do we have to resend unacked telegrams
|
||||
if (m_DbThread->resendCentralTelegrams(m_LastSendCounter))
|
||||
{
|
||||
emit checkSendToCentral(); // resend
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing has to be resent => update m_LastSendCounter
|
||||
m_LastSendCounter = m_SendCounter;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// do we have to inject a central-telegram?
|
||||
try
|
||||
{
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *centralInjectTelegram;
|
||||
@@ -512,13 +525,13 @@ void PrtCnvCentralThread::timeoutTick()
|
||||
<< " => could not inject radio-telegram, but we proceed...";
|
||||
}
|
||||
|
||||
|
||||
// send the periodically ack-telegram to central
|
||||
sendAck();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// see base-class
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::timeoutAliveAndConnection()
|
||||
{
|
||||
INFO_LOG(m_logger) << "timeoutAliveAndConnection socketState="
|
||||
@@ -543,16 +556,16 @@ void PrtCnvCentralThread::timeoutAliveAndConnection()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Sends a ack-telegram to central.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::sendAck()
|
||||
{
|
||||
TrainingAreaBase::TetraIcd::Acknowledge ack;
|
||||
ack.timeStamp = time(nullptr) * 1000;
|
||||
ack.ackCounter = m_ReceiveAckCounter;
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram tele(ack);
|
||||
|
||||
// send to socket
|
||||
if (m_webSocket)
|
||||
m_webSocket->sendTextMessage(QString::fromUtf8(tele.data()));
|
||||
else
|
||||
@@ -562,10 +575,10 @@ void PrtCnvCentralThread::sendAck()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Sends a central-telegram to socket or file, depending on
|
||||
// configuration. Before sending, the send-counter will be set.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::sendTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram)
|
||||
{
|
||||
PrtCnvStoredCentralTelegram *handle = nullptr;
|
||||
@@ -573,11 +586,11 @@ void PrtCnvCentralThread::sendTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_te
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Sends a central-telegram to socket or file, depending on
|
||||
// configuration. Before sending, the send-counter will be set.
|
||||
// After sending the Db will be updated.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::sendTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram,
|
||||
PrtCnvStoredCentralTelegram *a_handle)
|
||||
{
|
||||
@@ -585,43 +598,43 @@ void PrtCnvCentralThread::sendTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_te
|
||||
if (a_telegram->telegramId() == TelegramId::DEAKTIVIERUNG_EINZELMINE)
|
||||
{
|
||||
const MineTriggered tele(MineTriggered::fromJson(a_telegram->jsonData()));
|
||||
m_alreadyTriggeredMines[tele.mineAreaId].insert(tele.mineIndex - 1);
|
||||
m_alreadyTriggeredMines[tele.mineAreaId].insert(tele.mineIndex - 1); // starts at 1 ...
|
||||
INFO_LOG(m_logger) << "Adding triggered mine with id " << tele.mineIndex << " to area id " << tele.mineAreaId;
|
||||
}
|
||||
|
||||
|
||||
// set the counter, but keep old counter if we resend the telegram
|
||||
const int writeCounter = a_handle ? a_handle->writeCounter() : 0;
|
||||
if (writeCounter != 0)
|
||||
a_telegram->setCounter(writeCounter);
|
||||
else
|
||||
a_telegram->setCounter(++m_SendCounter);
|
||||
|
||||
|
||||
// send telegram to central
|
||||
DEBUG_LOG(m_logger) << "Send telegram to central: telId=" << a_telegram->telegramId()
|
||||
<< " wcounter=" << a_telegram->counter();
|
||||
|
||||
// send to socket
|
||||
if (m_webSocket)
|
||||
m_webSocket->sendTextMessage(QString::fromUtf8(a_telegram->data()));
|
||||
else
|
||||
emit directTextMessage(a_telegram->data());
|
||||
|
||||
|
||||
// mark in Db telegram as sent
|
||||
if (a_handle)
|
||||
m_DbThread->centralTelegramSent(a_telegram->counter(), a_handle);
|
||||
m_LogThread->writeCentralTelegramLog(a_telegram, true, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Processes the telegram
|
||||
// AnforderungStatistikBroadcastNachforderugen. The function
|
||||
// fills the answer telegram StatistikBroadNachforderungen
|
||||
// with the actual statistic.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::handleAnforderungStatistikBroadcastNachforderungen()
|
||||
{
|
||||
const auto nachforderungsStat = m_DbThread->getClaimStatistics();
|
||||
|
||||
|
||||
// inform central about the failure
|
||||
TrainingAreaBase::TetraIcd::BroadcastStatistics tele;
|
||||
tele.header.equipmentNumber = m_VirtualTeilnehmerId;
|
||||
tele.header.timeStamp = time(nullptr) * 1000LL;
|
||||
@@ -638,14 +651,14 @@ void PrtCnvCentralThread::handleAnforderungStatistikBroadcastNachforderungen()
|
||||
sendTelegram(&telegram);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Checks whether a telegram must be sent and sends it.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::checkSend()
|
||||
{
|
||||
|
||||
// eat all pending checkSend-signals, if we have to cleanup
|
||||
if (m_DoCleanup) return;
|
||||
if (PrtCnvSocketThread::e_WORKING != m_State) return;
|
||||
if (PrtCnvSocketThread::e_WORKING != m_State) return; // do nothing when we are not in working state
|
||||
PrtCnvStoredCentralTelegram *handle = nullptr;
|
||||
auto *centralTelegram = m_DbThread->getNextCentralTelegram(handle);
|
||||
if (centralTelegram)
|
||||
@@ -656,26 +669,26 @@ void PrtCnvCentralThread::checkSend()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Removes telegrams from ToCentral-table, if the central
|
||||
// acknowledges their reception
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::handleAck(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram)
|
||||
{
|
||||
TrainingAreaBase::TetraIcd::Acknowledge ack(TrainingAreaBase::TetraIcd::Acknowledge::fromJson(a_telegram->jsonData()));
|
||||
|
||||
// INFO_LOG(m_logger) << "Got Central-Ack with wcounter=" << a_ackTelegram.zaehler();
|
||||
m_DbThread->ackCentralTelegrams(ack.ackCounter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Db-thread when telegrams were stored
|
||||
// permanent. This function will then send the ack to central
|
||||
// (socket-based) or delete the telegramfiles (file-based)
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::permanentStored(int32_t a_centralCounter)
|
||||
{
|
||||
if (m_DoCleanup) return;
|
||||
if (PrtCnvSocketThread::e_WORKING != m_State) return;
|
||||
if (m_DoCleanup) return; // eat all pending permanentStored
|
||||
if (PrtCnvSocketThread::e_WORKING != m_State) return; // do nothing when we are not in working state
|
||||
DEBUG_LOG(m_logger) << "got permanentStored a_centralCounter=" << a_centralCounter;
|
||||
if (0 != a_centralCounter && a_centralCounter > m_ReceiveAckCounter)
|
||||
{
|
||||
@@ -732,10 +745,10 @@ void PrtCnvCentralThread::onRadioThreadInitDone()
|
||||
m_sendAckTimer->start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// returns true if telegram should be converted, stored and
|
||||
// sent to radio
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvCentralThread::handleSpecialTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram)
|
||||
{
|
||||
using namespace TrainingAreaBase::TetraIcd;
|
||||
@@ -750,17 +763,17 @@ bool PrtCnvCentralThread::handleSpecialTelegram(N_CoPrtCnv::CoPrtCnvCentralTeleg
|
||||
case ExerciseStateData::ExerciseState::Terminated:
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got Betriebszustandsmeldung Uebung_Aufraeumen => disconnect, cleanup and reconnect";
|
||||
m_DbThread->setMachineState(1);
|
||||
|
||||
m_DbThread->setMachineState(1); // store permanent that we cleanup now, so we will proceed cleanup, after a crash
|
||||
// send ack before disconnecting
|
||||
permanentStored(a_telegram->counter());
|
||||
m_DoCleanup = true;
|
||||
m_CentralStopped = false;
|
||||
m_RadioStopped = false;
|
||||
|
||||
// INFO_LOG(m_logger) << "stop timer";
|
||||
m_sendAckTimer->stop();
|
||||
m_DbThread->waitUntilDbWritten();
|
||||
disconnectSocket();
|
||||
m_RadioThread->prepareCleanUp();
|
||||
m_RadioThread->prepareCleanUp(); // this makes empty the message-queue of radio-thread faster
|
||||
emit stopRadio();
|
||||
m_reconnectTimer->start();
|
||||
break;
|
||||
@@ -779,7 +792,7 @@ bool PrtCnvCentralThread::handleSpecialTelegram(N_CoPrtCnv::CoPrtCnvCentralTeleg
|
||||
return false;
|
||||
}
|
||||
case Constraints<RequestBroadcastStatistics>::id():
|
||||
|
||||
// here we must not use sendAck(), because it could be that we ack central-telegrams which are not yet stored permanent
|
||||
m_DbThread->centralCounterReadyForAck(a_telegram->counter());
|
||||
handleAnforderungStatistikBroadcastNachforderungen();
|
||||
return false;
|
||||
@@ -796,7 +809,7 @@ bool PrtCnvCentralThread::handleSpecialTelegram(N_CoPrtCnv::CoPrtCnvCentralTeleg
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::connectSocket()
|
||||
{
|
||||
const QString host = m_Config->getString(getName(), QStringLiteral("HostName"), QStringLiteral("EXCTDS01"));
|
||||
@@ -827,7 +840,7 @@ void PrtCnvCentralThread::connectSocket()
|
||||
m_State = PrtCnvSocketThread::e_CONNECTING;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvCentralThread::disconnectSocket()
|
||||
{
|
||||
m_State = PrtCnvSocketThread::e_INITIAL;
|
||||
@@ -841,4 +854,4 @@ void PrtCnvCentralThread::disconnectSocket()
|
||||
m_webSocket = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvCentralThread
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -27,8 +27,15 @@ namespace PrtCnv
|
||||
{
|
||||
class PrtCnvRadioThread;
|
||||
class PrtCnvThreadStarter;
|
||||
|
||||
|
||||
/**
|
||||
* This class handles the protocoll to central. This includes:
|
||||
* - connection with files instead sockets (configurable)
|
||||
* - send and receive telegrams
|
||||
*
|
||||
* @author
|
||||
* @version 1.0
|
||||
* @created 05-Jan-2006 13:34:28
|
||||
*/
|
||||
class PrtCnvCentralThread : public PrtCnv::PrtCnvThread
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -37,199 +44,270 @@ private:
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 02-Jul-2009 14:32:58
|
||||
*/
|
||||
~PrtCnvCentralThread();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param a_parent The pointer to the starter-thread
|
||||
*/
|
||||
explicit PrtCnvCentralThread(PrtCnvThreadStarter* a_parent);
|
||||
|
||||
|
||||
/**
|
||||
* Creates all subcomponents and connects signals to slots
|
||||
*/
|
||||
int32_t create(NGL::Settings *settings) override;
|
||||
int32_t deinit() override;
|
||||
|
||||
|
||||
/**
|
||||
* Deallocates subcomponents.
|
||||
*/
|
||||
int32_t destroy() override;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the variables.
|
||||
*/
|
||||
int32_t init() override;
|
||||
|
||||
|
||||
/**
|
||||
* Starts the thread and connects to TCP-server
|
||||
*/
|
||||
int32_t start() override;
|
||||
|
||||
|
||||
/**
|
||||
* Stops the thread
|
||||
*/
|
||||
int32_t stop() override;
|
||||
|
||||
|
||||
// for direct communication
|
||||
void onDirectTextMessageReceived(const QByteArray &baJson);
|
||||
|
||||
signals:
|
||||
|
||||
// for direct communication
|
||||
void directTextMessage(const QByteArray &baJson);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Signal to start sending a telegram to central
|
||||
*/
|
||||
void checkSendToCentral();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to start sending a telegram to radio
|
||||
*/
|
||||
void checkSendToRadio();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to stop radio
|
||||
*/
|
||||
void stopRadio();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to start cleaning-process of radio-thread
|
||||
*/
|
||||
void cleanRadio();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to restart work of radio-thread
|
||||
*/
|
||||
void startRadio();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* For reading/writing json telegrams to socket
|
||||
*/
|
||||
QWebSocket *m_webSocket;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The send-counter (only for sockets)
|
||||
*/
|
||||
int32_t m_SendCounter;
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a telegram must be sent and sends it.
|
||||
*/
|
||||
void checkSend();
|
||||
|
||||
|
||||
/**
|
||||
* Stores that radio-thread has stopped. Cleans the Db and reinitializes when
|
||||
* central-thread has also stopped.
|
||||
*/
|
||||
void radioStopped();
|
||||
|
||||
|
||||
/**
|
||||
* Starts radio-thread and itself for proceeding work after cleaning the Db.
|
||||
*/
|
||||
void radioCleant();
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Db-thread when telegrams were stored permanent. This
|
||||
* function will then send the ack to central (socket-based) or delete the
|
||||
* telegramfiles (file-based)
|
||||
*
|
||||
* @param a_centralCounter
|
||||
*/
|
||||
void permanentStored(int32_t a_centralCounter);
|
||||
|
||||
|
||||
// called from Radio thread to indicate current connection state
|
||||
void onTetraConnectionState(bool bConnected);
|
||||
|
||||
// called from Radio thread to indicate the license state of an equipment
|
||||
void onPlayerLicencedChanged(int equipNo, N_CoPrtCnv::E_LicensingKind kind);
|
||||
|
||||
protected slots:
|
||||
|
||||
// an effect siumlation was (de)activated
|
||||
void onAreaEffectSimulationDeactivated(int wirkfeldKennung);
|
||||
void onAreaEffectSimulationActivated(int wirkfeldKennung);
|
||||
|
||||
|
||||
// radio thread completely initialized
|
||||
void onRadioThreadInitDone();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* called when websocket is connected
|
||||
*/
|
||||
void connected();
|
||||
|
||||
|
||||
/**
|
||||
* called when websocket is disconnected
|
||||
*/
|
||||
void disconnected();
|
||||
|
||||
|
||||
/**
|
||||
* used to send periodically an ack to central
|
||||
*/
|
||||
void timeoutTick();
|
||||
|
||||
|
||||
/**
|
||||
* see base-class
|
||||
*/
|
||||
void timeoutAliveAndConnection();
|
||||
|
||||
void onTextMessageReceived(const QString &msg);
|
||||
void stateChanged(QAbstractSocket::SocketState newState);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Sends a ack-telegram to central.
|
||||
*/
|
||||
void sendAck();
|
||||
|
||||
|
||||
/**
|
||||
* Stores a telegram to be sent to radio in volatile radio-list and permanent in
|
||||
* DB.
|
||||
*
|
||||
* @param a_telegram
|
||||
*/
|
||||
void handleTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram);
|
||||
bool checkAndUpdateReceiveCounter(const int32_t a_counter);
|
||||
|
||||
|
||||
/**
|
||||
* Sends a central-telegram to socket or file, depending on configuration. Before
|
||||
* sending, the send-counter will be set. After sending the Db will be updated.
|
||||
*
|
||||
* @param a_telegram The central-telegram to be sent.
|
||||
* @param a_handle The handle assigned to telegram to be sent, we got from Db.
|
||||
*/
|
||||
void sendTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram,
|
||||
PrtCnvStoredCentralTelegram *a_handle);
|
||||
|
||||
|
||||
/**
|
||||
* Processes the telegram AnforderungStatistikBroadcastNachforderugen. The
|
||||
* function fills the answer telegram StatistikBroadNachforderungen with the
|
||||
* actual statistic.
|
||||
*
|
||||
* @param a_umgMldTelegram
|
||||
*/
|
||||
void handleAnforderungStatistikBroadcastNachforderungen();
|
||||
|
||||
|
||||
/**
|
||||
* Removes telegrams from ToCentral-table, if the central acknowledges their
|
||||
* reception
|
||||
*
|
||||
* @param a_ackTelegram
|
||||
*/
|
||||
void handleAck(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram);
|
||||
|
||||
|
||||
/**
|
||||
* Calls clean of radio-thread and Db-thread and initializes the variables for
|
||||
* rework.
|
||||
*/
|
||||
void cleanAndReinit();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns true if telegram should be converted, stored and sent to radio
|
||||
*
|
||||
* @param a_telegram
|
||||
*/
|
||||
bool handleSpecialTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a central-telegram to socket or file, depending on configuration. Before
|
||||
* sending, the send-counter will be set.
|
||||
*
|
||||
* @param a_telegram The central-telegram to be sent.
|
||||
*/
|
||||
void sendTelegram(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connect as client to a TCP-server on ip-address configured as HostName and Port
|
||||
* configured as Port
|
||||
*/
|
||||
void connectSocket();
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from TCP-server
|
||||
*/
|
||||
void disconnectSocket();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* used for periodically send an ack to central
|
||||
*/
|
||||
PrtCnvRadioThread *m_RadioThread;
|
||||
|
||||
|
||||
/**
|
||||
* True if radio has stopped work
|
||||
*/
|
||||
bool m_RadioStopped;
|
||||
|
||||
|
||||
/**
|
||||
* True if central has stopped work
|
||||
*/
|
||||
bool m_CentralStopped;
|
||||
|
||||
|
||||
/**
|
||||
* Used for resending unacked telegrams
|
||||
*/
|
||||
int32_t m_LastSendCounter;
|
||||
|
||||
|
||||
/**
|
||||
* The (virtual) identify of the protocol-converter
|
||||
*/
|
||||
uint16_t m_VirtualTeilnehmerId;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The maximum equipment-ID for tetra - all telegrams with an higher ID will
|
||||
* be silently ignored
|
||||
*/
|
||||
uint16_t m_maxEqID;
|
||||
|
||||
|
||||
// timer to reconnect when no ack from central is coming anymore
|
||||
QTimer *m_aliveTimer;
|
||||
|
||||
|
||||
// timer to send ack to central
|
||||
QTimer *m_sendAckTimer;
|
||||
|
||||
|
||||
// timer to reconnect to central
|
||||
QTimer *m_reconnectTimer;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* True if the database has to be cleant up (used for fast empty of signal buffers)
|
||||
*/
|
||||
QAtomicInt m_DoCleanup;
|
||||
PrtCnvDbThread *m_DbThread;
|
||||
|
||||
// log telegrams in file
|
||||
PrtCnvTelegramLogThread *m_LogThread;
|
||||
|
||||
// get injected telegrams
|
||||
PrtCnvInjectionThread *m_InjectionThread;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Counter of received telegrams (only for sockets)
|
||||
*/
|
||||
int32_t m_ReceiveCounter;
|
||||
|
||||
|
||||
/**
|
||||
* Acknowledged telegrams counter (only for sockets)
|
||||
*/
|
||||
int32_t m_ReceiveAckCounter;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The state-event-machine state
|
||||
*/
|
||||
PrtCnvSocketThread::E_State m_State;
|
||||
|
||||
|
||||
// set with all already deactivated effect simulations to not send deactivate telegram twice
|
||||
QSet<int> m_deactivatedAreaEffectSimulations;
|
||||
|
||||
|
||||
// multimap with all mine areas and it's already triggered mines
|
||||
QHash<int, QSet<int>> m_alreadyTriggeredMines;
|
||||
|
||||
|
||||
// true when we don't use socket but direct connections (through onDirectTextMessageReceived)
|
||||
bool m_bDirectConnection;
|
||||
|
||||
bool m_bRadioThreadInitDone;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvDbThread
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -37,15 +37,28 @@ namespace PrtCnv
|
||||
class PrtCnvStoredCentralTelegram;
|
||||
class PrtCnvStoredRadioTelegram;
|
||||
class PrtCnvMember;
|
||||
|
||||
|
||||
/**
|
||||
* Handles all data which must be stored permanent:
|
||||
* - central-telegrams
|
||||
* - radio-telegrams
|
||||
* - radio-members (TNE)
|
||||
* - reset-counter
|
||||
* - states
|
||||
*
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @created 28-Jul-2009 16:08:53
|
||||
*/
|
||||
class PrtCnvDbThread : public PrtCnvThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with thread-starter as argument
|
||||
*
|
||||
* @param a_parent
|
||||
*/
|
||||
PrtCnvDbThread(const QString &dbDriver,
|
||||
const QString &dbHostName,
|
||||
const QString &dbDatabaseName,
|
||||
@@ -55,161 +68,287 @@ namespace PrtCnv
|
||||
PrtCnvThreadStarter* a_parent);
|
||||
~PrtCnvDbThread();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* starts this thread and its childs
|
||||
*/
|
||||
int32_t start() override;
|
||||
|
||||
|
||||
/**
|
||||
* stops this thread and its childs
|
||||
*/
|
||||
int32_t stop() override;
|
||||
|
||||
|
||||
/**
|
||||
* creates this thread and its childs
|
||||
*/
|
||||
int32_t create(NGL::Settings *settings) override;
|
||||
|
||||
|
||||
/**
|
||||
* initializes this thread and its childs
|
||||
*/
|
||||
int32_t init() override;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates the Db, which telegrams were successful received by central. This
|
||||
* will delete this telegrams from Db.
|
||||
*
|
||||
* @param a_counter
|
||||
*/
|
||||
void ackCentralTelegrams(int32_t a_counter);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the next telegram to send to central.
|
||||
* returns NULL if no telegram found.
|
||||
* ATTENTION: The caller is responsible to deallocate the returned
|
||||
* centralTelegram!
|
||||
*
|
||||
* @param a_handle
|
||||
*/
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *getNextCentralTelegram(PrtCnvStoredCentralTelegram *& a_handle);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Marks the central-telegram as to be sent
|
||||
*
|
||||
* @param a_counter The counter the telegram has while sent
|
||||
* @param a_handle The telegram-handle gotten from getNextCentralTelegram()
|
||||
*/
|
||||
void centralTelegramSent(const int32_t a_counter, PrtCnvStoredCentralTelegram *a_handle);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the counter for unsuccessful sending the telegram. If a maximal value
|
||||
* of this counter is reached, the central-telegram will be deleted.
|
||||
* a_handle could be deleted after calling this function!
|
||||
* This function could block some milliseconds, because it must wait until all
|
||||
* changes are written to DB.
|
||||
*
|
||||
* @param a_handle The telegram-handle gotten from getNextCentralTelegram()
|
||||
*/
|
||||
void centralTelegramCouldNotBeSent(PrtCnvStoredCentralTelegram *a_handle);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Marks the radio-telegram as to be sent
|
||||
*
|
||||
* @param a_sendCounter
|
||||
* @param a_handle
|
||||
* @param a_broadcastIndex
|
||||
*/
|
||||
void radioTelegramSent(const uint32_t a_sendCounter, PrtCnvStoredRadioTelegram *a_handle, const uint32_t a_broadcastIndex);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the next telegram to send to radio, respecting the priority.
|
||||
* returns NULL if no radio-telegram found.
|
||||
*
|
||||
* @param a_handle
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getNextRadioTelegram(PrtCnvStoredRadioTelegram *&a_handle);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns the next broadcast-telegram from list.
|
||||
* Deletes the telegram from this list.
|
||||
* returns NULL if list empty.
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getNextBroadcastTelegram();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* stores the telegram to be sent to central in working-list and also in Db.
|
||||
* Because storing data in XDR_Wrapper_it-format is complicated (has pointer to
|
||||
* data), we store them in the radio-telegram-format).
|
||||
* Attention: Be aware that centralTelegram and radioTelegram contain the same
|
||||
* data.
|
||||
* The DbThread takes control over centralTelegram and radioTelegram and deletes
|
||||
* them when no longer needed.
|
||||
*
|
||||
* @param a_centralTelegram
|
||||
* @param a_radioTelegram Must be the same telegram like the central-telegram
|
||||
* (used for storing the telegram in Db)
|
||||
*/
|
||||
void storeCentralTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvCentralTelegram> &a_centralTelegram,
|
||||
const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_radioTelegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Stores the telegram to be sent to radio in working-list and also in Db.
|
||||
* The DbThread takes control over a_telegram and deletes it when no longer needed.
|
||||
*
|
||||
*
|
||||
* @param a_telegram
|
||||
* @param a_readCounter
|
||||
*/
|
||||
void storeRadioTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram, const int32_t a_readCounter);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function causes acking a central-telegram, which must not be stored
|
||||
* permanent in Db, because it will be handled immediately (i.e.
|
||||
* AnforderungStatistikBroadcastNachforderungen).
|
||||
*
|
||||
* @param a_centralCounter The read-counter of the central-telegram
|
||||
*/
|
||||
void centralCounterReadyForAck(const int32_t a_centralCounter);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds an sql-command in the sql-command-list. On next iteration of
|
||||
* storePermanent() all command in list will be executed.
|
||||
*
|
||||
* @param a_sqlCommand
|
||||
*/
|
||||
void addSqlCommand(const QString &sql);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* erases and initializes the database
|
||||
*/
|
||||
void cleanAndInit();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether central-telegrams have to be resent. If yes, all actions will be
|
||||
* done, that getNextCentralTelegram() delivers the telegram(s) to be resent.
|
||||
* Returns true if there must telegrams be resent.
|
||||
*
|
||||
* @param a_lastSendCounter The counter of the telegram we expect a ack-
|
||||
* telegram has been received
|
||||
*/
|
||||
bool resendCentralTelegrams(const int32_t a_lastSendCounter);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the telegrams not yet acked from central for reconnection. This will
|
||||
* be done by setting the write-counter to 0.
|
||||
*/
|
||||
void prepareCentralTelegramsForReconnection();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Blocks until all SQL-commands were written to DB.
|
||||
*/
|
||||
void waitUntilDbWritten();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns NULL if no member found
|
||||
*
|
||||
* @param a_ISSI
|
||||
*/
|
||||
PrtCnvMember* getMemberByISSI(const uint32_t a_ISSI) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns NULL if member not found
|
||||
*
|
||||
* @param a_id
|
||||
*/
|
||||
PrtCnvMember* getMemberById(const uint16_t a_id);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Licenses the member
|
||||
*
|
||||
* @param a_member
|
||||
* @param a_doLicense
|
||||
*/
|
||||
bool licenseMember(PrtCnvMember *a_member, const bool a_doLicense = true);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the current exercise for this member
|
||||
*/
|
||||
void updateExerciseIdForMember(PrtCnvMember *a_member, int newExerciseId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* adds a member in the 2 maps, sorted by id and ISSI
|
||||
* returns the new member
|
||||
*
|
||||
* @param a_identity
|
||||
* @param a_ISSI
|
||||
*/
|
||||
PrtCnvMember* addMember(const int a_identity, const int a_ISSI);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* removes the member in the 2 maps, sorted by id and ISSI
|
||||
*
|
||||
* @param a_member
|
||||
*/
|
||||
void removeMember(PrtCnvMember* a_member);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the actual reset-counter
|
||||
*/
|
||||
uint8_t getResetCounter() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the actual reset-counter
|
||||
*
|
||||
* @param newVal
|
||||
*/
|
||||
void setResetCounter(uint8_t newVal);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The actual 'Betriebszustaende Gefechtsfeld' which will be sent to TNEs
|
||||
* periodically
|
||||
*/
|
||||
uint8_t getBattleFieldOperatingState() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets or unsets pause, depending on a_doSet.
|
||||
* (Bit 0 in UMGEBUNGS_MELDUNG(2))
|
||||
* @param a_doSet
|
||||
*/
|
||||
void setPause(const bool a_doSet = true);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the inhibit time for position telegrams (1 .. 31 Seconds)
|
||||
* (Bit 1-5 in UMGEBUNGS_MELDUNG(2))
|
||||
* @param a_doSet
|
||||
*/
|
||||
void setPositionSendTime(unsigned int sendTime);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the current air load to be sent with the Umgebungsmeldung
|
||||
* (Bit 6-7 in UMGEBUNGS_MELDUNG(2))
|
||||
* @param airLoad The current air-load received from Tetra
|
||||
*/
|
||||
void setAirLoad(PrtCnvRadioThread::E_TrafficLoad airLoad);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the resetCounter itself is different than the reset-counter of
|
||||
* the environment-telegram
|
||||
*/
|
||||
bool isEnvironmentResetCounterOld() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the actual Umgebungsmeldung
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> getEnvironmentTelegram();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the resetcounter of the environment-telegram to the actual reset-counter.
|
||||
*/
|
||||
void setResetCounterOnEnvironment();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Increments the counter for nachforderungen of the TNE with id a_identity.
|
||||
*
|
||||
* @param a_identity The identity of the TNE, which asked for nachforderung
|
||||
*/
|
||||
void incClaimCount(int a_identity);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fills the map with nachforderungsstatistic.
|
||||
* Returns the number of elements in map.
|
||||
*
|
||||
* @param a_statisticMap this map will be filled with pairs of
|
||||
* ausstattungsnummer and amount of nachforderungen
|
||||
*/
|
||||
std::map<int32_t, int32_t> getClaimStatistics() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the actual machine-state permanent, used to proceed cleaning db after a
|
||||
* crash.
|
||||
*
|
||||
* @param a_newMachineState The new machine-state. 0 => working; 1 => cleaning
|
||||
* DB
|
||||
*/
|
||||
void setMachineState(const int a_newMachineState);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if protocol-converter was crashed while cleanup DB.
|
||||
*/
|
||||
bool mustProceedCleanup() const;
|
||||
|
||||
protected:
|
||||
void closeDb();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* List of telegrams to be sent to central
|
||||
*/
|
||||
std::vector<PrtCnvStoredCentralTelegram*> m_CentralList;
|
||||
|
||||
|
||||
@@ -224,18 +363,23 @@ namespace PrtCnv
|
||||
|
||||
mutable QRecursiveMutex m_CentralListMutex;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The permanent DB
|
||||
*/
|
||||
QSqlDatabase m_db;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The last counter received from central as ack. Used for deleting no longer used
|
||||
* central-telegrams and for resending of central-telegrams.
|
||||
*/
|
||||
QAtomicInt m_CentralAckCounter;
|
||||
|
||||
|
||||
/**
|
||||
* Used for optimizing deletion of no longer needed central-telegrams.
|
||||
*/
|
||||
unsigned int m_OldCentralAckCounter;
|
||||
|
||||
|
||||
/**
|
||||
* List of telegrams to be sent to radio
|
||||
*/
|
||||
std::list<PrtCnvStoredRadioTelegram*> m_RadioList;
|
||||
|
||||
|
||||
@@ -252,77 +396,104 @@ namespace PrtCnv
|
||||
|
||||
|
||||
std::list<PrtCnvStoredRadioTelegram*> m_BroadcastList;
|
||||
|
||||
|
||||
/**
|
||||
* Used to wait until cleaning is finished and to suppress storing data within
|
||||
* database while cleaning
|
||||
*/
|
||||
bool m_DoClean;
|
||||
|
||||
|
||||
/**
|
||||
* Used for waiting data written to DB
|
||||
*/
|
||||
bool m_DoWaitUntilSqlWritten;
|
||||
|
||||
|
||||
/**
|
||||
* Holds all logged in members ordered by Id.
|
||||
*/
|
||||
std::unordered_map<int,PrtCnvMember*> m_MemberListById;
|
||||
|
||||
|
||||
/**
|
||||
* Holds all logged in members ordered by ISSI
|
||||
*/
|
||||
std::unordered_map<int,PrtCnvMember*> m_MemberListByISSI;
|
||||
|
||||
|
||||
/**
|
||||
* Used to prevent data storing within DB while restoring after crash
|
||||
*/
|
||||
bool m_DoStorePermanent;
|
||||
|
||||
|
||||
/**
|
||||
* the actual reset-counter
|
||||
*/
|
||||
uint8_t m_ResetCounter;
|
||||
|
||||
|
||||
/**
|
||||
* The actual 'Betriebszustaende Gefechtsfeld' which will be sent to TNEs
|
||||
* periodically
|
||||
*/
|
||||
uint8_t m_BattleFieldOperatingState;
|
||||
|
||||
|
||||
/**
|
||||
* The actual telegram "Umgebungsmeldung"
|
||||
*/
|
||||
PrtCnvStoredRadioTelegram* m_EnvironmentTelegram;
|
||||
|
||||
|
||||
/**
|
||||
* True if cleanup has to be proceed after crash.
|
||||
*/
|
||||
bool m_DoProceedCleanup;
|
||||
|
||||
|
||||
/**
|
||||
* Used to optimize send the signal permanentStored
|
||||
*/
|
||||
int32_t m_OldCentralCounter;
|
||||
|
||||
|
||||
/**
|
||||
* For ensure that not too much storePermanent-signals will be queued
|
||||
*/
|
||||
QBasicAtomicInt m_StorePermanentPending;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* nbr of unsuccessful send-attempts, before telegram will be deleted without
|
||||
* sending it
|
||||
*/
|
||||
uint32_t m_NbrOfAttempts;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* creates or restores the permanent database
|
||||
*/
|
||||
bool createDatabase();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a signal storePermanent if not already such a signal is pending
|
||||
*/
|
||||
void sendStorePermanentSignal();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper for storePermanent()
|
||||
*/
|
||||
void storeCentralTelegrams();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper for storePermanent()
|
||||
*/
|
||||
int32_t storeRadioTelegrams();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper for storePermanent()
|
||||
*/
|
||||
void handleSqlCommandList();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Delete all telegrams with the ids in telegramsToDelete
|
||||
* from a given table
|
||||
*/
|
||||
void deleteTelegramsFromDbById(const QString &table);
|
||||
|
||||
|
||||
/**
|
||||
* Update the write counter for the telegrams in
|
||||
* telegramsToUpdateCounter for the given table
|
||||
*/
|
||||
void updateTelegramsWriteCounter(const QString &table);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the broadcast counter for the telegrams in
|
||||
* telegramsToUpdateCounter for the given table
|
||||
*/
|
||||
void updateTelegramsBroadcast(const QString &table);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reinitialize the database
|
||||
*/
|
||||
void reinitDatabase();
|
||||
|
||||
QString toCentralTableName() const { return tableName(QStringLiteral("prtcnv_to_central")); }
|
||||
@@ -332,31 +503,39 @@ namespace PrtCnv
|
||||
QString versionTableName() const { return tableName(QStringLiteral("prtcnv_version")); }
|
||||
QString tableName(const QString &table) const { return m_dbSchemaName.isEmpty() ? table : m_dbSchemaName + QLatin1Char('.') + table; }
|
||||
protected slots:
|
||||
|
||||
|
||||
/**
|
||||
* Stores the radio-telegrams, central-telegrams in Db and executes the sql-
|
||||
* command-list.
|
||||
*/
|
||||
void storePermanent();
|
||||
|
||||
|
||||
/**
|
||||
* cleans up this thread and its childs
|
||||
*/
|
||||
void clean();
|
||||
|
||||
public:
|
||||
signals:
|
||||
|
||||
|
||||
/**
|
||||
* Signal to call storePermanent()
|
||||
*/
|
||||
void doStorePermanent();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to inform central-thread about stored telegrams
|
||||
*
|
||||
* @param a_centralCounter
|
||||
*/
|
||||
void permanentStored(int32_t a_centralCounter);
|
||||
|
||||
|
||||
/**
|
||||
* a signal to erase the permanent database
|
||||
*/
|
||||
void doClean();
|
||||
|
||||
void playerLicencedChanged(int equipNo, N_CoPrtCnv::E_LicensingKind kind);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
// local caches to memory (re)allocation all the time
|
||||
// note: std::vector.clear() does not release memory and therefore
|
||||
// a reallocation in the next turn is not neccessary
|
||||
std::vector<int64_t> m_telegramsToDelete;
|
||||
std::vector<std::pair<int64_t, int32_t> > m_telegramsToUpdateCounter;
|
||||
std::vector<std::pair<int64_t, int32_t> > m_telegramsToUpdateBC;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// manual class headers
|
||||
#include "PrtCnvInjectionSocket.hpp"
|
||||
#include <CoPrtCnv/CoPrtCnvInjectionHeader.hpp>
|
||||
#include <CoPrtCnv/CoPrtCnvCentralTelegram.hpp>
|
||||
@@ -33,9 +33,9 @@ PrtCnvInjectionSocket::~PrtCnvInjectionSocket()
|
||||
delete m_Socket;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Disconnects a TCP-client
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionSocket::disconnectClient()
|
||||
{
|
||||
INFO_LOG(m_logger) << "A client has disconnected from the injection-server";
|
||||
@@ -43,9 +43,9 @@ void PrtCnvInjectionSocket::disconnectClient()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Reads in TCP-data and handles them
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionSocket::processInputData()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Injection-server has data received";
|
||||
@@ -55,7 +55,7 @@ void PrtCnvInjectionSocket::processInputData()
|
||||
{
|
||||
if (injectionHeader.isIdCorrect())
|
||||
{
|
||||
|
||||
// check whether all bytes are available
|
||||
qint64 available = m_Socket->bytesAvailable();
|
||||
if (available < qint64(injectionHeader.m_Size + sizeof(injectionHeader)))
|
||||
{
|
||||
@@ -64,15 +64,15 @@ void PrtCnvInjectionSocket::processInputData()
|
||||
<< injectionHeader.m_Id1 << " id2=" << injectionHeader.m_Id2
|
||||
<< " kind=" << (int)injectionHeader.m_Kind << " size="
|
||||
<< injectionHeader.m_Size;
|
||||
return;
|
||||
return; // try it later, when (maybe) enough bytes are available...
|
||||
}
|
||||
|
||||
// enough bytes => read now all in
|
||||
m_Socket->read((char*)&injectionHeader, sizeof(injectionHeader));
|
||||
if (injectionHeader.isIdCorrect())
|
||||
{
|
||||
|
||||
//INFO_LOG(m_logger) << "kind=" << (int)injectionHeader.m_Kind << " size=" << injectionHeader.m_Size;
|
||||
|
||||
|
||||
// read the data
|
||||
QByteArray data(injectionHeader.m_Size, Qt::Uninitialized);
|
||||
m_Socket->read(data.data(), injectionHeader.m_Size);
|
||||
|
||||
@@ -111,7 +111,7 @@ void PrtCnvInjectionSocket::processInputData()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionSocket::setSocket(QTcpSocket* a_socket, PrtCnvInjectionThread* a_server)
|
||||
{
|
||||
m_Socket = a_socket;
|
||||
@@ -124,4 +124,4 @@ void PrtCnvInjectionSocket::setSocket(QTcpSocket* a_socket, PrtCnvInjectionThrea
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -21,8 +21,13 @@ class QTcpSocket;
|
||||
namespace PrtCnv
|
||||
{
|
||||
class PrtCnvInjectionThread;
|
||||
|
||||
|
||||
/**
|
||||
* Used for receiving the socket signals
|
||||
*
|
||||
* @author alois.wismer
|
||||
* @version 1.0
|
||||
* @created 06-Aug-2010 16:41:44
|
||||
*/
|
||||
class PrtCnvInjectionSocket : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -31,8 +36,11 @@ namespace PrtCnv
|
||||
PrtCnvInjectionSocket();
|
||||
~PrtCnvInjectionSocket();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a_socket
|
||||
* @param a_server
|
||||
*/
|
||||
void setSocket(QTcpSocket* a_socket, PrtCnvInjectionThread* a_server);
|
||||
|
||||
protected:
|
||||
@@ -42,19 +50,23 @@ namespace PrtCnv
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
protected slots:
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects a TCP-client
|
||||
*/
|
||||
void disconnectClient();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reads in TCP-data and handles them
|
||||
*/
|
||||
void processInputData();
|
||||
|
||||
|
||||
public:
|
||||
signals:
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a_injectSocket
|
||||
*/
|
||||
void disconnected(PrtCnvInjectionSocket* a_injectSocket);
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// manual class headers
|
||||
#include "PrtCnvInjectionThread.hpp"
|
||||
#include "PrtCnvInjectionSocket.hpp"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvInjectionThread::PrtCnvInjectionThread(PrtCnvThreadStarter* a_parent)
|
||||
: PrtCnvThread(a_parent, "PrtCnvInjectionThread")
|
||||
, m_Port(46666)
|
||||
@@ -41,7 +41,7 @@ PrtCnvInjectionThread::~PrtCnvInjectionThread()
|
||||
delete m_RadioListMutex;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvInjectionThread::create(NGL::Settings *settings)
|
||||
{
|
||||
INFO_LOG(m_logger) << "create";
|
||||
@@ -52,7 +52,7 @@ int32_t PrtCnvInjectionThread::create(NGL::Settings *settings)
|
||||
|
||||
m_Enabled = m_Config->getBoolean(getName(), QStringLiteral("Enable"), false);
|
||||
|
||||
|
||||
// prepare a tcp-server for simulating central
|
||||
if (m_Enabled)
|
||||
{
|
||||
m_Server = new QTcpServer(this);
|
||||
@@ -64,7 +64,7 @@ int32_t PrtCnvInjectionThread::create(NGL::Settings *settings)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvInjectionThread::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "init";
|
||||
@@ -76,15 +76,15 @@ int32_t PrtCnvInjectionThread::init()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Starts the thread and listen for TCP-clients
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvInjectionThread::start()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Start";
|
||||
PrtCnvThread::start();
|
||||
|
||||
|
||||
// start the TCP-server
|
||||
if (m_Enabled)
|
||||
{
|
||||
m_Server->setMaxPendingConnections(1);
|
||||
@@ -97,9 +97,9 @@ int32_t PrtCnvInjectionThread::start()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Connects a TCP-client
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionThread::connectClient()
|
||||
{
|
||||
INFO_LOG(m_logger) << "A client has connected to the injection-server";
|
||||
@@ -111,9 +111,9 @@ void PrtCnvInjectionThread::connectClient()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Disconnects a TCP-client
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionThread::disconnectClient(PrtCnvInjectionSocket *a_injectionSocket)
|
||||
{
|
||||
auto it = m_SocketList.find(a_injectionSocket);
|
||||
@@ -125,13 +125,13 @@ void PrtCnvInjectionThread::disconnectClient(PrtCnvInjectionSocket *a_injectionS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the next central-telegram to be injected. It will
|
||||
// automatically be taken out of the list.
|
||||
// The caller is responsible to delete the telegram, if no
|
||||
// longer used.
|
||||
// Returns NULL if no central-telegram available
|
||||
// ---------------------------------------------------------------
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *PrtCnvInjectionThread::getNextCentralInjectionTelegram()
|
||||
{
|
||||
QMutexLocker l(m_CentralListMutex);
|
||||
@@ -144,13 +144,13 @@ N_CoPrtCnv::CoPrtCnvCentralTelegram *PrtCnvInjectionThread::getNextCentralInject
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the next radio-telegram to be injected. It will
|
||||
// automatically be taken out of the list.
|
||||
// The caller is responsible to delete the telegram, if no
|
||||
// longer used.
|
||||
// Returns NULL if no radio-telegram available
|
||||
// ---------------------------------------------------------------
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *PrtCnvInjectionThread::getNextRadioInjectionTelegram()
|
||||
{
|
||||
QMutexLocker l(m_RadioListMutex);
|
||||
@@ -163,7 +163,7 @@ N_CoPrtCnv::CoPrtCnvCentralTelegram *PrtCnvInjectionThread::getNextRadioInjectio
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionThread::addToCentralList(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram)
|
||||
{
|
||||
QMutexLocker l(m_CentralListMutex);
|
||||
@@ -171,12 +171,12 @@ void PrtCnvInjectionThread::addToCentralList(N_CoPrtCnv::CoPrtCnvCentralTelegram
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvInjectionThread::addToRadioList(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram)
|
||||
{
|
||||
QMutexLocker l(m_RadioListMutex);
|
||||
m_RadioTelegramList.push(a_telegram);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -28,8 +28,16 @@ class CoPrtCnvCentralTelegram;
|
||||
namespace PrtCnv
|
||||
{
|
||||
class PrtCnvInjectionSocket;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents a thread, which acts as TCP-Server. The LogView-
|
||||
* application can connect to it and send radio- or central-telegrams. The
|
||||
* telegrams will be stored within this class and can be taken by another thread.
|
||||
* This mechanism will be used for inject telegrams to protocol-converter.
|
||||
*
|
||||
* @author alois.wismer
|
||||
* @version 1.0
|
||||
* @created 05-Aug-2010 11:17:06
|
||||
*/
|
||||
class PrtCnvInjectionThread : public PrtCnvThread
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -37,8 +45,10 @@ namespace PrtCnv
|
||||
|
||||
~PrtCnvInjectionThread();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a_parent
|
||||
*/
|
||||
explicit PrtCnvInjectionThread(PrtCnvThreadStarter* a_parent);
|
||||
|
||||
|
||||
@@ -47,31 +57,48 @@ namespace PrtCnv
|
||||
|
||||
int32_t init() override;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Starts the thread and listen for TCP-clients
|
||||
*/
|
||||
int32_t start() override;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next central-telegram to be injected. It will automatically be
|
||||
* taken out of the list.
|
||||
* The caller is responsible to delete the telegram, if no longer used.
|
||||
* Returns NULL if no central-telegram available
|
||||
*/
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *getNextCentralInjectionTelegram();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next radio-telegram to be injected. It will automatically be taken
|
||||
* out of the list.
|
||||
* The caller is responsible to delete the telegram, if no longer used.
|
||||
* Returns NULL if no radio-telegram available
|
||||
*/
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *getNextRadioInjectionTelegram();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a_telegram
|
||||
*/
|
||||
void addToCentralList(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a_telegram
|
||||
*/
|
||||
void addToRadioList(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_telegram);
|
||||
|
||||
protected:
|
||||
|
||||
protected: /**
|
||||
* The port of the injection-server (configurable with key 'Port' in group
|
||||
* [Injection])
|
||||
*/
|
||||
uint16_t m_Port;
|
||||
|
||||
|
||||
/**
|
||||
* true if injection-server is enabled (configurable with key 'Enable' in group
|
||||
* [Injection])
|
||||
*/
|
||||
bool m_Enabled;
|
||||
QTcpServer *m_Server;
|
||||
|
||||
@@ -89,11 +116,15 @@ namespace PrtCnv
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
/**
|
||||
* Connects a TCP-client
|
||||
*/
|
||||
void connectClient();
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects a TCP-client
|
||||
*
|
||||
* @param a_injectionSocket
|
||||
*/
|
||||
void disconnectClient(PrtCnvInjectionSocket* a_injectionSocket);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* \page Tetra-Interface Tetra-Interface
|
||||
*
|
||||
* This component is needed to communicate between the Server software and the players in
|
||||
* the field via Tetra. It's an extra component due to historical reasons only.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "PrtCnvApplication.hpp"
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
@@ -25,41 +31,41 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Become a daemon
|
||||
// ---------------------------------------------------------------
|
||||
static void daemonize()
|
||||
{
|
||||
#ifndef WIN32
|
||||
pid_t pid, sid;
|
||||
|
||||
|
||||
/* already a daemon */
|
||||
if ( getppid() == 1 )
|
||||
return;
|
||||
|
||||
|
||||
/* Fork off the parent process */
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* If we got a good PID, then we can exit the parent process. */
|
||||
if (pid > 0) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* At this point we are executing as the child process */
|
||||
|
||||
|
||||
/* Change the file mode mask */
|
||||
umask(0);
|
||||
|
||||
|
||||
/* Create a new SID for the child process */
|
||||
sid = setsid();
|
||||
if (sid < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Change the current working directory. This prevents the current
|
||||
directory from being locked; hence not being able to remove it. */
|
||||
if ((chdir("/")) < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
|
||||
// manual class headers
|
||||
#include "PrtCnvMember.hpp"
|
||||
#include <CoPrtCnv/CoPrtCnvRadioTelegram.hpp>
|
||||
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor with id and ISSI as parameter
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvMember::PrtCnvMember(int a_id, int a_issi)
|
||||
: m_ISSI(a_issi)
|
||||
, m_ClaimCount(0)
|
||||
@@ -35,9 +35,9 @@ PrtCnvMember::~PrtCnvMember()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Adds a radio-telegram-fragment to this member.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvMember::addFragmentedTelegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_radioTelegram)
|
||||
{
|
||||
m_FragmentedTelegramList.insert(std::make_pair(a_radioTelegram.getFragmentCounter(),
|
||||
@@ -46,28 +46,28 @@ void PrtCnvMember::addFragmentedTelegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the telegram-Id of the fragmented telegram assiged
|
||||
// to this member.
|
||||
// If not evaluable: 0 will be returned.
|
||||
// ---------------------------------------------------------------
|
||||
gef_telegramm_id_et PrtCnvMember::getFragmentedTelegramId() const
|
||||
{
|
||||
|
||||
// the fragment with the highest counter is the first fragment
|
||||
for (auto rit = m_FragmentedTelegramList.rbegin(); rit != m_FragmentedTelegramList.rend(); ++rit)
|
||||
{
|
||||
N_CoPrtCnv::CoPrtCnvRadioTelegram *firstFragment = rit->second;
|
||||
if (N_CoPrtCnv::CoPrtCnvRadioTelegram::e_FirstFragment == firstFragment->getFragmentStatus())
|
||||
return firstFragment->getTelID();
|
||||
}
|
||||
return GEF_BESTAETIGUNG;
|
||||
return GEF_BESTAETIGUNG; // no telegram found => return 0 (= GEF_BESTAETIGUNG)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Erases the radio-telegram-fragments assiged to this member.
|
||||
// The fragments itself will be deleted.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvMember::clearFragmentedList()
|
||||
{
|
||||
for (auto it : m_FragmentedTelegramList)
|
||||
@@ -76,23 +76,23 @@ void PrtCnvMember::clearFragmentedList()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the radio-telegram-fragments assembled to a only
|
||||
// big radio-telegram. The fragments will not be deleted.
|
||||
// Returns NULL if it was impossible to assemble the telegram.
|
||||
// ---------------------------------------------------------------
|
||||
QByteArray PrtCnvMember::getUnfragmentedTelegramData() const
|
||||
{
|
||||
return N_CoPrtCnv::CoPrtCnvRadioTelegram::getUnfragmentedData(m_FragmentedTelegramList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns true if the fragment-list is empty
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvMember::isFragmentedListEmpty() const
|
||||
{
|
||||
return m_FragmentedTelegramList.empty();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <map>
|
||||
#include <QtCore/QByteArray>
|
||||
|
||||
|
||||
// manual class imports
|
||||
|
||||
|
||||
namespace N_CoPrtCnv
|
||||
@@ -27,14 +27,23 @@ namespace N_CoPrtCnv
|
||||
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Hold the data of a TNE (Client on radio-side) needed for login, licensing,
|
||||
* nachforderungs-statistic and reading fragmented telegrams from TNE.
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 16-Mrz-2010 11:20:11
|
||||
*/
|
||||
class PrtCnvMember final
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The status of the member
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 16-Mrz-2010 11:20:11
|
||||
*/
|
||||
enum E_MemberStatus
|
||||
{
|
||||
e_Ok,
|
||||
@@ -44,40 +53,55 @@ namespace PrtCnv
|
||||
};
|
||||
~PrtCnvMember();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with id and ISSI as parameter
|
||||
*
|
||||
* @param a_id
|
||||
* @param a_issi
|
||||
*/
|
||||
PrtCnvMember(int a_id, int a_issi);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds a radio-telegram-fragment to this member.
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
*/
|
||||
void addFragmentedTelegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_radioTelegram);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the telegram-Id of the fragmented telegram assiged to this member.
|
||||
* If not evaluable: 0 will be returned.
|
||||
*/
|
||||
gef_telegramm_id_et getFragmentedTelegramId() const;
|
||||
|
||||
|
||||
/**
|
||||
* Erases the radio-telegram-fragments assiged to this member. The fragments
|
||||
* itself will be deleted.
|
||||
*/
|
||||
void clearFragmentedList();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the radio-telegram-fragments assembled to a only big radio-telegram.
|
||||
* The fragments will not be deleted.
|
||||
* Returns NULL if it was impossible to assemble the telegram.
|
||||
*/
|
||||
QByteArray getUnfragmentedTelegramData() const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the fragment-list is empty
|
||||
*/
|
||||
bool isFragmentedListEmpty() const;
|
||||
|
||||
public:
|
||||
|
||||
// The ISSI of this TNE (0..0xFFFFFF)
|
||||
int m_ISSI;
|
||||
|
||||
// Counts the Nachforderungen asked from this TNE
|
||||
int m_ClaimCount;
|
||||
|
||||
// the exercise where the member is currently logged in
|
||||
int m_loggedInExerciseId;
|
||||
|
||||
// The identification (also called Ausstattungs-Nummer) of this TNE (0..10000)
|
||||
int m_Id;
|
||||
|
||||
// true if TNE is licensed
|
||||
bool m_Licensed;
|
||||
|
||||
private:
|
||||
|
||||
// Map of radio-telegram-fragments ordered by fragment-number
|
||||
std::multimap<uint16_t,N_CoPrtCnv::CoPrtCnvRadioTelegram*> m_FragmentedTelegramList;
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvRadioThread
|
||||
// **************************************************************************
|
||||
#pragma once
|
||||
|
||||
#include "PrtCnvSocketThread.hpp"
|
||||
@@ -38,8 +38,17 @@ struct BiteError
|
||||
class PrtCnvMember;
|
||||
class PrtCnvRadioTrafficThread;
|
||||
class PrtCnvStoredRadioTelegram;
|
||||
|
||||
|
||||
/**
|
||||
* This class handles the protocol to radio. This includes:
|
||||
* - handle login and licensing of TNEs
|
||||
* - send and receive normal telegrams
|
||||
* - send normal broadcasts and nachforderungen
|
||||
* - optimize bandwith usage
|
||||
*
|
||||
* @author
|
||||
* @version 1.0
|
||||
* @created 05-Jan-2006 13:34:41
|
||||
*/
|
||||
class PrtCnvRadioThread : public PrtCnv::PrtCnvSocketThread
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -47,25 +56,33 @@ struct BiteError
|
||||
public:
|
||||
|
||||
PrtCnvRadioThread(int exerciseId, PrtCnvThreadStarter* a_parent);
|
||||
|
||||
|
||||
/**
|
||||
* Creates all subcomponents and connects signals to slots
|
||||
*/
|
||||
int32_t create(NGL::Settings *settings) override;
|
||||
|
||||
|
||||
/**
|
||||
* Deallocates subcomponents.
|
||||
*/
|
||||
int32_t destroy() override;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the variables.
|
||||
*/
|
||||
int32_t init() override;
|
||||
|
||||
|
||||
/**
|
||||
* Starts the thread and connects to TCP-server
|
||||
*/
|
||||
int32_t start() override;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Makes empty the message-queue faster, because the messages will be consumed
|
||||
* without action.
|
||||
*/
|
||||
void prepareCleanUp();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Immediatelly send the environment telegramm to inform the players
|
||||
* about the new state
|
||||
*/
|
||||
void sendEnvironmentTelegramTimerNow();
|
||||
|
||||
void exerciseEquipmentChanged(const TrainingAreaBase::TetraIcd::ExerciseEquipmentAssignmentComplete &data);
|
||||
@@ -80,124 +97,165 @@ public:
|
||||
int masterIssi);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to central-thread
|
||||
*/
|
||||
PrtCnvCentralThread *m_CentralThread;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to radio traffic counter thread
|
||||
*/
|
||||
PrtCnvRadioTrafficThread *m_radioTrafficThread;
|
||||
|
||||
public:
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
/**
|
||||
* Signal to start sending a telegram to central
|
||||
*/
|
||||
void checkSendToCentral();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to start sending a telegram to radio
|
||||
*/
|
||||
void checkSendToRadio();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to indicate thread has finished the cleaning-phase
|
||||
*/
|
||||
void cleant();
|
||||
|
||||
|
||||
/**
|
||||
* Signal to indicate thread has stopped work
|
||||
*/
|
||||
void stopped();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* a new equipment exercise mapping was received, check if member (all when identiy = -1)
|
||||
* is still in this exercise
|
||||
*/
|
||||
void checkMemberForValidLogin(int identity, int issi);
|
||||
|
||||
|
||||
|
||||
// emitted when the tetra connection state changes
|
||||
void tetraConnectionState(bool connected);
|
||||
|
||||
|
||||
// an effect siumlation was (de)activated
|
||||
void areaEffectSimulationActivated(int wirkfeldKennung);
|
||||
void areaEffectSimulationDeactivated(int wirkfeldKennung);
|
||||
|
||||
|
||||
// initialization of the thread is finished
|
||||
void initDone();
|
||||
|
||||
|
||||
// a player was (un)licensed
|
||||
void playerLicencedChanged(int equipNo, N_CoPrtCnv::E_LicensingKind kind);
|
||||
void warehouseMessageFromPtrCnv(const QByteArray &jsonData);
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Counts the sended telegrams
|
||||
*/
|
||||
uint32_t m_SendCounter;
|
||||
|
||||
|
||||
/**
|
||||
* The ISSI of the protocol-converter
|
||||
*/
|
||||
uint32_t m_HostISSI;
|
||||
|
||||
|
||||
/**
|
||||
* The lowest vaild value for the counter
|
||||
*/
|
||||
const uint32_t START_COUNTER;
|
||||
|
||||
|
||||
/**
|
||||
* One more than the highest vaild value for the counter
|
||||
*/
|
||||
const uint32_t END_COUNTER;
|
||||
|
||||
|
||||
/**
|
||||
* This timer will be used for periodically send the Umgebungsmeldung to TNEs
|
||||
*/
|
||||
QTimer *m_EnvironmentTelegramTimer;
|
||||
|
||||
|
||||
/**
|
||||
* The ISSI used for broadcast-telegrams
|
||||
*/
|
||||
uint32_t m_BroadcastISSI;
|
||||
|
||||
|
||||
/**
|
||||
* The directory and prefix for the login-log-file
|
||||
*/
|
||||
QString m_LoginPathWithPrefix;
|
||||
|
||||
|
||||
/**
|
||||
* Übungskennung (used for login-logfile name)
|
||||
*/
|
||||
int m_ExerciseId;
|
||||
|
||||
|
||||
/**
|
||||
* Bit-map for evaluating whether a playerid is valid
|
||||
*/
|
||||
std::set<uint16_t> m_AllowedIdentities;
|
||||
|
||||
|
||||
/**
|
||||
* true => TPU will be licensed whether selftest and configtest fails or not
|
||||
*/
|
||||
bool m_DoLicenseDespiteSelftestOrConfigFailure;
|
||||
|
||||
|
||||
/**
|
||||
* true => identify of TPU will be checked, whether allowed
|
||||
*/
|
||||
bool m_DoCheckIdentity;
|
||||
PrtCnvBroadcastMgr m_BroadcastManager;
|
||||
|
||||
|
||||
/**
|
||||
* True => received telegrams will be dumped to common log-file
|
||||
*/
|
||||
bool m_DoDumpReceivedTelegrams;
|
||||
|
||||
|
||||
/**
|
||||
* True => sent telegrams will be dumped to common log-file
|
||||
*/
|
||||
bool m_DoDumpSentTelegrams;
|
||||
|
||||
|
||||
/**
|
||||
* True => radio-telegrams will be sent in SDS-TL-format
|
||||
*/
|
||||
bool m_DoUseSDSTL;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Identities that need an active position response after licensing
|
||||
*/
|
||||
std::set<uint16_t> m_DoNeedActPosResp;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The ISSI used for emergency call-telegrams
|
||||
*/
|
||||
uint32_t m_EmergencyCallISSI;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a telegram to radio. It will be fragmented if needed. It will be checked,
|
||||
* whether the receiver is logged in, licensed, the content is valid and the
|
||||
* telegram is not expired and an error-message will be sent to central if needed.
|
||||
* It will be tested, whether the maximal broadcast-counter is reached and if it
|
||||
* is, the needed action will be done.
|
||||
*
|
||||
* @param a_telegram
|
||||
* @param a_handle
|
||||
* @param a_doCheckWhetherExpired
|
||||
*/
|
||||
void sendTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram,
|
||||
PrtCnvStoredRadioTelegram *a_handle,
|
||||
const bool a_doCheckWhetherExpired = true);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends the register-indication to TETRA
|
||||
*/
|
||||
void doRegister();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send a register group message to TETRA
|
||||
*/
|
||||
void registerGroups();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Processes the register-response-telegram
|
||||
*
|
||||
* @param a_regsitrationStatus
|
||||
*/
|
||||
void handleRegisterRsp(const uint8_t a_regsitrationStatus);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author alois.wismer
|
||||
* @version 1.0
|
||||
* @updated 06-Apr-2010 16:01:59
|
||||
*/
|
||||
enum class E_TrafficLoad
|
||||
{
|
||||
Unknown = -1,
|
||||
@@ -206,12 +264,14 @@ public:
|
||||
FullLoad
|
||||
};
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Holds the radio-telegram for sending Umgebungsmeldung periodically
|
||||
*/
|
||||
N_CoPrtCnv::CoPrtCnvRadioTelegram *m_EnvironmentTelegram;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* load of traffic from Protocolconverter to TETRA
|
||||
*/
|
||||
E_TrafficLoad m_SendLoad;
|
||||
|
||||
uint32_t m_SendQueueFullLoad;
|
||||
@@ -219,79 +279,125 @@ public:
|
||||
uint32_t m_SendTelegramsNormalLoad;
|
||||
uint32_t m_SendTelegramsHighLoad;
|
||||
uint32_t m_SendTelegramsFullLoad;
|
||||
|
||||
|
||||
/**
|
||||
* The number of telegrams sent within the last second
|
||||
*/
|
||||
uint32_t m_SentTelegrams;
|
||||
|
||||
|
||||
/**
|
||||
* The number of bytes sent within last second
|
||||
*/
|
||||
uint32_t m_SentBytes;
|
||||
|
||||
|
||||
/**
|
||||
* how many times tick must be called until 1 second has elapsed
|
||||
*/
|
||||
uint32_t m_TickCounter;
|
||||
|
||||
|
||||
/**
|
||||
* how many times tick was called (used for knowing when 1 second has elapsed,
|
||||
* which we use for sent-bytes and receive-bytes statistics)
|
||||
*/
|
||||
uint32_t m_TicksPerSecond;
|
||||
|
||||
|
||||
/**
|
||||
* How many values we use for computing average
|
||||
*/
|
||||
static const int AVERAGE_COUNT = 10;
|
||||
|
||||
|
||||
/**
|
||||
* The last few number of bytes sent, used for calculating the average
|
||||
*/
|
||||
uint32_t m_SentBytesAverage[AVERAGE_COUNT];
|
||||
|
||||
|
||||
/**
|
||||
* index for writing into aveage-array
|
||||
*/
|
||||
uint8_t m_AverageIndex;
|
||||
|
||||
|
||||
/**
|
||||
* The number of telegrams sent within the last second
|
||||
*/
|
||||
uint32_t m_ReceivedTelegrams;
|
||||
|
||||
|
||||
/**
|
||||
* The number of bytes sent within last second
|
||||
*/
|
||||
uint32_t m_ReceivedBytes;
|
||||
|
||||
|
||||
/**
|
||||
* The last few number of bytes sent, used for calculating the average
|
||||
*/
|
||||
uint32_t m_ReceivedBytesAverage[AVERAGE_COUNT];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The groups which should be listened to
|
||||
*/
|
||||
std::set<uint32_t> m_ListenGroups;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief use scrambling yes/no (Radio/UseScrambling)
|
||||
*/
|
||||
bool m_bUseScrambling;
|
||||
|
||||
|
||||
/**
|
||||
* The logger object for statistics
|
||||
*/
|
||||
NGL::INGLLogger &m_loggerStats;
|
||||
|
||||
|
||||
// mapping which equipNos are in which exercise
|
||||
std::unordered_map<int, std::unordered_set<int>> m_exerciseEquipmentAssignments;
|
||||
std::unordered_map<int, TrainingAreaBase::TetraIcd::GroupIssiInformation> m_groupIssiInformation;
|
||||
mutable QRecursiveMutex m_exerciseEquipmentAssignmentMutex;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* generates an answer to TNE from protocoll-converter for some special radio-
|
||||
* telegrams (i.e. NachforderungBroadcast, BITE-Meldung)
|
||||
* returns true when the telegram must be sent to central
|
||||
*
|
||||
* @param a_centralTelegram
|
||||
* @param a_radioTelegram
|
||||
*/
|
||||
bool sendAnswer(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_radioTelegram);
|
||||
|
||||
|
||||
/**
|
||||
* After calling this function, the caller must no longer use a_data, because this
|
||||
* function 'consumes' a_data and will delete a_data, when no longer needed.
|
||||
*
|
||||
* @param a_data A pointer to the telegram-data, including frame-header.
|
||||
* Control over a_data will be lost (see description of function itself)
|
||||
*/
|
||||
void handleReceivedTelegram(const QByteArray &data);
|
||||
|
||||
|
||||
/**
|
||||
* Processes the data-indication-telegram
|
||||
*
|
||||
* @param a_data
|
||||
* @param bDoDeleteData is set to true when the caller can properly delete the data
|
||||
*/
|
||||
void handleDataIndReq(const QByteArray &data, bool bIsMaybeScrambled);
|
||||
|
||||
|
||||
/**
|
||||
* Processes the login-telegram
|
||||
*
|
||||
* @param a_loginTelegram
|
||||
*/
|
||||
void handleLoginTelegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_loginTelegram);
|
||||
|
||||
|
||||
/**
|
||||
* Processes a fragment of a telegram
|
||||
*
|
||||
* @param a_fragmentedTelegram
|
||||
*/
|
||||
void handleFragmentedTelegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_fragmentedTelegram);
|
||||
|
||||
|
||||
/**
|
||||
* Sends a telegram "FehlermeldungGefechtsfeld" to central
|
||||
*
|
||||
* @param a_identity
|
||||
* @param a_errorCause
|
||||
* @param a_telegramId
|
||||
*/
|
||||
void sendFehlermeldungGefechtsfeldToCentral(const uint16_t a_identity,
|
||||
const TrainingAreaBase::TetraIcd::CtaDataError::Reason a_errorCause,
|
||||
const gef_telegramm_id_et a_telegramId = GEF_BESTAETIGUNG);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ISSI of TNE with a_TNE_Id
|
||||
*
|
||||
* @param a_TNE_Id
|
||||
*/
|
||||
uint32_t getDestinationISSI(const uint16_t a_TNE_Id) const;
|
||||
|
||||
|
||||
/**
|
||||
* Processes the BITE/BITE extended-telegram
|
||||
*
|
||||
* @param a_BITE_CentralTelegram
|
||||
*/
|
||||
bool handleBITEEXT_Telegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_BITE_RadioTelegram);
|
||||
bool handleBITE_Telegram(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_BITE_RadioTelegram,
|
||||
TrainingAreaBase::TetraIcd::BiteReport::LoginType anmeldeart,
|
||||
@@ -302,47 +408,86 @@ public:
|
||||
const QList<PrtCnv::BiteError> &fehlerListe
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a login-telegram to radio
|
||||
*
|
||||
* @param a_loginTelegramStatus
|
||||
* @param a_identity
|
||||
* @param a_ISSI
|
||||
*/
|
||||
void sendLoginResponse(const N_CoPrtCnv::CoPrtCnvRadioTelegram::E_LoginStatus a_loginTelegramStatus, const uint16_t a_identity, const uint32_t a_ISSI);
|
||||
void sendLoginResponse(const N_CoPrtCnv::CoPrtCnvRadioTelegram::E_LoginStatus a_loginTelegramStatus,
|
||||
const uint16_t a_identity, const uint32_t a_ISSI, const TrainingAreaBase::TetraIcd::GroupIssiInformation &group);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a telegram "LizenzierungTNE" to radio
|
||||
*
|
||||
* @param a_identity AusstattungsId
|
||||
* @param a_issi
|
||||
* @param a_licensingKind
|
||||
* @param a_errorCause
|
||||
*/
|
||||
void sendLizenzierungTneToRadio(const uint16_t a_identity, const uint32_t a_issi,
|
||||
const N_CoPrtCnv::E_LicensingKind a_licensingKind,
|
||||
const N_CoPrtCnv::E_LicensingErrorCode a_errorCause);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Writes the login of a TNE to the login-logfile
|
||||
*
|
||||
* @param a_radioTelegram
|
||||
* @param a_prosaText
|
||||
*/
|
||||
void writeLoginLog(const N_CoPrtCnv::CoPrtCnvRadioTelegram &a_radioTelegram, const QString &a_prosaText);
|
||||
void writeLoginLog(const N_CoPrtCnv::CoPrtCnvRadioTelegram *a_radioTelegram, const QString &a_prosaText);
|
||||
void writeLoginLog(uint32_t identity, uint32_t issi, const QString &a_prosaText);
|
||||
|
||||
|
||||
/**
|
||||
* Receives the file with allowed playerId, or the lowest and hightest allowed
|
||||
* playerIds
|
||||
*/
|
||||
void initIdentityArray();
|
||||
|
||||
|
||||
/**
|
||||
* Reads one line of the playerId-file.
|
||||
* Aborts when not successful
|
||||
*
|
||||
* @param a_idAsText
|
||||
* @param a_line
|
||||
* @param a_fileName
|
||||
*/
|
||||
uint16_t readIdentity(const QByteArray& a_idAsText, const uint32_t a_line, const QString& a_fileName);
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the playerId is allowd.
|
||||
*
|
||||
* @param a_identity
|
||||
*/
|
||||
bool isIdentityValid(uint16_t a_identity) const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Allows this playerId.
|
||||
*
|
||||
* @param a_identity
|
||||
*/
|
||||
void setIdentityVaild(uint16_t a_identity);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fragment a telegram and sends the fragments to radio.
|
||||
*
|
||||
* @param a_telegram
|
||||
*/
|
||||
void sendFragmentedTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* sends the telegram to radio-socket
|
||||
* returns the broadcastIndex (0 if it was no broadcast)
|
||||
*
|
||||
* @param a_telegram
|
||||
*/
|
||||
uint16_t sendToSocket(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Processes the report-indication-telegram
|
||||
*
|
||||
* @param a_data
|
||||
*/
|
||||
void handleReportIndReq(const QByteArray &data);
|
||||
void prepareWareHouseMessage(qint32 equipNr,
|
||||
bool doLicence,
|
||||
@@ -353,59 +498,78 @@ public:
|
||||
const QList<PrtCnv::BiteError> &fehlerListe);
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
||||
|
||||
/**
|
||||
* @brief oslot to handle call to sendEnvironmentTelegramTimerNow in correct thread
|
||||
*/
|
||||
void onSendEnvironmentTelegramTimerNow();
|
||||
|
||||
|
||||
/**
|
||||
* see base-class
|
||||
*/
|
||||
void timeoutAliveAndConnection() override;
|
||||
|
||||
|
||||
/**
|
||||
* Processes the periodical stuff, like broadcasts and nachforderungen
|
||||
*/
|
||||
void timeoutTick() override;
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a normal telegram must be sent and sends it.
|
||||
*/
|
||||
void checkSend();
|
||||
|
||||
|
||||
/**
|
||||
* see base-class
|
||||
*/
|
||||
void readyRead() override;
|
||||
|
||||
|
||||
/**
|
||||
* see base-class
|
||||
*/
|
||||
void disconnected() override;
|
||||
|
||||
|
||||
/**
|
||||
* see base-class
|
||||
*/
|
||||
void connected() override;
|
||||
|
||||
|
||||
/**
|
||||
* Processes the periodical sending of Umgebungsmeldung
|
||||
*/
|
||||
void timeoutEnvironmentTelegram();
|
||||
|
||||
|
||||
/**
|
||||
* Clean the DB.
|
||||
*/
|
||||
void doClean();
|
||||
|
||||
|
||||
/**
|
||||
* Restart work after cleaning Db
|
||||
*/
|
||||
void doStart();
|
||||
|
||||
|
||||
/**
|
||||
* Stops work for cleaning DB
|
||||
*/
|
||||
void doStop();
|
||||
|
||||
|
||||
|
||||
// a broadcastTelegrams request was received from EXCON (e.g. through Wls)
|
||||
void onBroadcastTelegramsRequestFromCentral(int equipmentNumber, int broadcastIndex, int resetCounter);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* Processes the status-telegram
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
void handleStatusIndReq(const QByteArray &data);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Processes the air-interface-report-telegram
|
||||
*
|
||||
* @param a_data
|
||||
*/
|
||||
void handleAirInterfaceLoadReq(const QByteArray &data);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Computes and logs the sent- and receive-statistics
|
||||
*/
|
||||
void computeAndLogTrafficStatistics();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* returns true, if at the moment no more telegrams should be sent
|
||||
*/
|
||||
bool isSendLimitReached() const;
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// @RDE_HEADER@
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvRadioTrafficThread
|
||||
// **************************************************************************
|
||||
|
||||
#include "PrtCnvRadioTrafficThread.hpp"
|
||||
#include "PrtCnvDbThread.hpp"
|
||||
@@ -46,7 +46,7 @@ void PrtCnvRadioTrafficThread::newTelegramArrived(unsigned int size)
|
||||
|
||||
int32_t PrtCnvRadioTrafficThread::start()
|
||||
{
|
||||
|
||||
// read data from m_Config
|
||||
const QString trafficControlGroup(QStringLiteral("TrafficControl"));
|
||||
int highLoad = m_Config->getInteger(trafficControlGroup, QStringLiteral("ReceiveQueueHighLoad"), 60);
|
||||
int fullLoad = m_Config->getInteger(trafficControlGroup, QStringLiteral("ReceiveQueueFullLoad"), 80);
|
||||
@@ -55,7 +55,7 @@ int32_t PrtCnvRadioTrafficThread::start()
|
||||
float trafficPerReceiverKB = m_Config->getFloat(trafficControlGroup, QStringLiteral("ReceiveThroughput"), 3.6f);
|
||||
int cntTransceiver = m_Config->getInteger(trafficControlGroup, QStringLiteral("TransceiverCount"), 6);
|
||||
|
||||
|
||||
// sanity checks
|
||||
if (highLoad < 0 || highLoad > 100)
|
||||
highLoad = 60;
|
||||
if (fullLoad < highLoad || fullLoad > 100)
|
||||
@@ -74,7 +74,7 @@ int32_t PrtCnvRadioTrafficThread::start()
|
||||
m_fullLoad = maxTrafficBytes * fullLoad / 100.f;
|
||||
m_highLoad = maxTrafficBytes * highLoad / 100.f;
|
||||
m_hystLoad = maxTrafficBytes * hystLoad / 100.f;
|
||||
m_cleanupTimeout = avgTime * 1000;
|
||||
m_cleanupTimeout = avgTime * 1000; // ms
|
||||
|
||||
DEBUG_LOG(m_logger) << "Read config ReceiveQueueHighLoad: " << highLoad;
|
||||
DEBUG_LOG(m_logger) << "Read config ReceiveQueueFullLoad: " << fullLoad;
|
||||
@@ -100,12 +100,12 @@ void PrtCnvRadioTrafficThread::onCalculateTrafficLoad()
|
||||
unsigned int payload = 0;
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
|
||||
// fuer aktuelle Sekunde haben wir noch nicht alle Daten
|
||||
for (int i = 1; i <= m_cleanupTimeout / 1000; ++i)
|
||||
payload += m_data.value(curTime - i);
|
||||
}
|
||||
|
||||
|
||||
// Durchschnitt ...
|
||||
payload /= (m_cleanupTimeout / 1000);
|
||||
|
||||
INFO_LOG(m_logger) << "Average Payload in the last "
|
||||
@@ -116,34 +116,34 @@ void PrtCnvRadioTrafficThread::onCalculateTrafficLoad()
|
||||
PrtCnvRadioThread::E_TrafficLoad newReceiveLoad;
|
||||
if (payload >= m_fullLoad)
|
||||
{
|
||||
|
||||
// full load
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::FullLoad;
|
||||
|
||||
// Hysterese nach oben
|
||||
if (m_receiveLoad == PrtCnvRadioThread::E_TrafficLoad::HighLoad)
|
||||
{
|
||||
|
||||
|
||||
// wenn cnt in Bereich m_fullLoad ... m_fullLoad + m_hystLoad
|
||||
// -> noch warten
|
||||
if(payload < m_fullLoad + m_hystLoad)
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::HighLoad;
|
||||
}
|
||||
}
|
||||
else if (payload >= m_highLoad)
|
||||
{
|
||||
|
||||
// high load
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::HighLoad;
|
||||
|
||||
// Hysterese nach oben
|
||||
if (m_receiveLoad == PrtCnvRadioThread::E_TrafficLoad::NormalLoad)
|
||||
{
|
||||
|
||||
|
||||
// wenn cnt in Bereich m_highLoad ... m_highLoad + m_hystLoad
|
||||
// -> noch warten
|
||||
if (payload < m_highLoad + m_hystLoad)
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::NormalLoad;
|
||||
}
|
||||
|
||||
// Hysterese nach unten
|
||||
if (m_receiveLoad == PrtCnvRadioThread::E_TrafficLoad::FullLoad)
|
||||
{
|
||||
|
||||
|
||||
// wenn cnt in Bereich m_fullLoad ... m_fullLoad - m_hystLoad
|
||||
// -> noch warten
|
||||
if (payload >= m_fullLoad - m_hystLoad)
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::FullLoad;
|
||||
}
|
||||
@@ -151,11 +151,11 @@ void PrtCnvRadioTrafficThread::onCalculateTrafficLoad()
|
||||
else
|
||||
{
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::NormalLoad;
|
||||
|
||||
// Hysterese nach unten
|
||||
if (m_receiveLoad == PrtCnvRadioThread::E_TrafficLoad::HighLoad)
|
||||
{
|
||||
|
||||
|
||||
// wenn cnt in Bereich m_highLoad ... m_highLoad - m_hystLoad
|
||||
// -> noch warten
|
||||
if(payload >= m_highLoad - m_hystLoad)
|
||||
newReceiveLoad = PrtCnvRadioThread::E_TrafficLoad::HighLoad;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ void PrtCnvRadioTrafficThread::onCalculateTrafficLoad()
|
||||
if (m_receiveLoad != newReceiveLoad)
|
||||
{
|
||||
m_receiveLoad = newReceiveLoad;
|
||||
|
||||
// Achtung: Nicht mehr als 31 Sekunden erlaubt
|
||||
unsigned int wartezeit_posmldg = (static_cast<unsigned int>(m_receiveLoad) * 10) + 1;
|
||||
|
||||
INFO_LOG(m_logger) << "New traffic load: " << m_receiveLoad;
|
||||
@@ -191,18 +191,18 @@ void PrtCnvRadioTrafficThread::onCleanupTimeout()
|
||||
while (it != m_data.end())
|
||||
{
|
||||
const time_t key = it.key();
|
||||
|
||||
// 10 als Puffer (siehe auch onCalculateTrafficLoad())
|
||||
if (key < curTime - m_cleanupTimeout - 10)
|
||||
{
|
||||
m_data.erase(it++);
|
||||
m_telegrams.remove(key);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
break; // arbitrarily ordered
|
||||
}
|
||||
}
|
||||
|
||||
QTimer::singleShot(m_cleanupTimeout, this, &PrtCnvRadioTrafficThread::onCleanupTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// @RDE_HEADER@
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvRadioTrafficThread
|
||||
// **************************************************************************
|
||||
#pragma once
|
||||
|
||||
#include "PrtCnvThread.hpp"
|
||||
@@ -21,63 +21,76 @@
|
||||
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* This class handles the traffic counting for the
|
||||
* incoming radio data
|
||||
*/
|
||||
class PrtCnvRadioTrafficThread final : public PrtCnvThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PrtCnvRadioTrafficThread(PrtCnvThreadStarter* a_parent);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A new telegram arrived.
|
||||
*/
|
||||
void newTelegramArrived(unsigned int size);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Start the thread handling
|
||||
*/
|
||||
int32_t start() override;
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
||||
|
||||
/**
|
||||
* Timeout to recalculate traffic load
|
||||
*/
|
||||
void onCalculateTrafficLoad();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Timeout to throw away old data
|
||||
*/
|
||||
void onCleanupTimeout();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* The current traffic load
|
||||
*/
|
||||
PrtCnvRadioThread::E_TrafficLoad m_receiveLoad;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Full load
|
||||
*/
|
||||
unsigned int m_fullLoad;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* High load
|
||||
*/
|
||||
unsigned int m_highLoad;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hysterese
|
||||
*/
|
||||
unsigned int m_hystLoad;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Timeout for recalculation
|
||||
*/
|
||||
int m_calcTimeout;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Timeout until data is thrown away
|
||||
*/
|
||||
int m_cleanupTimeout;
|
||||
|
||||
|
||||
|
||||
QRecursiveMutex m_mutex;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* map<time, nTelegrams>
|
||||
*/
|
||||
QMap<time_t, unsigned int> m_data;
|
||||
QMap<time_t, unsigned int> m_telegrams;
|
||||
};
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvSocketThread
|
||||
// **************************************************************************
|
||||
|
||||
#include "PrtCnvSocketThread.hpp"
|
||||
#include <utility>
|
||||
@@ -25,9 +25,9 @@
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor with pointer to thread-starter as parameter
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvSocketThread::PrtCnvSocketThread(PrtCnv::PrtCnvThreadStarter* a_parent, const char *loggerName)
|
||||
: PrtCnvThread(a_parent, loggerName)
|
||||
, m_ConnectionTimer(nullptr)
|
||||
@@ -54,9 +54,9 @@ PrtCnvSocketThread::~PrtCnvSocketThread()
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Creates all subcomponents and connects signals to slots
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvSocketThread::create(NGL::Settings *settings)
|
||||
{
|
||||
PrtCnvThread::create(settings);
|
||||
@@ -76,10 +76,10 @@ int32_t PrtCnvSocketThread::create(NGL::Settings *settings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Creates a new socket to avoid getting old stuff from the
|
||||
// former socket when reconnecting
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::createNewSocket()
|
||||
{
|
||||
INFO_LOG(m_logger) << "createNewSocket m_oldSocket=" << m_Socket;
|
||||
@@ -87,11 +87,11 @@ void PrtCnvSocketThread::createNewSocket()
|
||||
|
||||
if (m_Socket)
|
||||
{
|
||||
m_Socket->disconnectFromHost();
|
||||
m_Socket->disconnect();
|
||||
m_Socket->disconnectFromHost(); // Falls noch connected
|
||||
m_Socket->disconnect(); // Alle Signals/Slots aufräumen
|
||||
if (m_Socket->state() != QAbstractSocket::UnconnectedState)
|
||||
m_Socket->waitForDisconnected();
|
||||
m_Socket->deleteLater();
|
||||
m_Socket->deleteLater(); // und weg damit
|
||||
}
|
||||
|
||||
m_Socket = new QTcpSocket(this);
|
||||
@@ -106,9 +106,9 @@ void PrtCnvSocketThread::createNewSocket()
|
||||
connect(m_Socket, &QTcpSocket::readyRead, this, &PrtCnvSocketThread::readyRead, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Deallocates subcomponents.
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvSocketThread::destroy()
|
||||
{
|
||||
PrtCnvThread::destroy();
|
||||
@@ -124,9 +124,9 @@ void PrtCnvSocketThread::cleanup()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Initializes the variables.
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvSocketThread::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "PrtCnvSocketThread::init()";
|
||||
@@ -140,10 +140,10 @@ int32_t PrtCnvSocketThread::init()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Connect as client to a TCP-server on ip-address configured
|
||||
// as HostName and Port configured as Port
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::connectSocket()
|
||||
{
|
||||
int sockState = m_Socket ? m_Socket->state() : -1;
|
||||
@@ -152,7 +152,7 @@ void PrtCnvSocketThread::connectSocket()
|
||||
{
|
||||
if (m_Socket)
|
||||
{
|
||||
m_Socket->disconnectFromHost();
|
||||
m_Socket->disconnectFromHost(); // Falls noch connected
|
||||
if (m_Socket->state() != QAbstractSocket::UnconnectedState)
|
||||
m_Socket->waitForDisconnected();
|
||||
}
|
||||
@@ -175,9 +175,9 @@ void PrtCnvSocketThread::connectSocket()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Disconnects from TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::disconnectSocket()
|
||||
{
|
||||
m_Socket->disconnectFromHost();
|
||||
@@ -186,46 +186,46 @@ void PrtCnvSocketThread::disconnectSocket()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have connected to
|
||||
// TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::connected()
|
||||
{
|
||||
INFO_LOG(m_logger) << "connected (implement connected() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have disconnected
|
||||
// to TCP-server
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::disconnected()
|
||||
{
|
||||
INFO_LOG(m_logger) << "got signal 'disconnected' (implement disconnected() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have have read
|
||||
// data over socket
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::readyRead()
|
||||
{
|
||||
INFO_LOG(m_logger) << "got signal 'newData' (implement newData() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// this slot is used for connection, disconnection and alive
|
||||
// timeouts
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::timeoutAliveAndConnection()
|
||||
{
|
||||
INFO_LOG(m_logger) << "got signal 'reconnectTimeout' (implement reconnectTimeout() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when we have a socket-error
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::error(QAbstractSocket::SocketError a_socketError)
|
||||
{
|
||||
switch (a_socketError)
|
||||
@@ -237,7 +237,7 @@ void PrtCnvSocketThread::error(QAbstractSocket::SocketError a_socketError)
|
||||
ERROR_LOG(m_logger) << getName() << ": RemoteHostClosedError";
|
||||
break;
|
||||
case QAbstractSocket::HostNotFoundError:
|
||||
|
||||
//ERROR_LOG(m_logger) << getName() << ": HostNotFoundError";
|
||||
break;
|
||||
default:
|
||||
ERROR_LOG(m_logger) << getName() << ": got signal 'error(QAbstractSocket::SocketError=" << a_socketError << ")'";
|
||||
@@ -245,28 +245,28 @@ void PrtCnvSocketThread::error(QAbstractSocket::SocketError a_socketError)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when the host was found
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::hostFound()
|
||||
{
|
||||
|
||||
// INFO_LOG(m_logger) << "got signal 'hostFound' (implement hostFound() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Will be called from Qt-Framework when socket-state has
|
||||
// changed
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::stateChanged(QAbstractSocket::SocketState a_socketState)
|
||||
{
|
||||
Q_UNUSED(a_socketState);
|
||||
|
||||
// INFO_LOG(m_logger) << "got signal 'stateChanged(" << ao_socketState << ")' (implement stateChanged() in inherited class, if you want use this signal...)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// calls storeRadioTelegram of DbThread, see there
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::storeRadioTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram,
|
||||
const uint32_t a_readCounter)
|
||||
{
|
||||
@@ -274,9 +274,9 @@ void PrtCnvSocketThread::storeRadioTelegram(const std::shared_ptr<N_CoPrtCnv::Co
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to check whether the other side is still alive
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startAliveTimer()
|
||||
{
|
||||
m_ConnectionTimer->setInterval(m_AliveTimeout);
|
||||
@@ -284,9 +284,9 @@ void PrtCnvSocketThread::startAliveTimer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to retry connection
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startConnectionTimer()
|
||||
{
|
||||
m_ConnectionTimer->setInterval(m_ConnectTimeout);
|
||||
@@ -294,10 +294,10 @@ void PrtCnvSocketThread::startConnectionTimer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used to abort connection, when normal disconnection is not
|
||||
// successful
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startDisconnectionTimer()
|
||||
{
|
||||
m_ConnectionTimer->setInterval(m_DisconnectTimeout);
|
||||
@@ -305,36 +305,36 @@ void PrtCnvSocketThread::startDisconnectionTimer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// used for periodically ticks (i.e. for acks or sending
|
||||
// nachforderungen)
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvSocketThread::startTickTimer()
|
||||
{
|
||||
|
||||
// INFO_LOG(m_logger) << "start timer";
|
||||
m_TickTimer->setInterval(m_TickTimeout);
|
||||
m_TickTimer->start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// The counter will be set to a_startCounter if a_maxCounter
|
||||
// is reached
|
||||
// returns true if receive-counter is ok
|
||||
// returns false if a telegram is repeated or lost
|
||||
// ---------------------------------------------------------------
|
||||
bool PrtCnvSocketThread::checkAndUpdateReceiveCounter(const uint32_t a_counter, const uint32_t a_maxCounter, const uint32_t a_startCounter)
|
||||
{
|
||||
TRACE_LOG(m_logger) << "checkAndUpdateReceiveCounter: " << a_counter << ", " << m_ReceiveCounter;
|
||||
|
||||
// check for wrap
|
||||
if (a_maxCounter == ++m_ReceiveCounter)
|
||||
{
|
||||
m_ReceiveCounter = a_startCounter;
|
||||
}
|
||||
|
||||
// has the counter the expected value?
|
||||
if (m_ReceiveCounter != a_counter)
|
||||
{
|
||||
|
||||
//if (m_ReceiveCounter != 1)
|
||||
{
|
||||
if (m_ReceiveCounter > a_counter)
|
||||
{
|
||||
@@ -349,13 +349,13 @@ bool PrtCnvSocketThread::checkAndUpdateReceiveCounter(const uint32_t a_counter,
|
||||
}
|
||||
#if 0
|
||||
m_ReceiveCounter--;
|
||||
return false;
|
||||
return false; // failure
|
||||
#else
|
||||
m_ReceiveCounter = a_counter;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
return true; // all ok
|
||||
}
|
||||
|
||||
void PrtCnvSocketThread::readHostAdresses()
|
||||
@@ -380,4 +380,4 @@ void PrtCnvSocketThread::readHostAdresses()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvSocketThread
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -33,15 +33,30 @@ namespace PrtCnv
|
||||
class PrtCnvDbThread;
|
||||
class PrtCnvTelegramLogThread;
|
||||
class PrtCnvInjectionThread;
|
||||
|
||||
|
||||
/**
|
||||
* The father-class of radio- and central-thread. It implements common-parts like
|
||||
* - socket-connection and -disconnection
|
||||
* - telegram-counter
|
||||
* - timers
|
||||
* - telegram-log
|
||||
* - thread-state
|
||||
*
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @created 26-Jun-2009 07:39:05
|
||||
*/
|
||||
class PrtCnvSocketThread : public PrtCnvThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The different states for the state-event-machine
|
||||
*
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @created 02-Jul-2009 14:16:49
|
||||
*/
|
||||
enum E_State
|
||||
{
|
||||
e_INITIAL,
|
||||
@@ -51,139 +66,195 @@ namespace PrtCnv
|
||||
e_DISCONNECTING,
|
||||
e_REINIT
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with pointer to thread-starter as parameter
|
||||
*
|
||||
* @param a_parent
|
||||
*/
|
||||
PrtCnvSocketThread(PrtCnvThreadStarter* a_parent, const char *loggerName);
|
||||
~PrtCnvSocketThread();
|
||||
|
||||
|
||||
/**
|
||||
* Creates all subcomponents and connects signals to slots
|
||||
*/
|
||||
int32_t create(NGL::Settings *settings) override;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new socket to avoid getting old stuff from the
|
||||
* former socket when reconnecting
|
||||
*/
|
||||
void createNewSocket();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the variables.
|
||||
*/
|
||||
int32_t init() override;
|
||||
|
||||
|
||||
/**
|
||||
* Deallocates subcomponents.
|
||||
*/
|
||||
int32_t destroy() override;
|
||||
void cleanup();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* this timer is used for controlling connection and disconnection
|
||||
*/
|
||||
QTimer *m_ConnectionTimer;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The TCP-socket
|
||||
*/
|
||||
QTcpSocket *m_Socket;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the hostname to connect to
|
||||
*/
|
||||
void readHostAdresses();
|
||||
|
||||
protected slots:
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Qt-Framework when we have connected to TCP-server
|
||||
*/
|
||||
virtual void connected();
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Qt-Framework when we have have read data over socket
|
||||
*/
|
||||
virtual void readyRead();
|
||||
|
||||
|
||||
/**
|
||||
* this slot is used for connection, disconnection and alive timeouts
|
||||
*/
|
||||
virtual void timeoutAliveAndConnection();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Processes the periodical stuff, like broadcasts, acks
|
||||
*/
|
||||
virtual void timeoutTick() {}
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Qt-Framework when we have a socket-error
|
||||
*
|
||||
* @param a_socketError
|
||||
*/
|
||||
virtual void error(QAbstractSocket::SocketError a_socketError);
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Qt-Framework when the host was found
|
||||
*/
|
||||
virtual void hostFound();
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Qt-Framework when socket-state has changed
|
||||
*
|
||||
* @param a_socketState
|
||||
*/
|
||||
virtual void stateChanged(QAbstractSocket::SocketState a_socketState);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* used for periodically send an ack to central
|
||||
*/
|
||||
QTimer *m_TickTimer;
|
||||
|
||||
|
||||
/**
|
||||
* Counter of received telegrams (only for sockets)
|
||||
*/
|
||||
uint32_t m_ReceiveCounter;
|
||||
|
||||
|
||||
/**
|
||||
* Acknowledged telegrams counter (only for sockets)
|
||||
*/
|
||||
uint32_t m_ReceiveAckCounter;
|
||||
|
||||
|
||||
/**
|
||||
* The state-event-machine state
|
||||
*/
|
||||
PrtCnvSocketThread::E_State m_State;
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to DbThread
|
||||
*/
|
||||
PrtCnvDbThread *m_DbThread;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The time to wait until connection has happenend [ms]. After this time
|
||||
* connection will be retryed.
|
||||
*/
|
||||
int32_t m_ConnectTimeout;
|
||||
|
||||
|
||||
/**
|
||||
* The time to wait until disconnection has happenend [ms]. After this time has
|
||||
* elapsed it will be aborted.
|
||||
*/
|
||||
int32_t m_DisconnectTimeout;
|
||||
|
||||
|
||||
/**
|
||||
* The period to wait until timeout of connection is detected [ms]
|
||||
*/
|
||||
int32_t m_AliveTimeout;
|
||||
|
||||
|
||||
/**
|
||||
* The period of m_TickTimer [ms]
|
||||
*/
|
||||
int32_t m_TickTimeout;
|
||||
|
||||
|
||||
/**
|
||||
* True if the database has to be cleant up (used for fast empty of signal buffers)
|
||||
*/
|
||||
QAtomicInt m_DoCleanup;
|
||||
|
||||
|
||||
/**
|
||||
* for independent logging of telegrams
|
||||
*/
|
||||
PrtCnvTelegramLogThread *m_LogThread;
|
||||
|
||||
PrtCnvInjectionThread *m_InjectionThread;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A vector with hostname - port pairs to connect to
|
||||
*/
|
||||
QVector<QPair<QString, uint16_t> > m_hostAdresses;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The current index to connect to in m_hostAdresses
|
||||
*/
|
||||
int m_currentHostAdressIndex;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Will be called from Qt-Framework when we have disconnected to TCP-server
|
||||
*/
|
||||
virtual void disconnected();
|
||||
|
||||
|
||||
/**
|
||||
* used to check whether the other side is still alive
|
||||
*/
|
||||
void startAliveTimer();
|
||||
|
||||
|
||||
/**
|
||||
* used to retry connection
|
||||
*/
|
||||
void startConnectionTimer();
|
||||
|
||||
|
||||
/**
|
||||
* used to abort connection, when normal disconnection is not successful
|
||||
*/
|
||||
void startDisconnectionTimer();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connect as client to a TCP-server on ip-address configured as HostName and Port
|
||||
* configured as Port
|
||||
*/
|
||||
void connectSocket();
|
||||
|
||||
|
||||
/**
|
||||
* Disconnects from TCP-server
|
||||
*/
|
||||
void disconnectSocket();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* used for periodically ticks (i.e. for acks or sending nachforderungen)
|
||||
*/
|
||||
void startTickTimer();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The counter will be set to a_startCounter if a_maxCounter is reached
|
||||
* returns true if receive-counter is ok
|
||||
* returns false if a telegram is repeated or lost
|
||||
*
|
||||
* @param a_counter
|
||||
* @param a_maxCounter
|
||||
* @param a_startCounter
|
||||
*/
|
||||
bool checkAndUpdateReceiveCounter(const uint32_t a_counter, const uint32_t a_maxCounter, const uint32_t a_startCounter);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* calls storeRadioTelegram of DbThread, see there
|
||||
*
|
||||
* @param a_telegram
|
||||
* @param a_readCounter
|
||||
*/
|
||||
void storeRadioTelegram(const std::shared_ptr<N_CoPrtCnv::CoPrtCnvRadioTelegram> &a_telegram, const uint32_t a_readCounter);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/**
|
||||
* Helper to store/fetch a central telegram into/from database
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-22
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -19,20 +24,27 @@ public:
|
||||
|
||||
int writeCounter() const { return m_WriteCounter; }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Assigned central-telegram.
|
||||
*/
|
||||
std::shared_ptr<N_CoPrtCnv::CoPrtCnvCentralTelegram> m_CentralTelegram;
|
||||
|
||||
|
||||
/**
|
||||
* The number of unsuccessful attempts to send the telegram to central
|
||||
*/
|
||||
uint32_t m_Attempts = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The counter while sending this telegram to central
|
||||
*/
|
||||
int m_WriteCounter = 0;
|
||||
|
||||
|
||||
/**
|
||||
* True if the telegram must be resent.
|
||||
*/
|
||||
bool m_DoResend = false;
|
||||
|
||||
|
||||
/**
|
||||
* True if the telegram must be deleted.
|
||||
* Use this boolean only if you want delete a telegram as an exception (i.e.
|
||||
* corrupt telegram, which cannot be sent)
|
||||
*/
|
||||
bool m_DoDelete = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/**
|
||||
* Helper to store/fetch a radio telegram into/from database
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-22
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -12,20 +17,26 @@ class PrtCnvStoredRadioTelegram : public PrtCnv::PrtCnvStoredTelegram
|
||||
public:
|
||||
using PrtCnv::PrtCnvStoredTelegram::PrtCnvStoredTelegram;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The counter while reading this telegram from central
|
||||
*/
|
||||
int32_t m_ReadCounter = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The broadcast index if it is a broadcast-telegram and it was sent first time,
|
||||
* otherwise 0.
|
||||
*/
|
||||
uint16_t m_BroadcastIndex = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The frame-counter while sending this telegram to radio.
|
||||
*/
|
||||
uint8_t m_WriteCounter = 0;
|
||||
|
||||
|
||||
/**
|
||||
* True if telegram must be deleted.
|
||||
*/
|
||||
bool m_DoDelete = false;
|
||||
|
||||
|
||||
/**
|
||||
* True if telegram was sent.
|
||||
*/
|
||||
bool m_IsSent = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/**
|
||||
* Helper to store/fetch a telegram into/from database
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-22
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// manual class headers
|
||||
#include "PrtCnvTelegramLogThread.hpp"
|
||||
#include <CoPrtCnv/CoPrtCnvCentralTelegram.hpp>
|
||||
#include <CoPrtCnv/CoPrtCnvLogHeader.hpp>
|
||||
@@ -28,7 +28,7 @@
|
||||
static int gettimeofday(struct timeval *__p, void *__t)
|
||||
{
|
||||
union {
|
||||
unsigned long long ns100;
|
||||
unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
|
||||
FILETIME ft;
|
||||
} now;
|
||||
|
||||
@@ -48,7 +48,7 @@ static int gettimeofday(struct timeval *__p, void *__t)
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvTelegramLogThread::PrtCnvTelegramLogThread(PrtCnvThreadStarter* a_parent)
|
||||
: PrtCnvThread(a_parent, "PrtCnvTelegramLogThread")
|
||||
, m_DoLogCentralTelegram(true)
|
||||
@@ -58,7 +58,7 @@ PrtCnvTelegramLogThread::PrtCnvTelegramLogThread(PrtCnvThreadStarter* a_parent)
|
||||
m_Name = QStringLiteral("TelegramLog");
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvTelegramLogThread::create(NGL::Settings *settings)
|
||||
{
|
||||
PrtCnvThread::create(settings);
|
||||
@@ -71,7 +71,7 @@ int32_t PrtCnvTelegramLogThread::create(NGL::Settings *settings)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
int32_t PrtCnvTelegramLogThread::init()
|
||||
{
|
||||
PrtCnvThread::init();
|
||||
@@ -86,7 +86,7 @@ int32_t PrtCnvTelegramLogThread::init()
|
||||
if (!m_LogTelegramPathWithPrefix.endsWith(QLatin1Char('_')))
|
||||
m_LogTelegramPathWithPrefix += QLatin1Char('_');
|
||||
|
||||
|
||||
// create the telegram-log-path when it not yet exists
|
||||
QFileInfo fileInfo(m_LogTelegramPathWithPrefix);
|
||||
QDir dir;
|
||||
dir.mkpath(fileInfo.absolutePath());
|
||||
@@ -101,9 +101,9 @@ static inline int setSend(int protocol, bool bIsSend)
|
||||
return (protocol | (bIsSend ? N_CoPrtCnv::CoPrtCnvLogHeader::e_DestSend : N_CoPrtCnv::CoPrtCnvLogHeader::e_DestReceive));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Writes a received or sent central-telegram into log-file
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvTelegramLogThread::writeCentralTelegramLog(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_centralTelegram, bool a_isSend, int a_priority)
|
||||
{
|
||||
if (!m_DoLogCentralTelegram)
|
||||
@@ -115,9 +115,9 @@ void PrtCnvTelegramLogThread::writeCentralTelegramLog(N_CoPrtCnv::CoPrtCnvCentra
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Writes a received or sent wls-telegram into log-file
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvTelegramLogThread::writeWlsTelegramLog(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *tele, bool a_isSend, int a_priority)
|
||||
{
|
||||
if (!m_DoLogWlsTelegram)
|
||||
@@ -130,9 +130,9 @@ void PrtCnvTelegramLogThread::writeWlsTelegramLog(const TrainingAreaBase::TetraI
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Writes a received or sent radio-telegram into log-file
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvTelegramLogThread::writeRadioTelegramLog(const QByteArray &tele, bool a_isSend, int a_priority)
|
||||
{
|
||||
if (!m_DoLogRadioTelegram)
|
||||
@@ -144,27 +144,27 @@ void PrtCnvTelegramLogThread::writeRadioTelegramLog(const QByteArray &tele, bool
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Writes the telegram to the file
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvTelegramLogThread::writeTelegramLog(const QByteArray &a_data, int a_protocolType, int a_priority)
|
||||
{
|
||||
|
||||
// get time with microseconds
|
||||
timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
uint64_t exactTime = tv.tv_sec;
|
||||
exactTime = exactTime << 32;
|
||||
exactTime += tv.tv_usec;
|
||||
|
||||
|
||||
// generate the filename of the telegram-file: "PrefixYYMMDD_HH.krlog"
|
||||
QString fileName = QStringLiteral("%1%2.krlog")
|
||||
.arg(m_LogTelegramPathWithPrefix, QDateTime::fromSecsSinceEpoch(tv.tv_sec).toString(QStringLiteral("yyMMdd_hh")));
|
||||
|
||||
|
||||
// open the log-file
|
||||
QFile telegramFile(fileName);
|
||||
(void)telegramFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||
|
||||
|
||||
// write header
|
||||
N_CoPrtCnv::CoPrtCnvLogHeader lh;
|
||||
lh.m_Length = a_data.size() + sizeof(N_CoPrtCnv::CoPrtCnvLogHeader);
|
||||
lh.m_Version = 3;
|
||||
@@ -174,9 +174,9 @@ void PrtCnvTelegramLogThread::writeTelegramLog(const QByteArray &a_data, int a_p
|
||||
lh.m_Reserved = 0;
|
||||
telegramFile.write(reinterpret_cast<const char*>(&lh), sizeof(N_CoPrtCnv::CoPrtCnvLogHeader));
|
||||
|
||||
|
||||
// write telegram-data
|
||||
telegramFile.write(a_data);
|
||||
telegramFile.close();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -30,15 +30,25 @@ struct TrainingAreaTelegram;
|
||||
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* This thread is used to log telegrams in a log-file. This action is separated
|
||||
* from central/radio-thead because of 2 reasons:
|
||||
*
|
||||
* 1. An unwanted synchronisation of radio- and central thread will be avoided
|
||||
* 2. Storing to a file is very slow and would thwart the radio and central-thread
|
||||
* @author alois.wismer
|
||||
* @version 1.0
|
||||
* @updated 03-Mai-2010 17:57:34
|
||||
*/
|
||||
class PrtCnvTelegramLogThread final : public PrtCnvThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a_parent
|
||||
*/
|
||||
explicit PrtCnvTelegramLogThread(PrtCnvThreadStarter* a_parent);
|
||||
|
||||
int32_t create(NGL::Settings *settings) override;
|
||||
@@ -46,41 +56,61 @@ namespace PrtCnv
|
||||
int32_t init() override;
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
/**
|
||||
* Writes a received or sent central-telegram into log-file
|
||||
*/
|
||||
void writeCentralTelegramLog(N_CoPrtCnv::CoPrtCnvCentralTelegram *a_centralTelegram, bool a_isSend, int a_priority);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Writes a received or sent central-telegram into log-file
|
||||
*/
|
||||
void writeWlsTelegramLog(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *tele, bool a_isSend, int a_priority);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Writes a received or sent radio-telegram into log-file
|
||||
*/
|
||||
void writeRadioTelegramLog(const QByteArray &tele, bool a_isSend, int a_priority);
|
||||
|
||||
private:
|
||||
signals:
|
||||
|
||||
|
||||
/**
|
||||
* This signal will be emitted when this thread receives a new telegram to log
|
||||
*
|
||||
* @param a_data
|
||||
* @param a_protocolType
|
||||
* @param a_isSend
|
||||
* @param a_priority
|
||||
*/
|
||||
void telegramLogReceived(const QByteArray &a_data, int a_protocolType, int a_priority);
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
/**
|
||||
* Writes the telegram to the file
|
||||
*
|
||||
* @param a_data
|
||||
* @param a_protocolType
|
||||
* @param a_isSend
|
||||
* @param a_priority
|
||||
*/
|
||||
void writeTelegramLog(const QByteArray &a_data, int a_protocolType, int a_priority);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* The directory where we want to log the telegrams (configureable over parameter
|
||||
* file)
|
||||
*/
|
||||
QString m_LogTelegramPathWithPrefix;
|
||||
|
||||
|
||||
/**
|
||||
* True if we want to log central-telegrams (configureable over parameter file)
|
||||
*/
|
||||
bool m_DoLogCentralTelegram;
|
||||
|
||||
|
||||
/**
|
||||
* True if we want to log wls-telegrams (configureable over parameter file)
|
||||
*/
|
||||
bool m_DoLogWlsTelegram;
|
||||
|
||||
|
||||
/**
|
||||
* True if we want to log TETRA-telegrams (configureable over parameter file)
|
||||
*/
|
||||
bool m_DoLogRadioTelegram;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvThread
|
||||
// **************************************************************************
|
||||
#include "PrtCnvThread.hpp"
|
||||
#include <QtCore/QThread>
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace PrtCnv
|
||||
|
||||
bool PrtCnvThread::m_DoCleanDb = false;
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor with thread-starter as parameter
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvThread::PrtCnvThread(PrtCnv::PrtCnvThreadStarter* a_parent, const char *loggerName)
|
||||
: m_Parent(a_parent)
|
||||
, m_currentThreadId(nullptr)
|
||||
@@ -71,4 +71,4 @@ int32_t PrtCnvThread::destroy()
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvThread
|
||||
// **************************************************************************
|
||||
#pragma once
|
||||
|
||||
#include "IAppComponent.hpp"
|
||||
@@ -21,29 +21,44 @@
|
||||
namespace PrtCnv
|
||||
{
|
||||
class PrtCnvThreadStarter;
|
||||
|
||||
|
||||
/**
|
||||
* The father-class of all threads in protocol-converter. It implements access to
|
||||
* config-system and knows whether we have a restart after crash or a normal start
|
||||
* (from scratch).
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 21-Jan-2010 08:38:23
|
||||
*/
|
||||
class PrtCnvThread : public QObject, public N_AppComponent::IAppComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Used to get configuration-parameter
|
||||
*/
|
||||
NGL::Settings* m_Config;
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to ThreadStarter
|
||||
*/
|
||||
PrtCnvThreadStarter *m_Parent;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Id of the current thread (for debug purposes)
|
||||
*/
|
||||
Qt::HANDLE m_currentThreadId;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Indicates what happens with the DB while startup. True => it will be cleant;
|
||||
* False => it will be restored (after crash). This variable will be True at
|
||||
* startup when you use the parameter --cleandb when starting PrtCnv.
|
||||
*/
|
||||
static bool m_DoCleanDb;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with thread-starter as parameter
|
||||
*
|
||||
* @param a_parent
|
||||
*/
|
||||
PrtCnvThread(PrtCnvThreadStarter* a_parent, const char *loggerName);
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvThreadStarter
|
||||
// **************************************************************************
|
||||
#include "PrtCnvThreadStarter.hpp"
|
||||
#include "PrtCnvCentralThread.hpp"
|
||||
#include "PrtCnvRadioThread.hpp"
|
||||
@@ -23,9 +23,9 @@
|
||||
namespace PrtCnv
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Constructor with id and ptr to main-app as parameters.
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvThreadStarter::PrtCnvThreadStarter(const PrtCnv::PrtCnvApplication::E_ThreadId a_id,
|
||||
const QString &configFileName,
|
||||
PrtCnv::PrtCnvApplication* a_mainApp)
|
||||
@@ -45,14 +45,14 @@ PrtCnvThreadStarter::~PrtCnvThreadStarter()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// The run()-function, which will be called by Qt-Framework,
|
||||
// when starting the thread.
|
||||
// ---------------------------------------------------------------
|
||||
void PrtCnvThreadStarter::run()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Entering event loop for thread " << this << ", id: " << m_Id;
|
||||
|
||||
// allocate the thread
|
||||
switch (m_Id)
|
||||
{
|
||||
case PrtCnvApplication::e_Central:
|
||||
@@ -114,12 +114,12 @@ void PrtCnvThreadStarter::run()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the desired thread.
|
||||
// ---------------------------------------------------------------
|
||||
PrtCnvThread *PrtCnvThreadStarter::getOtherThread(PrtCnvApplication::E_ThreadId a_threadId) const
|
||||
{
|
||||
return m_Application->getThreadStarter(a_threadId)->m_Thread;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// Implementation of the Class PrtCnvThreadStarter
|
||||
// **************************************************************************
|
||||
#pragma once
|
||||
|
||||
#include "PrtCnvApplication.hpp"
|
||||
@@ -23,29 +23,42 @@ namespace NGL {
|
||||
namespace PrtCnv
|
||||
{
|
||||
class PrtCnvThread;
|
||||
|
||||
|
||||
/**
|
||||
* This class is responsible for starting threads. It also impelements an access
|
||||
* to other threads.
|
||||
* @author wia
|
||||
* @version 1.0
|
||||
* @updated 21-Jan-2010 08:33:58
|
||||
*/
|
||||
class PrtCnvThreadStarter : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to the started thread
|
||||
*/
|
||||
PrtCnvThread *m_Thread;
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to main-application
|
||||
*/
|
||||
PrtCnvApplication *m_Application;
|
||||
|
||||
|
||||
/**
|
||||
* The id of the thread
|
||||
*/
|
||||
PrtCnvApplication::E_ThreadId m_Id;
|
||||
|
||||
|
||||
/**
|
||||
* The settings object
|
||||
*/
|
||||
NGL::Settings *m_settings;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with id and ptr to main-app as parameters.
|
||||
*
|
||||
* @param a_id
|
||||
* @param a_mainApp The pointer to the main-app
|
||||
*/
|
||||
PrtCnvThreadStarter(const PrtCnvApplication::E_ThreadId a_id,
|
||||
const QString &settingsFile,
|
||||
PrtCnvApplication *a_mainApp);
|
||||
@@ -54,12 +67,17 @@ protected:
|
||||
|
||||
PrtCnvThread *getThread() const { return m_Thread; }
|
||||
PrtCnvApplication *getMainApp() const { return m_Application; }
|
||||
|
||||
|
||||
/**
|
||||
* Returns the desired thread.
|
||||
*
|
||||
* @param a_threadId The id of the desired thread.
|
||||
*/
|
||||
PrtCnvThread *getOtherThread(PrtCnvApplication::E_ThreadId a_threadId) const;
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* The run()-function, which will be called by Qt-Framework, when starting the
|
||||
* thread.
|
||||
*/
|
||||
void run() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* Main for Tetra Simulation
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QPointF>
|
||||
@@ -127,7 +132,7 @@ int main(int argc, char **argv)
|
||||
QSettings serverSettings(app.applicationDirPath() + QLatin1String("/") + options.iniFile(), QSettings::IniFormat);
|
||||
|
||||
TTSArgs ttsArgs;
|
||||
|
||||
// args.destIssi = serverSettings.value(QLatin1String("Radio/HostISSI"), 2).toInt();
|
||||
ttsArgs.destIssi = options.isSet(QLatin1String("issi")) ? options.value(QLatin1String("issi")).toInt() : 2;
|
||||
ttsArgs.cntPlayer = options.isSet(QLatin1String("player")) ? options.value(QLatin1String("player")).toInt() : 0;
|
||||
int northPos_arg = options.isSet(QLatin1String("northing")) ? options.value(QLatin1String("northing")).toInt() : 77777;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* Listen Server for Tetra Simulation
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#include "server.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* Listen Server for Tetra Simulation
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* Worker for Tetra Simulation
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "worker.h"
|
||||
#include <utility>
|
||||
@@ -23,7 +28,7 @@ TTWorker::TTWorker(QTcpSocket *socket, const TTSArgs &ttsArgs)
|
||||
, m_generalPosition(ttsArgs.position)
|
||||
.getNGLLogger("TTWorker"))
|
||||
{
|
||||
qsrand(time(nullptr));
|
||||
qsrand(time(nullptr)); // randomize for later use in class "Player"
|
||||
}
|
||||
|
||||
bool TTWorker::init()
|
||||
@@ -47,16 +52,16 @@ bool TTWorker::init()
|
||||
|
||||
void TTWorker::startExecution()
|
||||
{
|
||||
|
||||
//mTimer->start(mTtsargs.movs_per_msec);
|
||||
m_timer->start(m_ttsArgs.movs_per_msec);
|
||||
NOTICE_LOG(m_logger) << "Start Exe login all Player";
|
||||
|
||||
// create all players & add them to the players-list, send logins
|
||||
for (unsigned int i = 0; i < m_ttsArgs.cntPlayer; i++)
|
||||
{
|
||||
int eqId = m_ttsArgs.eqIdStart + i;
|
||||
int issi = m_ttsArgs.eqIdStart + i + 2000;
|
||||
int issi = m_ttsArgs.eqIdStart + i + 2000; // = Ausstattungsnummer + 2000
|
||||
QPointF posUTM((m_generalPosition.x() + (i / m_ttsArgs.pprow) * m_ttsArgs.pspacing),
|
||||
(m_generalPosition.y() + (i % m_ttsArgs.pprow) * m_ttsArgs.pspacing));
|
||||
(m_generalPosition.y() + (i % m_ttsArgs.pprow) * m_ttsArgs.pspacing)); // initial position for a player
|
||||
Player *p = new Player(eqId, issi, m_ttsArgs.minimumDeathTicks, m_ttsArgs.maximumDeathTicks, posUTM);
|
||||
m_playerList.append(p);
|
||||
|
||||
@@ -69,8 +74,8 @@ void TTWorker::startExecution()
|
||||
if (m_ttsArgs.demandOldBraodcastTelegrams)
|
||||
QTimer::singleShot(1000, this, &TTWorker::onSendNachforderungBroadcastTelegramm);
|
||||
|
||||
|
||||
|
||||
// QTimer::singleShot(25000, this , &TTWorker::onSendNlosSimulatorDirection);
|
||||
// QTimer::singleShot(120000, this , &TTWorker::onSendNlosFireResult);
|
||||
}
|
||||
|
||||
QVector<runningPattern> TTWorker::interpretPattern(QString pattern) const
|
||||
@@ -81,56 +86,56 @@ QVector<runningPattern> TTWorker::interpretPattern(QString pattern) const
|
||||
exit(8);
|
||||
}
|
||||
|
||||
if (pattern.at(0) == QLatin1Char('%'))
|
||||
if (pattern.at(0) == QLatin1Char('%')) // this pattern is a predefined pattern from the settings file
|
||||
{
|
||||
pattern.remove(0, 1);
|
||||
pattern.remove(0, 1); // delete '%'-character as it disturbes the interpreter
|
||||
|
||||
QString patternAlias = pattern;
|
||||
|
||||
pattern = m_ttsArgs.settings->value(QLatin1String("pattern/") + patternAlias).toString();
|
||||
|
||||
if (pattern.isEmpty())
|
||||
if (pattern.isEmpty()) // there is no pattern with this alias!
|
||||
{
|
||||
ERROR_LOG(m_logger) << "INVALID PATTERN - alias '" << patternAlias << "' is not available in settings file! Program halted.";
|
||||
exit(9);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// now the pattern (if it was only an alias) is refered, continue..:
|
||||
|
||||
if (pattern.at(pattern.count() - 1) == QLatin1Char('#'))
|
||||
if (pattern.at(pattern.count() - 1) == QLatin1Char('#')) // delete the character ';' if there is one at the end of string - because of strtok/split
|
||||
pattern.remove(pattern.count() - 1, 1);
|
||||
|
||||
QVector<runningPattern> newPatternList;
|
||||
runningPattern rp;
|
||||
QStringList strings = pattern.split(QLatin1Char('#'));
|
||||
QStringList stringy;
|
||||
int i;
|
||||
QVector<runningPattern> newPatternList; // list we give back to replace the patternList in this class
|
||||
runningPattern rp; // pattern we use (and reuse) to add a new runningPattern instance to the patternList
|
||||
QStringList strings = pattern.split(QLatin1Char('#')); // list of pattern (f.g. "1,2,3", "1,2,3");
|
||||
QStringList stringy; // list of pattern-ingredients ;) (f.g. "1", "2", "3")
|
||||
int i; // counter, global because of error message at the end of this function (see variable "strings")
|
||||
|
||||
for (i = 0; i < strings.count(); i++)
|
||||
{
|
||||
stringy = strings.at(i).split(QLatin1Char(','));
|
||||
stringy = strings.at(i).split(QLatin1Char(',')); // split one pattern to the "ingredients"
|
||||
|
||||
if (stringy.count() != 3)
|
||||
if (stringy.count() != 3) // pattern consists of 3 numbers, if there are more or less, then the pattern is wrong
|
||||
break;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
rp.steps = stringy.at(0).toInt(&ok); if (!ok) break;
|
||||
rp.ethering = stringy.at(1).toInt(&ok); if (!ok) break;
|
||||
rp.northering = stringy.at(2).toInt(&ok); if (!ok) break;
|
||||
rp.steps = stringy.at(0).toInt(&ok); if (!ok) break; // is not a number, so throw an error and exit this application
|
||||
rp.ethering = stringy.at(1).toInt(&ok); if (!ok) break; // ^
|
||||
rp.northering = stringy.at(2).toInt(&ok); if (!ok) break; // ^
|
||||
|
||||
newPatternList.append(rp);
|
||||
newPatternList.append(rp); // add a new instance to the list (i hope this will create an instance and does not use a reference !!1)
|
||||
|
||||
if (i == strings.count() - 1)
|
||||
return newPatternList;
|
||||
if (i == strings.count() - 1) // are we at the end of the strings.count ? if yes, then return the list - important to NOT throw a error message
|
||||
return newPatternList; // IMPORTANT! Or an wrong error message will be thrown
|
||||
}
|
||||
|
||||
ERROR_LOG(m_logger) << "INVALID PATTERN: '" << strings.at(i) << "'. Cannot start without correct pattern!";
|
||||
|
||||
exit(5);
|
||||
exit(5); // we can't work - exit!
|
||||
|
||||
return QVector<runningPattern>();
|
||||
return QVector<runningPattern>(); // for security & compiler issues..
|
||||
}
|
||||
|
||||
void TTWorker::sendLogin(uint32_t eqId, uint32_t issi)
|
||||
@@ -165,7 +170,7 @@ void TTWorker::onReadyRead()
|
||||
<< " - but I proceed with this telegram.";
|
||||
}
|
||||
|
||||
|
||||
// prepare data-bucket for entire telegram
|
||||
uint16_t dataSize = header.m_Length + sizeof(header);
|
||||
if (m_socket->bytesAvailable() < dataSize)
|
||||
{
|
||||
@@ -173,7 +178,7 @@ void TTWorker::onReadyRead()
|
||||
return;
|
||||
}
|
||||
QByteArray buf(dataSize, Qt::Uninitialized);
|
||||
|
||||
// read the telegram with header
|
||||
bytesRead = 0;
|
||||
while (bytesRead < dataSize)
|
||||
{
|
||||
@@ -189,18 +194,18 @@ void TTWorker::onReadyRead()
|
||||
void TTWorker::handleReceivedTelegram(const QByteArray &data)
|
||||
{
|
||||
INFO_LOG(m_logger) << data.size();
|
||||
|
||||
// evaluate PDU-Type
|
||||
switch (data.at(4))
|
||||
{
|
||||
|
||||
// response to register indication
|
||||
case N_CoPrtCnv::CoPrtCnvRadioTelegram::e_RegisterInd:
|
||||
handleRegisterInd();
|
||||
startExecution();
|
||||
break;
|
||||
|
||||
case N_CoPrtCnv::CoPrtCnvRadioTelegram::e_DataIndReq:
|
||||
handleDataIndReq(data);
|
||||
|
||||
handleDataIndReq(data); // tele->getDestISSI() == ISSI an des angesprochenen Teilnehmers
|
||||
// data is deleted inside handleDataIndReq()
|
||||
break;
|
||||
default:
|
||||
INFO_LOG(m_logger) << "Radio-Telegram with PDU-Type=" << (int)data[4]
|
||||
@@ -214,7 +219,7 @@ void TTWorker::sendTelegram(N_CoPrtCnv::CoPrtCnvRadioTelegram *radioTelegram, ui
|
||||
radioTelegram->setZaehler(m_counter++);
|
||||
radioTelegram->setDestISSI(m_ttsArgs.destIssi);
|
||||
radioTelegram->setSrcISSI(issi);
|
||||
|
||||
//INFO_LOG(mLogger) << "BITE message sent for Player (" << eqId << ") with ISSI: " << issi;
|
||||
m_socket->write(radioTelegram->data());
|
||||
m_socket->flush();
|
||||
delete radioTelegram;
|
||||
@@ -232,9 +237,9 @@ void TTWorker::onSendNachforderungBroadcastTelegramm()
|
||||
tel.setBroadcastIndex(0);
|
||||
tel.setDestISSI(m_ttsArgs.destIssi);
|
||||
tel.setSrcISSI(p->issi);
|
||||
tel.setPayload4Byte(0);
|
||||
tel.setPayload1Byte(0);
|
||||
tel.setPayload2Byte(m_ttsArgs.demandOldBraodcastTelegramsCounter);
|
||||
tel.setPayload4Byte(0); // gps_zeit
|
||||
tel.setPayload1Byte(0); // ruecksetzzaehler
|
||||
tel.setPayload2Byte(m_ttsArgs.demandOldBraodcastTelegramsCounter); // broadcast index
|
||||
m_socket->write(tel.data());
|
||||
}
|
||||
else
|
||||
@@ -267,56 +272,60 @@ void TTWorker::onSendDeaktivierungEinzelminen()
|
||||
QTimer::singleShot(1000, this, &TTWorker::onSendDeaktivierungEinzelminen);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Send sample NlosFireResult Telegram every three minutes (FOR TESTING NLOS)
|
||||
\author Niklas Schmidt
|
||||
*/
|
||||
// void TTWorker::onSendNlosFireResult()
|
||||
// {
|
||||
// if (m_playerList.isEmpty())
|
||||
// {
|
||||
// ERROR_LOG(m_logger) << "No player for onSendNlosFireResult...";
|
||||
// return;
|
||||
// }
|
||||
// Player *p = m_playerList.at(0);
|
||||
|
||||
// TrainingAreaBase::TetraIcd::NlosDirectionOrShootingResult fireResult;
|
||||
// fireResult.header.equipmentNumber = p->eqId;
|
||||
// fireResult.header.timeStamp = time(nullptr) * 1000;
|
||||
// fireResult.messageId = 0xE401;
|
||||
// fireResult.version = 4;
|
||||
// fireResult.shootingRes = TrainingAreaBase::TetraIcd::NlosDirectionOrShootingResult::ShootingResult::Hit;
|
||||
// fireResult.targetEquipmentNumber = 1205;
|
||||
// INFO_LOG(m_logger) << "Send NlosFireResult";
|
||||
// sendTelegram(fireResult, p->issi);
|
||||
|
||||
// QTimer::singleShot(120000, this, &TTWorker::onSendNlosFireResult);
|
||||
// }
|
||||
|
||||
/*!
|
||||
\brief Send sample NlosSimulatorDirection Telegram(FOR TESTING NLOS)
|
||||
\author Niklas Schmidt
|
||||
*/
|
||||
// void TTWorker::onSendNlosSimulatorDirection()
|
||||
// {
|
||||
|
||||
// if (m_playerList.isEmpty())
|
||||
// {
|
||||
// ERROR_LOG(m_logger) << "No player for onSendNlosFireResult...";
|
||||
// return;
|
||||
// }
|
||||
// Player *p = m_playerList.at(0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TrainingAreaBase::TetraIcd::NlosDirectionOrShootingResult simulatorDirection;
|
||||
// simulatorDirection.header.equipmentNumber = 7150;
|
||||
// simulatorDirection.header.timeStamp = time(nullptr) * 1000;
|
||||
// simulatorDirection.messageId = 0xE400;
|
||||
// std::random_device rd; //Will be used to obtain a seed for the random number engine
|
||||
// std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
|
||||
// std::uniform_int_distribution<long long> distrib(1, 34999);
|
||||
// simulatorDirection.version = 4;
|
||||
// simulatorDirection.directionInDegree = 0/*distrib(gen)*/;
|
||||
// simulatorDirection.attachmentInDegree = 0;
|
||||
// INFO_LOG(m_logger) << "Send NlosSimulatorDirection";
|
||||
// sendTelegram(simulatorDirection, p->issi);
|
||||
// QTimer::singleShot(100000, this, &TTWorker::onSendNlosSimulatorDirection);
|
||||
// }
|
||||
|
||||
void TTWorker::sendTaktischerStatus(uint32_t eqId, uint32_t issi, TrainingAreaBase::TetraIcd::VulnerabilityState vbg)
|
||||
{
|
||||
@@ -345,7 +354,7 @@ void TTWorker::sendTaktischerStatus(uint32_t eqId, uint32_t issi, TrainingAreaBa
|
||||
void TTWorker::sendSanitationReport(uint32_t eqId, uint32_t issi)
|
||||
{
|
||||
m_toogle = false;
|
||||
return;
|
||||
return; //NOTE: Will never be executed
|
||||
TrainingAreaBase::TetraIcd::SanitaryMaterialStockReport tele;
|
||||
tele.header.equipmentNumber = eqId;
|
||||
tele.header.timeStamp = time(nullptr) * 1000;
|
||||
@@ -360,20 +369,20 @@ void TTWorker::sendSanitationReport(uint32_t eqId, uint32_t issi)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// void TTWorker::sendSanitation(uint32_t eqId, uint32_t issi)
|
||||
// {
|
||||
// m_toogle = true;
|
||||
// return; //NOTE: Will never be executed
|
||||
// TrainingAreaBase::TetraIcd::Sanitation tele;
|
||||
// tele.header.equipmentNumber = eqId;
|
||||
// tele.header.timeStamp = time(nullptr) * 1000;
|
||||
// tele.proceduresTaken = 1117;
|
||||
// tele.uniqeId = 2777777;
|
||||
// tele.originatorEquipmentNumber = 1001;
|
||||
// tele.qualification = TrainingAreaBase::TetraIcd::Qualification::FAA;
|
||||
// tele.sanitationResult = TrainingAreaBase::TetraIcd::SanitationResult::Needed;
|
||||
// sendTelegram(tele, issi);
|
||||
// }
|
||||
|
||||
void TTWorker::sendBITE(uint32_t eqId, uint32_t issi)
|
||||
{
|
||||
@@ -383,21 +392,21 @@ void TTWorker::sendBITE(uint32_t eqId, uint32_t issi)
|
||||
tele.loginType = TrainingAreaBase::TetraIcd::BiteReport::LoginType::Relogin;
|
||||
tele.configError = false;
|
||||
sendTelegram(tele, issi);
|
||||
sendTaktischerStatus(eqId, issi, TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady);
|
||||
sendTaktischerStatus(eqId, issi, TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady); // rebirth for old Players, who are still dead
|
||||
}
|
||||
|
||||
void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
{
|
||||
QScopedPointer<N_CoPrtCnv::CoPrtCnvRadioTelegram> radioTelegram(new N_CoPrtCnv::CoPrtCnvRadioTelegram(data));
|
||||
int telID = radioTelegram->getTelID();
|
||||
int telID = radioTelegram->getTelID(); // get the Telegram ID, to switch through it
|
||||
|
||||
switch (telID)
|
||||
{
|
||||
#if 0
|
||||
TODO
|
||||
case GEF_AUSLOESUNG_DUS_TREFFER:
|
||||
case GEF_AUSLOESUNG_DUS_TREFFER: // player hit! send a taktischer status that we are dead
|
||||
{
|
||||
|
||||
/* TODO: only receive damage, do not die instantly - rt_data unused */
|
||||
|
||||
DEBUG_LOG(mLogger) << "handleAusloeserDUSTreffer: eqId=" << radioTelegram->getIdentity() <<
|
||||
" issi=" << radioTelegram->getDestISSI();
|
||||
@@ -410,14 +419,14 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
const ausloesung_dus_treffer_rt &rt_data = static_cast<XDR_AUSLOESUNG_DUS_TREFFER_Wrapper *>(wrapper)->get_rt();
|
||||
|
||||
if (rt_data.bek_wirkung > 90)
|
||||
sendTaktischerStatus(radioTelegram->getIdentity(), radioTelegram->getDestISSI(), TOTALAUSFALL);
|
||||
sendTaktischerStatus(radioTelegram->getIdentity(), radioTelegram->getDestISSI(), TOTALAUSFALL); // kill Player
|
||||
else
|
||||
sendTaktischerStatus(radioTelegram->getIdentity(), radioTelegram->getDestISSI(), ANNAEHENDER_TREFFER);
|
||||
delete wrapper;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
case GEF_TAKTISCHER_STATUS:
|
||||
case GEF_TAKTISCHER_STATUS: // just resend this one to answer the station's question
|
||||
{
|
||||
N_CoPrtCnv::CoPrtCnvCentralTelegram *tele = N_CoPrtCnv::CoPrtCnvTelegramConverter::convertToCentral(radioTelegram.data());
|
||||
TrainingAreaBase::TetraIcd::StateChange sc = TrainingAreaBase::TetraIcd::StateChange::fromJson(tele->jsonData());
|
||||
@@ -426,7 +435,7 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
|
||||
sc.header.timeStamp = time(nullptr) * 1000;
|
||||
uint32_t issi = 0;
|
||||
for (int i = 0; i < m_playerList.count(); i++)
|
||||
for (int i = 0; i < m_playerList.count(); i++) // get issi from player's eqId
|
||||
{
|
||||
if (radioTelegram->getIdentity() == m_playerList.at(i)->eqId)
|
||||
{
|
||||
@@ -436,7 +445,7 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
}
|
||||
|
||||
ERROR_LOG(m_logger) << " Try to Resetnd S2tate " << sc.header.equipmentNumber << " we got state: " << static_cast<int>(sc.vulnerabilityState) << " and this bits here: " << sc.vulnerabilityBits;
|
||||
sendTelegram(sc, issi);
|
||||
sendTelegram(sc, issi); // resend
|
||||
return;
|
||||
}
|
||||
case GEF_SANITAETSDIENST_INSTANDSETZUNG_PVSAN:
|
||||
@@ -449,7 +458,7 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
|
||||
sc.header.timeStamp = time(nullptr) * 1000;
|
||||
uint32_t issi = 0;
|
||||
for (int i = 0; i < m_playerList.count(); i++)
|
||||
for (int i = 0; i < m_playerList.count(); i++) // get issi from player's eqId
|
||||
{
|
||||
if (radioTelegram->getIdentity() == m_playerList.at(i)->eqId)
|
||||
{
|
||||
@@ -459,15 +468,15 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
}
|
||||
|
||||
ERROR_LOG(m_logger) << " Try to Resetnd S2tate " << sc.header.equipmentNumber << " we got state: " << sc.proceduresTaken;
|
||||
sendTelegram(sc, issi);
|
||||
sendTelegram(sc, issi); // resend
|
||||
return;
|
||||
}
|
||||
case GEF_TREFFER_AUSLOESUNG:
|
||||
case GEF_INIT:
|
||||
case GEF_TREFFER_AUSLOESUNG: // we have got a new status (f.g. wounded lying) and send back our new status
|
||||
case GEF_INIT: // ?? .. or just act like this is a treffer ausloesung ....... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
{
|
||||
TrainingAreaBase::TetraIcd::StateChange tele;
|
||||
uint32_t issi = 0;
|
||||
for (int i = 0; i < m_playerList.count(); i++)
|
||||
for (int i = 0; i < m_playerList.count(); i++) // get issi from player's eqId
|
||||
{
|
||||
if (radioTelegram->getIdentity() == m_playerList.at(i)->eqId)
|
||||
{
|
||||
@@ -477,17 +486,17 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
}
|
||||
TrainingAreaBase::TetraIcd::VulnerabilityState state = (telID == GEF_TREFFER_AUSLOESUNG)
|
||||
? static_cast<TrainingAreaBase::TetraIcd::VulnerabilityState>(radioTelegram->getPayloadDataUInt8(7))
|
||||
: TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady;
|
||||
: TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady; //get vbg from radio
|
||||
|
||||
tele.originatorType = TrainingAreaBase::TetraIcd::OriginatorType::Initialisation;
|
||||
tele.header.equipmentNumber = radioTelegram->getIdentity();
|
||||
tele.originatorType = TrainingAreaBase::TetraIcd::OriginatorType::Initialisation; //set origin
|
||||
tele.header.equipmentNumber = radioTelegram->getIdentity(); //set header
|
||||
tele.header.timeStamp = time(nullptr) * 1000;
|
||||
uint32_t vulcomplete = radioTelegram->getPayloadDataUInt32(8, 2);
|
||||
uint32_t vitality = vulcomplete &= 0xF000;
|
||||
vitality >>= 12;
|
||||
|
||||
tele.tasVulnerabilityKindId = vulcomplete &= 0x0FFF;
|
||||
|
||||
//including vitality
|
||||
tele.tasVulnerabilityKindId <<= 16;
|
||||
tele.tasVulnerabilityKindId |= 0xB1;
|
||||
|
||||
@@ -500,47 +509,47 @@ void TTWorker::handleDataIndReq(const QByteArray &data)
|
||||
else
|
||||
tele.vulnerabilityState = state;
|
||||
|
||||
sendTelegram(tele, issi);
|
||||
sendTelegram(tele, issi); // send new status
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// case GEF_NLOS_DATENVERKEHR_TDS_GEF:
|
||||
// {
|
||||
// ERROR_LOG(m_logger) << "NlosTargetData empfangen";
|
||||
// N_CoPrtCnv::CoPrtCnvCentralTelegram *tele = N_CoPrtCnv::CoPrtCnvTelegramConverter::convertToCentral(radioTelegram.data());
|
||||
// TrainingAreaBase::TetraIcd::NlosTargetData sc = TrainingAreaBase::TetraIcd::NlosTargetData::fromJson(tele->jsonData());
|
||||
// delete tele;
|
||||
// QJsonDocument doc(sc.toJson());
|
||||
// ERROR_LOG(m_logger) << "Receive NlosTargetData Size: " << radioTelegram.data()->getSize() << "\n Structure: " << doc.toJson(QJsonDocument::Indented);
|
||||
// return;
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// miscellaneous messages..
|
||||
|
||||
if (radioTelegram->isLoginTelegram())
|
||||
{
|
||||
|
||||
// fixme: login accepted ?
|
||||
DEBUG_LOG(m_logger) << "player cont: " << m_playerList.count();
|
||||
for (int i = 0; i < m_playerList.count(); i++)
|
||||
for (int i = 0; i < m_playerList.count(); i++) // set player isLogin true
|
||||
{
|
||||
Player *p = m_playerList.at(i);
|
||||
if (radioTelegram->getDestISSI() == p->issi)
|
||||
if (radioTelegram->getDestISSI() == p->issi) // is this the player we look for?
|
||||
{
|
||||
if (p->isLogin)
|
||||
return;
|
||||
DEBUG_LOG(m_logger) << "Player #" << i << " with eqId=" << p->eqId << " and issi=" << p->issi << " is now logged in.";
|
||||
p->isLogin = true;
|
||||
sendBITE(p->eqId, p->issi);
|
||||
sendBITE(p->eqId, p->issi); // send BITE message to log us in, though
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// player not found
|
||||
ERROR_LOG(m_logger) << "Invalid player was logged in. issi: '" << radioTelegram->getDestISSI() << "'";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// none of our swicthes & conditions wanted this received message! we have got a unused or invalid message.. throw it away and give, at least, a DEBUG message
|
||||
DEBUG_LOG(m_logger) << "Received unused or invalid telegram with Telegram-ID: " << telID;
|
||||
}
|
||||
|
||||
@@ -565,38 +574,38 @@ void TTWorker::handleRegisterInd()
|
||||
|
||||
m_socket->write(buf);
|
||||
|
||||
|
||||
//mTimer->start(1000);
|
||||
}
|
||||
|
||||
void TTWorker::movePlayer(Player *p)
|
||||
void TTWorker::movePlayer(Player *p) // move the player like the pattern says
|
||||
{
|
||||
|
||||
// use all variables from the Player POINTER (do not use new instances)
|
||||
|
||||
if (p->patternInList > m_patternList.count() - 1)
|
||||
p->patternInList = 0;
|
||||
if (p->patternInList > m_patternList.count() - 1) // if patternInList is HIGHER than the list-count is, then jump back to position 0 to start again
|
||||
p->patternInList = 0; // set to list-start
|
||||
else
|
||||
{
|
||||
if (p->stepInPattern > m_patternList.at(p->patternInList).steps)
|
||||
if (p->stepInPattern > m_patternList.at(p->patternInList).steps) // if we have less steps than the stepInPattern says, then we have obsolved all wnted steps, so we can jump to the new pattern in the List
|
||||
{
|
||||
p->stepInPattern = 1;
|
||||
if (p->patternInList == m_patternList.count() - 1)
|
||||
p->stepInPattern = 1; // reset steps for the new pattern
|
||||
if (p->patternInList == m_patternList.count() - 1) // if there is NOT a next pattern, then reset pattern counter to 0
|
||||
p->patternInList = 0;
|
||||
else
|
||||
p->patternInList++;
|
||||
p->patternInList++; // jump to next pattern IF there is a next pattern
|
||||
}
|
||||
}
|
||||
|
||||
p->posUTM.setX(p->posUTM.x() +
|
||||
m_patternList.at(p->patternInList).northering);
|
||||
m_patternList.at(p->patternInList).northering); // increase northering as the pattern says
|
||||
p->posUTM.setY(p->posUTM.y() +
|
||||
m_patternList.at(p->patternInList).ethering);
|
||||
m_patternList.at(p->patternInList).ethering); // ^^^^^^^^ ethering ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
p->stepInPattern++;
|
||||
p->stepInPattern++; // increase the step counter before we leave, so the player can be moved the next time!!
|
||||
}
|
||||
|
||||
void TTWorker::onSendPlayerPositions()
|
||||
{
|
||||
|
||||
// return;
|
||||
qint64 bytesSent = 0;
|
||||
int playerCount = 0;
|
||||
TrainingAreaBase::TetraIcd::PositionReport tele;
|
||||
@@ -604,23 +613,23 @@ void TTWorker::onSendPlayerPositions()
|
||||
{
|
||||
Player *p = m_playerList.at(i);
|
||||
|
||||
if (!p->isLogin)
|
||||
if (!p->isLogin) // do not send position data if one player is not logged in
|
||||
{
|
||||
INFO_LOG(m_logger) << "Player with eqId=" << p->eqId << " and issi=" << p->issi << " is not logged in.";
|
||||
break;
|
||||
}
|
||||
playerCount++;
|
||||
|
||||
|
||||
if (p->vbg != TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady && p->isEndOfTicks())
|
||||
sendTaktischerStatus(p->eqId, p->issi, TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady);
|
||||
// respawn :
|
||||
if (p->vbg != TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady && p->isEndOfTicks()) // only count to zero (isEndOfTicks = are the ticks running out ?) for respawn, if Player is NOT alive!
|
||||
sendTaktischerStatus(p->eqId, p->issi, TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady); // only give rebirth, do not kill //(unsigned short)!p->isAlive); // kill Player if he is alive, give rebirth to Player if he is dead
|
||||
|
||||
tele.header.equipmentNumber = p->eqId;
|
||||
if (m_toogle)
|
||||
sendSanitationReport(p->eqId, p->issi);
|
||||
|
||||
|
||||
movePlayer(p);
|
||||
// else
|
||||
// sendSanitation(p->eqId, p->issi);
|
||||
movePlayer(p); // move players
|
||||
tele.relPosition.offsetY = p->posUTM.y();
|
||||
tele.relPosition.offsetX = p->posUTM.x();
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* Worker for Tetra Simulation
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -29,21 +34,21 @@ NGL::INGLLogger &m_logger;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// PU simulation vars:
|
||||
uint32_t eqId;
|
||||
uint32_t issi;
|
||||
QPointF posUTM;
|
||||
|
||||
|
||||
// PU login-state vars:
|
||||
bool isLogin;
|
||||
bool isValidBITE;
|
||||
TrainingAreaBase::TetraIcd::VulnerabilityState vbg;
|
||||
|
||||
|
||||
int patternInList;
|
||||
int stepInPattern;
|
||||
// pattern vars:
|
||||
int patternInList; // >-| which pattern to take from the pattern list
|
||||
int stepInPattern; // <-| which step we have in the current pattern (see "patternInList" above)
|
||||
|
||||
|
||||
// x seconds, for a Player to respawn [maximum / mininum]
|
||||
uint32_t deathTicks;
|
||||
uint32_t minimumDeathTicks;
|
||||
uint32_t maximumDeathTicks;
|
||||
@@ -64,12 +69,12 @@ public:
|
||||
randomizeDeathTicks();
|
||||
}
|
||||
|
||||
bool isEndOfTicks()
|
||||
bool isEndOfTicks() // gives TRUE if deathTicks is lower than 1 and randomizes deathTicks again, so this function can be reused everytime
|
||||
{
|
||||
deathTicks--;
|
||||
if (deathTicks < 1)
|
||||
{
|
||||
randomizeDeathTicks();
|
||||
randomizeDeathTicks(); // randomize again
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -87,8 +92,8 @@ public:
|
||||
|
||||
private Q_SLOTS:
|
||||
void onReadyRead();
|
||||
void onSendPlayerPositions();
|
||||
|
||||
void onSendPlayerPositions(); // -> nur senden, wenn isLogin & isValidBite für tln ok
|
||||
// wenn LoginOk von PrtCnv -> onSendBite(eqId)
|
||||
void onSocketError();
|
||||
void onSendNachforderungBroadcastTelegramm();
|
||||
void onSendDeaktivierungEinzelminen();
|
||||
@@ -112,7 +117,7 @@ protected:
|
||||
void sendBITE(uint32_t eqId, uint32_t issi);
|
||||
void sendTaktischerStatus(uint32_t eqId, uint32_t issi, TrainingAreaBase::TetraIcd::VulnerabilityState vbg);
|
||||
void sendSanitationReport(uint32_t eqId, uint32_t issi);
|
||||
|
||||
//void sendSanitation(uint32_t eqId, uint32_t issi);
|
||||
private:
|
||||
QTcpSocket *m_socket;
|
||||
QTimer *m_timer;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Building Config - logging facility
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
@@ -27,4 +32,4 @@ LOGGER_T getLogger(const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
@@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Logging for AereaEffectSimulation
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -15,4 +20,4 @@ inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
} // namespace PrtCnv
|
||||
Reference in new issue
Block a user