rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
kst_prog_card.c File Reference

The programmer's files on the card: the save, the list and the load of kst_prog.h as the state sends them and takes their answers back. More...

#include <string.h>
#include "kst_prog.h"
#include "kst_prog_int.h"

Functions

static kst_prog_msg_id_t card_free (const kst_prog_t *p)
 Whether the card can take a request now.
static kst_prog_msg_id_t load_ready (const kst_prog_t *p, unsigned *arg)
 What a load needs of the servo, when it is asked for and when the file is there.
kst_prog_msg_id_t kst_prog_save (kst_prog_t *p, const char *name)
 Save the servo's image to a new file with name.
kst_prog_msg_id_t kst_prog_files (kst_prog_t *p, unsigned first)
 Ask for the list of files from file first on, counted from 0: up to KST_PROG_FILES_MAX of them.
unsigned kst_prog_files_first (const kst_prog_t *p)
 The number of the last list's first file among the card's.
kst_prog_msg_id_t kst_prog_load (kst_prog_t *p, const char *name)
 Load the file with name into the draft.
bool kst_prog_card_busy (const kst_prog_t *p)
 A save, a list or a load is on its way.
uint32_t kst_prog_files_seq (const kst_prog_t *p)
 The sequence number of the file list.
const char * kst_prog_file_name (const kst_prog_t *p, unsigned i)
 The names of the last list, i from 0; "" beyond them.
unsigned kst_prog_file_count (const kst_prog_t *p, unsigned *total)
 The entries of the last list and, when total is not NULL, the servo files on the card.
unsigned kst_prog_file_type (const kst_prog_t *p, unsigned i)
 That file's servo type as the card's side gave it; 0 none.
kst_field_set_t kst_prog_load_skipped (const kst_prog_t *p)
 The fields in which the file in the draft differs from the servo and that are never written; 0 once the servo is read again or the draft is discarded.
const char * kst_prog_preset_name (const kst_prog_t *p)
 The next preset name as the last list gave it; "" when none is left.
const char * kst_prog_card_name (const kst_prog_t *p)
 The file last saved or asked for.
kst_prog_file_kind_t kst_prog_load_kind (const kst_prog_t *p)
 What the file last loaded is.
unsigned kst_prog_load_named (const kst_prog_t *p, unsigned *fields)
 The fields the file last loaded gives a value for, and through fields, when not NULL, the named fields a file has: 0 where the card's side did not count them.
bool kst_prog_card_take (kst_prog_t *p, kst_prog_card_req_t *out)
 A request for the card's side; false while there is none.
static void name_copy (char *to, const char *from)
 Copies a file name, at most KST_PROG_NAME_MAX - 1 characters.
static unsigned card_message (unsigned result, bool load)
 The message for a card result.
static void save_done (kst_prog_t *p, const kst_prog_card_done_t *d)
 Takes the answer of a save.
static void list_done (kst_prog_t *p, const kst_prog_card_done_t *d)
 Takes the answer of a list.
static void load_done (kst_prog_t *p, const kst_prog_card_done_t *d)
 Takes the answer of a load.
static void save_late (kst_prog_t *p, const kst_prog_card_done_t *d)
 The card ends a save this model gave up at KST_PROG_CARD_MS.
void kst_prog_card_done (kst_prog_t *p, const kst_prog_card_done_t *done)
 What the card's side made of it.

Detailed Description

The programmer's files on the card: the save, the list and the load of kst_prog.h as the state sends them and takes their answers back.

See kst_prog.h and kst_card.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ card_free()

kst_prog_msg_id_t card_free ( const kst_prog_t * p)
static

Whether the card can take a request now.

Parameters
pThe programmer state.
Returns
KST_PROG_MSG_NONE when it can, else the reason it cannot.

◆ card_message()

unsigned card_message ( unsigned result,
bool load )
static

The message for a card result.

Parameters
resultThe card result.
loadtrue for a load, false for a save or a list.
Returns
The message id.

◆ kst_prog_card_busy()

bool kst_prog_card_busy ( const kst_prog_t * p)

A save, a list or a load is on its way.

Parameters
pThe programmer state.
Returns
true while a card operation runs.

◆ kst_prog_card_done()

void kst_prog_card_done ( kst_prog_t * p,
const kst_prog_card_done_t * done )

What the card's side made of it.

An answer to a request that is no longer awaited changes nothing, but for one: the OK of a save given up at KST_PROG_CARD_MS names its file and, for the servo as it was saved, is the session's backup.

Parameters
pThe programmer state.
doneThe answer of the card.

◆ kst_prog_card_name()

const char * kst_prog_card_name ( const kst_prog_t * p)

The file last saved or asked for.

Parameters
pThe programmer state.
Returns
The name.

◆ kst_prog_card_take()

bool kst_prog_card_take ( kst_prog_t * p,
kst_prog_card_req_t * out )

A request for the card's side; false while there is none.

Parameters
pThe programmer state.
outReceives the request.
Returns
true when a request was taken.

◆ kst_prog_file_count()

