#if DtDIS
#include <vl/disPduFactory.h>
#endif
#if DtHLA
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializerHLA.h>
#include <vl/interactionFactory.h>
#include <vl/interactionHLA.h>
#include <vlutil/vlRtiMismatchException.h>
#endif
#include <vlutil/vlMiniDumper.h>
#include <iostream>
#include <cmdLine/cmdLine.h>
using namespace MAKLogger;
#if DtDIS
const char defaultFileName[] = "..\\logger_tapes\\bombMission2016-DIS.lgr";
#elif DtHLA_1516_EVOLVED
const char defaultFileName[] = "..\\logger_tapes\\bombMission2018-HLAe-RPR20.lgr";
#elif DtHLA_1516
const char defaultFileName[] = "..\\logger_tapes\\bombMission2018-HLA516-RPR20.lgr";
#else
const char defaultFileName[] = "..\\logger_tapes\\bombMission2018-HLA13-RPR20.lgr";
#endif
bool keyCheck(const char* keysToCheck)
{
if(DtKbHit())
{
int c = DtGetCh();
return strchr(keysToCheck,c) != 0;
}
return false;
}
#if DtDIS
void readPacket(
const DtPacket* packet)
{
static DtDisPduFactory factory;
{
DtPdu* Pdu = factory.createPdu (
reinterpret_cast<const DtNetPacket*>(packet->
data()),
reinterpret_cast<DtBufferPtr>(const_cast<char*>(packet->
data())));
Pdu->print();
delete Pdu;
}
}
{
DtLgrDisPlaybackFile* file(0);
DtLgrDisMessageIOInfo* ioInfo(0);
try
{
file = DtLgrDisPlaybackFile::create(filename, false);
return DtLoggerFileReader::create(ioInfo,file);
}
{
DtInfo << output << std::endl;
return 0;
}
}
#endif
#if DtHLA
DtInteractionFactory* theInteractionFactory;
void readPacket(
const DtPacket* packet)
{
if(hlaMessage.isInteraction())
{
theInteractionFactory,
*theOnlineFom);
inter->print();
}
}
{
try
{
return DtLoggerFileReader::create(ioInfo,file);
}
{
DtInfo << output << std::endl;
return 0;
}
}
void setConfigParameters(DtExerciseConnInitializer& exConnInit, const DtFilename& filename)
{
try
{
}
{
DtInfo << output << std::endl;
}
if(configPacket)
{
}
exConnInit.setRprFomVersion(configData.
fomVersion().toDouble());
{
{
}
}
{
}
DtFilename fedFile(configData.
fedFile());
fedFile.stripPath();
exConnInit.setFedFileName(fedFile);
#if DtHLA_1516_EVOLVED
std::vector<DtString> fomModNames;
int numberModules = fomModNames.size();
if (numberModules > 0)
{
for (int fmIndex=0; fmIndex < numberModules; ++fmIndex)
{
DtFilename fmFilename(fomModNames[fmIndex]);
fmFilename.stripPath();
fomModNames[fmIndex] = fmFilename;
}
exConnInit.setFomModules(fomModNames);
}
if (!configData.
mim().isEmpty())
{
DtFilename mim(configData.
mim());
mim.stripPath();
exConnInit.setMimModule(mim);
}
#endif
delete file;
}
#endif
bool fileTypeMatches(
DtString& filename)
{
unsigned int magic = 0;
std::ifstream fs;
fs.open(filename.c_str(),std::ios::binary );
if(!fs.is_open() || !fs.good())
{
DtInfo << "Unable to open file: " << filename << "." << std::endl;
exit(1);
}
fs.read((char*)&magic,4);
magic = (magic >> 24) | ((magic >> 8) & 0xFF00) |
((magic << 8) & 0xFF0000) | (magic << 24);
#if DtDIS
return DtString(
"Unknown") != DtLgrDisFileFormats::versionString(magic);
#else
#endif
}
int readFile(int argc,char** argv)
{
DtCmdLine::UnlabeledMultiArg<DtString> filenameArg("Filename","The name of the logger file to read.","string");
cmdLine.add(&filenameArg);
cmdLine.parse(argc,argv);
std::vector<DtString> values = filenameArg.getValue();
if(values.size() == 0)
{
values.push_back(defaultFileName);
}
DtFilename filename(values.front());
if (filename.isEmpty())
{
filename = defaultFileName;
}
#if DtDIS
DtLgrDisFileFormats::registerFormats();
#else
#endif
if (!fileTypeMatches(filename))
{
DtInfo << "Unable to process file (" <<
filename.c_str() << "): file format designator does not match, unknown or corrupted." << std::endl;
return 1;
}
#if DtHLA
DtExerciseConnInitializer exConnInit;
setConfigParameters(exConnInit, filename);
try
{
}
catch( DtVlRtiMismatchException )
{
DtFatal << "Mismatching RTI compiler Version. Please reconfigure your environment" << std::endl;
return -1;
}
theInteractionFactory = theExerciseConn->interactionFactory();
theOnlineFom = DtLgrOnlineFomDesc::create(theExerciseConn);
#endif
if(!reader)
{
DtInfo << "Unable to open file: " << filename << " for reading." << std::endl;
return 1;
}
else
{
DtInfo << "Opened file: " << filename << " for reading." << std::endl;
}
#if DtHLA
theMessageState = DtLgrHlaMessageState::create();
theMessageState->setInputInfo(reader->
info());
theMessageState->setOutputInfo(DtLgrHlaMessageIOInfo::create(
#endif
bool quit = false;
{
if (keyCheck("q\r"))
{
quit = true;
break;
}
if(buffer.
size() == 0)
break;
#if DtHLA
theMessageState->modifyMessages(buffer);
#endif
DtMessageBuffer::PacketList::iterator packetIterator;
for(packetIterator = buffer.
begin(); packetIterator != buffer.
end();++packetIterator)
{
static int packetCount = 0;
DtInfo <<
"***********************************************" << std::endl <<
"* Packet #" << ++packetCount <<
" Type = " << packet->
type() <<
readPacket(packet);
if (keyCheck("q\r"))
{
quit = true;
break;
}
}
}
delete reader;
#if DtHLA
delete theMessageState;
delete theExerciseConn;
#endif
return 0;
}
int main(int argc,char** argv)
{
DtINIT_MINIDUMPER( "ReadFile" );
return readFile(argc,argv);
}