GRL.TestSimulator 1.0.1

dotnet add package GRL.TestSimulator --version 1.0.1
                    
NuGet\Install-Package GRL.TestSimulator -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GRL.TestSimulator" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GRL.TestSimulator" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="GRL.TestSimulator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GRL.TestSimulator --version 1.0.1
                    
#r "nuget: GRL.TestSimulator, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GRL.TestSimulator@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GRL.TestSimulator&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=GRL.TestSimulator&version=1.0.1
                    
Install as a Cake Tool

GRL.TestSimulator

Pluggable hardware simulation and DMA metadata-logging library for GRL backend projects.

Version .NET Framework License: MIT


Overview

GRL.TestSimulator provides two complementary modes for GRL backend projects:

  • Metadata Logging Mode — records live DMA traffic from real hardware into compact golden report files on disk
  • Simulation Mode — replays recorded golden reports in place of real hardware, enabling fully offline test execution

Only two types are exposed to consumer projects: SimulatorHub (the static entry point) and ISimulatorPlugin (Plugin to use the simulator mode and meta data logging mode). All implementation detail is internal.


Requirements

.NET Framework 4.8
Newtonsoft.Json 13.0.1 (auto-installed)
Visual Studio 2019 / 2022

Installation

Package Manager Console:

Install-Package GRL.TestSimulator -Version 1.0.1 -Source "LocalPackages"

Upgrade from 1.0.0:

Update-Package GRL.TestSimulator

dotnet CLI:

dotnet add package GRL.TestSimulator --version 1.0.1 --source "D:\LocalNuGetPackages"

Public API

SimulatorHub — static entry point

// Activate a mode — call once at startup or when switching modes through any external APIs
ISimulatorPlugin SimulatorHub.Activate(
    bool isSimulationMode,
    bool isMetadataLoggingMode,
    bool isSkipDelayInSimulationMode = false   // true = skip inter-DMA timing delays
);

// Set device identity — call at connection setup
SimulatorHub.SetConnectionContext(
    string swType,
    string swVersion,
    string fwVersion,
    string basePath,
    string hwVersion   = "",   // optional
    string framVersion = ""    // optional
);

// Set test identity — call before Start Streamer
SimulatorHub.SetTestContext(string certification, string powerProfile, string testcase);

// Lifecycle
SimulatorHub.PrepareForTestStart();  // call after SetTestContext and before Start Streamer
SimulatorHub.NotifyTestStopped();    // call after Stop Streamer

ISimulatorPlugin - Contract interface for Consumer application

bool IsSimulationMode { get; }                                         // true = no HW needed
bool IsActive         { get; }                                         // true = either mode on
bool ReadSimulated(ref byte[] data, bool isDataRead);                  // replaces HW read
void TryLogDmaChunk(byte requestHeader, int dmaIndex, byte[] response); // records DMA chunk

Operation Modes

isSimulationMode isMetadataLoggingMode Behaviour
false false Pure HW — passthrough, plugin inactive
false true HW + Record — live HW, DMA data saved to golden reports
true false Simulation — golden reports replayed, no HW needed
true true Not recommended

Step-by-Step Consumer Integration Guide

Integration touches four places in your application. Each step below shows exactly what to add and where.


Step 1 - Engine Where HW Read and Write methods are implemnted: declare the plugin and wrap ReadReg / WriteReg

This is the only project that needs to reference GRL.TestSimulator directly via NuGet. All other projects access the plugin indirectly through the static IsSimulationActive flag.

1a - Add the plugin field and static flag:

using GRL.TestSimulator;

// Field — stores the active plugin instance
private ISimulatorPlugin _plugin = null;

// Static helper — lets sibling projects check mode without a direct reference
public static bool IsSimulationActive => m_etherneteng?._plugin?.IsSimulationMode ?? false;

1b - Add RegisterPlugin() - call this from your API layer:

public void RegisterPlugin(bool isSimulationMode, bool isMetadataLoggingMode,
    bool isSkipDelayInSimulationMode = false)
{
    _plugin = SimulatorHub.Activate(isSimulationMode, isMetadataLoggingMode,
                  isSkipDelayInSimulationMode);
}

Set isSkipDelayInSimulationMode = true to skip the inter-DMA timing delays during playback for faster automated test execution. Leave false (default) for realistic hardware timing.

1c - Update ReadReg():

public bool ReadReg(ref byte[] data, string sApiDesc = "", bool isDataReadCommand = false)
{
    // Capture DMA header before any read so it is available for logging
    byte  reqHeader   = (data?.Length > 0) ? data[0] : (byte)0;
    int   reqDmaIndex = (data?.Length > 1) ? data[1] : -1;

    bool result = (_plugin?.IsSimulationMode == true)
        ? _plugin.ReadSimulated(ref data, isDataReadCommand)   // simulation: serve from file
        : ReadDatafromFW(ref data, sApiDesc, isDataReadCommand); // live: read from hardware

    _plugin?.TryLogDmaChunk(reqHeader, reqDmaIndex, data);     // logging: persist DMA chunk

    return result;
}

1d — Update WriteReg() — block hardware writes in simulation mode:

public bool WriteReg(byte[] dataBuffer, string sApiDesc = "")
{
    if (IsSimulationActive)
        return true;   // simulation: skip HW write silently

    // ... your existing write logic ...
    return true;
}

Step 2 — ConnectionSetup: set device context at connection

Call SetConnectionContext before and after the hardware connection is established so the simulator always has up-to-date version information.

using GRL.TestSimulator;

