Class UdpStreamlinedSender

UDP sender implementing Unity's Streamlined Input Manager binary protocol.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

JSON configuration:

{
  "UnitySender": {
    "Type": "UdpStreamlinedSender",
    "Inputs": [ "ControlAlgorithm", "Myo", "Resampler" ],
    "Params": [ "127.0.0.1", 5005 ]
  }
}

Params:

IndexDescription
0HostIp (string) — target UDP host IP address.
1Port (int) — target UDP port number.

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
UdpStreamlinedSender
Namespace: MOSAIC.Models.Streaming
Assembly: MOSAIC.dll
Syntax
public sealed class UdpStreamlinedSender : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Overview: Sends structured binary messages over UDP with a standardised header. The block dispatches on the upstream sender's type name to determine the data category and serialisation format.

Packet layout:

| 0: count | 1: value type | 2: data type | 3: data subtype | 4–11: timestamp | 12…N-2: DATA | N-2…N-1: counter (UInt16) |

Data type / subtype combinations:

  • [0,0] EMG raw, [0,1] EMG ARV.
  • [1,x] PositionControl — subtype is DegreesOfActuation enum value.
  • [2,0] FMG raw, [2,1] FMG ARV.
  • [3,x] PositionControl2 — bimanual, same subtypes as [1,x].

Sender dispatch: The block uses the upstream block's type name to select the serialisation path: "ControlAlgorithm" / "ManualControl" → per-DOA double messages, "Myo" → sbyte EMG raw, "Resampler" → double EMG ARV, anything else with a vector → generic FMG raw as doubles.

Stream size: Upstream blocks control the stream size by choosing which DOAs to include in the published dictionary. Any DOA not in the dict is simply not serialised and no packet is sent for it. ManualControl exposes group gates (fingers / wrist / elbow) for exactly this purpose.

CSV logging: This block publishes vectors for downstream consumption. When a Path is specified, Dumper automatically logs published vectors via Publish(object).

Constructors

UdpStreamlinedSender(string, double, string, int)

Initializes a new UdpStreamlinedSender block.

Declaration
public UdpStreamlinedSender(string name = "UdpSender", double desiredRate = 0, string hostIp = "127.0.0.1", int port = 5005)
Parameters
Type Name Description
string name
double desiredRate
string hostIp
int port

Fields

FloatingTypes

Supported floating-point types for the binary protocol.

Declaration
private static readonly Type[] FloatingTypes
Field Value
Type Description
Type[]

MaxLogEntries

Maximum entries in the message log before oldest are trimmed.

Declaration
private const int MaxLogEntries = 50
Field Value
Type Description
int

SignedTypes

Supported signed integer types for the binary protocol.

Declaration
private static readonly Type[] SignedTypes
Field Value
Type Description
Type[]

UnsignedTypes

Supported unsigned integer types for the binary protocol.

Declaration
private static readonly Type[] UnsignedTypes
Field Value
Type Description
Type[]

_hostIp

Target host IP address.

Declaration
[ObservableProperty]
private string _hostIp
Field Value
Type Description
string

_isConnected

Whether the UDP connection has been established.

Declaration
[ObservableProperty]
private bool _isConnected
Field Value
Type Description
bool

_lastDataType

Last data type category sent (for UI display).

Declaration
[ObservableProperty]
private string _lastDataType
Field Value
Type Description
string

_lastSenderType

Last sender block type name (for UI display).

Declaration
[ObservableProperty]
private string _lastSenderType
Field Value
Type Description
string

_port

Target UDP port.

Declaration
[ObservableProperty]
private int _port
Field Value
Type Description
int

_totalBytesSent

Total bytes sent since connection.

Declaration
[ObservableProperty]
private long _totalBytesSent
Field Value
Type Description
long

_udpClient

UDP client for sending to Unity.

Declaration
private UdpClient _udpClient
Field Value
Type Description
UdpClient

_udpCounter

Rolling UDP message counter (wraps at UInt16 max).

Declaration
[ObservableProperty]
private ushort _udpCounter
Field Value
Type Description
ushort

_viz

Optional visualization bundle. Set by the ViewModel so the block can feed data to all monitors in one call.

Declaration
private BlockVisualization? _viz
Field Value
Type Description
BlockVisualization

Properties

HostIp

Target host IP address.

