Struct PowerPlan
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
ActiveUsulongThe interval at a healthy charge, in microseconds.
SaverUsulongThe longer interval used to conserve, in microseconds.
CriticalUsulongThe longest interval, in microseconds.
SaverBelowfloatEnter Saver below this charge.
CriticalBelowfloatEnter Critical below this charge.
HysteresisfloatHow 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
Properties
ActiveUs
The interval at a healthy charge, in microseconds.
public ulong ActiveUs { get; init; }
Property Value
CriticalBelow
Enter Critical below this charge.
public float CriticalBelow { get; init; }
Property Value
CriticalUs
The longest interval, in microseconds.
public ulong CriticalUs { get; init; }
Property Value
Hysteresis
How far above a threshold the charge must climb before the plan leaves the lower mode.
public float Hysteresis { get; init; }
Property Value
SaverBelow
Enter Saver below this charge.
public float SaverBelow { get; init; }
Property Value
SaverUs
The longer interval used to conserve, in microseconds.
public ulong SaverUs { get; init; }
Property Value
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
activeUsulongThe interval at a healthy charge, in microseconds.
saverUsulongThe longer interval used to conserve, in microseconds.
criticalUsulongThe 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
modePowerModeThe mode to look up.
Returns
- ulong
The interval in microseconds.
Exceptions
- ArgumentOutOfRangeException
modeis 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
socfloatThe 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
socfloatThe 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
socfloatThe battery state of charge, from 0 through 1.
chargingboolWhether 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
currentPowerModeThe mode the node is running in.
socfloatThe 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
currentis 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
currentPowerModeThe mode the node is running in, as this returned it last time.
socfloatThe battery state of charge, from 0 through 1.
chargingboolWhether the node is taking charge.
Returns
- PowerMode
The mode the node should run in next.
Exceptions
- ArgumentOutOfRangeException
currentis not one of the PowerMode values.
WithHysteresis(float)
Returns a plan with the hysteresis margin moved.
public PowerPlan WithHysteresis(float margin)
Parameters
marginfloatHow 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
saverBelowfloatEnter saver mode below this charge.
criticalBelowfloatEnter critical mode below this charge.
Returns
- PowerPlan
The adjusted plan.