K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Parameter limits

Data Structures

struct  kfsw_limits_rule
 
struct  kfsw_limits_status
 

Macros

#define KFSW_LIMITS_PARAM_TABLE_ID   40U
 
#define KFSW_LIMITS_PARAM_TABLE_NAME   "limits"
 
#define KFSW_LIMITS_FTP_PATH   "limits"
 
#define KFSW_LIMITS_BOUND_TEXT_MAX   24U
 
#define KFSW_LIMITS_INTERVAL_MIN_MS   100U
 
#define KFSW_LIMITS_INTERVAL_MAX_MS   3600000U
 
#define KFSW_LIMITS_DWELL_MAX   255U
 
#define KFSW_LIMITS_NO_RULE   255U
 

Types

typedef bool(* kfsw_limits_visitor_t) (const struct kfsw_limits_rule *rule, void *context)
 

Enumerations

enum  kfsw_limits_event { KFSW_EVENT_LIMITS_FIRED = 1 }
 
enum  kfsw_limits_cmp {
  KFSW_LIMITS_GT = 0 , KFSW_LIMITS_GE = 1 , KFSW_LIMITS_LT = 2 , KFSW_LIMITS_LE = 3 ,
  KFSW_LIMITS_EQ = 4 , KFSW_LIMITS_NE = 5
}
 

Functions

int kfsw_limits_init (void)
 
int kfsw_limits_load (const char *name)
 
int kfsw_limits_sweep (void)
 
int kfsw_limits_set_interval_ms (uint32_t interval_ms)
 
void kfsw_limits_get_status (struct kfsw_limits_status *status)
 
void kfsw_limits_visit_rules (kfsw_limits_visitor_t visitor, void *context)
 
const char * kfsw_limits_cmp_text (enum kfsw_limits_cmp cmp)
 

Variables

uint8_t kfsw_limits_enabled
 
uint32_t kfsw_limits_interval_ms
 
const struct kfsw_param_definition_set kfsw_limits_param_definitions
 

Description

Watches local or remote numeric parameters against a bound and releases a command when one is crossed.

The rules live in one text file under the FTP root, uploaded as a procedure is, and read at boot and on command:

# parameter cmp bound dwell node action
stack_worst_used > 90 3 0 resmon sample

The first five whitespace separated fields are the parameter, comparison, bound, dwell and node. Everything after them is the action, a registered command with its arguments, kept as written. A line starting with # is a comment. The parameter may be prefixed with <node>: to read remotely; 0: and this node's own address read locally. The node column still names the action destination. Nonzero prefixes require PARAM_CSP. Remote types and bounds are bound on reading, so the peer may be absent at load. Failed remote reads break the dwell, preserve the latch and release nothing.

A file with any bad line is refused whole and the previous rule set stays in force, so a rule set is never half loaded.

A rule fires once per crossing. It latches when its action is released and re-arms on the first sweep that finds the comparison false. The action goes through kfsw_fbo_schedule_add(), so the release is recorded, may target another node, and has no execution path of its own.

Macro Documentation

◆ KFSW_LIMITS_BOUND_TEXT_MAX

#define KFSW_LIMITS_BOUND_TEXT_MAX   24U

#include <limits.h>

Longest bound as written in the file, including the terminator.

◆ KFSW_LIMITS_DWELL_MAX

#define KFSW_LIMITS_DWELL_MAX   255U

#include <limits.h>

Longest dwell a rule may ask for.

◆ KFSW_LIMITS_FTP_PATH

#define KFSW_LIMITS_FTP_PATH   "limits"

#include <limits.h>

Rule files live in this directory of the FTP root.

◆ KFSW_LIMITS_INTERVAL_MAX_MS

#define KFSW_LIMITS_INTERVAL_MAX_MS   3600000U

#include <limits.h>

Longest periodic sweep.

◆ KFSW_LIMITS_INTERVAL_MIN_MS

#define KFSW_LIMITS_INTERVAL_MIN_MS   100U

#include <limits.h>

Shortest periodic sweep.

Zero turns the periodic sweep off.

