Table of Contents

Struct PowerPlan

Namespace
Pamoja.Power
Assembly
Pamoja.Power.dll

The work intervals a node uses in each mode, and where they change.

public readonly record struct PowerPlan : IEquatable<PowerPlan>
Implements
Inherited Members

Remarks

A node on a battery and a panel has to decide how often to do anything at all. A plan stretches the interval between work as the charge falls, so a node that would otherwise go dark in a cloudy week keeps reporting, less often.

Constructors

PowerPlan(ulong, ulong, ulong, float, float, float)

The work intervals a node uses in each mode, and where they change.

public PowerPlan(ulong ActiveUs, ulong SaverUs, ulong CriticalUs, float SaverBelow, float CriticalBelow, float Hysteresis = 0.05)

Parameters

ActiveUs ulong

The interval at a healthy charge, in microseconds.

SaverUs ulong

The longer interval used to conserve, in microseconds.

CriticalUs ulong

The longest interval, in microseconds.

SaverBelow float

Enter Saver below this charge.

CriticalBelow float

Enter Critical below this charge.

Hysteresis float

How far above a threshold the charge must climb before the plan leaves the lower mode.

Remarks

A node on a battery and a panel has to decide how often to do anything at all. A plan stretches the interval between work as the charge falls, so a node that would otherwise go dark in a cloudy week keeps reporting, less often.

Fields

DefaultHysteresis

The margin a charge must climb past a threshold before a plan leaves the lower mode.

public const float DefaultHysteresis = 0.05

Field Value

float

Properties

ActiveUs

The interval at a healthy charge, in microseconds.

public ulong ActiveUs { get; init; }

Property Value

ulong

CriticalBelow

Enter Critical below this charge.

public float CriticalBelow { get; init; }

Property Value

float

CriticalUs

The longest interval, in microseconds.

public ulong CriticalUs { get; init; }

Property Value

ulong

Hysteresis

How far above a threshold the charge must climb before the plan leaves the lower mode.

public float Hysteresis { get; init; }

Property Value

float

SaverBelow

Enter Saver below this charge.

public float SaverBelow { get; init; }

Property Value

float

SaverUs

The longer interval used to conserve, in microseconds.

public ulong SaverUs { get; init; }

Property Value

ulong

Methods

Create(ulong, ulong, ulong)

Creates a plan from its three work intervals, with the defaults.

public static PowerPlan Create(ulong activeUs, ulong saverUs, ulong criticalUs)

Parameters

activeUs ulong

The interval at a healthy charge, in microseconds.

saverUs ulong

The longer interval used to conserve, in microseconds.

criticalUs ulong

The longest interval, in microseconds.

Returns

PowerPlan

The power plan.

Remarks

The defaults enter Saver below 50% charge and Critical below 20%, and leave each lower mode once the charge is DefaultHysteresis above the threshold that brought it on.

IntervalForUs(PowerMode)

Returns the work interval for a mode, in microseconds.

public ulong IntervalForUs(PowerMode mode)

Parameters

mode PowerMode

The mode to look up.

Returns

ulong

The interval in microseconds.

Exceptions

ArgumentOutOfRangeException

mode is not one of the PowerMode values.

IntervalUs(float)

Returns the work interval at a state of charge, in microseconds.

public ulong IntervalUs(float soc)

Parameters

soc float

The battery state of charge, from 0 through 1.

Returns

ulong

The interval in microseconds.

Mode(float)

Returns the mode this plan calls for at a state of charge.

public PowerMode Mode(float soc)

Parameters

soc float

The battery state of charge, from 0 through 1.

Returns

PowerMode

The mode the node should run in.

Remarks

A charge that is not a number, such as a fuel gauge that failed to answer, is taken as critical.

ModeWhileCharging(float, bool)

Returns the mode, eased one step toward full duty while charging.

public PowerMode ModeWhileCharging(float soc, bool charging)

Parameters

soc float

The battery state of charge, from 0 through 1.

charging bool

Whether the node is taking charge.

Returns

PowerMode

The mode the node should run in.

NextMode(PowerMode, float)

Returns the mode a node in current moves to at a new charge.

public PowerMode NextMode(PowerMode current, float soc)

Parameters

current PowerMode

The mode the node is running in.

soc float

The battery state of charge, from 0 through 1.

Returns

PowerMode

The mode the node should run in next.

Remarks

The node drops to a lower mode as soon as the charge falls below that mode's threshold, and climbs back only once the charge reaches the threshold plus Hysteresis, so a charge wandering around a threshold keeps the node where it is.

Exceptions

ArgumentOutOfRangeException

current is not one of the PowerMode values.

NextModeWhileCharging(PowerMode, float, bool)

Returns the mode a node in current moves to, eased one step toward full duty while charging.

public PowerMode NextModeWhileCharging(PowerMode current, float soc, bool charging)

Parameters

current PowerMode

The mode the node is running in, as this returned it last time.

soc float

The battery state of charge, from 0 through 1.

charging bool

Whether the node is taking charge.

Returns

PowerMode

The mode the node should run in next.

Exceptions

ArgumentOutOfRangeException

current is not one of the PowerMode values.

WithHysteresis(float)

Returns a plan with the hysteresis margin moved.

public PowerPlan WithHysteresis(float margin)

Parameters

margin float

How far above a threshold the charge must climb before the plan leaves the lower mode; 0 switches at the thresholds themselves, and a margin below zero or not a number is taken as 0.

Returns

PowerPlan

The adjusted plan.

WithThresholds(float, float)

Returns a plan with the state-of-charge thresholds moved.

public PowerPlan WithThresholds(float saverBelow, float criticalBelow)

Parameters

saverBelow float

Enter saver mode below this charge.

criticalBelow float

Enter critical mode below this charge.

Returns

PowerPlan

The adjusted plan.