Utilities
GUIDUtil
- class rtiumaapy.guid_util.GUIDUtil[source]
Bases:
objectGUID generation and conversion for NumericGUID (octet[16]) fields.
UMAA identifier fields (
sessionID,source.id,destination.id,setID, etc.) are allNumericGUID—typedef octet NumericGUID[16]— raw 16-byte arrays. This class provides generation, conversion, and hex formatting for CFT filter expressions.- static generate() bytes[source]
Generate a random 128-bit GUID as 16 raw bytes.
Uses
uuid.uuid4()(cryptographic random) under the hood.
- static to_hex(guid: bytes) str[source]
Convert 16 raw bytes to space-separated hex for
&hex()CFT filters.Example:
>>> GUIDUtil.to_hex(b'\x55\x0e\x84\x00' + b'\x00' * 12) '55 0e 84 00 00 00 00 00 00 00 00 00 00 00 00 00'
- static to_string(guid: bytes) str[source]
Convert 16 raw bytes to a human-readable UUID string.
Example:
>>> GUIDUtil.to_string(bytes.fromhex('550e8400e29b41d4a716446655440000')) '550e8400-e29b-41d4-a716-446655440000'
- static from_string(s: str) bytes[source]
Convert a UUID string to 16 raw bytes.
Example:
>>> GUIDUtil.from_string('550e8400-e29b-41d4-a716-446655440000') b'U\x0e\x84\x00\xe2\x9bA\xd4\xa7\x16DfUD\x00\x00'
- static make_source_id(guid_hex: str | None = None)[source]
Build an
IdentifierTypefrom an optional hex GUID string.If guid_hex is
None, a random GUID is generated automatically.- Parameters:
guid_hex – A 32-character hex string (with or without dashes). If omitted, a random UUID4 is generated.
- Returns:
An
IdentifierTypewith bothidandparentIDset to the sameNumericGUID.
GUID generation and conversion for UMAA NumericGUID (octet[16]) fields.
from rtiumaapy import GUIDUtil
# Generate a random GUID
guid_bytes = GUIDUtil.generate() # → 16 bytes
# Convert to hex for CFT filter expressions
hex_str = GUIDUtil.to_hex(guid_bytes)
# → "55 0e 84 00 e2 9b 41 d4 a7 16 44 66 55 44 00 00"
# Convert to human-readable UUID string
uuid_str = GUIDUtil.to_string(guid_bytes)
# → "550e8400-e29b-41d4-a716-446655440000"
# Parse back from UUID string
parsed = GUIDUtil.from_string("550e8400-e29b-41d4-a716-446655440000")
UmaaTimestamp
- class rtiumaapy.timestamp.UmaaTimestamp[source]
Bases:
objectConversion between UMAA
DateTimeTypeand Pythondatetime.All methods are static — no instance state required.
The
DateTimeTypeIDL struct carries two fields:seconds— POSIX epoch seconds (int64)nanoseconds— sub-second nanoseconds (uint32, 0–999 999 999)
These helpers convert to/from Python
datetimeobjects in UTC.- static now() DateTimeFields[source]
Return the current UTC time as
DateTimeFields.Microsecond precision (Python
datetimelimit) — nanosecond field is set tomicrosecond * 1000.
- static from_datetime(dt: datetime) DateTimeFields[source]
Convert a Python
datetimetoDateTimeFields.If dt is naive (no tzinfo), it is assumed to be UTC.
Conversion between UMAA DateTimeType and Python datetime.
from rtiumaapy import UmaaTimestamp, set_timestamp
# Set a sample's timestamp to now
set_timestamp(my_sample)
# Get current time as DateTimeFields
ts = UmaaTimestamp.now()
print(ts.seconds, ts.nanoseconds)
# Convert from Python datetime
from datetime import datetime, timezone
dt = datetime.now(timezone.utc)
ts = UmaaTimestamp.from_datetime(dt)
# Convert back to datetime
dt_back = UmaaTimestamp.to_datetime(ts)
Building Source Identities
UMAA services require an IdentifierType with id and parentID
fields (both NumericGUID). Here’s the standard pattern:
import rti.connextdds as dds
from rtiumaapy import GUIDUtil
from rtiumaapy.datamodel.HealthReportType import (
UMAA_Common_IdentifierType as IdentifierType,
UMAA_Common_Measurement_NumericGUID as NumericGUID,
)
guid_bytes = GUIDUtil.generate()
source_id = IdentifierType(
id=NumericGUID(value=dds.Uint8Seq(guid_bytes)),
parentID=NumericGUID(value=dds.Uint8Seq(guid_bytes)),
)
For command providers, this identity is used as the content filter — only
commands addressed to this source_id are delivered.