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

Public Headers

file  command.h
 

Data Structures

struct  kfsw_command_stats
 
struct  kfsw_command_claim_state
 
struct  kfsw_command_arg
 
struct  kfsw_command_source
 
struct  kfsw_command_result
 
struct  kfsw_command_definition
 
struct  kfsw_command_definition_set
 
struct  kfsw_command_info
 

Macros

#define KFSW_COMMAND_MAX_ARGS   4U
 
#define KFSW_COMMAND_MAX_TEXT_SIZE   64U
 
#define KFSW_COMMAND_MAX_DETAIL_SIZE   96U
 
#define KFSW_COMMAND_TIMEOUT_MIN_MS   1000U
 
#define KFSW_COMMAND_TIMEOUT_MAX_MS   120000U
 
#define KFSW_COMMAND_FLAG_MUTATING   BIT(0)
 
#define KFSW_COMMAND_CLAIM_NAME_MAX   32U
 
#define KFSW_COMMAND_PARAM_TABLE_ID   28U
 
#define KFSW_COMMAND_PARAM_TABLE_NAME   "command"
 

Types

typedef int(* kfsw_command_handler_t) (const struct kfsw_command_arg *args, size_t arg_count, const struct kfsw_command_source *source, struct kfsw_command_result *result)
 
typedef bool(* kfsw_command_visitor_t) (const struct kfsw_command_info *info, void *context)
 
typedef void(* kfsw_command_echo_handler_t) (bool enabled)
 

Enumerations

enum  kfsw_command_type { KFSW_COMMAND_TYPE_U32 = 1 , KFSW_COMMAND_TYPE_I32 = 2 , KFSW_COMMAND_TYPE_TEXT = 3 }
 
enum  kfsw_command_status {
  KFSW_COMMAND_OK = 0 , KFSW_COMMAND_UNKNOWN = 1 , KFSW_COMMAND_INVALID_ARGUMENT = 2 , KFSW_COMMAND_DENIED = 3 ,
  KFSW_COMMAND_BUSY = 4 , KFSW_COMMAND_FAILED = 5 , KFSW_COMMAND_UNAVAILABLE = 6
}
 
enum  kfsw_event_command_id { KFSW_EVENT_COMMAND_INVOKED = 1 , KFSW_EVENT_COMMAND_UNKNOWN = 2 , KFSW_EVENT_COMMAND_REJECTED = 3 }
 
enum  kfsw_command_claim_mode { KFSW_COMMAND_CLAIM_SHARED = 0 , KFSW_COMMAND_CLAIM_EXCLUSIVE = 1 }
 

Functions

int kfsw_command_init (const struct kfsw_command_definition_set *const *sets, size_t set_count)
 
bool kfsw_command_is_initialized (void)
 
void kfsw_command_visit (kfsw_command_visitor_t visitor, void *context)
 
int kfsw_command_parse_arg (const char *text, enum kfsw_command_type type, struct kfsw_command_arg *arg)
 
int kfsw_command_find (const char *name, struct kfsw_command_info *info)
 
int kfsw_command_invoke (const char *name, const struct kfsw_command_arg *args, size_t arg_count, struct kfsw_command_result *result)
 
int kfsw_command_invoke_id (uint16_t id, const struct kfsw_command_arg *args, size_t arg_count, const struct kfsw_command_source *source, struct kfsw_command_result *result)
 
int kfsw_command_claim_acquire (enum kfsw_command_claim_mode mode, const char *owner)
 
int kfsw_command_claim_release (void)
 
int kfsw_command_claim_get (struct kfsw_command_claim_state *state)
 
const char * kfsw_command_status_name (enum kfsw_command_status status)
 
int kfsw_command_get_stats (struct kfsw_command_stats *stats)
 
void kfsw_command_set_echo_handler (kfsw_command_echo_handler_t handler)
 
bool kfsw_command_echo_enabled (void)
 
void kfsw_command_set_echo (bool enabled)
 

Variables

const struct kfsw_param_definition_set kfsw_command_param_definitions
 

Description

Local and remote commands.

kfsw_command_init() aggregates compile-time definition sets and freezes the registry. kfsw_command_invoke() resolves by name for a local caller; kfsw_command_invoke_id() resolves by wire identifier for the CSP front end. Both reach the same handler through the same validation.

kfsw_command_source carries the origin node and an authentication result that is always false. Authentication is not implemented; a handler must not treat any source as trusted.

Macro Documentation

◆ KFSW_COMMAND_CLAIM_NAME_MAX

#define KFSW_COMMAND_CLAIM_NAME_MAX   32U

#include <command.h>

Longest claim owner name, including the terminator.

◆ KFSW_COMMAND_FLAG_MUTATING

#define KFSW_COMMAND_FLAG_MUTATING   BIT(0)

#include <command.h>

Command flags.

◆ KFSW_COMMAND_PARAM_TABLE_ID

#define KFSW_COMMAND_PARAM_TABLE_ID   28U

#include <command.h>

Parameter table of this service, in the service band.

◆ KFSW_COMMAND_PARAM_TABLE_NAME

#define KFSW_COMMAND_PARAM_TABLE_NAME   "command"

#include <command.h>

Parameter table name.

Type Documentation

◆ kfsw_command_echo_handler_t

typedef void(* kfsw_command_echo_handler_t) (bool enabled)

#include <command.h>

Applies console echo; provided by the application.

◆ kfsw_command_handler_t

typedef int(* kfsw_command_handler_t) (const struct kfsw_command_arg *args, size_t arg_count, const struct kfsw_command_source *source, struct kfsw_command_result *result)

#include <command.h>

Command implementation.

