VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Receiving Spot Reports Example (receiveSpotReport)

Table of Contents

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

To run the application:

  1. Start VR-Forces GUI and SIM through the "vrfLauncher.exe" - e.g. select the DIS (7) localhost protocol.
  2. Open an existing scenario in the VR-Forces - e.g. HawaiiGround.scnx.
  3. Turn on Spot Report by going to Settings->Application->Spot Report Settings and make sure "Send Spot Reports" is checked.
  4. Open a separate command line window and switch to the VR-Forces "/bin64/" directory
  5. Start the receiveSpotReport application as "receiveSpotReportDIS.exe with the vrfSimDIS command line arguments.

    Note: You need to supply the same set of command line arguments as the ones required to run the vrfSimDIS.exe. The necessary command line arguments for the receiveSpotReportDIS.exe - can be copied from the backend command line arguments from the Launcher UI.

  6. Play the scenario.
  7. Observe the receiveSpotReportDIS.exe console to view the reported messages - e.g. :

    Spot Report:
    CH-47 1 spotted Cvln 1 of force Other nearby.

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>
using namespace makVrf;
// 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());
controller->tick();
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 Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)