Overview
This example creates an accessory that installs itself into DtCigiDriver objects and hooks into signals that are triggered when particular CIGI messages are received.
Expected Result
The following should be printed to the console window:
Received a CIGI Component Control Message
-- Instance ID: 2
Received a CIGI Wave Control Message
-- Wave ID: 1
-- Wave Height: 5
Received a CIGI Message of an Unknown Type
If VR-Vantage is connected with CIGI Version 4.0, 4096 will also be printed.
Example details
The CIGI driver emits signals when a CIGI message is received. An accessory can be installed, that listens to particular CIGI messages and does some type of processing when they are received. Much of this example is like exampleAccessory, except the accessory listens to the session created signal from the DtCigiDriver.
void DtCigiAccessory::install(DtDriver* driver)
{
DtCigiDriver* cd = dynamic_cast<DtCigiDriver*>(driver);
if(cd)
{
mySessionCreatedConnection = cd->signal_sessionCreated.connect(
boost::bind(&DtCigiAccessory::slot_onSimCreated, this, boost::placeholders::_1));
}
}
When the session is created, the accessory waits for the CIGI driver to be connected.
void DtCigiAccessory::slot_onSimCreated(DtCigiConnection* connection)
{
connection->signal_connected.connect(
boost::bind(&DtCigiAccessory::slot_onSimConnected, this, connection));
connection->signal_toBeDisconnected.connect(
boost::bind(&DtCigiAccessory::slot_onSimAboutToBeDisconnected, this, connection));
}
On connection, a DtCigiExtender object is created (much like the DtPrintVisualizer of exampleAccessory).
void DtCigiAccessory::slot_onSimConnected(DtCigiConnection* connection)
{
if(connection)
{
DtCigiExtender* vis = new DtCigiExtender(*connection);
connection->registerInstance("DtCigiExtender", vis);
}
}
The DtCigiExtender class listens for component control, wave control, and custom CIGI messages, and prints out the contents of known messages. The constructor connects to the appropriate signals.
DtCigiExtender::DtCigiExtender( DtCigiConnection& connection )
: DtVirtualBaseClass()
, myConnection( connection )
{
myConnections += DtCigiSignalProcessor::instance( connection ).signal_componentControlReceived.connect(
boost::bind( &DtCigiExtender::slot_componentControlReceived, this, boost::placeholders::_1 ) );
myConnections += DtCigiSignalProcessor::instance( connection ).signal_waveControlReceived.connect(
boost::bind( &DtCigiExtender::slot_waveControlReceived, this, boost::placeholders::_1 ) );
myConnections += DtCigiSignalProcessor::instance( connection ).signal_unrecognizedPacketReceived.connect(
boost::bind( &DtCigiExtender::slot_customPacketReceived, this, boost::placeholders::_1 ) );
CustomV4Packet * myPacket = new CustomV4Packet();
myConnection.networkIO().session().RegisterUserPacket( myPacket, 0x1000, true, false );
}
The methods are called when the particular type of CIGI message is received.
void DtCigiExtender::slot_componentControlReceived( CigiBaseCompCtrl& msg )
{
if(myConnection.getCigiVersion().CigiMajorVersion == 3)
{
CigiCompCtrlV3_3 * compCtrlMsgV3 = static_cast<CigiCompCtrlV3_3*>(&msg);
std::cout << "Received a CIGI Component Control Message" << std::endl;
std::cout << " -- Instance ID: " << (int)compCtrlMsgV3->GetInstanceID() << std::endl;
}
else if(myConnection.getCigiVersion().CigiMajorVersion == 4)
{
CigiCompCtrlV4 * compCtrlMsgV4 = static_cast<CigiCompCtrlV4*>(&msg);
std::cout << "Received a CIGI Component Control Message" << std::endl;
std::cout << " -- Instance ID: " << (int)compCtrlMsgV4->GetInstanceID() << std::endl;
}
}
void DtCigiExtender::slot_waveControlReceived( CigiBaseWaveCtrl& msg )
{
if(myConnection.getCigiVersion().CigiMajorVersion == 3)
{
CigiWaveCtrlV3* waveCtrlMsgV3 = static_cast<CigiWaveCtrlV3*>(&msg);
std::cout << "Received a CIGI Wave Control Message" << std::endl;
std::cout << " -- Wave ID: " << (int)waveCtrlMsgV3->GetWaveID() << std::endl;
std::cout << " -- Wave Height: " << waveCtrlMsgV3->GetWaveHt() << std::endl;
}
else if(myConnection.getCigiVersion().CigiMajorVersion == 4)
{
CigiWaveCtrlV4* waveCtrlMsgV4 = static_cast<CigiWaveCtrlV4*>(&msg);
std::cout << "Received a CIGI Wave Control Message" << std::endl;
std::cout << " -- Wave ID: " << (int)waveCtrlMsgV4->GetWaveID() << std::endl;
std::cout << " -- Wave Height: " << waveCtrlMsgV4->GetWaveHt() << std::endl;
}
}
In the case of custom messages, the CigiBasePacket will need to be casted to a user-defined type so that the data can be extracted.
void DtCigiExtender::slot_customPacketReceived( CigiBasePacket& msg )
{
std::cout << "Received a CIGI Message of an Unknown Type" << std::endl;
if(myConnection.getCigiVersion().CigiMajorVersion == 4)
{
CustomV4Packet * customPacketTest = dynamic_cast<CustomV4Packet*>(&msg);
if(customPacketTest)
{
std::cout << customPacketTest->GetPacketID() << std::endl;
}
}
}
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is a plug-in. You can run it by running ./bin64/exampleCigiExtension_stealth.bat (on Windows) or ./bin64/exampleCigiExtension_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Once VR-Stealth is started, open the Simulation Connections page and choose the CIGI Connections tab. Select a CIGI Version, a Driver Mode of Asynchronous, and set the IG Network Interface Address to 127.0.0.1 (the remaining options can be left as defaults). Press the 'Connect' button.
Open a Cygwin or other window that can run a 3.x Python script. Change directory in this window to ./tools/CigiUtilities/pyCigi<3|4>. From here you can run pyCigiV<3|4>-NT-ExampleCigiExtensionTest.py. You should see the output indicated above in the console window.
Alternatively, if you are familiar with the Host Emulator utility (./tools/CigiHostEmulator<3|4>) you can choose a Synchronous Driver Mode in the CIGI connections tab instead, and send Component Control and Wave Control messages from there (but you won't be able to send an unknown packet type).
Example Source Files
exampleCigiExtensionPlugin.cxx
#include <boost/bind/bind.hpp>
static vrvSignalsLib::connection postInitializeConnection;
{
postInitializeConnection.disconnect();
}
{
{
}
}
{
{
return true;
}
return false;
}
Contains makVrv::DtAccessoryManager class.
Contains DtCigiAccessory class.
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
static DtAccessoryManager & instance(DtDe &de)
Lazily create singleton.
This class defines an accessory that will install itself into DtCigiDriver objects and hook into sign...
Definition DtCigiAccessory.h:24
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
bool featureSupported(DeFeatures feature) const
Check to see if a feature is supported.
@ Features_3D
Definition DtDeInitializer.h:58
void loadAccessory(makVrv::DtDe *de)
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtCigiAccessory.h
#pragma once
{
class DtCigiConnection;
class DtCigiAccessory : public DtBaseAccessory
{
public:
virtual void install(DtDriver* driver);
protected:
protected:
};
}
Contains makVrv::DtBaseAccessory class.
virtual void slot_onSimCreated(DtCigiConnection *connection)
Called when the driver creates a new connection.
virtual void uninstall(DtDriver *baseConn)
Called when this accessory is uninstalled.
virtual void slot_onSimAboutToBeDisconnected(DtCigiConnection *connection)
Called when a sim connection is disconnected.
vrvSignalsLib::connection mySessionCreatedConnection
Definition DtCigiAccessory.h:53
virtual bool isCompatible(DtDriver *driver)
Called to find out if this accessory is compatible with a particular connector. In this case,...
DtCigiAccessory()
\Default constructor
virtual void slot_onSimConnected(DtCigiConnection *connection)
Called when a sim connection is connected.
virtual ~DtCigiAccessory()
\Default destructor
virtual void install(DtDriver *driver)
Called when this accessory is installed into a connector.
Contains DLL export macros.
DtCigiExtender.h
#pragma once
class CigiBaseCompCtrl;
class CigiBaseWaveCtrl;
class CigiBasePacket;
{
class DtCigiExtender : public DtVirtualBaseClass
{
public:
protected:
};
}
Contains makVrv::DtCigiConnection class.
Base class to provide boost signal/slot management.
Contains makVrv::DtVirtualBaseClass class.
DtSignalConnectionManager myConnections
Definition DtCigiExtender.h:48
DtCigiConnection & myConnection
CIGI connection the driver is using.
Definition DtCigiExtender.h:46
virtual void slot_customPacketReceived(CigiBasePacket &)
DtCigiExtender(DtCigiConnection &connection)
CTOR.
virtual void slot_componentControlReceived(CigiBaseCompCtrl &)
Receives a component control and prints out some data.
virtual void slot_waveControlReceived(CigiBaseWaveCtrl &)
Receives a wave control and prints out some data.
DtCigiAccessory.cxx
#include <boost/bind/bind.hpp>
#include <iostream>
{
{
}
{
}
{
if(cd)
{
}
}
{
if(vld)
{
mySessionCreatedConnection.disconnect();
}
}
{
if(dd)
{
return true;
}
return false;
}
{
connection->signal_connected.connect(
connection->signal_toBeDisconnected.connect(
}
{
if(connection)
{
connection->registerInstance("DtCigiExtender", vis);
}
}
{
if(sim)
{
}
}
}
Contains makVrv::DtCigiDriver class.
Contains makVrv::DtCigiExtender class.
An accessory is like a plugin into a driver. The DtBaseAccessory is the base class for all accessorie...
Definition DtBaseAccessory.h:29
virtual void registerInstance(const std::string &instanceName, DtVirtualBaseClass *instance)
Register an object as an instance of instanceName, and transfer memory ownership of the instance to t...
Definition DtCigiConnection.h:59
Definition DtCigiDriver.h:48
vrvSignalsLib::signal< void(DtCigiConnection *)> signal_sessionCreated
This signal is emitted when the CIGI session is created.
Definition DtCigiDriver.h:96
Definition DtCigiExtender.h:26
The DtDriver is an abstract class. Developers derive from this to create logic that "directs" things ...
Definition DtDriver.h:32
DtCigiExtender.cxx
#include <CigiCompCtrlV3_3.h>
#include <CigiCompCtrlV4.h>
#include <CigiWaveCtrlV3.h>
#include <CigiWaveCtrlV4.h>
#include <CigiIGSession.h>
#include <CigiIncomingMsg.h>
#include <boost/bind/bind.hpp>
#include <iostream>
{
class CustomV4Packet : public CigiBasePacket
{
public:
CustomV4Packet() :
CigiBasePacket(),
packSize( 8 ),
packID( 0x1000 )
{
PacketID = packID;
PacketSize = packSize;
Version = 4;
MinorVersion = 0;
}
virtual int Pack( CigiBasePacket* Base, Cigi_uint8* Buff, void* Spec ) const
{
PackPointer CDta;
CDta.c = Buff;
*CDta.s++ = packID;
*CDta.s++ = packSize;
*CDta.l++ = 13375;
return packSize;
}
virtual int Unpack( Cigi_uint8 * Buff, bool Swap, void *Spec )
{
return 8;
}
Cigi_uint16 packSize;
Cigi_uint16 packID;
};
, myConnection( connection )
{
CustomV4Packet * myPacket = new CustomV4Packet();
myConnection.networkIO().session().RegisterUserPacket( myPacket, 0x1000, true, false );
}
{
}
{
if(myConnection.getCigiVersion().CigiMajorVersion == 3)
{
CigiCompCtrlV3_3 * compCtrlMsgV3 = static_cast<CigiCompCtrlV3_3*>(&msg);
std::cout << "Received a CIGI Component Control Message" << std::endl;
std::cout << " -- Instance ID: " << (int)compCtrlMsgV3->GetInstanceID() << std::endl;
}
else if(myConnection.getCigiVersion().CigiMajorVersion == 4)
{
CigiCompCtrlV4 * compCtrlMsgV4 = static_cast<CigiCompCtrlV4*>(&msg);
std::cout << "Received a CIGI Component Control Message" << std::endl;
std::cout << " -- Instance ID: " << (int)compCtrlMsgV4->GetInstanceID() << std::endl;
}
}
{
if(myConnection.getCigiVersion().CigiMajorVersion == 3)
{
CigiWaveCtrlV3* waveCtrlMsgV3 = static_cast<CigiWaveCtrlV3*>(&msg);
std::cout << "Received a CIGI Wave Control Message" << std::endl;
std::cout << " -- Wave ID: " << (int)waveCtrlMsgV3->GetWaveID() << std::endl;
std::cout << " -- Wave Height: " << waveCtrlMsgV3->GetWaveHt() << std::endl;
}
else if(myConnection.getCigiVersion().CigiMajorVersion == 4)
{
CigiWaveCtrlV4* waveCtrlMsgV4 = static_cast<CigiWaveCtrlV4*>(&msg);
std::cout << "Received a CIGI Wave Control Message" << std::endl;
std::cout << " -- Wave ID: " << (int)waveCtrlMsgV4->GetWaveID() << std::endl;
std::cout << " -- Wave Height: " << waveCtrlMsgV4->GetWaveHt() << std::endl;
}
}
{
std::cout << "Received a CIGI Message of an Unknown Type" << std::endl;
if(myConnection.getCigiVersion().CigiMajorVersion == 4)
{
CustomV4Packet * customPacketTest = dynamic_cast<CustomV4Packet*>(&msg);
if(customPacketTest)
{
std::cout << customPacketTest->GetPacketID() << std::endl;
}
}
}
}
Contains makVrv::DtCigiNetworkIO class.
Contains makVrv::DtCigiSignalProcessor class.
static DtCigiSignalProcessor & instance(DtCigiConnection &sim)
Static instance accessor.
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators,...
Definition DtVirtualBaseClass.h:20
Contains DLL export macros.