![]() |
VR-Link API Documentation for HLA 1.3
|
This is a simple program that prints all received HLA Interactions and all HLA Object updates.
/******************************************************************************* ** Copyright (c) 1992-2010 VT MAK ** All rights reserved. *******************************************************************************/ #if !defined(DtDIS) && !defined(DtTENA) #include <vl/exerciseConn.h> #include <vlutil/vlKeyboard.h> #include <vlutil/vlProcessControl.h> #include <vl/reflEntList.h> #include <vl/reflAggList.h> #include <vl/hRefDesigList.h> #include <vl/hRefEmSysList.h> #include <vl/hRefRadRvList.h> #include <vl/hRefRadXmList.h> #include <vl/hRefEnvList.h> #include <vl/hRefGrDatList.h> #include <vl/hRefIffList.h> #include <vl/hRefActSonarList.h> #include <vl/hRefPropNoiseList.h> #include <vl/hRefAddPassActList.h> #include <vl/fom.h> #include <vl/intClassDesc.h> #include <vl/interaction.h> #include <vl/hStateMsg.h> #include <vl/simRprFomMap.h> #include "stealthControlRegister.h" #include <vlutil/vlString.h> #include <cmdLine/cmdLine.h> #include "ddmFedAmb13.h" #include "ddmFedAmb1516.h" #include "ddmFedAmb1516e.h" #include <vl/geodeticRegion.h> #include <vlutil/vlStringUtil.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string> void reflectCb( const DtStateMsg& msg, DtHlaObject* obj, void* usr ); void removeObjectCb( DtHlaObject* obj, void* usr ); void discoverObjectCb( DtHlaObject* obj, void* usr ); void receiveInterCb( DtInteraction* inter, void* usr ); int keybrdTick( void ); // Control characters that are used to clear the screen. Empty string // means don't clear. std::string clearScreen(""); const std::string theSeperator("************************************************************\n"); DtCmdLine::SwitchArg raw("r", "raw", "Print Raw HLA Data", false); DtCmdLine::SwitchArg fullReport("M", "noFullReport", "Disable Printing of Update Specifics", true); DtCmdLine::SwitchArg clearScreenSwitch("c", "clearScreen", "Clear Screen Between Updates", false); DtCmdLine::SwitchArg ddmDump("d", "ddmDump", "Print DDM region data", false); DtCmdLine::SwitchArg showRegionData("", "showRegionData", "Show Region Data with Updates", false); DtCmdLine::SwitchArg subWithDdm("", "subWithDdm", "Subscribe with DDM", false); #if !DtHLA_1516 std::map<RTI::ObjectHandle, DtDdmFederateAmbassador::DtRegionInfo> myRegionInfo; #else std::map<RTI::ObjectInstanceHandle, DtDdmFederateAmbassador::DtRegionInfo> myRegionInfo; #endif RTI::DimensionHandle myXHandle; RTI::DimensionHandle myYHandle; #if VXWORKS #define main realMain DT_VXWORKS_APP(hlaNetdump) #endif int main( int argc, char* argv[] ) { DtCmdLine::CmdLine cmd("HLA Netdump", ' ' , DtExerciseConn::vrlinkVersion().c_str()); DtString fedName = "hlaNetdump"; DtCmdLine::ValueArg<DtString> fedFileName("F","fedFileName", "Fed File Name", false, "", "File Name",cmd); DtCmdLine::ValueArg<DtString> execName("x","execName", "Fed Execution Name", false, "VR-Link", "string",cmd); DtCmdLine::ValueArg<DtString> fomMapperLib("f","fomMapperLib", "FOM Mapper Library Name", false, "", "string",cmd); DtCmdLine::ValueArg<DtString> fomMapperInitData("","fomMapperInitData", "FOM Mapper Initialization String", false, "", "string",cmd); DtCmdLine::ValueArg<double> rprFomVersion("R","rprFomVersion", "RPR FOM Version", false, 1.0, "double",cmd); DtCmdLine::ValueArg<int> rprFomRevision("","rprFomRevision", "RPR FOM Revision", false, 1, "int",cmd); DtCmdLine::SwitchArg includeMom("m", "printMom", "print MOM HLA data", false,cmd); DtCmdLine::ValueArg<double> regionOriginLat("", "regionLat", "Region Origin Latitude (degrees)", false, 0.0, "double", cmd); DtCmdLine::ValueArg<double> regionOriginLon("", "regionLon", "Region Origin Longitude (degrees)", false, 0.0, "double", cmd); DtCmdLine::ValueArg<double> regionSize("", "regionSize", "Region Size (in meters)", false, 10.0, "double", cmd); cmd.add(raw); cmd.add(clearScreenSwitch); cmd.add(fullReport); cmd.add(ddmDump); cmd.add(showRegionData); cmd.add(subWithDdm); cmd.parse(argc, argv); if (clearScreenSwitch) { // will not work on all terminals clearScreen = "\033[H\033[2J"; } if (ddmDump || showRegionData) { DtExerciseConn::setFedAmbCreator(DtDdmFederateAmbassador::create); } DtExerciseConn::InitializationStatus status = DtExerciseConn::DtINIT_SUCCESS; DtExerciseConn* exConn = 0; if ( !fomMapperLib.getValue().isEmpty() ) { // A FOM Mapper shared library was specified if ( fomMapperInitData.getValue().isEmpty() ) { exConn = new DtExerciseConn( execName.getValue().c_str(), fedName.c_str(), fomMapperLib.getValue().c_str(), fedFileName.getValue().c_str(), (void*)0, &status ); } else { exConn = new DtExerciseConn( execName.getValue().c_str(), fedName.c_str(), fomMapperLib.getValue().c_str(), fedFileName.getValue().c_str(), (void*)fomMapperInitData.getValue().c_str(), &status ); } if (status != DtExerciseConn::DtINIT_SUCCESS) { return 1; } } else { // FOM Mapper shared lib was not specified DtFomMapper* mapper = new DtRprFomMapper( rprFomVersion, rprFomRevision ); exConn = new DtExerciseConn( execName.getValue().c_str(), fedName.c_str(), mapper, fedFileName.getValue().c_str(), &status ); if (status != DtExerciseConn::DtINIT_SUCCESS) { return 1; } // Add view control interaction encoders and decoders DtStealthControlRegister(exConn); } DtDDMRegionSP region = DtDDMRegionSP(); DtDDMRegionSet* regionSet = 0; if (subWithDdm) { try { DtGeodeticRegionSP geodRegion(new DtGeodeticRegion(exConn)); DtVector geocentricPoint; DtGeodeticCoord geodOrigin(DtDeg2Rad(regionOriginLat.getValue()), DtDeg2Rad(regionOriginLon.getValue()), 0); geodOrigin.getGeocentric(geocentricPoint); geodRegion->setRegionBounds(geocentricPoint, regionSize.getValue(), regionSize.getValue()); region = geodRegion; regionSet = new DtDDMRegionSet(); regionSet->insert(region); } catch (RTI::Exception& except) { std::cout << "Caught exception creating region: " << except << std::endl; std::cout << "Exiting..." << std::endl; return -1; } catch (DtException& except) { std::cout << "Caught exception creating region: " << except << std::endl; std::cout << "Exiting..." << std::endl; return -1; } } if (ddmDump || showRegionData) { DtDdmFederateAmbassador* fedAmb = dynamic_cast<DtDdmFederateAmbassador*>( exConn->fedAmb()); if (fedAmb) { try { #if !DtHLA_1516 RTI::SpaceHandle spaceHandle = exConn->rtiAmb()->getRoutingSpaceHandle( "BenchmarkGeographicSpace"); myXHandle = exConn->rtiAmb()->getDimensionHandle( "X", spaceHandle); myYHandle = exConn->rtiAmb()->getDimensionHandle( "Y", spaceHandle); #else myXHandle = exConn->rtiAmb()->getDimensionHandle( DtToWString("X")); myYHandle = exConn->rtiAmb()->getDimensionHandle( DtToWString("Y")); #endif fedAmb->setXHandle(myXHandle); fedAmb->setYHandle(myYHandle); } catch (RTI::Exception& ) { // ignore } catch (...) { // ignore } } } DtReflectedEntityList* rel = 0; if ( !raw ) { // insures that each hlaObject will be given an ESR. // needed for non-raw mode rel = new DtReflectedEntityList( exConn, false, regionSet ); } DtReflectedAggregateList* ral = 0; if ( !raw ) { // insures that each hlaObject will be given an ASR. // needed for non-raw mode ral = new DtReflectedAggregateList( exConn, false, regionSet ); } DtReflectedDesignatorList* rdl = 0; if ( !raw ) { // insures that each hlaObject will be given a DSR. // needed for non-raw mode rdl = new DtReflectedDesignatorList( exConn, regionSet ); } DtReflectedEmitterSystemList* rsl = 0; if ( !raw ) { // insures that each hlaObject will be given a ESR. // needed for non-raw mode rsl = new DtReflectedEmitterSystemList( exConn, true, regionSet ); } DtReflectedRadioReceiverList* rrl = 0; if ( !raw ) { // insures that each hlaObject will be given an RSR. // needed for non-raw mode rrl = new DtReflectedRadioReceiverList( exConn, regionSet ); } DtReflectedRadioTransmitterList* rtl = 0; if ( !raw ) { // insures that each hlaObject will be given an TSR. // needed for non-raw mode rtl = new DtReflectedRadioTransmitterList( exConn, regionSet ); } DtReflectedIffList *ril = 0; if ( !raw ) { // insures that each hlaObject will be given an ISR. // needed for non-raw mode ril = new DtReflectedIffList( exConn, regionSet ); } DtReflectedEnvironmentProcessList* repl = 0; if ( !raw ) { // insures that each hlaObject will be given an EPSR. // needed for non-raw mode repl = new DtReflectedEnvironmentProcessList( exConn, regionSet ); } DtReflectedGriddedDataList* rgdl = 0; if ( !raw ) { // insures that each hlaObject will be given an GDSR. // needed for non-raw mode rgdl = new DtReflectedGriddedDataList( exConn, regionSet ); } DtReflectedActiveSonarList* rasl = 0; if ( !raw ) { // insures that each hlaObject will be given an GDSR. // needed for non-raw mode rasl = new DtReflectedActiveSonarList( exConn, regionSet ); } DtReflectedPropulsionNoiseList* rpnl = 0; if ( !raw ) { // insures that each hlaObject will be given an GDSR. // needed for non-raw mode rpnl = new DtReflectedPropulsionNoiseList( exConn, regionSet ); } DtReflectedAdditionalPassiveActivitiesList* rapal = 0; if ( !raw ) { // insures that each hlaObject will be given an asr. // needed for non-raw mode rapal = new DtReflectedAdditionalPassiveActivitiesList( exConn, regionSet ); } DtObjClassDesc* objClassDesc = 0; DtFom* fom = exConn->fom(); #if DtHLA_1516 for (std::list<DtObjClassDesc*>::const_iterator item = fom->objClassList().begin(); item != fom->objClassList().end(); ++item) { objClassDesc = const_cast<DtObjClassDesc*>(*item); #else for( objClassDesc = fom->firstObjClass(); objClassDesc; objClassDesc = fom->nextObjClass( objClassDesc ) ) { #endif // The Mom Manager class has a different name in 1516 than in // 1.3. We can read both types of files through VR-Link so // we first check for the 1.3 version, and if its not found // we look for the 1516 version DtObjClassDesc *momClass = fom->objClassByName( "Manager" ); if (!momClass) { momClass = fom->objClassByName( "HLAmanager" ); } DtObjClassDesc *rootClass = fom->objClassByName("ObjectRoot"); if (!rootClass) { rootClass = fom->objClassByName("HLAobjectRoot"); } if ( includeMom || (momClass &&!objClassDesc->isOfClass(momClass->handle()))) { if (rootClass && (objClassDesc->handle() != rootClass->handle())) { objClassDesc->subscribe(); } } } DtInterClassDesc* intClassDesc = 0; #if DtHLA_1516 for (std::list<DtInterClassDesc*>::const_iterator item = fom->interClassList().begin(); item != fom->interClassList().end(); ++item) { intClassDesc = const_cast<DtInterClassDesc*>(*item);; #else for( intClassDesc = fom->firstInterClass(); intClassDesc; intClassDesc = fom->nextInterClass( intClassDesc ) ) { #endif DtInterClassDesc *momClass = fom->interClassByName("Manager"); if (!momClass) { momClass = fom->interClassByName("HLAmanager"); } DtInterClassDesc *rootClass = fom->interClassByName("InteractionRoot"); if (!rootClass) { rootClass = fom->interClassByName("HLAinteractionRoot"); } // The Mom Manager class has a different name in 1516 than in // 1.3. We can read both types of files through VR-Link so // we first check for the 1.3 version, and if its not found // we look for the 1516 version if ( includeMom || (momClass && !intClassDesc->isOfClass( momClass->handle() )) ) { if (rootClass && (intClassDesc->handle() != rootClass->handle())) { intClassDesc->subscribe(); } } } #if DtHLA_1516 exConn->addDiscoverObjectCallback( RTI::ObjectClassHandle(), discoverObjectCb, 0 ); exConn->addInteractionCallback( RTI::InteractionClassHandle(), receiveInterCb, 0, region ); #else exConn->addDiscoverObjectCallback( 0, discoverObjectCb, 0 ); exConn->addInteractionCallback( 0, receiveInterCb, 0, region ); #endif // Main application loop int forever = 1; while( forever ) { if ( keybrdTick() == -1 ) { break; } exConn->drainInput(); DtSleep( 0.001 ); } #if DtHLA_1516 for (std::list<DtObjClassDesc*>::const_iterator item = fom->objClassList().begin(); item != fom->objClassList().end(); ++item) { objClassDesc = const_cast<DtObjClassDesc*>(*item); #else for( objClassDesc = fom->firstObjClass(); objClassDesc; objClassDesc = fom->nextObjClass( objClassDesc ) ) { #endif // The Mom Manager class has a different name in 1516 than in // 1.3. We can read both types of files through VR-Link so // we first check for the 1.3 version, and if its not found // we look for the 1516 version DtObjClassDesc *momClass = fom->objClassByName( "Manager" ); if (!momClass) { momClass = fom->objClassByName( "HLAmanager" ); } if ( includeMom || (momClass &&!objClassDesc->isOfClass(momClass->handle()))) { objClassDesc->unsubscribe(); } } #if DtHLA_1516 for (std::list<DtInterClassDesc*>::const_iterator item = fom->interClassList().begin(); item != fom->interClassList().end(); ++item) { intClassDesc = const_cast<DtInterClassDesc*>(*item); #else for( intClassDesc = fom->firstInterClass(); intClassDesc; intClassDesc = fom->nextInterClass( intClassDesc ) ) { #endif DtInterClassDesc *momClass = fom->interClassByName("Manager"); if (!momClass) { momClass = fom->interClassByName("HLAmanager"); } // The Mom Manager class has a different name in 1516 than in // 1.3. We can read both types of files through VR-Link so // we first check for the 1.3 version, and if its not found // we look for the 1516 version if ( includeMom || (momClass && !intClassDesc->isOfClass( momClass->handle() )) ) { intClassDesc->subscribe(); } } DtDELETE ( rel ); DtDELETE ( ral ); DtDELETE ( rdl ); DtDELETE ( rsl ); DtDELETE ( rrl ); DtDELETE ( rtl ); DtDELETE ( ril ); DtDELETE ( repl ); DtDELETE ( rgdl ); DtDELETE ( rasl ); DtDELETE ( rpnl ); DtDELETE ( rapal ); if (subWithDdm) { delete regionSet; region.reset(); } DtDELETE ( exConn ); return 0; } void reflectCb( const DtStateMsg& msg, DtHlaObject* obj, void* usr ) { DtExerciseConn* exConn = obj->exerciseConn(); DtClock* clock = obj->exerciseConn()->clock(); DtString lastProducingFederateName = "Unknown"; #if DtHLA_1516_EVOLVED lastProducingFederateName = obj->lastProducingFederate(); #endif if (ddmDump) { DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>( obj->exerciseConn()->fedAmb()); const DtDdmFederateAmbassador::DtRegionInfo& regionInfo = ddmFedAmb->regionInfoForObject(obj->objectId()); bool printProducingFederate = false; if (regionInfo.infoSet) { std::map<RTI::ObjectHandle, DtDdmFederateAmbassador::DtRegionInfo>::iterator iter = myRegionInfo.find(obj->objectId()); if (iter == myRegionInfo.end()) { myRegionInfo[obj->objectId()] = regionInfo; std::cout << clearScreen << theSeperator << "*************** Update at " << clock->elapsedRealTime() << "secs ***************\n" << theSeperator << "Object: " << obj->objectId() << "\n" << "Name: " << obj->name() << "\n" #if DtHLA_1516_EVOLVED << "Updated by Federate: " << lastProducingFederateName << "\n" #endif << "DDM Info: " << "\n" << " -- Lower X Bound: " << regionInfo.lowerXBound << "\n" << " -- Upper X Bound: " << regionInfo.upperXBound << "\n" << " -- Lower Y Bound: " << regionInfo.lowerYBound << "\n" << " -- Upper Y Bound: " << regionInfo.upperYBound << "\n"; } else { // See if it's changed. If so, update it and print it out const DtDdmFederateAmbassador::DtRegionInfo& lastRegion = iter->second; if (regionInfo.lowerXBound != lastRegion.lowerXBound || regionInfo.upperXBound != lastRegion.upperXBound || regionInfo.lowerYBound != lastRegion.lowerYBound || regionInfo.upperYBound != lastRegion.upperYBound) { myRegionInfo[obj->objectId()] = regionInfo; std::cout << clearScreen << theSeperator << "*************** Update at " << clock->elapsedRealTime() << "secs ***************\n" << theSeperator << "Object: " << obj->objectId() << "\n" << "Name: " << obj->name() << "\n" #if DtHLA_1516_EVOLVED << "Updated by Federate: " << lastProducingFederateName << "\n" #endif << "DDM Info: " << "\n" << " -- Lower X Bound: " << regionInfo.lowerXBound << "\n" << " -- Upper X Bound: " << regionInfo.upperXBound << "\n" << " -- Lower Y Bound: " << regionInfo.lowerYBound << "\n" << " -- Upper Y Bound: " << regionInfo.upperYBound << "\n"; } } } else { std::cout << clearScreen << theSeperator << "*************** Update at " << clock->elapsedRealTime() << "secs ***************\n" << theSeperator << "Object: " << obj->objectId() << "\n" << "Name: " << obj->name() << "\n" #if DtHLA_1516_EVOLVED << "Updated by Federate: " << lastProducingFederateName << "\n" #endif << "DDM Info: " << "\n" << " -- No DDM Region information set." << "\n"; } } else { std::cout << clearScreen << theSeperator << "*************** Update at " << clock->elapsedRealTime() << "secs ***************\n" << theSeperator #if DtHLA_1516_EVOLVED << "Updated by Federate: " << lastProducingFederateName #endif << "\n"; if ( raw ) { msg.print( obj->exerciseConn(), obj->objectClassHandle() ); } else { msg.print( obj, fullReport ); } if (showRegionData) { DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>( obj->exerciseConn()->fedAmb()); const DtDdmFederateAmbassador::DtRegionInfo& regionInfo = ddmFedAmb->regionInfoForObject(obj->objectId()); std::cout << "DDM Region Data: "; if (regionInfo.infoSet) { std::cout << "\n" << " -- Lower X Bound: " << regionInfo.lowerXBound << "\n" << " -- Upper X Bound: " << regionInfo.upperXBound << "\n" << " -- Lower Y Bound: " << regionInfo.lowerYBound << "\n" << " -- Upper Y Bound: " << regionInfo.upperYBound << "\n"; } else { std::cout << "None" << "\n"; } } std::cout << std::endl; } } void removeObjectCb( DtHlaObject* obj, void* usr ) { obj->removeRemoveObjectCb( removeObjectCb, 0 ); obj->removePostReflectCb( reflectCb, 0 ); } void discoverObjectCb( DtHlaObject* obj, void* usr ) { obj->addPostReflectCb( reflectCb, 0 ); obj->addRemoveObjectCb( removeObjectCb, 0 ); } void receiveInterCb( DtInteraction* inter, void* usr ) { DtClock* clock = inter->exerciseConn()->clock(); std::cout << clearScreen << theSeperator << "*************** Interaction at " << clock->elapsedRealTime() << "secs ***************\n" << theSeperator; if (!ddmDump) { if ( raw ) { inter->printParams( true ); } else { inter->print(); } if (showRegionData) { DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>( inter->exerciseConn()->fedAmb()); DtDdmFederateAmbassador::DtRegionInfo regionInfo = ddmFedAmb->lastInteractionRegion(); ddmFedAmb->clearLastInteractionRegion(); std::cout << "DDM Region Data: "; if (regionInfo.infoSet) { std::cout << std::endl; std::cout << " -- Lower X Bound: " << regionInfo.lowerXBound << std::endl; std::cout << " -- Upper X Bound: " << regionInfo.upperXBound << std::endl; std::cout << " -- Lower Y Bound: " << regionInfo.lowerYBound << std::endl; std::cout << " -- Upper Y Bound: " << regionInfo.upperYBound << std::endl; } else { std::cout << "None" << std::endl; } } std::cout << std::endl; } else { std::cout << "Interaction Class: " << inter->interactionClassName() << std::endl; DtDdmFederateAmbassador* ddmFedAmb = dynamic_cast<DtDdmFederateAmbassador*>( inter->exerciseConn()->fedAmb()); DtDdmFederateAmbassador::DtRegionInfo regionInfo = ddmFedAmb->lastInteractionRegion(); ddmFedAmb->clearLastInteractionRegion(); if (regionInfo.infoSet) { std::cout << " -- Lower X Bound: " << regionInfo.lowerXBound << std::endl; std::cout << " -- Upper X Bound: " << regionInfo.upperXBound << std::endl; std::cout << " -- Lower Y Bound: " << regionInfo.lowerYBound << std::endl; std::cout << " -- Upper Y Bound: " << regionInfo.upperYBound << std::endl; } else { std::cout << "-- No Interaction Region" << std::endl; } } } // ---------keyboard input ---------------------- int keybrdTick() { char* keyPtr = DtPollBlockingInputLine(); if ( !keyPtr ) { return 0; // no input } switch( *keyPtr ) { case 'q': case 'Q': { return -1; } default: { std::cout << "Unrecognized command key <"<< *keyPtr <<">" << std::endl; break; } } return 0; } #endif