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

Data Structures

struct  kfsw_hk_entry
 
struct  kfsw_hk_sample
 
struct  kfsw_hk_stats
 
struct  kfsw_hk_store_info
 
struct  kfsw_hk_store_filter
 

Macros

#define KFSW_HK_PARAM_TABLE_ID   33U
 
#define KFSW_HK_PARAM_TABLE_NAME   "hk"
 
#define KFSW_HK_PROTOCOL_VERSION   1U
 
#define KFSW_HK_CLASS_MAX   7U
 
#define KFSW_HK_CLASS_DEFAULT   4U
 
#define KFSW_HK_CLASS_MASK_ALL   0xFFU
 
#define KFSW_HK_REPORT_ALL   0xFFU
 
#define KFSW_HK_HEADER_SIZE   10U
 
#define KFSW_HK_FLAG_INCOMPLETE   0x01U
 
#define KFSW_HK_FLAG_CLOCK_UNSET   0x02U
 
#define KFSW_HK_NODE_LOCAL   0U
 
#define KFSW_HK_APPLIED_UNSAVED   1
 
#define KFSW_HK_STORE_PATH   "/kfsw/hk"
 

Functions

int kfsw_hk_init (void)
 
bool kfsw_hk_is_ready (void)
 
int kfsw_hk_save (void)
 
int kfsw_hk_start (void)
 
int kfsw_hk_server_start (void)
 
int kfsw_hk_define (uint8_t report, const struct kfsw_hk_entry *entries, size_t count)
 
int kfsw_hk_define_class (uint8_t report, const struct kfsw_hk_entry *entries, size_t count, uint8_t retrieval_class)
 
int kfsw_hk_get_class (uint8_t report, uint8_t *retrieval_class)
 
int kfsw_hk_get_selected (uint8_t class_mask, uint16_t index, struct kfsw_hk_sample *sample)
 
int kfsw_hk_clear (uint8_t report)
 
int kfsw_hk_get_definition (uint8_t report, struct kfsw_hk_entry *entries, size_t *count)
 
int kfsw_hk_collect (uint8_t report)
 
int kfsw_hk_get (uint8_t report, uint16_t age, struct kfsw_hk_sample *sample)
 
int kfsw_hk_depth (uint8_t report, uint16_t *depth)
 
int kfsw_hk_set_period (uint8_t report, uint32_t period_ms)
 
int kfsw_hk_get_period (uint8_t report, uint32_t *period_ms)
 
void kfsw_hk_get_stats (struct kfsw_hk_stats *stats)
 
void kfsw_hk_set_enabled (bool enabled)
 
int kfsw_hk_set_store (uint8_t report, uint32_t interval_ms)
 
int kfsw_hk_set_beacon (uint8_t report, uint16_t node, uint32_t interval_ms)
 
int kfsw_hk_get_beacon (uint8_t report, uint16_t *node, uint32_t *interval_ms)
 
int kfsw_hk_clear_store (uint8_t report)
 
int kfsw_hk_get_store (uint8_t report, uint32_t *interval_ms)
 
bool kfsw_hk_enabled (void)
 
int kfsw_hk_store_query (uint8_t report, struct kfsw_hk_store_info *info)
 
int kfsw_hk_store_count (const struct kfsw_hk_store_filter *filter, uint16_t *records)
 
int kfsw_hk_store_read (const struct kfsw_hk_store_filter *filter, uint16_t index, struct kfsw_hk_sample *sample)
 
int kfsw_hk_store_extract (const struct kfsw_hk_store_filter *filter, const char *path, uint16_t *records)
 

Variables

const struct kfsw_param_definition_set kfsw_hk_param_definitions
 

Description

Macro Documentation

◆ KFSW_HK_APPLIED_UNSAVED

#define KFSW_HK_APPLIED_UNSAVED   1

#include <hk.h>

A setting took effect in RAM, but its snapshot could not be saved.

Setters return this value; last_save_error holds the filesystem error. A rejected snapshot is preserved until an explicit kfsw_hk_save().

◆ KFSW_HK_CLASS_MASK_ALL

#define KFSW_HK_CLASS_MASK_ALL   0xFFU

#include <hk.h>

All eight retrieval classes selected.

◆ KFSW_HK_CLASS_MAX

#define KFSW_HK_CLASS_MAX   7U

#include <hk.h>

K-FSW retrieval classes: a three-bit value, lower classes retrieved first.

◆ KFSW_HK_FLAG_CLOCK_UNSET

#define KFSW_HK_FLAG_CLOCK_UNSET   0x02U

#include <hk.h>

Set when the node's clock was not set, so the timestamp is zero.

Periodic collection waits for the clock, so this only appears on manual collections.

◆ KFSW_HK_FLAG_INCOMPLETE

#define KFSW_HK_FLAG_INCOMPLETE   0x01U

#include <hk.h>

Set when at least one entry could not be sampled and was zero-filled.

◆ KFSW_HK_HEADER_SIZE

#define KFSW_HK_HEADER_SIZE   10U

#include <hk.h>

Bytes before the first value in a serialised sample.

◆ KFSW_HK_NODE_LOCAL

