Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Test application for VWM
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Gerlinde Rudolphus, SLSE, 2016-01-25
|
||||
*/
|
||||
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include "vwm_api.h"
|
||||
#include "vwm_math.h"
|
||||
#include "test_read_xml.h"
|
||||
#include "bcu_xml_reader.h"
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
|
||||
Test::Test()
|
||||
: m_api(new BuildingControlUnit::VWM::Api(this))
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("BCU.VWM.Test"))
|
||||
{
|
||||
connect(m_api, &BuildingControlUnit::VWM::Api::hitResult,
|
||||
this, &Test::hitResult);
|
||||
QTimer::singleShot(0, this, &Test::test1);
|
||||
}
|
||||
|
||||
Test::~Test()
|
||||
{
|
||||
delete m_api;
|
||||
}
|
||||
|
||||
void Test::hitResult(const BuildingControlUnit::HitResult &result)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Hit Result: sensorId = " << result.sensorId
|
||||
<< ", originatorId = " << result.originatorId
|
||||
<< ", chargeTypeId = " << result.chargeTypeId
|
||||
<< ", dmgPercentOld = " << result.damagePercentOld
|
||||
<< ", dmgPercentNew = " << result.damagePercentNew
|
||||
<< ", effectSoundId = " << result.effectSoundId
|
||||
<< ", effectTime = " << QDateTime::fromMSecsSinceEpoch(result.effectTimeMSec).toString(QStringLiteral("hh:mm:ss.zzz"))
|
||||
<< ", damageState = " << result.damageState
|
||||
<< ", #rooms = " << result.rooms.size();
|
||||
}
|
||||
|
||||
void Test::test1()
|
||||
{
|
||||
// Incoming hit: sensorId = 11003, originatorId = 1, originatorType = OriginatorType::DirectHit, chargeId = 1,
|
||||
// effectTimeMSec = 1486718229883, position = 2.084/-0.05/3.823, direction = 0/0/-1
|
||||
// Searching hit position for position 2.084/-0.05/3.823, direction 0/0/-1
|
||||
//m_api->onHitOptical(QDateTime::currentMSecsSinceEpoch(), 11001, 4711, 1, 0, 0);
|
||||
const auto bsmMap = m_api->bsmMap();
|
||||
for (const BuildingControlUnit::Bsm &bsm : bsmMap)
|
||||
{
|
||||
const auto rooms = m_api->building().rooms();
|
||||
|
||||
const auto hitPos = BuildingControlUnit::VWM::Math::checkBsmPosition(bsm.position, bsm.direction, rooms);
|
||||
if (hitPos.state != BuildingControlUnit::VWM::HitPosition::State::OuterWall)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Effect on bsm " << bsm.id << " does not hit building ! - position: "
|
||||
<< bsm.position << ", direction: " << bsm.direction;
|
||||
}
|
||||
else if (hitPos.distance < 0)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Effect on bsm " << bsm.id << " results in hit pos behind a wall ("
|
||||
<< hitPos.distance << "m) instead in front - BSM is not modelled in the correct place: "
|
||||
<< bsm.position << ", direction: " << bsm.direction << ", roomId which was hit: " << hitPos.roomId;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "BSM with id " << bsm.id << " looks fine - room which will be hit: " << hitPos.roomId;
|
||||
}
|
||||
}
|
||||
|
||||
QTimer::singleShot(1000, this, &Test::test2);
|
||||
}
|
||||
// 9.19/5.1/2.83, p2 = 9.19/5.1/6.06, p3 = 9.19/9.05/6.06
|
||||
|
||||
void Test::test2()
|
||||
{
|
||||
m_api->onHitOpticalOC(QDateTime::currentMSecsSinceEpoch(), 2, 0, 7, BuildingControlUnit::DamageState::Destroyed);
|
||||
QTimer::singleShot(1000, this, &Test::test3);
|
||||
}
|
||||
|
||||
void Test::test3()
|
||||
{
|
||||
m_api->onHitOpticalOC(QDateTime::currentMSecsSinceEpoch(), 2, 1, 8, BuildingControlUnit::DamageState::NoDamage);
|
||||
QTimer::singleShot(1000, this, &Test::test4);
|
||||
}
|
||||
|
||||
void Test::test4()
|
||||
{
|
||||
m_api->onHitEcc(2, BuildingControlUnit::DamageState::Destroyed, QVector<int>());
|
||||
m_api->onHitEcc(2, BuildingControlUnit::DamageState::NoDamage, QVector<int>());
|
||||
QTimer::singleShot(1000, this, &Test::test5);
|
||||
}
|
||||
|
||||
void Test::test5()
|
||||
{
|
||||
m_api->onHitOptical(QDateTime::currentMSecsSinceEpoch(), 1, 4711, 5, 0, 0);
|
||||
QTimer::singleShot(1000, this, &Test::test6);
|
||||
}
|
||||
|
||||
void Test::test6()
|
||||
{
|
||||
// Todo: Correct ChargeTypeID!
|
||||
// outside
|
||||
m_api->onHitCes(QDateTime::currentMSecsSinceEpoch(), 112, 42, 55, 66, LtsUtils::QPoint3D(30,-30,0), {});
|
||||
// inside
|
||||
m_api->onHitCes(QDateTime::currentMSecsSinceEpoch(), 112, 42, 55, 66, LtsUtils::QPoint3D(2,2,0), QLatin1String(""));
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("BCU", 1);
|
||||
|
||||
QString path = QCoreApplication::applicationDirPath();
|
||||
QString chargesConfig = path + QLatin1String("/bldg_7_charges.xml");
|
||||
QString vulConfig = path + QLatin1String("/bldg_7_vulnerability_model.xml");
|
||||
QString bldConfigFile = path + QLatin1String("/bldg_7_building_config.xml");
|
||||
|
||||
if (app.arguments().size() > 1)
|
||||
{
|
||||
// assume: /tmp/bldg_7
|
||||
path = app.arguments().at(1);
|
||||
chargesConfig = path + QLatin1String("_charges.xml");
|
||||
vulConfig = path + QLatin1String("_vulnerability_model.xml");
|
||||
bldConfigFile = path + QLatin1String("_building_config.xml");
|
||||
}
|
||||
|
||||
BuildingControlUnit::BuildingBsmConfig bsmConfig;
|
||||
BuildingControlUnit::BuildingEgcuConfig egcuConfig;
|
||||
if (!BuildingControlUnit::parseBuildingConfigXml(bldConfigFile, bsmConfig, egcuConfig))
|
||||
return 1;
|
||||
|
||||
Test *test = new Test;
|
||||
if (!test->m_api->init(chargesConfig, vulConfig, bsmConfig, true))
|
||||
{
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
app.exec();
|
||||
|
||||
delete test;
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user