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

The extendPdu example demonstrates how to replace Logger's default handling for a DIS PDU kind with a custom PDU class, keep encode/decode registration in sync with connection lifecycle, and update filter/UI naming so operators see the custom PDU name.

Table of Contents

What This Example Addresses

This plugin and class pair address three major Logger extension tasks:

  1. Extend the set of PDUs the Logger can decode, capture, and record.
    • The example binds DIS kind 200 to a custom class, ExtendPdu.
    • Incoming packets of that kind are created through ExtendPdu::create.
  2. Re-register a PDU kind that Logger normally has by default.
    • In this example, kind 200 is normally associated with an existing/default entry (for example, the NP Collision mapping in a default DIS descriptor).
    • Conceptually, the example replaces that default NP Collision kind mapping with TestPduKind (kind 200) handled by ExtendPdu.
    • The plugin re-registers kind 200 to use the example's TestPduKind and custom class/encoder path instead.
  3. Update filtering/UI naming to show the extended PDU name.
    • The plugin rebuilds descriptor copies so kind 200 appears as "ExtendCustomPdu".
    • This allows filter controls (including PDU type filter dialogs) to show the new name instead of the default one.

The ExtendPdu Class (extendPdu.h / extendPdu.cxx)

Purpose

ExtendPdu is a DtPdu subclass that demonstrates a variable-length DIS PDU layout while keeping a fixed PDU kind value (kind 200).

Network Representation

The class uses this layout concept:

Because b is variable-length, c is located using byte arithmetic at runtime.

Key Behavior

The extendPdu Plugin (extendPduPlugin.cxx)

Responsibilities

The plugin installs a custom DIS protocol registration and does the following:

  1. Re-map kind 200 to the custom ExtendPdu creator/decoder.
  2. Re-register encoder handling for kind 200 (ExtendPduEncoder).
  3. Rename kind 200 in descriptor copies to "ExtendCustomPdu" so filters and related UI present the custom name.
  4. Keep registration valid across reconnects by re-registering after ExerciseConn changes in driver tick().

Runtime Flow

Why Rename and Re-register

Without these steps:

This plugin explicitly handles all three concerns.

How To Run

Build the Plugin

  1. Build the extendPdu example target so the plugin library is produced (extendPduDIS on DIS builds).
  2. Confirm the built plugin is in Logger's plugin search path (typically bin/bin64 depending on platform/configuration).

Update lgrConfigDIS.xml

Update the DIS config so Logger loads this plugin as the protocol library.

In the <defaults> section:

Example:

<var name="protocolLibrary" type="string" value="extendPduDIS"/>
<var name="protocolGuiLibrary" type="string" value="lgrSimGuiDIS"/>

Why this is required:

Start Logger and Verify

  1. Start Logger using the DIS config that references extendPduDIS.
  2. Connect to DIS traffic containing kind-200 packets.
  3. Verify in Logger/filter UI that kind 200 appears as "ExtendCustomPdu".
  4. Verify capture/record path processes these packets through the custom registration.

Optional Notes

Source Code

extendPdu.h

#pragma once
#if DtDIS
// This file defines a custom DIS PDU implementation that reuses PDU kind 200.
// At runtime, the plugin remaps this kind to the display name "ExtendCustomPdu"
// and registers this class as the creator/decoder for that kind.
#include <vl/pdu.h>
#include <vl/exerciseConnDIS.h>
typedef struct NetTestPdu
{
DtNetPduHeader header;
DtNetInt32 a;
DtNetInt32 b[1];
} NetTestPdu;
const DtPduKind TestPduKind = DtPduKind(200);
class ExtendPdu;
typedef void (*ExtendPduCb)(ExtendPdu* pdu, void* usr);
class ExtendPdu : public DtPdu
{
public:
ExtendPdu(DtBufferPtr buffer = DtUSE_INTERNAL_BUFFER);
ExtendPdu(const NetTestPdu* initial,
DtBufferPtr buffer = DtUSE_INTERNAL_BUFFER, DtPduFactory* pduFactory = 0);
virtual ~ExtendPdu();
ExtendPdu(const ExtendPdu& orig);
ExtendPdu& operator=(const ExtendPdu& orig);
virtual void printDataToStream(std::ostream& stream) const;
virtual void setA(int val);
virtual int a() const;
virtual void setB(int index, int val);
virtual int b(int index) const;
virtual void setC(float val);
virtual float c() const;
virtual NetTestPdu* netTestPdu();
virtual const NetTestPdu* netTestPdu() const;
public:
static DtPdu* create(const DtNetPacket* initial,
DtBufferPtr buffer = DtUSE_INTERNAL_BUFFER, DtPduFactory* pduFactory = 0);
static void addCallback(DtExerciseConn* conn, ExtendPduCb cb, void* usr);
static void removeCallback(DtExerciseConn* conn, ExtendPduCb cb, void* usr);
protected:
virtual DtPduKind internalGetPduKind() const;
};
#endif