unsigned kst_prog_file_count ( const kst_prog_t * p,
unsigned * total )

The entries of the last list and, when total is not NULL, the servo files on the card.

Parameters
pThe programmer state.
totalReceives the total number of servo files on the card, or NULL.
Returns
The number of files listed.

◆ kst_prog_file_name()

const char * kst_prog_file_name ( const kst_prog_t * p,
unsigned i )

The names of the last list, i from 0; "" beyond them.

Parameters
pThe programmer state.
iThe index in the list.
Returns
The name, or an empty string beyond the list.

◆ kst_prog_file_type()

unsigned kst_prog_file_type ( const kst_prog_t * p,
unsigned i )

That file's servo type as the card's side gave it; 0 none.

Parameters
pThe programmer state.
iThe index in the list.
Returns
The type, or 0 beyond the list.

◆ kst_prog_files()

kst_prog_msg_id_t kst_prog_files ( kst_prog_t * p,
unsigned first )

Ask for the list of files from file first on, counted from 0: up to KST_PROG_FILES_MAX of them.

kst_prog_files_seq() moves when it is there. Refused with KST_PROG_MSG_NEED_READ while the servo is in doubt.

Parameters
pThe programmer state.
firstThe index of the first file to list.
Returns
The message id.

◆ kst_prog_files_first()

unsigned kst_prog_files_first ( const kst_prog_t * p)

The number of the last list's first file among the card's.

Parameters
pThe programmer state.
Returns
The index.

◆ kst_prog_files_seq()

uint32_t kst_prog_files_seq ( const kst_prog_t * p)

The sequence number of the file list.

Parameters
pThe programmer state.
Returns
The sequence number, which moves when the list changes.

◆ kst_prog_load()

kst_prog_msg_id_t kst_prog_load ( kst_prog_t * p,
const char * name )

Load the file with name into the draft.

Taken with a servo read that passes the fingerprint and is not in doubt. A file of another servo type, a file with a value that is not taken, a file that breaks a hard rule and a file that is not whole change nothing. A file that breaks soft rules waits for kst_prog_soft_confirm().

Parameters
pThe programmer state.
nameThe file name.
Returns
The message id.

◆ kst_prog_load_kind()

kst_prog_file_kind_t kst_prog_load_kind ( const kst_prog_t * p)

What the file last loaded is.

Parameters
pThe programmer state.
Returns
The kind, as kst_prog_file_kind_t.

◆ kst_prog_load_named()

unsigned kst_prog_load_named ( const kst_prog_t * p,
unsigned * fields )

The fields the file last loaded gives a value for, and through fields, when not NULL, the named fields a file has: 0 where the card's side did not count them.

Parameters
pThe programmer state.
fieldsReceives the field set, or NULL.
Returns
The number of named fields.

◆ kst_prog_load_skipped()

kst_field_set_t kst_prog_load_skipped ( const kst_prog_t * p)

The fields in which the file in the draft differs from the servo and that are never written; 0 once the servo is read again or the draft is discarded.

Parameters
pThe programmer state.
Returns
The skipped fields.

◆ kst_prog_preset_name()

const char * kst_prog_preset_name ( const kst_prog_t * p)

The next preset name as the last list gave it; "" when none is left.

Parameters
pThe programmer state.
Returns
The preset name.

◆ kst_prog_save()

kst_prog_msg_id_t kst_prog_save ( kst_prog_t * p,
const char * name )

Save the servo's image to a new file with name.

The card's side says whether the name is one a file may have; a file is never replaced.

Parameters
pThe programmer state.
nameThe file name.
Returns
The message id.

◆ list_done()

void list_done ( kst_prog_t * p,
const kst_prog_card_done_t * d )
static

Takes the answer of a list.

Parameters
pThe programmer state.
dThe answer of the card.

◆ load_done()

void load_done ( kst_prog_t * p,
const kst_prog_card_done_t * d )
static

Takes the answer of a load.

Parameters
pThe programmer state.
dThe answer of the card.

◆ load_ready()

kst_prog_msg_id_t load_ready ( const kst_prog_t * p,
unsigned * arg )
static

What a load needs of the servo, when it is asked for and when the file is there.

Parameters
pThe programmer state.
argReceives the argument of that message.
Returns
The message for what is missing, or KST_PROG_MSG_NONE.

◆ name_copy()

void name_copy ( char * to,
const char * from )
static

Copies a file name, at most KST_PROG_NAME_MAX - 1 characters.

Parameters
toReceives the name.
fromThe name to copy.

◆ save_done()

void save_done ( kst_prog_t * p,
const kst_prog_card_done_t * d )
static

Takes the answer of a save.

Parameters
pThe programmer state.
dThe answer of the card.

◆ save_late()

void save_late ( kst_prog_t * p,
const kst_prog_card_done_t * d )
static

The card ends a save this model gave up at KST_PROG_CARD_MS.

The file is on the card: it is named, and it is the session's backup where a save by hand would be, so that the write that follows makes no second one.

Parameters
pThe programmer state.
dThe answer of the card.