#define KFSW_HK_NODE_LOCAL   0U

#include <hk.h>

Node number meaning the local node.

◆ KFSW_HK_PARAM_TABLE_ID

#define KFSW_HK_PARAM_TABLE_ID   33U

#include <hk.h>

Housekeeping parameter table.

◆ KFSW_HK_PROTOCOL_VERSION

#define KFSW_HK_PROTOCOL_VERSION   1U

#include <hk.h>

Wire format version; other versions are rejected.

◆ KFSW_HK_REPORT_ALL

#define KFSW_HK_REPORT_ALL   0xFFU

#include <hk.h>

Report selector for class-based retrieval across reports.

◆ KFSW_HK_STORE_PATH

#define KFSW_HK_STORE_PATH   "/kfsw/hk"

#include <hk.h>

Where stored samples are kept.

File transfer already serves this directory read-only, so an extract written here is downloadable without anything else.

Function Documentation

◆ kfsw_hk_clear()

int kfsw_hk_clear ( uint8_t  report)

#include <hk.h>

Delete a report definition and its samples.

◆ kfsw_hk_clear_store()

int kfsw_hk_clear_store ( uint8_t  report)

#include <hk.h>

Stop storing a report and delete its file.

Setting the interval to zero stops writing but keeps the file.

Parameters
reportReport index.
Return values
0Stopped, and the file is gone.
-EINVALUnknown report.

◆ kfsw_hk_collect()

int kfsw_hk_collect ( uint8_t  report)

#include <hk.h>

Collect a report now.

Blocks while remote values are read. Don't call it from a parameter sample callback, which holds the table lock this needs. Existing samples stay readable meanwhile. Returns -EAGAIN and drops the sample if the definition changed during the collection.

◆ kfsw_hk_define()

int kfsw_hk_define ( uint8_t  report,
const struct kfsw_hk_entry *  entries,
size_t  count 
)

#include <hk.h>

Set the values a report collects, replacing the old definition.

Every parameter must exist and the values must fit one sample. If not, the definition is refused and the previous one stays. Uses class 4 by default.

◆ kfsw_hk_define_class()

int kfsw_hk_define_class ( uint8_t  report,
const struct kfsw_hk_entry *  entries,
size_t  count,
uint8_t  retrieval_class 
)

#include <hk.h>

Define a report with a retrieval class (0..7).

Refuses larger values with -ERANGE before changing anything. Replacing a definition discards its history. Class affects retrieval only, never collection or scheduling.

◆ kfsw_hk_depth()

int kfsw_hk_depth ( uint8_t  report,
uint16_t *  depth 
)

#include <hk.h>

How many samples a report is currently holding.

◆ kfsw_hk_enabled()

bool kfsw_hk_enabled ( void  )

#include <hk.h>

Whether periodic collection is enabled.

Returns
True when reports with a period are being collected.

◆ kfsw_hk_get()

int kfsw_hk_get ( uint8_t  report,
uint16_t  age,
struct kfsw_hk_sample *  sample 
)

#include <hk.h>

Read back a collected sample, counting backwards from the newest.

age of 0 is the most recent. Returns -ENOENT past what the ring holds.

◆ kfsw_hk_get_beacon()

int kfsw_hk_get_beacon ( uint8_t  report,
uint16_t *  node,
uint32_t *  interval_ms 
)

#include <hk.h>

Read back a report's beacon destination and interval.

Parameters
reportReport index.
[out]nodeDestination address.
[out]interval_msMilliseconds between beacons, 0 when not beaconing.
Return values
0Written.
-EINVALUnknown report or a NULL destination.

◆ kfsw_hk_get_class()

int kfsw_hk_get_class ( uint8_t  report,
uint8_t *  retrieval_class 
)

#include <hk.h>

Read the class carried by a report definition; -ENOENT when undefined.

◆ kfsw_hk_get_definition()

int kfsw_hk_get_definition ( uint8_t  report,
struct kfsw_hk_entry *  entries,
size_t *  count 
)

#include <hk.h>

Copy a report's definition.

count is in and out.

◆ kfsw_hk_get_period()

int kfsw_hk_get_period ( uint8_t  report,
uint32_t *  period_ms 
)

#include <hk.h>

Read the configured period.

◆ kfsw_hk_get_selected()

int kfsw_hk_get_selected ( uint8_t  class_mask,
uint16_t  index,
struct kfsw_hk_sample *  sample 
)

#include <hk.h>

Read selected RAM samples across reports: lower class first, newest collection first within each class.

Bit n of class_mask selects class n; zero selects nothing. Index counts from zero. Returns -ENOENT past selected history.

◆ kfsw_hk_get_stats()

void kfsw_hk_get_stats ( struct kfsw_hk_stats *  stats)

#include <hk.h>

Copy the service counters.

◆ kfsw_hk_get_store()

int kfsw_hk_get_store ( uint8_t  report,
uint32_t *  interval_ms 
)

#include <hk.h>

Read back a report's store interval.

Parameters
reportReport index.
[out]interval_msMilliseconds between writes, 0 when RAM only.
Return values
0The interval was written.
-EINVALUnknown report or NULL destination.