Declaration
[ExcludeFromCodeCoverage]
public string HostIp { get; set; }
Property Value
Type Description
string

IsConnected

Whether the UDP connection has been established.

Declaration
[ExcludeFromCodeCoverage]
public bool IsConnected { get; set; }
Property Value
Type Description
bool

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

LastDataType

Last data type category sent (for UI display).

Declaration
[ExcludeFromCodeCoverage]
public string LastDataType { get; set; }
Property Value
Type Description
string

LastSenderType

Last sender block type name (for UI display).

Declaration
[ExcludeFromCodeCoverage]
public string LastSenderType { get; set; }
Property Value
Type Description
string

MessageLog

Rolling log of recent messages (newest first, max 50).

Declaration
public ObservableCollection<string> MessageLog { get; }
Property Value
Type Description
ObservableCollection<string>

Port

Target UDP port.

Declaration
[ExcludeFromCodeCoverage]
public int Port { get; set; }
Property Value
Type Description
int

TotalBytesSent

Total bytes sent since connection.

Declaration
[ExcludeFromCodeCoverage]
public long TotalBytesSent { get; set; }
Property Value
Type Description
long

UdpCounter

Rolling UDP message counter (wraps at UInt16 max).

Declaration
[ExcludeFromCodeCoverage]
public ushort UdpCounter { get; set; }
Property Value
Type Description
ushort

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
Remarks

Blocks own their scope as a public Viz property rather than inheriting one, so the base class has no way to reach it. Overriding this is what lets the rate below be wired up automatically. With correct publication metadata, the bundle derives the time axis for one vector per publication or fixed-size contiguous sample packets from the feed shape.

When a plot needs a rate that publication frequency and feed shape cannot express (for example, variable-sized packets or overlapping windows), declare it with Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block with several bundles must configure each one; this hook exposes only one bundle.

Viz

Live plot for this block. Assigned by the ViewModel, which owns the scope.

Declaration
public BlockVisualization? Viz { get; set; }
Property Value
Type Description
BlockVisualization
Remarks

Setting this re-pushes the publish rate: the rate is normally pushed when it changes, which for these blocks happens during construction — before the ViewModel has handed over the scope — so without this the scope would never learn its time base.

Methods

ConfigureInput(IServiceProvider, JsonModel)

Creates a UdpStreamlinedSender from a JSON pipeline definition.

Declaration
public static UdpStreamlinedSender ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
UdpStreamlinedSender

Connect()

Opens the UDP connection to HostIp:Port.

Declaration
public void Connect()

Disconnect()

Closes and disposes the UDP client.

Declaration
public void Disconnect()

Dispose()

Disposes visualization, disconnects UDP, and releases base class resources.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

GetByteForType(Type)

Returns the protocol byte encoding for a numeric data type.

Declaration
private static byte GetByteForType(Type type)
Parameters
Type Name Description
Type type
Returns
Type Description
byte

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

OnHostIpChanged(string)

Executes the logic for when HostIp just changed.

Declaration
private void OnHostIpChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of HostIp is changed.

OnHostIpChanged(string?, string)

Executes the logic for when HostIp just changed.

Declaration
private void OnHostIpChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of HostIp is changed.

OnHostIpChanging(string)

Executes the logic for when HostIp is changing.

Declaration
private void OnHostIpChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of HostIp is changed.

OnHostIpChanging(string?, string)

Executes the logic for when HostIp is changing.

Declaration
private void OnHostIpChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of HostIp is changed.

OnIsConnectedChanged(bool)

Executes the logic for when IsConnected just changed.

Declaration
private void OnIsConnectedChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsConnected is changed.

OnIsConnectedChanged(bool, bool)

Executes the logic for when IsConnected just changed.

Declaration
private void OnIsConnectedChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsConnected is changed.

OnIsConnectedChanging(bool)

Executes the logic for when IsConnected is changing.

Declaration
private void OnIsConnectedChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsConnected is changed.

OnIsConnectedChanging(bool, bool)

Executes the logic for when IsConnected is changing.

Declaration
private void OnIsConnectedChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsConnected is changed.

OnLastDataTypeChanged(string)

Executes the logic for when LastDataType just changed.

Declaration
private void OnLastDataTypeChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of LastDataType is changed.

OnLastDataTypeChanged(string?, string)

