The talkListenDds example is two separate applications: one which publishes a simple DDS entity, and one which listens for published DDS entities.
This is a standalone example that can be run independently from VR-Exchange, and serves to illustrate the procedures involved in publishing and reflecting DDS objects. These applications can be used in conjuction with the DDS broker for testing or development.
talk.cxx
#include <vl/entityStateRepository.h>
#include <vl/topoView.h>
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlMiniDumper.h>
#include <vlutil/vlKeyboard.h>
#include <iostream>
void updateLocationOrientation( DtTime t, DtTopoView& view );
using namespace MAKVrExchange::DtDdsBroker;
int main( int argc, char* argv[] )
{
DtINIT_MINIDUMPER( "DDS Talk" );
try
{
if ( argc > 1 )
{
partitionName = argv[1];
}
DtClock* clock = exConn.clock();
DtEntityType type( "1:2:225:50:4:1:0" );
DtEntityPublisher publisher( &exConn, "Predator_UAV" );
DtEntityStateRepository* entSr = publisher.esr();
entSr->setGlobalId( DtEntityIdentifier(1,2,3) );
entSr->setEntityId( DtEntityIdentifier(1,2,3) );
entSr->setMarkingText( "Predator_UAV" );
entSr->setForceId( DtForceFriendly );
entSr->setEntityType( type );
entSr->setGuise( type );
DtTopoView topoView( entSr, DtDeg2Rad(35.699760), DtDeg2Rad(-121.326577) );
updateLocationOrientation( clock->elapsedRealTime(), topoView );
while ( true )
{
char* keyPtr = DtPollBlockingInputLine();
if ( keyPtr && ( *keyPtr == 'q' || *keyPtr == 'Q' ) )
{
break;
}
clock->setSimTime( clock->elapsedRealTime() );
updateLocationOrientation( clock->elapsedRealTime(), topoView );
exConn.drainInput();
publisher.tick();
DtSleep( 0.1 );
}
}
DtCATCH_AND_WARN( std::cout );
return 0;
}
void updateLocationOrientation( DtTime t, DtTopoView& view )
{
const float radius = 200;
const float period = 20.0;
const float speed = M_2PI*radius/period;
float angle = t*M_2PI/period;
float advAngle = angle + M_PI_2;
view.setLocation( DtVector64(200*cos(angle),-200*sin(angle),-1230.0) );
view.setVelocity( DtVector32(speed*cos(advAngle),speed*sin(advAngle),-1230.0) );
view.setOrientation( DtTaitBryan(-advAngle,0,DtDeg2Rad(-15)) );
}
listen.cxx
#include <vl/entityStateRepository.h>
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlMiniDumper.h>
#include <vlutil/vlKeyboard.h>
#include <iostream>
using namespace MAKVrExchange::DtDdsBroker;
void discoverObject( void* refObj, void* );
void updateObject( void* refObj, void* );
void removeObject( void* refObj, void* );
int main( int argc, char* argv[] )
{
DtINIT_MINIDUMPER( "DDS Listen" );
try
{
if ( argc > 1 )
{
partitionName = argv[1];
}
exConn.addEntityAdditionCallback( discoverObject, 0 );
exConn.addEntityRemovalCallback( removeObject, 0 );
DtClock* clock = exConn.clock();
while ( true )
{
char* keyPtr = DtPollBlockingInputLine();
if ( keyPtr && ( *keyPtr == 'q' || *keyPtr == 'Q' ) )
{
break;
}
clock->setSimTime( clock->elapsedRealTime() );
exConn.drainInput();
DtSleep( 0.1 );
}
}
DtCATCH_AND_WARN( std::cout );
return 0;
}
void discoverObject( void* refObj, void* )
{
DtReflectedEntity* entity = (DtReflectedEntity*) refObj;
std::cout << "Discovered new Entity:" << std::endl;
std::cout << *entity->esr() << std::endl;
std::cout << std::endl;
entity->addPostUpdateCallback( updateObject, 0 );
}
void updateObject( void* refObj, void* )
{
DtReflectedEntity* entity = (DtReflectedEntity*) refObj;
std::cout << "Received Entity Update:" << std::endl;
std::cout << *entity->esr() << std::endl;
std::cout << std::endl;
}
void removeObject( void* refObj, void* )
{
DtReflectedEntity* entity = (DtReflectedEntity*) refObj;
std::cout << "Entity Removed:" << std::endl;
std::cout << *entity->esr() << std::endl;
std::cout << std::endl;
}