MAK Data Logger API Documentation for HLA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
recordFile Example

The recordFile program creates a logger, opens a logger tape, and plays it back.

Periodic messages output the current tape time. If 'q' is pressed playback stops and the program exits\ immediately, otherwise it will continue to the end of the tape at which point it will exit.


The main application:

/*******************************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*******************************************************************************/
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlPrint.h>
#include <vlutil/vlMiniDumper.h>
#if DtDIS
#include <vl/exerciseConnInitializerDIS.h>
#endif
#if DtHLA
#include <vl/exerciseConnInitializerHLA.h>
#endif
#include <cmdLine/cmdLine.h>
using namespace MAKLogger;
// Hard coded paths for files. Relative to the bin directories.
#if DtHLA
const char defaultFileName[] = ".\\outputFileHLA.lgr";
#endif
#if DtDIS
const char defaultFileName[] = ".\\outputFileDIS.lgr";
#endif
// Record time for 1 minute.
const double totalTimeToRecord = 60.0;
// Global variables.
DtLgrSimInterface* simInterface;
DtLgrRecordInterface* recInterface;
// Function creates the interfaces to the logger. Interfaces are how to
// control modules of the logger as well as get info about those modules.
void createInterfaces(DtLogger& logger)
{
simInterface = DtLgrSimInterface::create(logger);
assert(simInterface);
recInterface = DtLgrRecordInterface::create(logger);
assert(recInterface);
}
// Function for ticking the logger as well as updating the interfaces. To get
// up to date information from the logger an interface must be updated. If an
// interface is not updated messages from the logger will be remain in memory
// and eventually could result in the system running out of memory. After
// every command sent by and interface the logger must be ticked to execute
// the command. It is acceptable to send multiple command before ticking the
// logger.
void tickAndUpdate(DtLogger& logger)
{
bool canContinue = logger.tick();
if(!canContinue) return;
assert(simInterface);
simInterface->update();
assert(recInterface);
recInterface->update();
}
// Function foe checking if any keys in the array are pressed.
bool keyCheck(const char* keysToCheck)
{
if(DtKbHit())
{
int c = DtGetCh();
return strchr(keysToCheck,c) != 0;
}
return false;
}
// Example entry point
int recordFile(int argc, char** argv)
{
DtCmdLine::CmdLine cmdLine("writeFile","Example of how to write a logger file.",LOGGER_VERSION_STRING);
DtCmdLine::UnlabeledMultiArg<DtString> filenameArg("Filename","The name of the logger file to write.","string");
DtString description = "Description text for the logger tape";
cmdLine.add(&filenameArg);
cmdLine.parse(argc,argv);
std::vector<DtString> values = filenameArg.getValue();
if(values.size() == 0)
{
values.push_back(defaultFileName);
}
DtString theFileName(values.front());
// Create the logger based upon it's protocol. These helped sub classes
// automatically register the protocol and provide additional utility
// functions.
#if DtDIS
DtDisLogger* aLogger = DtDisLogger::create(true);
#endif
#if DtHLA
DtHlaLogger* aLogger = DtHlaLogger::create(true);
#endif
// Initialize logger with default settings.
DtExerciseConnInitializer exConnInit;
#if DtHLA
#if DtHLA_1516_EVOLVED
exConnInit.setFedFileName("VR-Link_evolved.xml");
#elif DtHLA_1516
exConnInit.setFedFileName("VR-Link.xml");
#else
exConnInit.setFedFileName("VR-Link.fed");
#endif
#endif
aLogger->connect(exConnInit);
createInterfaces(*aLogger);
tickAndUpdate(*aLogger);
if(!simInterface->isConnected())
{
DtInfo << "Unable to connect." << std::endl;
return 1;
}
recInterface->startNewFile(theFileName, description, true);
#if 0
// Record to a multipart logger file
recInterface->setRecordToMultipleFilesSettings( 10, "%FileDir%/%FileName%_%Index%.lgr" );
tickAndUpdate(*aLogger);
recInterface->recordToMultipleFiles( theFileName );
tickAndUpdate(*aLogger);
#endif
tickAndUpdate(*aLogger);
if(!recInterface->isFileLoaded())
{
DtInfo << "Unable to start new file." << std::endl;
return 1;
}
// Start recording.
recInterface->record();
tickAndUpdate(*aLogger);
// Verify that it is recording.
if(!recInterface->isRecording())
{
DtInfo << "Unable to start recording." << std::endl;
return 1;
}
// The number of seconds between print outs.
double printDelay = 1.0;
double printLoopTotal = 0;
// The time of a loop.
double loopDelay = .1;
DtInfo << "Recording file: " << theFileName << "." << std::endl;
DtInfo << "Press 'q' or 'enter' to quit." << std::endl;
while(recInterface->currentTime() < totalTimeToRecord)
{
tickAndUpdate(*aLogger);
if(printLoopTotal >= printDelay)
{
DtInfo << "Current Time = " << recInterface->currentTime() << "." << std::endl;
printLoopTotal = 0.0;
}
printLoopTotal += loopDelay;
DtSleep(loopDelay);
// Break out if q or enter was pressed.
if(keyCheck("q\r")) break;
}
// Stop the recording.
recInterface->stop(false);
tickAndUpdate(*aLogger);
// Close the file.
recInterface->closeFile();
tickAndUpdate(*aLogger);
DtRestoreKbHit();
DtDELETE(aLogger);
return 0;
}
// The application entry point
int main(int argc,char** argv)
{
DtINIT_MINIDUMPER( "RecordFile" );
return recordFile(argc,argv);
}

Document ID: Generated on Thu Apr 7 20:50:59 EDT 2016 from SVN revision 163818
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)