extendPdu.cxx

#if DtDIS
#include "extendPdu.h"
#include <vl/pduFactory.h>
#include <iostream>
// Implementation notes:
// - This class stores a variable-length payload in the "b" array.
// - Field "a" is the cardinality for "b" and drives packet resizing.
// - PDU kind is fixed to TestPduKind (200) via internalGetPduKind().
// - The plugin registers this class as the creator for kind 200 so incoming
// packets are decoded into ExtendPdu.
ExtendPdu::ExtendPdu(DtBufferPtr buffer)
: DtPdu()
{
// Must call initPdu, passing the minimal size of this type of PDU, and the
// buffer pointer passed to us.
// Here, minimal size occurs when "b" has 0
// elements. The size of the PDU is therefore the size of the header plus
// the size of the DtNetInt32 field "a" plus the size of the DtNetFloat32
// field "c".
int minimalSize = sizeof(DtNetPduHeader) + sizeof(DtNetInt32) +
sizeof(DtFloat32);
initPdu(minimalSize, buffer);
}
ExtendPdu::~ExtendPdu()
{
}
// From-network-representation constructor.
ExtendPdu::ExtendPdu(const NetTestPdu* initial, DtBufferPtr buffer, DtPduFactory* pduFactory)
{
// Must call initPdu, passing the network representation and the buffer
// that were passed to us.
initPdu(initial, buffer, pduFactory);
}
// Copy constructor.
ExtendPdu::ExtendPdu(const ExtendPdu& orig) :
DtPdu(orig)
{}
// Assignment operator.
ExtendPdu& ExtendPdu::operator=(const ExtendPdu& orig)
{
// Guard against assignment to yourself.
if (this == &orig)
{
return *this;
}
DtPdu::operator=(orig);
return *this;
}
void ExtendPdu::printDataToStream(std::ostream& stream) const
{
std::cout << "A: " << a() << "\n"
<< "B: \n";
// Remember that a() indicates the length of array "b".
for (int index = 0; index < a(); index++)
{
std::cout << b(index) << '\n';
}
std::cout << "C: " << c() << std::endl;
}
void ExtendPdu::setA(int val)
{
// Since "a" represents the number of elements in the "b" array, we must
// insert or delete bytes from the PDU layout whenever we change "a"
// through this mutator.
// Get the old value of "a".
int oldA = a();
if (val > oldA)
{
// Insert space for (val - oldA) 32-bit integers after the current last
// element of the "b" array. insertBytes will push the rest of the PDU
// data (in this case just "c") down past the end of the byte being
// added.
insertBytes(&(netTestPdu()->b[oldA]),
(val - oldA) * sizeof(DtNetInt32));
}
else if (val < oldA)
{
// Delete space used by the last (oldA - val) 32-bit integers.
// deleteBytes pulls up the rest of the PDU data (in this cast just "c",
// so that it occupies the space vacated by the deleted bytes.
deleteBytes(&(netTestPdu()->b[val]), (oldA - val) * sizeof(DtNetInt32));
}
// Now set the value of the "a" field (array length for "b").
netTestPdu()->a = val;
}
int ExtendPdu::a() const
{
return netTestPdu()->a;
}
void ExtendPdu::setB(int index, int val)
{
// Do bounds checking, then set the index'th element of the "b" array to
// val.
if (index < 0 || index > a())
{
std::cout << "TestPdu::setB(): index out of range.\n";
return;
}
netTestPdu()->b[index] = val;
}
int ExtendPdu::b(int index) const
{
// Do bounds checking, then return the index'th element of the "b" array.
if (index < 0 || index > a())
{
std::cout << "ExtendPdu::b(): index out of range.\n";
return 0;
}
return netTestPdu()->b[index];
}
void ExtendPdu::setC(float val)
{
// We can find "c" after the last element of "b".
DtNetFloat32* netC = (DtNetFloat32*)&(netTestPdu()->b[a()]);
// val will be implicitly cast to a DtNetFloat32.
*netC = val;
}
float ExtendPdu::c() const
{
// We can find "c" after the last element of "b".
DtNetFloat32* netC = (DtNetFloat32*)&(netTestPdu()->b[a()]);
// netC will be implicitly cast to a native float.
return *netC;
}
NetTestPdu* ExtendPdu::netTestPdu()
{
return (NetTestPdu*)packet();
}
const NetTestPdu* ExtendPdu::netTestPdu() const
{
return (const NetTestPdu*)packet();
}
DtPdu* ExtendPdu::create(const DtNetPacket* initial, DtBufferPtr buffer, DtPduFactory* pduFactory)
{
// Factory entry point used by DtPduFactory for kind 200.
return new ExtendPdu((NetTestPdu*)initial, buffer, pduFactory);
}
void ExtendPdu::addCallback(DtExerciseConn* conn, ExtendPduCb cb, void* usr)
{
// Register this class' create function with the DtExerciseConn's
// pduFactory so that the DtExerciseConn will know to create an instance of
// this class to represent incoming PDUs of the appropriate kind. If this
// is not done here, the user of this class will have to explicitly register
// the class with the PDU factory himself.
conn->pduFactory()->addCreator(TestPduKind, ExtendPdu::create);
// Cast the TestPduCb to the more general DtPduCallbackFcn and pass it along
// with the PDU kind to the DtExerciseConn who actually maintains the
// callback lists for all PDU kinds.
conn->addPduCallback(TestPduKind, (DtPduCallbackFcn)cb, usr);
}
void ExtendPdu::removeCallback(DtExerciseConn* conn, ExtendPduCb cb, void* usr)
{
// Cast the ExtendPduCb to the more general DtPduCallbackFcn and pass it along
// with the PDU kind to the DtExerciseConn who actually maintains the
// callback lists for all PDU kinds.
conn->removePduCallback(TestPduKind, (DtPduCallbackFcn)cb, usr);
}
DtPduKind ExtendPdu::internalGetPduKind() const
{
// Emit this packet using the reused kind 200.
return TestPduKind;
}
#endif

