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 new logger tape, and records for up to one minute.

It prints the current recording time periodically. Press 'q' or Enter to stop early.


The main application:

/*******************************************************************************
** Copyright (c) 1992-2026 MAK Technologies, Inc
** 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>
#include "vlutil/vlLogFileInfo.h"
#include "lgrUtil/svnRev.h"
#include <cassert>
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());
// Initialize logger with default settings.
DtVrlApplicationInitializer exConnInit(argc, argv, "recordFile");
// 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
exConnInit.setFederateType("recordFile");
exConnInit.setFederateName("recordFile");
DtHlaLogger* aLogger = DtHlaLogger::create(true);
#endif
#if DtHLA
// Connection settings (exec name, FED file, RPR FOM version, FOM modules,
// etc.) are loaded from DtDefaultConfigFile ("MAK-ONE-XXXX-Config.xml") by
// default, which is the default config file path for DtVrlApplicationInitializer.
#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)
{
// Used for error handling
DtLogFileInfo::instance().setAppName("RecordFile");
DtLogFileInfo::instance().setProtocol(DT_PROTOCOL_SHORT_NAME);
DtLogFileInfo::instance().setSvnRev(SVN_REV);
DtLogFileInfo::instance().setVersion(LOGGER_VERSION_STRING);
DtINIT_MINIDUMPER(DtLogFileInfo::instance().getFullString().c_str());
return recordFile(argc,argv);
}

Document ID: Generated on Tue Nov 17 15:25:07 EST 2026 from SVN revision 298446
Copyright © 2026 MAK Technologies. All Rights Reserved (www.mak.com)