Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* Simulate players
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLTE, 2022-03-29
|
||||
*/
|
||||
|
||||
#include "simulated_player.h"
|
||||
#include "position_helper.h"
|
||||
|
||||
#include <WirelessLocationSystem/wls_sfm_message_converter.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <LtsUtils/LtsUtilsCore/sfm_bytemessage_converter.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
namespace WlsRandomPositions
|
||||
{
|
||||
|
||||
SimulatedPlayer::SimulatedPlayer(int equipNo, qint64 mac, int msecs, int jitter, double maxDistance, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_equipNo(equipNo)
|
||||
, m_macAddress(toMacString(mac))
|
||||
, m_msecs(msecs)
|
||||
, m_jitter(jitter)
|
||||
, m_maxDistance(maxDistance)
|
||||
, m_pos({{},0.0})
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(QString::fromLatin1("SimulatedPlayer.%1").arg(QString::number(m_equipNo)).toStdString()))
|
||||
{
|
||||
}
|
||||
|
||||
void SimulatedPlayer::start()
|
||||
{
|
||||
QString eqNoString = QString::number(m_equipNo);
|
||||
QString initialTelegram = QString::fromLatin1("%1;%2;%3").arg(4).arg(m_macAddress).arg(eqNoString);
|
||||
|
||||
INFO_LOG(m_logger) << "initTelegram: " << initialTelegram;
|
||||
|
||||
WirelessLocationSystem::SfmMsgEquipmentId msg;
|
||||
msg.setEquipmentNumber(m_equipNo);
|
||||
QByteArray ba = WirelessLocationSystem::SfmMessageConverter::generateTxMessage(msg);
|
||||
|
||||
emit sendInitTelegram(m_macAddress, ba);
|
||||
|
||||
QTimer::singleShot(m_msecs + (((rand() % 200) - 100) / 100) * m_jitter, this, &SimulatedPlayer::onTimerTimeout);
|
||||
}
|
||||
|
||||
void SimulatedPlayer::onTimerTimeout()
|
||||
{
|
||||
QPair<QPointF,double> pos;
|
||||
if (qFuzzyIsNull(m_maxDistance) || m_pos.first.isNull())
|
||||
pos = PositionHelper::randPos();
|
||||
else
|
||||
pos = PositionHelper::randPos(m_pos.first, m_maxDistance);
|
||||
|
||||
DEBUG_LOG(m_logger) << "posTelegram: x: " << pos.first.x() << ", y: " << pos.first.y() << ", z: " << pos.second;
|
||||
DEBUG_LOG(m_logger) << "MGRS: " << LtsCoordTrans::UtmCoordinate::fromGeographic(pos.first).mgrs(5, true);
|
||||
|
||||
emit sendPositionTelegram(m_macAddress, pos.first, pos.second);
|
||||
|
||||
m_pos = pos;
|
||||
QTimer::singleShot(m_msecs + (((rand() % 200) - 100) / 100) * m_jitter, this, &SimulatedPlayer::onTimerTimeout);
|
||||
}
|
||||
|
||||
QString SimulatedPlayer::toMacString(qint64 mac)
|
||||
{
|
||||
QString macString = QString::number(mac, 16);
|
||||
macString = macString.prepend(QString(12 - macString.length(), QLatin1Char('0')));
|
||||
macString.insert(10, QLatin1Char(':'));
|
||||
macString.insert( 8, QLatin1Char(':'));
|
||||
macString.insert( 6, QLatin1Char(':'));
|
||||
macString.insert( 4, QLatin1Char(':'));
|
||||
macString.insert( 2, QLatin1Char(':'));
|
||||
return macString;
|
||||
}
|
||||
|
||||
} // Namespace WlsRandomPositions
|
||||
Reference in new issue
Block a user