202 lines
6.2 KiB
C++
202 lines
6.2 KiB
C++
|
|
|
|
#include <QCoreApplication>
|
|
#include <QStringList>
|
|
#include <QFile>
|
|
#include <QByteArray>
|
|
#include <QDateTime>
|
|
#include <QBuffer>
|
|
#include <QSet>
|
|
|
|
#include <CoPrtCnv/CoPrtCnvLogHeader.hpp>
|
|
#include <CoPrtCnv/CoPrtCnvRadioTelegram.hpp>
|
|
#include <CoPrtCnv/CoPrtCnvTelegramConverter.hpp>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <TrainingAreaBase/training_area_telegrams.h>
|
|
|
|
static QSet<int> s_eqIds;
|
|
template <typename T>
|
|
bool validEqId(const T &tele)
|
|
{
|
|
if (!s_eqIds.isEmpty() && !s_eqIds.contains(tele.header.equipmentNumber))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
QByteArray formatTime(quint64 t)
|
|
{
|
|
const quint64 secs = t >> 32;
|
|
const quint64 usecs = t & 0xFFFFFFFF;
|
|
const quint64 msecs = usecs / 1000;
|
|
return QDateTime::fromMSecsSinceEpoch(secs * 1000 + msecs).toString(QLatin1String("yy-MM-dd hh:mm:ss.zzz")).toUtf8();
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
using namespace TrainingAreaBase::TetraIcd;
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx_tetra.props", false);
|
|
|
|
NGL::INGLLogger &logger(NGL::NGLLoggerBootstrap::getNGLRootLogger());
|
|
|
|
if (app.arguments().count() < 3)
|
|
{
|
|
ERROR_LOG(logger) << "Usage: " << app.arguments().at(0)
|
|
<< " <logfile> <telId> <equipId>";
|
|
return 1;
|
|
}
|
|
|
|
QFile telegramFile(app.arguments().at(1));
|
|
if (!telegramFile.open(QIODevice::ReadOnly))
|
|
{
|
|
ERROR_LOG(logger) << "Error opening " << telegramFile.fileName()
|
|
<< " for reading: " << telegramFile.errorString();
|
|
return 2;
|
|
}
|
|
bool bOk;
|
|
int telIdToSearch = app.arguments().at(2).toUShort(&bOk);
|
|
if (!bOk)
|
|
{
|
|
ERROR_LOG(logger) << "Error reading telId - not a (valid) number: "
|
|
<< app.arguments().at(2);
|
|
return 3;
|
|
}
|
|
s_eqIds.clear();
|
|
for (int i = 3; i < app.arguments().size(); ++i)
|
|
{
|
|
int eqId = app.arguments().at(i).toUShort(&bOk);
|
|
if (!bOk)
|
|
{
|
|
ERROR_LOG(logger) << "Error reading equipId - not a (valid) number: "
|
|
<< app.arguments().at(i);
|
|
return 4;
|
|
}
|
|
s_eqIds += eqId;
|
|
}
|
|
|
|
|
|
while (true)
|
|
{
|
|
|
|
N_CoPrtCnv::CoPrtCnvLogHeader lh;
|
|
if (sizeof(lh) == telegramFile.read((char *)&lh, sizeof(lh)))
|
|
{
|
|
if (lh.m_Version == 3)
|
|
{
|
|
|
|
qint64 telegramLength = lh.m_Length - sizeof(lh);
|
|
QByteArray telegramData(telegramLength, Qt::Uninitialized);
|
|
if (telegramLength == telegramFile.read(telegramData.data(), telegramLength))
|
|
{
|
|
|
|
N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol dest = (N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol)
|
|
(lh.m_Protocol & N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolMask);
|
|
|
|
switch (dest)
|
|
{
|
|
case N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolCentral:
|
|
{
|
|
const QJsonObject obj = QJsonDocument::fromJson(telegramData).object();
|
|
int telId = obj.value(QStringLiteral("typeId")).toInt();
|
|
if (telIdToSearch != telId)
|
|
continue;
|
|
|
|
const QJsonObject objData = obj.value(QStringLiteral("data")).toObject();
|
|
|
|
const QByteArray tBA = formatTime(lh.m_Time);
|
|
const char *timeStr = tBA.constData();
|
|
|
|
switch (telId)
|
|
{
|
|
case Constraints<CreateFunctionalArea>::id():
|
|
{
|
|
const CreateFunctionalArea tele(CreateFunctionalArea::fromJson(objData));
|
|
if (!validEqId(tele))
|
|
break;
|
|
fprintf(stdout, "%s, FUNKTIONSRAUM: '%s', %d, %d\n",
|
|
timeStr,
|
|
tele.name.c_str(),
|
|
tele.aesDdsId,
|
|
tele.header.equipmentNumber
|
|
);
|
|
break;
|
|
}
|
|
case Constraints<DeactivateEffectSimulation>::id():
|
|
{
|
|
const DeactivateEffectSimulation tele(DeactivateEffectSimulation::fromJson(objData));
|
|
fprintf(stdout, "%s, DEAKTIVIERUNG_WIRKFELD: typ: %d - kennung: %d\n",
|
|
timeStr,
|
|
int(tele.aesType),
|
|
tele.aesDdsId
|
|
);
|
|
break;
|
|
}
|
|
case Constraints<PositionReport>::id():
|
|
{
|
|
const PositionReport tele(PositionReport::fromJson(objData));
|
|
if (!validEqId(tele))
|
|
break;
|
|
if (tele.opsPosition.opsId == 0)
|
|
break;
|
|
fprintf(stdout, "%s, IPS_POSITIONSDATEN: %d - OPS: %d\n",
|
|
timeStr,
|
|
tele.header.equipmentNumber,
|
|
tele.opsPosition.opsId
|
|
);
|
|
break;
|
|
}
|
|
case BESTAETIGUNG:
|
|
case UMGEBUNGS_MELDUNG2:
|
|
break;
|
|
default:
|
|
fprintf(stderr, "Printing telegram with id %d not implemented\n", telId);
|
|
break;
|
|
|
|
}
|
|
break;
|
|
}
|
|
case N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolTetra:
|
|
{
|
|
N_CoPrtCnv::CoPrtCnvRadioTelegram radioTelegram(telegramData);
|
|
gef_telegramm_id_et telId = radioTelegram.getTelID();
|
|
if (telId == GEF_UMGEBUNGS_MELDUNG2)
|
|
{
|
|
const QByteArray tBA = formatTime(lh.m_Time);
|
|
const char *timeStr = tBA.constData();
|
|
static uint16_t bci = 0xFFFF;
|
|
if (bci != radioTelegram.getBroadcastIndex())
|
|
{
|
|
if (bci > radioTelegram.getBroadcastIndex() && bci != 0xFFFF)
|
|
{
|
|
fprintf(stdout, "BCI reset in %s at %s!\n",
|
|
qPrintable(telegramFile.fileName()),
|
|
timeStr);
|
|
}
|
|
fprintf(stdout, "BCI: %d\n", radioTelegram.getBroadcastIndex());
|
|
bci = radioTelegram.getBroadcastIndex();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ERROR_LOG(logger) << "Wrong LogHeader version: " << lh.m_Version;
|
|
return 4;
|
|
}
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|