|
K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
|
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 } |
Variables | |
| const struct kfsw_param_definition_set | kfsw_command_param_definitions |
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.
| #define KFSW_COMMAND_CLAIM_NAME_MAX 32U |
#include <command.h>
Longest claim owner name, including the terminator.
| #define KFSW_COMMAND_FLAG_MUTATING BIT(0) |
#include <command.h>
Command flags.
| #define KFSW_COMMAND_PARAM_TABLE_ID 28U |
#include <command.h>
Parameter table of this service, in the service band.
| #define KFSW_COMMAND_PARAM_TABLE_NAME "command" |
#include <command.h>
Parameter table name.
| typedef void(* kfsw_command_echo_handler_t) (bool enabled) |
#include <command.h>
Applies console echo; provided by the application.
| 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.
#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. |
| enum kfsw_command_status |
#include <command.h>
Outcome of one command invocation.
| enum kfsw_command_type |
#include <command.h>
Argument and result value kinds carried on the wire.
#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.
| 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.
| mode | How to treat another thread's invocation. |
| owner | Short name of the holder, shown in a refusal and in status. |
| 0 | Claimed. |
| -EINVAL | owner is NULL, empty or longer than the limit. |
| -EBUSY | Another thread holds the claim. |
| int kfsw_command_claim_get | ( | struct kfsw_command_claim_state * | state | ) |
| int kfsw_command_claim_release | ( | void | ) |
#include <command.h>
Release a claim held by the calling thread.
| 0 | Released, or nothing was held. |
| -EPERM | Another thread holds the claim. |
| bool kfsw_command_echo_enabled | ( | void | ) |
| int kfsw_command_find | ( | const char * | name, |
| struct kfsw_command_info * | info | ||
| ) |
| int kfsw_command_get_stats | ( | struct kfsw_command_stats * | stats | ) |
| 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.
| 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.
| 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.
| bool kfsw_command_is_initialized | ( | void | ) |
#include <command.h>
Return whether the registry was built successfully.
| 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.
| text | Argument as written. | |
| type | Type the command declares for that position. | |
| [out] | arg | Destination. |
| 0 | Converted. |
| -EINVAL | text is not a number where one is required, or a NULL was given. |
| -ENAMETOOLONG | The text is longer than KFSW_COMMAND_MAX_TEXT_SIZE. |
| -ENOTSUP | The type is not one this service carries. |
| void kfsw_command_set_echo | ( | bool | enabled | ) |
#include <command.h>
Change console echo and apply it through the registered 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.
| 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.
| void kfsw_command_visit | ( | kfsw_command_visitor_t | visitor, |
| void * | context | ||
| ) |
#include <command.h>
Visit each registered command.
|
extern |
#include <command.h>
Command counters and reply timeout.