VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Receiving Spot Reports Example

The Receive Spot Report example demonstrates the following:

How to Run the Example

This example demonstrates how to use the remote control API for controlling a VR-Forces back-end. It is a standalone console application that will display spot reports received from the SIM engine when Spot Reports are enabled.

Usage

(Release) receiveSpotReport

(Debug) receiveSpotReportd

To run the application:

  1. Open a command line and switch to the VR-Forces "bin" directory
  2. Launch VR-Forces with "vrfLauncher.exe"
  3. Start the receiveSpotReport application as "receiveSpotReportDIS.exe \--deviceAddress <device address>"
  4. Open a scenario.
  5. Turn on Spot Report by going to Settings->Application->Spot Report Settings and make sure "Send Spot Reports" is checked.
  6. Play the scenario and observe the receiveSpotReport console to view the reported messages.

Classes

DtRemoteControlInitializerThis subclass of DtVrlApplicationInitializer adds command line options for the HLA version of the example.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include "remoteControlInit.h"
//VR-Forces headers
//VR-Link headers
#include <vl/exerciseConn.h>
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlKeyboard.h>
#include "vlutil/vlList.h"
#include <vector>
// Returns -1 if user entered q or Q, 0 otherwise
int keybrdTick(void);
//Callback function to print out spot report messages
void simMessageCallback(const DtVrfObjectMessage* msg, void* usr)
{
DtReportMessage* reportMsg = (DtReportMessage*)msg;
//Check that the message and report type are what is expected for a spot report
{
//Get the collection of reports
DtSimReportCollection* reportCollection = static_cast<DtSimReportCollection*>(reportMsg->report());
std::vector<DtSimReport*> reports = reportCollection->reports();
//Start at the first report
std::vector<DtSimReport*>::const_iterator iter = reports.begin();
//iterate through the collection of reports received and print a spot report message for each
while (iter != reports.end())
{
DtSpotReport* spotReport = dynamic_cast<DtSpotReport*>(*iter);
//Get the contact force
DtString forceType = "";
switch (spotReport->contactForce())
{
case 0:
forceType = "Other";
break;
case 1:
forceType = "Friendly";
break;
case 2:
forceType = "Opposing";
break;
case 3:
forceType = "Neutral";
break;
default:
break;
}
//Print the spot report
DtInfo("Spot Report: \n\t %s spotted %s of force %s nearby.\n",
spotReport->spotterMarkingText().c_str(),
spotReport->contactMarkingText().c_str(),
forceType.c_str()
);
iter++;
}
return;
}
}
int main(int argc, char** argv)
{
//Create initializer object used to provide initialization data to the
//exercise connection, configured through command line arguments.
DtRemoteControlInitializer appInitializer(argc, argv);
appInitializer.parseCmdLine();
//Create the controller
//Create an exercise connection
DtExerciseConn* exConn = new DtExerciseConn(appInitializer);
controller->init(exConn);
//Register callback function to listen for incoming report messages
controller->radioMessageListener()->addMessageCallbackByCategory(DtReportMessageType, simMessageCallback, NULL);
//Processing: read stdin and call drainInput.
//Calling drainInput() ensures that the controller receives
//necessary feedback from VR-Forces backend applications.
while (keybrdTick() != -1)
{
exConn->clock()->setSimTime(exConn->clock()->elapsedRealTime());
exConn->drainInput();
DtSleep(0.1);
}
delete controller;
delete exConn;
return 0;
}
int keybrdTick()
{
char *keyPtr = DtPollInputLine();
if (!keyPtr)
return 0; // no input
switch (*keyPtr)
{
case 'q':
case 'Q':
return -1;
default:
printf("Unrecognized command key <%c>\n", *keyPtr);
break;
}
return 0;
}

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)