Table of Contents

Class Node

Namespace
Pamoja.Profile
Assembly
Pamoja.Profile.dll

A profile assembled around the parts that make it run.

public sealed class Node : IDisposable
Inheritance
Node
Implements
Inherited Members

Remarks

Each TickAsync() reads, lets the profile's policy decide, switches the output when the policy calls for it, and publishes the reading to the profile's topic. RunAsync(Func<ValueTask<(float Charge, bool Charging)>>?, Func<Tick, ValueTask>?, Func<Exception, ValueTask>?, int?, Func<TimeSpan, CancellationToken, Task>?, CancellationToken) repeats that at the cadence the profile's power schedule sets for the battery's charge. A node owns the controller it built for the profile, and disposing it releases that.

Constructors

Assembles a node.

public Node(Profile profile, Func<ValueTask<float>> read, ILink link, Func<bool, ValueTask>? drive = null, IPolicy? policy = null, Func<float, byte[]>? encode = null)

Parameters

profile Profile

The profile the node runs.

read Func<ValueTask<float>>

Takes one reading, in the unit the profile reads.

link ILink

The link each reading is published over, connected before the node runs.

drive Func<bool, ValueTask>

Switches the output a profile drives; required for a setpoint profile.

policy IPolicy

What decides each reading: the profile's own controller unless given, a policy of the program's own, or what Resolve(Profile) returned.

encode Func<float, byte[]>

Writes a reading as the payload published; the number as JSON text unless given.

Exceptions

PamojaException

The profile drives an output and no drive is given, or its control kind is custom and no policy decides it.

Properties

PowerMode

Gets the power mode the last Schedule(float, bool) chose, or null before the first.

public PowerMode? PowerMode { get; }

Property Value

PowerMode?

Profile

Gets the profile the node runs.

public Profile Profile { get; }

Property Value

Profile

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

RunAsync(Func<ValueTask<(float Charge, bool Charging)>>?, Func<Tick, ValueTask>?, Func<Exception, ValueTask>?, int?, Func<TimeSpan, CancellationToken, Task>?, CancellationToken)

Ticks, then waits the interval the battery's charge calls for, until cancelled.

public Task RunAsync(Func<ValueTask<(float Charge, bool Charging)>>? battery = null, Func<Tick, ValueTask>? onTick = null, Func<Exception, ValueTask>? onError = null, int? ticks = null, Func<TimeSpan, CancellationToken, Task>? wait = null, CancellationToken cancellationToken = default)

Parameters

battery Func<ValueTask<(float Charge, bool Charging)>>

Reads the battery before each wait, as a charge from 0 to 1 and whether the panel is charging; a node without one samples at the active cadence.

onTick Func<Tick, ValueTask>

Hears each tick, such as to log it or to act on an alert.

onError Func<Exception, ValueTask>

Hears a tick that failed. The loop carries on at the same cadence; without one, the failure ends the loop and is thrown.

ticks int?

How many ticks to run before returning; until cancelled unless given.

wait Func<TimeSpan, CancellationToken, Task>

Waits between ticks; Delay(TimeSpan, CancellationToken) unless given, which a test replaces to run at once.

cancellationToken CancellationToken

Stops the loop between ticks.

Returns

Task

A task that completes once cancelled or the ticks run out.

Schedule(float, bool)

Says what power mode the battery's charge puts the node in and how long to wait before the next tick.

public (PowerMode Mode, TimeSpan Wait) Schedule(float charge, bool charging = false)

Parameters

charge float

The state of charge, from 0 to 1.

charging bool

Whether the panel is delivering charge.

Returns

(PowerMode Mode, TimeSpan Wait)

The mode, and the wait.

Remarks

The node remembers the mode it chose, so a charge hovering at a threshold keeps the slower cadence until it clears the schedule's hysteresis.

TickAsync()

Runs one read, decide, act, and publish cycle.

public Task<Tick> TickAsync()

Returns

Task<Tick>

The reading and what the policy decided about it.