Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+132
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* main for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <QNetworkProxy>
|
||||
#include <memory>
|
||||
#include "main_handler.h"
|
||||
#include "logger.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <LtsUtilsCore/sfm_bytemessage_converter.h>
|
||||
#include "wls_sfm_message.h"
|
||||
#include "wls_sfm_message_converter.h"
|
||||
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser()
|
||||
{
|
||||
addOption({ QStringList() << QLatin1String("c") << QLatin1String("checkData"),
|
||||
QLatin1String("Testdata"),
|
||||
QLatin1String("data to check as hex (e.g. '02044c221f8091660bb300001a31313131313131313131313131313131313131313131313131312503'"),
|
||||
QString()
|
||||
});
|
||||
}
|
||||
|
||||
bool isCheckData() const { return isSet(QLatin1String("c")); }
|
||||
QByteArray dataToCheck() const { return value(QLatin1String("c")).toUtf8(); }
|
||||
};
|
||||
|
||||
namespace WirelessLocationSystem
|
||||
{
|
||||
bool sendBinarySfmData(const QByteArray &ba, int sendCounter)
|
||||
{
|
||||
int chunkLen = 0;
|
||||
int chunkCount = 1;
|
||||
|
||||
if (!WlsParticipant::calcChunkCountAndLen(ba, chunkCount, chunkLen))
|
||||
{
|
||||
fprintf(stderr, "Chunk count is not ok - data size: %d\n", ba.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
int fragmentNumber = 1;
|
||||
int iPos = 0;
|
||||
while (iPos < ba.size())
|
||||
{
|
||||
const SfmMsgTetra_tx tx(sendCounter,
|
||||
chunkCount,
|
||||
fragmentNumber,
|
||||
ba.mid(iPos, chunkLen));
|
||||
const auto payload(SfmMessageConverter::generateTxMessage(tx));
|
||||
const unsigned int fragmentParts = ((payload.size() + WlsHandler::s_maxLenTransparentData - 1) / WlsHandler::s_maxLenTransparentData);
|
||||
if (fragmentParts != 1)
|
||||
fprintf(stderr, "Calculation mismatch - only expected one part, got %d\n", fragmentParts);
|
||||
|
||||
SfmMsgTetra_rx rx;
|
||||
rx.setPayload(tx.getPayload());
|
||||
fprintf(stdout, "Output: len: %d(%d), %s, sendCounter: %d(0x%02x), is fragmented: %d, fragment: %d/%d\n",
|
||||
payload.size(), tx.getPayload().size(), payload.data(),
|
||||
rx.sendCounter(), rx.sendCounter(), rx.isFragmented(), rx.fragmentNumber(), rx.fragmentCount());
|
||||
|
||||
++sendCounter;
|
||||
++fragmentNumber;
|
||||
iPos += chunkLen;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int checkData(const QByteArray &data)
|
||||
{
|
||||
const QByteArray ba(QByteArray::fromHex(data));
|
||||
try
|
||||
{
|
||||
const auto msg = LtsUtils::byteStreamToSfmMessage(ba);
|
||||
fprintf(stdout, "Message payload: len: %d, %s\n", msg.payload().size(), msg.payload().toHex().data());
|
||||
if (msg.id() == int(SfmMessage::MsgId::TetraMessage))
|
||||
{
|
||||
WirelessLocationSystem::SfmMsgTetra_rx rx;
|
||||
rx.setPayload(msg.payload());
|
||||
fprintf(stdout, "SfmMsgTetra payload: len: %d, %s, ", rx.payload().size(), rx.payload().toHex().data());
|
||||
fprintf(stdout, "sendCounter: %d(0x%02x), is fragmented: %d, fragment: %d/%d\n",
|
||||
rx.sendCounter(), rx.sendCounter(), rx.isFragmented(), rx.fragmentNumber(), rx.fragmentCount());
|
||||
sendBinarySfmData(rx.payload(), 0x02); // 0x02 -> a value which has to be substituted
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
fprintf(stderr, "Could not decode message: %s\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // namespace WirelessLocationSystem
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
QNetworkProxy::setApplicationProxy(QNetworkProxy());
|
||||
|
||||
int iRet = -1;
|
||||
CmdLineParser options;
|
||||
if (!options.init())
|
||||
return iRet;
|
||||
app.createLogger("WLS", 0);
|
||||
|
||||
if (options.isCheckData())
|
||||
return WirelessLocationSystem::checkData(options.dataToCheck());
|
||||
|
||||
WirelessLocationSystem::Settings::setIniFile(options.iniFile());
|
||||
|
||||
{
|
||||
std::unique_ptr<WirelessLocationSystem::MainHandler> mainHandler(new WirelessLocationSystem::MainHandler);
|
||||
if (mainHandler->init(options.domainId()))
|
||||
{
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
iRet = app.exec();
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
}
|
||||
}
|
||||
|
||||
return iRet;
|
||||
}
|
||||
Reference in new issue
Block a user