extendPduPlugin.cxx

#ifdef _WIN32
#ifdef EXTENDPDU_EXPORTS
#define DT_DLL_EXTPDU __declspec(dllexport)
#else
#define DT_DLL_EXTPDU __declspec(dllimport)
#endif
#else
#define DT_DLL_EXTPDU
#endif
#define DT_LGR_PLUGIN_EXPORT_MACRO DT_DLL_EXTPDU
#if DtDIS
// Plugin responsibilities:
// 1) Re-register PDU kind 200 to decode as ExtendPdu and encode with a custom encoder.
// 2) Rename kind 200 in DIS descriptors to "ExtendCustomPdu" so UI/filter dialogs
// show the custom name instead of the default -- MAK Extended PDU (NP Collision), in this case.
// 3) Provide custom DIS driver/interface wiring so Logger uses this behavior.
//
// Configuration required (lgrConfigDIS.xml):
// - This plugin replaces the default DIS protocol registration, so it must be
// loaded as the protocol library (not in addition to the default one).
// - In <defaults>, change:
// protocolLibrary = "lgrSimDIS"
// to:
// protocolLibrary = "extendPduDIS"
// - Keep protocolGuiLibrary (for example "lgrSimGuiDIS") as-is unless you are
// also replacing GUI behavior.
//
// Why this is required:
// - EnableLoggerPlugin() in this module installs ExtendPduDisProtocolRegistration,
// which overrides DIS driver/interface behavior for kind 200 naming and
// creator/encoder registration.
// - If lgrSimDIS is still loaded as protocolLibrary, the default DIS protocol
// registration wins and your custom behavior may not be active.
// - If both are loaded as protocol providers, duplicate command/protocol
// registration conflicts can occur.
#include "extendPdu.h"
#include <lgrCore/logger.h>
#include <vl/exerciseConn.h>
#include <vl/pduEncoderFactory.h>
#include <vl/pduFactory.h>
#include <vl/pduEncoder.h>
namespace
{
// Rebuilds a descriptor so kind 200 appears with the custom display name.
// All other PDU descriptors are copied through unchanged.
static void setExtendCustomPduName(MAKLogger::DtDisDescriptor*& descRef)
{
if (!descRef)
{
return;
}
const MAKLogger::DtDisDescriptor* sourceDesc = descRef;
const MAKLogger::DtPduDescriptor* testPduDesc = sourceDesc->pduDesc(TestPduKind);
int entityIdOffset = 0;
int entityTypeOffset = 0;
if (testPduDesc)
{
entityIdOffset = testPduDesc->entityIdOffset();
entityTypeOffset = testPduDesc->entityTypeOffset();
}
MAKLogger::DtDisDescriptor* updatedDesc = MAKLogger::DtDisDescriptor::create();
updatedDesc->addPduKind("ExtendCustomPdu", TestPduKind, entityIdOffset, entityTypeOffset);
for (MAKLogger::DtDisDescriptor::const_iterator iter = sourceDesc->begin(); iter != sourceDesc->end(); ++iter)
{
const MAKLogger::DtPduDescriptor* pduDesc = iter->second;
if (pduDesc && pduDesc->kind() != TestPduKind)
{
updatedDesc->addPduDesc(*pduDesc);
}
}
delete descRef;
descRef = updatedDesc;
}
static void setExtendCustomPduName(MAKLogger::DtLgrDisSimulationManager* simManager)
{
if (!simManager || !simManager->disDescription())
{
return;
}
MAKLogger::DtDisDescriptor* updatedDesc = MAKLogger::DtDisDescriptor::copy(*simManager->disDescription());
setExtendCustomPduName(updatedDesc);
simManager->setDisDescription(updatedDesc);
}
class ExtendPduEncoder : public DtPduEncoder
{
public:
virtual void encode(DtPdu* pdu)
{
// Placeholder encoder: this example only needs registration to prove
// that kind 200 can be redirected through ExerciseConn factories.
(void)pdu;
}
virtual DtPduEncoder* clone() const
{
return new ExtendPduEncoder(*this);
}
};
static void registerExtendPdu(DtExerciseConn* exConn, MAKLogger::DtLgrDisSimulationManager* simManager)
{
if (!exConn)
{
return;
}
// Update runtime descriptor name used by filters and related UI.
setExtendCustomPduName(simManager);
// Register decoder/creator for incoming kind-200 packets.
exConn->pduFactory()->addCreator(TestPduKind, ExtendPdu::create);
// Register encoder for outgoing kind-200 packets.
DtPduEncoder* oldEncoder =
exConn->pduEncoderFactory()->addEncoder(TestPduKind, new ExtendPduEncoder());
delete oldEncoder;
}
class ExtendPduDisSimDriver;
class ExtendPduDisSimInterface : public MAKLogger::DtLgrDisSimInterface
{
public:
static ExtendPduDisSimInterface* createNonThreadsafe(MAKLogger::DtLogger& logger,
const ExtendPduDisSimDriver& driver);
protected:
ExtendPduDisSimInterface(MAKLogger::DtLogger& logger, const ExtendPduDisSimDriver& driver);
};
class ExtendPduDisSimDriver : public MAKLogger::DtLgrDisSimDriver
{
public:
typedef ExtendPduDisSimInterface Interface;
ExtendPduDisSimDriver(MAKLogger::DtLgrSystemDriver& driver)
: MAKLogger::DtLgrDisSimDriver(driver)
, myRegisteredConn(0)
{
setExtendCustomPduName(disSimManager());
syncPduTypeFilterDescription();
}
{
return new ExtendPduDisSimDriver(driver);
}
virtual void tick()
{
MAKLogger::DtLgrDisSimDriver::tick();
MAKLogger::DtLgrDisSimulationManager* simMgr = disSimManager();
DtExerciseConn* exConn = simMgr ? simMgr->exerciseConn() : 0;
if (!exConn)
{
myRegisteredConn = 0;
return;
}
if (exConn != myRegisteredConn)
{
// Re-register after (re)connect, because ExerciseConn instances change.
registerExtendPdu(exConn, simMgr);
syncPduTypeFilterDescription();
myRegisteredConn = exConn;
}
}
private:
void syncPduTypeFilterDescription()
{
// PDU type filter maintains its own descriptor copy; keep it aligned so
// the "Filter By PDU Kind" dialog shows ExtendCustomPdu for kind 200.
if (myPduFilter && disSimManager() && disSimManager()->disDescription())
{
myPduFilter->setDisDescrition(MAKLogger::DtDisDescriptor::copy(*disSimManager()->disDescription()));
}
}
DtExerciseConn* myRegisteredConn;
};
MAKLogger::DtLgrSimInterface* ExtendPduDisSimInterface::createBase(MAKLogger::DtLogger& logger)
{
// Resolve the currently active protocol registration from the logger.
// We need this so we can obtain the exact sim driver instance that was
// installed by this plugin (ExtendPduDisSimDriver).
if (registration)
{
// simDriver() is non-const in the SDK API, so cast away const to call it.
MAKLogger::DtLgrProtocolRegistration* mutableRegistration =
const_cast<MAKLogger::DtLgrProtocolRegistration*>(registration);
// Ensure the active sim driver is our custom DIS driver type.
// If this cast fails, return null and let caller handle missing interface.
const ExtendPduDisSimDriver* simDriver =
dynamic_cast<const ExtendPduDisSimDriver*>(mutableRegistration->simDriver());
if (simDriver)
{
// Create the non-threadsafe interface bound to that custom driver.
ExtendPduDisSimInterface* commandInterface =
ExtendPduDisSimInterface::createNonThreadsafe(logger, *simDriver);
return commandInterface;
}
}
// No compatible registration/driver found.
return 0;
}
ExtendPduDisSimInterface* ExtendPduDisSimInterface::createNonThreadsafe(
MAKLogger::DtLogger& logger, const ExtendPduDisSimDriver& driver)
{
// Standard interface factory entry: construct directly on caller thread.
return new ExtendPduDisSimInterface(logger, driver);
}
ExtendPduDisSimInterface::ExtendPduDisSimInterface(
MAKLogger::DtLogger& logger, const ExtendPduDisSimDriver& driver)
: MAKLogger::DtLgrDisSimInterface(logger, driver)
{
// Interface keeps its own descriptor copy for GUI-side reads,
// so apply the kind-200 rename here as well (independent of sim manager/filter copies).
setExtendCustomPduName(myDisDescriptor);
}
class ExtendPduDisProtocolRegistration : public MAKLogger::DtLgrProtocolRegistration
{
public:
ExtendPduDisProtocolRegistration(MAKLogger::DtLogger& logger)
: MAKLogger::DtLgrProtocolRegistration(&MAKLogger::DtDisStateObject::createBase,
&ExtendPduDisSimInterface::createBase,
MAKLogger::DtLgrCommandType::Protocol_DIS,
DtString("DIS"),
ExtendPduDisSimDriver::create(logger.driver()),
0)
{
// Keep a direct pointer to the simulation manager created by our
// custom DIS sim driver.
mySimManager = simDriver()->simManager();
// Ensure entity tracking uses the DIS tracker implementation.
MAKLogger::DtLgrEntityTracker::setCreator(MAKLogger::DtLgrDisEntityTracker::createBase);
// Register DIS file format handlers used by playback/record operations.
MAKLogger::DtLgrDisFileFormats::registerFormats();
// Register all DIS filter types so Logger can create and apply these
// filters from UI/commands.
MAKLogger::DtLgrPacketFilterFactory::registerFilterType(MAKLogger::DtLgrPduTypeFilter::theType(),
&MAKLogger::DtLgrPduTypeFilter::createBase);
MAKLogger::DtLgrPacketFilterFactory::registerFilterType(MAKLogger::DtLgrDisEntityTypeFilter::theType(),
&MAKLogger::DtLgrDisEntityTypeFilter::createBase);
&MAKLogger::DtLgrEntityIdFilter::createBase);
MAKLogger::DtLgrPacketFilterFactory::registerFilterType(MAKLogger::DtLgrDisMarkingFilter::theType(),
&MAKLogger::DtLgrDisMarkingFilter::createBase);
&MAKLogger::DtLgrDisVRFMessageFilter::createBase);
// Select the DIS-specific data view implementation for the GUI.
MAKLogger::DtLgrDataViewSet::setCreator(&MAKLogger::DtLgrDisDataViewSet::createBase);
// Bind packet filter factory to this active sim driver instance so
// created filters resolve against the correct runtime context.
}
};
}
#endif
extern "C"
{
void LoadPlugin()
{
}
{
#if DtDIS
// Install this plugin's custom DIS protocol registration so Logger uses
// the extended sim driver/interface (kind-200 remap + ExtendCustomPdu naming).
logger.registerSimulationProtocol(new ExtendPduDisProtocolRegistration(logger));
#else
(void)logger;
#endif
}
{
(void)loggerApp;
}
{
}
}

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)