Executes the logic for when LastDataType just changed.

Declaration
private void OnLastDataTypeChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of LastDataType is changed.

OnLastDataTypeChanging(string)

Executes the logic for when LastDataType is changing.

Declaration
private void OnLastDataTypeChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of LastDataType is changed.

OnLastDataTypeChanging(string?, string)

Executes the logic for when LastDataType is changing.

Declaration
private void OnLastDataTypeChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of LastDataType is changed.

OnLastSenderTypeChanged(string)

Executes the logic for when LastSenderType just changed.

Declaration
private void OnLastSenderTypeChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of LastSenderType is changed.

OnLastSenderTypeChanged(string?, string)

Executes the logic for when LastSenderType just changed.

Declaration
private void OnLastSenderTypeChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of LastSenderType is changed.

OnLastSenderTypeChanging(string)

Executes the logic for when LastSenderType is changing.

Declaration
private void OnLastSenderTypeChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of LastSenderType is changed.

OnLastSenderTypeChanging(string?, string)

Executes the logic for when LastSenderType is changing.

Declaration
private void OnLastSenderTypeChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of LastSenderType is changed.

OnPortChanged(int)

Executes the logic for when Port just changed.

Declaration
private void OnPortChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of Port is changed.

OnPortChanged(int, int)

Executes the logic for when Port just changed.

Declaration
private void OnPortChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of Port is changed.

OnPortChanging(int)

Executes the logic for when Port is changing.

Declaration
private void OnPortChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of Port is changed.

OnPortChanging(int, int)

Executes the logic for when Port is changing.

Declaration
private void OnPortChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of Port is changed.

OnReceive(object, object)

Dispatches incoming data based on the upstream sender type and serialises it using the Streamlined Input Manager binary protocol.

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender
object data
Overrides
BaseBlock.OnReceive(object, object)

OnTotalBytesSentChanged(long)

Executes the logic for when TotalBytesSent just changed.

Declaration
private void OnTotalBytesSentChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of TotalBytesSent is changed.

OnTotalBytesSentChanged(long, long)

Executes the logic for when TotalBytesSent just changed.

Declaration
private void OnTotalBytesSentChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of TotalBytesSent is changed.

OnTotalBytesSentChanging(long)

Executes the logic for when TotalBytesSent is changing.

Declaration
private void OnTotalBytesSentChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of TotalBytesSent is changed.

OnTotalBytesSentChanging(long, long)

Executes the logic for when TotalBytesSent is changing.

Declaration
private void OnTotalBytesSentChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of TotalBytesSent is changed.

OnUdpCounterChanged(ushort)

Executes the logic for when UdpCounter just changed.

Declaration
private void OnUdpCounterChanged(ushort value)
Parameters
Type Name Description
ushort value

The new property value that was set.

Remarks

This method is invoked right after the value of UdpCounter is changed.

OnUdpCounterChanged(ushort, ushort)

Executes the logic for when UdpCounter just changed.

Declaration
private void OnUdpCounterChanged(ushort oldValue, ushort newValue)
Parameters
Type Name Description
ushort oldValue

The previous property value that was replaced.

ushort newValue

The new property value that was set.

Remarks

This method is invoked right after the value of UdpCounter is changed.

OnUdpCounterChanging(ushort)

Executes the logic for when UdpCounter is changing.

Declaration
private void OnUdpCounterChanging(ushort value)
Parameters
Type Name Description
ushort value

The new property value being set.

Remarks

This method is invoked right before the value of UdpCounter is changed.

OnUdpCounterChanging(ushort, ushort)

Executes the logic for when UdpCounter is changing.

Declaration
private void OnUdpCounterChanging(ushort oldValue, ushort newValue)
Parameters
Type Name Description
ushort oldValue

The previous property value that is being replaced.

ushort newValue

The new property value being set.

Remarks

This method is invoked right before the value of UdpCounter is changed.

Reconnect()

Disconnects and reconnects (with potentially updated host/port).

Declaration
public void Reconnect()

SendUdpMessage(byte, Type, byte[], byte[])

Sends a standardised UDP message with the protocol header.

Declaration
private void SendUdpMessage(byte numCount, Type valType, byte[] dataType, byte[] data)
Parameters
Type Name Description
byte numCount
Type valType
byte[] dataType
byte[] data

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.