/** * Handler for player data * $Id$ * $HeadURL$ * $Author$ * Created by hjl, SLSE, 2017-02-20 */ #include #include #include #include "initialization.h" #include "handler_tab_data.h" #include "handler_effect_show.h" #include "handler_effect_show_vehicle_status.h" #include "handler_effect_show_actor_relocation.h" #include "esm_convert_to_tab.h" #include "settings.h" namespace EffectShowManagement { static inline QString plText(const std::vector &pl) { return QString::fromLatin1(LtsUtils::toQByteArray(pl).toHex()); } //============================================================================= HandlerTabData::HandlerTabData(Initialization *mainHandler, QObject *parent) : QObject(parent) , m_mainHandler(mainHandler) , m_logger(getLogger("HandlerTabData")) { } // end of ctor() //============================================================================= bool HandlerTabData::init() { DEBUG_LOG(m_logger) << "Begin HandlerTabData"; auto dtcTab = m_mainHandler->dds()->dtcTab(); connect(dtcTab.get(), &TrainingAreaBase::Interface::Dtc::fireSmokeMarkerDataChanged, this, &HandlerTabData::onFireSmokeMarkerDataChanged); // Get current data for all Fire Smoke Marker { auto cb = [this](const TrainingAreaBase::FireSmokeMarkerData & fireSmokeMarker) { onFireSmokeMarkerDataChanged(fireSmokeMarker, DataModification::eAdded); }; if (!dtcTab->fireSmokeMarkerDatas(cb)) return false; } DEBUG_LOG(m_logger) << "End HandlerTabData"; return true; } // end of init() //============================================================================= void HandlerTabData::effectShowVehicleStatusRequest(int equipmentNumber, int participantId) { DEBUG_LOG(m_logger) << "Trigger Status Request " << equipmentNumber << ' ' << participantId; TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertStatusRequest()); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of onVehicleStatusStatusRequest() //============================================================================= void HandlerTabData::relocationOrder(int equipmentNumber, int participantId, const ConvertToTab::RelocationOrder_t &relocationOrder) { DEBUG_LOG(m_logger) << "Trigger Relocation Order " << equipmentNumber << ' ' << participantId; TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertRelocationOrder(relocationOrder)); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of relocationOrder() //============================================================================= void HandlerTabData::effectShowOrder(int equipmentNumber, int participantId, const ConvertToTab::EffectShowOrder_t &effectShowOrder) { TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertEffectShowOrder(effectShowOrder)); Core::GeoPosition2D posCenter = effectShowOrder.centerPosition; Core::GeoPosition2D posLl = effectShowOrder.lowerLeftPosition; DEBUG_LOG(m_logger) << "Trigger Effect Show Order " << equipmentNumber << ' ' << participantId << "\n idEffectShow " << effectShowOrder.idEffectShow << "\n startTime " << effectShowOrder.startTime << "\n centerPosition " << LtsCoordTrans::mgrsFromGeographic(posCenter.lon(), posCenter.lat()) << "\n areaDepth " << effectShowOrder.areaDepth << "\n areaWidth " << effectShowOrder.areaWidth << "\n rotation " << effectShowOrder.rotation << "\n lowerLeftPosition " << LtsCoordTrans::mgrsFromGeographic(posLl.lon(), posLl.lat()) << "\n numOfVolley " << int(effectShowOrder.numOfVolley) << "\n shotsPerVolley " << int(effectShowOrder.shotsPerVolley) << "\n typeOfAmmunition " << int(effectShowOrder.typeOfAmmunition) << "\n duration " << effectShowOrder.duration << "\n name " << effectShowOrder.name << "\n payload" << plText(out.payload()); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of effetShowOrder() //============================================================================= void HandlerTabData::effectShowStop(int equipmentNumber, int participantId, const qint16 &idEffectShow) { DEBUG_LOG(m_logger) << "Trigger Effect Show Stop " << equipmentNumber << ' ' << participantId; TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertEffectShowStop(idEffectShow)); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of effectShowStop() //============================================================================= void HandlerTabData::effectShowContinue(int equipmentNumber, int participantId, const ConvertToTab::EffectShowContinue_t &effectShowContinue) { TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertEffectShowContinue(effectShowContinue)); DEBUG_LOG(m_logger) << "Trigger Effect Show Continue " << equipmentNumber << ' ' << participantId << "\n idEffectShow " << effectShowContinue.idEffectShow << "\n executionTime " << effectShowContinue.executionTime << "\n payload" << plText(out.payload()); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of effectShowContinue() //============================================================================= void HandlerTabData::retractOrder(int equipmentNumber, int participantId, const ConvertToTab::RetractOrder_t &retractOrder) { TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertOrderRetract(retractOrder)); DEBUG_LOG(m_logger) << "Trigger Retract Order " << equipmentNumber << ' ' << participantId << "\n orderType " << retractOrder.orderType << "\n id " << retractOrder.id << "\n payload" << plText(out.payload()); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of retractOrder() //============================================================================= void HandlerTabData::meteoData(int equipmentNumber, int participantId, const MeteoDataManagement::MeteoData &meteoData) { TrainingAreaBase::SendFireSmokeMarkerDataRequest out; out.equipmentNumber(equipmentNumber); out.participantId(participantId); out.payload(ConvertToTab::convertMeteoData(meteoData)); DEBUG_LOG(m_logger) << "Trigger Meteo data " << equipmentNumber << ' ' << participantId << "\n temperature " << meteoData.temperature() << "\n humidity " << meteoData.humidity() << "\n pressure " << meteoData.pressure() << "\n windDirection " << meteoData.windDirection() << "\n payload" << plText(out.payload()); m_mainHandler->dds()->ftcTab()->sendFireSmokeMarkerDataRequest(out, this); } // end of //============================================================================= void HandlerTabData::onSendFireSmokeMarkerDataReply(const Core::FunctionReplyObject &reply) { if (reply.error()) ERROR_LOG(m_logger) << "Fire Smoke Marker Data could not be send: " << reply.str(); else DEBUG_LOG(m_logger) << "Fire Smoke Marker Data send successfully to TAB!"; } // end of onSendFireSmokeMarkerDataReply() //----------------------------------------------------------------------------- void HandlerTabData::onFireSmokeMarkerDataChanged(const TrainingAreaBase::FireSmokeMarkerData &data, DataModification modType) { if (modType == DataModification::eRemoved) return; DEBUG_LOG(m_logger) << "Got Fire Smoke Marker " << data.sampleTime(); switch (ConvertFromTab::isTelegram(data)) { case ConvertFromTab::RxTelegram_e::VehicleStatus: { DEBUG_LOG(m_logger) << "Got Vehicle Status"; m_mainHandler->handlerEffectShowVehicleStatus()->vehicleStatusReceived(ConvertFromTab::getVehicleStatus(data)); break; } case ConvertFromTab::RxTelegram_e::OrderConfirmation: { DEBUG_LOG(m_logger) << "Got Order Confirmation "; switch (modType) { case DataModification::eAdded: case DataModification::eModified: { const ConvertFromTab::OrderConfirmation_t orderConfirmation = ConvertFromTab::getOrderConfirmation(data); if (orderConfirmation.orderType == ConvertFromTab::OrderType_e::Relocation) { DEBUG_LOG(m_logger) << "relocationOrderConfirmationReceived(orderConfirmation)"; m_mainHandler->handlerEffectShowActorRelocation()->relocationOrderConfirmationReceived(orderConfirmation); } else { DEBUG_LOG(m_logger) << "effectShowOrderConfirmationReceived(orderConfirmation)"; m_mainHandler->handlerEffectShow()->effectShowOrderConfirmationReceived(orderConfirmation); } break; } case DataModification::eRemoved: break; } break; } case ConvertFromTab::RxTelegram_e::unknown: break; } } // end of onFireSmokeMarkerDataChanged() //----------------------------------------------------------------------------- void HandlerTabData::publishVehicleStatus(const EffectShowManagement::EffectShowVehicleStatus &vehicleStatus) { DEBUG_LOG(m_logger) << "Vehicle Status published esmParticipantId: " << vehicleStatus.esmParticipantId() << ' ' << vehicleStatus.operational(); m_mainHandler->dds()->dts()->publish(vehicleStatus); } // end of publishVehicleStatus() //----------------------------------------------------------------------------- void HandlerTabData::sendAdlerFqFb(const int aesId) { DEBUG_LOG(m_logger) << "Send Adler Feuerbereitschaft"; TrainingAreaBase::AdlerFqFbRequest out; out.aesItemId(aesId); m_mainHandler->dds()->ftcTab()->adlerFqFbRequest(out, this); } //============================================================================= void HandlerTabData::onAdlerFqFbReply(const Core::FunctionReplyObject &reply) { if (reply.error()) ERROR_LOG(m_logger) << "Adler Feuerbereitschaft could not be send: " << reply.str() << ", id:" << reply.id(); else DEBUG_LOG(m_logger) << "Adler Feuerbereitschaft successfully to TAB!"; } } // namespace EffectShowManagement