Runs in the caller's thread under the command mutex. Remote requests use the command server thread, not the CSP router. Arguments have been checked for count and type. Text is NUL-terminated and valid only during the call.

Enumeration Documentation

◆ kfsw_command_claim_mode

#include <command.h>

How a claim holder shares the command path with everything else.

A claim does not serialize anything by itself: handlers already run one at a time. It decides what happens to an invocation from another thread while the holder is part way through a sequence of them.

Enumerator
KFSW_COMMAND_CLAIM_SHARED 

Another thread's invocation is served, and counted as an intrusion.

KFSW_COMMAND_CLAIM_EXCLUSIVE 

Another thread's invocation is refused, naming the holder.

◆ kfsw_command_status

#include <command.h>

Outcome of one command invocation.

◆ kfsw_command_type

#include <command.h>

Argument and result value kinds carried on the wire.

◆ kfsw_event_command_id

#include <command.h>

Event IDs of the command service.

IDs are never reused. Payload: command ID and source node as big-endian u16, then the status byte.

Enumerator
KFSW_EVENT_COMMAND_INVOKED 

A command ran, whatever its outcome.

KFSW_EVENT_COMMAND_UNKNOWN 

A request named a command this node does not implement.

KFSW_EVENT_COMMAND_REJECTED 

A request failed validation before any handler ran.

Function Documentation

◆ kfsw_command_claim_acquire()

int kfsw_command_claim_acquire ( enum kfsw_command_claim_mode  mode,
const char *  owner 
)

#include <command.h>

Claim the command path for a sequence of invocations.

The calling thread becomes the holder. Its own invocations are unaffected; an invocation from any other thread is served and counted in kfsw_command_claim_state::intrusions when the mode is shared, and refused with KFSW_COMMAND_BUSY naming owner when it is exclusive.

Calling it again from the holder changes the mode and keeps the counters, so a sequence can protect one part of itself.

Parameters
modeHow to treat another thread's invocation.
ownerShort name of the holder, shown in a refusal and in status.
Return values
0Claimed.
-EINVALowner is NULL, empty or longer than the limit.
-EBUSYAnother thread holds the claim.

◆ kfsw_command_claim_get()

int kfsw_command_claim_get ( struct kfsw_command_claim_state *  state)

#include <command.h>

Read the claim.

Returns -EINVAL for a NULL destination.

◆ kfsw_command_claim_release()

int kfsw_command_claim_release ( void  )

#include <command.h>

Release a claim held by the calling thread.

Return values
0Released, or nothing was held.
-EPERMAnother thread holds the claim.

◆ kfsw_command_echo_enabled()

bool kfsw_command_echo_enabled ( void  )

#include <command.h>

Whether console echo is enabled.

Off by default.

◆ kfsw_command_find()

int kfsw_command_find ( const char *  name,
struct kfsw_command_info *  info 
)

#include <command.h>

Look up one registered command by name.

Returns -ENOENT when absent.

◆ kfsw_command_get_stats()

int kfsw_command_get_stats ( struct kfsw_command_stats *  stats)

#include <command.h>

Read service statistics.

Returns -EINVAL for a NULL destination.

◆ kfsw_command_init()

int kfsw_command_init ( const struct kfsw_command_definition_set *const *  sets,
size_t  set_count 
)

#include <command.h>

Aggregate the supplied definition sets and freeze the registry.

Rejects duplicate identifiers, duplicate names, missing handlers, and argument counts above KFSW_COMMAND_MAX_ARGS.

◆ kfsw_command_invoke()

int kfsw_command_invoke ( const char *  name,
const struct kfsw_command_arg *  args,
size_t  arg_count,
struct kfsw_command_result *  result 
)

#include <command.h>

Invoke a command on this node by name.

◆ kfsw_command_invoke_id()

int kfsw_command_invoke_id ( uint16_t  id,
const struct kfsw_command_arg *  args,
size_t  arg_count,
const struct kfsw_command_source *  source,
struct kfsw_command_result *  result 
)

#include <command.h>

Invoke a command on this node by wire identifier.

◆ kfsw_command_is_initialized()

bool kfsw_command_is_initialized ( void  )

#include <command.h>

Return whether the registry was built successfully.

◆ kfsw_command_parse_arg()

int kfsw_command_parse_arg ( const char *  text,
enum kfsw_command_type  type,
struct kfsw_command_arg *  arg 
)

#include <command.h>

Convert one text argument to the type a command declares.

A text argument is not copied: text must outlive the invocation.

Parameters
textArgument as written.
typeType the command declares for that position.
[out]argDestination.
Return values
0Converted.
-EINVALtext is not a number where one is required, or a NULL was given.
-ENAMETOOLONGThe text is longer than KFSW_COMMAND_MAX_TEXT_SIZE.
-ENOTSUPThe type is not one this service carries.

◆ kfsw_command_set_echo()

void kfsw_command_set_echo ( bool  enabled)

#include <command.h>

Change console echo and apply it through the registered handler.

◆ kfsw_command_set_echo_handler()

void kfsw_command_set_echo_handler ( kfsw_command_echo_handler_t  handler)

#include <command.h>

Register the function that applies console echo, and apply the current value.

◆ kfsw_command_status_name()

const char * kfsw_command_status_name ( enum kfsw_command_status  status)

#include <command.h>

Human-readable name for a status, for shell output and logs.

◆ kfsw_command_visit()

void kfsw_command_visit ( kfsw_command_visitor_t  visitor,
void *  context 
)

#include <command.h>

Visit each registered command.

Variable Documentation

◆ kfsw_command_param_definitions

const struct kfsw_param_definition_set kfsw_command_param_definitions
extern

#include <command.h>

Command counters and reply timeout.