Skip to content

Commit

Permalink
Add timestamped struct base
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Aug 10, 2024
1 parent f675dbd commit 46c97df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
36 changes: 32 additions & 4 deletions runtimepy/net/arbiter/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from vcorelib.io.types import JsonObject as _JsonObject
from vcorelib.logging import LoggerMixin as _LoggerMixin
from vcorelib.logging import LoggerType as _LoggerType
from vcorelib.math import default_time_ns
from vcorelib.math.keeper import TimeSource
from vcorelib.namespace import Namespace as _Namespace

# internal
Expand All @@ -30,7 +32,7 @@
from runtimepy.net.arbiter.result import OverallResult, results
from runtimepy.net.connection import Connection as _Connection
from runtimepy.net.manager import ConnectionManager
from runtimepy.primitives import Uint32
from runtimepy.primitives import Uint32, Uint64
from runtimepy.primitives.array import PrimitiveArray
from runtimepy.struct import RuntimeStructBase
from runtimepy.struct import StructMap as _StructMap
Expand Down Expand Up @@ -67,17 +69,43 @@ async def build(self, app: "AppInfo", **kwargs) -> None:
self.array = self.env.array(**kwargs).array


class TimestampedStruct(RuntimeStruct):
"""A bast struct with a timestamp field."""

time_keeper: TimeSource = default_time_ns
timestamp: Uint64

def init_env(self) -> None:
"""Initialize this sample environment."""

self.timestamp = Uint64(value=type(self).time_keeper())
self.env.channel(
"timestamp",
self.timestamp,
description=(
"The nanosecond timestamp when this struct "
"instance was last updated."
),
)

def poll(self) -> None:
"""Update this instance's timestamp."""

self.timestamp.value = type(self).time_keeper()


W = _TypeVar("W", bound=RuntimeStruct)


class TrigStruct(RuntimeStruct, TrigMixin):
class TrigStruct(TimestampedStruct, TrigMixin):
"""A simple trig struct."""

iterations: Uint32

def init_env(self) -> None:
"""Initialize this sample environment."""

super().init_env()
TrigMixin.__init__(self, self.env)
self.iterations = Uint32()
self.env.int_channel("iterations", self.iterations, commandable=True)
Expand All @@ -91,16 +119,16 @@ def poll(self) -> None:
# Pylint bug?
self.dispatch_trig(self.iterations.value) # pylint: disable=no-member
self.iterations.value += 1 # pylint: disable=no-member
super().poll()


class SampleStruct(TrigStruct):
"""A sample runtime structure."""

def init_env(self) -> None:
"""Initialize this sample environment."""

sample_env(self.env)
super().init_env()
sample_env(self.env)

def poll(self) -> None:
"""
Expand Down
2 changes: 0 additions & 2 deletions tests/net/test_mtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# module under test
from runtimepy.net.mtu import discover_mtu

# from runtimepy.net.util import IPv6Host, normalize_host


def test_ipv4_mtu_discovery() -> None:
"""Test that we can discover maximum transmission units."""
Expand Down

0 comments on commit 46c97df

Please sign in to comment.