Class Node
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
Node(Profile, Func<ValueTask<float>>, ILink, Func<bool, ValueTask>?, IPolicy?, Func<float, byte[]>?)
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
profileProfileThe profile the node runs.
readFunc<ValueTask<float>>Takes one reading, in the unit the profile reads.
linkILinkThe link each reading is published over, connected before the node runs.
driveFunc<bool, ValueTask>Switches the output a profile drives; required for a setpoint profile.
policyIPolicyWhat decides each reading: the profile's own controller unless given, a policy of the program's own, or what Resolve(Profile) returned.
encodeFunc<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
driveis 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
Profile
Gets the profile the node runs.
public Profile Profile { get; }
Property Value
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
batteryFunc<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.
onTickFunc<Tick, ValueTask>Hears each tick, such as to log it or to act on an alert.
onErrorFunc<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.
ticksint?How many ticks to run before returning; until cancelled unless given.
waitFunc<TimeSpan, CancellationToken, Task>Waits between ticks; Delay(TimeSpan, CancellationToken) unless given, which a test replaces to run at once.
cancellationTokenCancellationTokenStops 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
chargefloatThe state of charge, from 0 to 1.
chargingboolWhether the panel is delivering charge.
Returns
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()