◆ KFSW_LIMITS_NO_RULE

#define KFSW_LIMITS_NO_RULE   255U

#include <limits.h>

Value of last_fired_index before any rule has fired.

◆ KFSW_LIMITS_PARAM_TABLE_ID

#define KFSW_LIMITS_PARAM_TABLE_ID   40U

#include <limits.h>

Table 40: the counters of this service and its two switches.

◆ KFSW_LIMITS_PARAM_TABLE_NAME

#define KFSW_LIMITS_PARAM_TABLE_NAME   "limits"

#include <limits.h>

Parameter table name.

Type Documentation

◆ kfsw_limits_visitor_t

typedef bool(* kfsw_limits_visitor_t) (const struct kfsw_limits_rule *rule, void *context)

#include <limits.h>

Visit the rules in force.

Returning false stops the walk. The rule set is locked during the walk, so a visitor must not call back into this service.

Enumeration Documentation

◆ kfsw_limits_cmp

#include <limits.h>

How a parameter is compared with its bound.

◆ kfsw_limits_event

#include <limits.h>

Event source id of this service is KFSW_EVENT_SOURCE_LIMITS.

Enumerator
KFSW_EVENT_LIMITS_FIRED 

A rule released its action.

Payload: rule index, then the node as a big-endian u16.

Function Documentation

◆ kfsw_limits_cmp_text()

const char * kfsw_limits_cmp_text ( enum kfsw_limits_cmp  cmp)

#include <limits.h>

The symbol for a comparison, for listings.

◆ kfsw_limits_get_status()

void kfsw_limits_get_status ( struct kfsw_limits_status *  status)

#include <limits.h>

Read the counters.

◆ kfsw_limits_init()

int kfsw_limits_init ( void  )

#include <limits.h>

Read the configured rule file and start the periodic sweep.

A missing file or storage is not a failure: the node simply has no rules until one is loaded.

Return values
0Started, with or without rules.
negativeThe file exists and could not be loaded; see kfsw_limits_load(). The periodic sweep runs regardless.

◆ kfsw_limits_load()

int kfsw_limits_load ( const char *  name)

#include <limits.h>

Replace the rule set with the rules in a file.

Parameters
nameFile under the rule directory, without a path.
Return values
0The file was loaded; the streaks and latches of every rule restart.
-EINVALname is NULL, empty, too long or has a path, or a line of the file is bad. The previous set stays in force and the line is in kfsw_limits_get_status().
-ENODEVThere is no storage.
-ENOENTNo such file.
-EFBIGThe file is larger than the rule set could be.

◆ kfsw_limits_set_interval_ms()

int kfsw_limits_set_interval_ms ( uint32_t  interval_ms)

#include <limits.h>

Change the periodic sweep.

Zero stops it. Returns -ERANGE out of bounds.

◆ kfsw_limits_sweep()

int kfsw_limits_sweep ( void  )

#include <limits.h>

Evaluate local rules, then remote groups within a bounded time share.

Remote reads may block for half the interval, capped at 5000 ms; a manual sweep with interval zero uses 5000 ms. Deferred remote rules retain their streak and latch and resume next sweep. Do not call from the system workqueue.

Returns
Rules attempted, excluding deferred remote rules.
Return values
-EACCESThe service is disabled; streaks restart.

◆ kfsw_limits_visit_rules()

void kfsw_limits_visit_rules ( kfsw_limits_visitor_t  visitor,
void *  context 
)

#include <limits.h>

Visit the rules in force.

Variable Documentation

◆ kfsw_limits_enabled

uint8_t kfsw_limits_enabled
extern

#include <limits.h>

Nonzero lets the sweeps run.

Backs the limits_enabled parameter.

◆ kfsw_limits_interval_ms

uint32_t kfsw_limits_interval_ms
extern

#include <limits.h>

Milliseconds between periodic sweeps.

Backs limits_interval_ms.

◆ kfsw_limits_param_definitions

const struct kfsw_param_definition_set kfsw_limits_param_definitions
extern

#include <limits.h>

Parameter table of this service.