◆ kfsw_hk_init()

int kfsw_hk_init ( void  )

#include <hk.h>

Prepare the service.

Safe to call before CSP exists.

◆ kfsw_hk_is_ready()

bool kfsw_hk_is_ready ( void  )

#include <hk.h>

True after restore finishes, including diagnostic operation with defaults.

◆ kfsw_hk_save()

int kfsw_hk_save ( void  )

#include <hk.h>

Save current settings explicitly; permits replacing a rejected snapshot.

◆ kfsw_hk_server_start()

int kfsw_hk_server_start ( void  )

#include <hk.h>

Serve housekeeping requests from other nodes.

Call after the router starts.

◆ kfsw_hk_set_beacon()

int kfsw_hk_set_beacon ( uint8_t  report,
uint16_t  node,
uint32_t  interval_ms 
)

#include <hk.h>

Send a report's newest sample to a node periodically.

The frame is the one a request gets, sent without a connection at low priority, and skipped when CSP buffers are short. Nothing is sent while the report is not collecting or the clock is not set.

Parameters
reportReport index.
nodeDestination address.
interval_msMilliseconds between beacons, or 0 to stop.
Return values
0Configured.
-EINVALUnknown report, or an address outside 1..KFSW_CSP_BROADCAST_ADDRESS - 1.
-ERANGEThe interval is below CONFIG_KFSW_HK_BEACON_FLOOR_MS.

◆ kfsw_hk_set_enabled()

void kfsw_hk_set_enabled ( bool  enabled)

#include <hk.h>

Start or stop periodic collection.

Definitions and samples are kept, and manual collection still works.

Parameters
enabledTrue to collect on each report's period.

◆ kfsw_hk_set_period()

int kfsw_hk_set_period ( uint8_t  report,
uint32_t  period_ms 
)

#include <hk.h>

Collect this report every period_ms, or stop when it is zero.

◆ kfsw_hk_set_store()

int kfsw_hk_set_store ( uint8_t  report,
uint32_t  interval_ms 
)

#include <hk.h>

Store a report's samples in a file, written every interval_ms.

The interval is capped by the ring depth so no sample is overwritten before it is written.

Parameters
reportReport index.
interval_msMilliseconds between writes, or 0 to keep samples in RAM.
Return values
0Storage configured.
-EINVALUnknown report.
-ENOENTThe report is not defined.
-ERANGEThe interval is below CONFIG_KFSW_HK_STORE_FLOOR_MS.
-ENOSPCThe file would not fit.
-ENODEVThere is no storage.

◆ kfsw_hk_start()

int kfsw_hk_start ( void  )

#include <hk.h>

Start collecting reports that have been given a period.

◆ kfsw_hk_store_count()

int kfsw_hk_store_count ( const struct kfsw_hk_store_filter *  filter,
uint16_t *  records 
)

#include <hk.h>

Count the stored records a filter selects.

Parameters
filterWhat to select.
[out]recordsHow many match.
Returns
The codes of kfsw_hk_store_query.

◆ kfsw_hk_store_extract()

int kfsw_hk_store_extract ( const struct kfsw_hk_store_filter *  filter,
const char *  path,
uint16_t *  records 
)

#include <hk.h>

Write the stored records a filter selects to a file, for downlink.

The file is a 20-byte header (magic KHKD, version, report, record size, record count, the first and last sequence, and a CRC32) followed by the matching records unchanged, so the ground decodes them with the report definition it already has. It is written beside the target and renamed over it, so an interrupted extract leaves the previous file.

Parameters
filterWhat to select.
pathFile to write.
[out]recordsHow many were written. May be NULL.
Return values
0The file holds the selected records.
-EINVALA NULL argument, or a path that is empty or too long.
-ENOENTNothing matched, and no file was written.
<0An errno from the filesystem; any previous file is unchanged.
Returns
Otherwise the codes of kfsw_hk_store_query.

◆ kfsw_hk_store_query()

int kfsw_hk_store_query ( uint8_t  report,
struct kfsw_hk_store_info *  info 
)

#include <hk.h>

Read what a report's stored history holds.

Parameters
reportReport index.
[out]infoDestination.
Return values
0Written.
-EINVALUnknown report or a NULL destination.
-ENODEVThere is no storage.
-ENOENTThe report has no file.
-EBADMSGThe file is not this report's store.

◆ kfsw_hk_store_read()

int kfsw_hk_store_read ( const struct kfsw_hk_store_filter *  filter,
uint16_t  index,
struct kfsw_hk_sample *  sample 
)

#include <hk.h>

Read one stored record a filter selects, oldest first.

The sample is the one kfsw_hk_get would have returned when it was collected, so the same printer and the same remote reply serve both.

Parameters
filterWhat to select.
indexPosition among the matching records, 0 being the oldest.
[out]sampleDestination.
Return values
0Written.
-ENOENTFewer records match than index asks for.
Returns
Otherwise the codes of kfsw_hk_store_query.

Variable Documentation

◆ kfsw_hk_param_definitions

const struct kfsw_param_definition_set kfsw_hk_param_definitions
extern

#include <hk.h>

Definitions this service publishes as parameter table 33.