private void UpdateSimulatorContext()
{
    SimulatorHub.SetConnectionContext(
        swType:      /* your SW type string  */,
        swVersion:   /* your SW version      */,
        fwVersion:   /* your FW version      */,
        basePath:    /* root path for golden reports / recordings */,
        hwVersion:   /* your HW revision     */,   // optional — leave out if not applicable
        framVersion: /* your FRAM version    */    // optional — leave out if not applicable
    );
}

basePath is the root folder under which golden reports are stored. The library builds the full path as: basePath \ Simulator Golden Reports \ swType \ certification \ powerProfile \ testcase


Step 3 — DataStreamService: set test context and manage lifecycle

Call these in order around each test run:

using GRL.TestSimulator;

// ── Before Start Streamer ─────────────────────────────────────────────
SimulatorHub.SetTestContext(certification, powerProfile, testCaseName);
SimulatorHub.PrepareForTestStart();
// then start your streamer ...

// ── After Stop Streamer ───────────────────────────────────────────────
// ... stop your streamer, clear DMA tasks ...
SimulatorHub.NotifyTestStopped();
Call Simulation mode behaviour Logging mode behaviour
PrepareForTestStart() Unzips golden report ZIP, pre-loads all DMA metadata Creates the recording folder for the current testcase
NotifyTestStopped() Closes bin streams, deletes unzipped temp folder Flushes bin streams, zips the session folder, removes raw files

Step 4 — HW Initializer: bypass real hardware in simulation mode

In the method where your hardware port is opened, check IsSimulationActive and skip the real connection:

using GRL.TestSimulator;

public static void InitHWCommunication(string ipAddress)
{
    // ... your existing ping / pre-check logic ...

    if (EthernetEngine.IsSimulationActive)
    {
        // No hardware needed — mark as connected and continue
        FWAppObj.FWHost.EthernetConnectionStatus = EthernetConnectionState.CONNECTED;
    }
    else
    {
        EthernetEngine.EthernetCommunication.InitilizePort();
    }
}

Step 5 — API / UI Layer: expose mode switching at runtime

Expose an endpoint so developers can switch modes while the application is in READY state without restarting.

using GRL.TestSimulator;

[HttpPut("PutSimulatorVariables")]
public void PutSimulatorVariables(
    bool isSimulationMode,
    bool isMetadataLoggingMode,
    bool isSkipDelayInSimulationMode = false)
{
    if (FWAppObj.FWHost.HostState != HostState.READY)
        return;

    EthernetEngine.GetEthernetEngine(false)
                  .RegisterPlugin(isSimulationMode, isMetadataLoggingMode,
                      isSkipDelayInSimulationMode);
}

Integration Checklist

[ ] Step 1 — EthernetEngine
      [ ] ISimulatorPlugin _plugin field added
      [ ] IsSimulationActive static property added
      [ ] RegisterPlugin() method added
      [ ] ReadReg() updated — ReadSimulated + TryLogDmaChunk
      [ ] WriteReg() updated — IsSimulationActive guard added

[ ] Step 2 — ConnectionSetupController
      [ ] SetConnectionContext() called before and after connection

[ ] Step 3 — DataStreamService
      [ ] SetTestContext() called before Start Streamer
      [ ] PrepareForTestStart() called after SetTestContext
      [ ] NotifyTestStopped() called after Stop Streamer

[ ] Step 4 — HW Initializer
      [ ] IsSimulationActive bypass added in InitHWCommunication

[ ] Step 5 — API / UI Layer
      [ ] Mode-switch endpoint exposed and guarded by READY state check

Golden Report Structure

Each recorded session produces a ZIP file containing:

File Description
master_metadata.json Session header (versions, DMA count) + file references per DMA channel
metadata_0.jsonmetadata_N.json Per-DMA chunk index — offsets, sizes, timestamps, checksums
raw_data_0.binraw_data_N.bin Binary DMA data (trailing zeros stripped per chunk)

dataSize_bytes = 0 in a chunk entry means the full hardware buffer for that chunk was all zeros. The playback engine automatically reconstructs a zero-filled buffer — no bin file access needed. Use fileOffset_bytes to seek directly to a chunk's data in the bin file.


Version History

1.0.1 — March 2026

  • Trailing zero bytes stripped per chunk before bin write — reduces golden report file size on disk; all-zeros chunks stored as dataSize_bytes = 0 and reconstructed on playback
  • chunks array removed from master_metadata.json — stored only in per-DMA metadata_{id}.json; master file holds lightweight dataset references
  • hwVersion and framVersion added to SetConnectionContext() as optional parameters
  • JSON metadata field names updated to include units (_bytes, _ms)
  • DMACount in session header is now derived dynamically from recorded DMA channels
  • SimulatorHub.Activate() gains optional isSkipDelayInSimulationMode parameter
  • All implementation classes are now internal — only SimulatorHub and ISimulatorPlugin are visible to consumers

1.0.0 — March 2026

  • Initial release

License

MIT License — Copyright © GRL 2026

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 112 3/25/2026
1.0.0 112 3/10/2026

v1.0.1 -
   chunks removed from master_metadata.json (stored only in metadata_{id}.json);
   DMADatasetRef DTO added;
   DMACount now dynamic;
   hwVersion and framVersion added to SetConnectionContext;
   JSON property names updated with units (_bytes, _ms);
   internal visibility applied to all implementation classes;
   trailing zeros are removed in golden reports - saving file size on disk;
   included additional configurable boolean to skip the DMA delays in simulation mode.