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

The programmer's journal file: the text of a write to the servo that survives a restart of the panel, and the parse of it. More...

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

Data Structures

struct  loaded_t
 A parsed file: its journal record and its target image. More...

Functions

static uint16_t crc16 (const char *s, size_t n)
 The link CRC-16 of n bytes.
static char * put (char *at, const char *s)
 Appends a string without its terminator.
static char * put_hex (char *at, unsigned v, unsigned digits)
 Appends v as upper-case hexadecimal digits.
static char * put_image (char *at, const char *key, const kst_image_t *img)
 Appends a line of a key and the image's registers in hexadecimal.
size_t kst_prog_file_text (const kst_prog_t *p, char *out, size_t n)
 The text of the state as it is, for a caller that only reads.
size_t kst_prog_file_take (kst_prog_t *p, char *out, size_t n)
 The file text is to be written: fill out and return its length; 0 while nothing is to be written or n is too small.
void kst_prog_file_done (kst_prog_t *p, bool ok)
 How the write of the text kst_prog_file_take() gave went.
static int hex (char c)
 The value of one hexadecimal digit.
static long take_hex (const char *s, unsigned digits)
 Reads a number of hexadecimal digits.
static bool take_image (const char *s, size_t left, const char *key, kst_image_t *img)
 "key" + 64 digits + newline at s, left bytes there.
static bool parse (loaded_t *into, const char *text, size_t len)
 Parses a file text into the loaded state.
bool kst_prog_file_whole (const char *text, size_t len)
 Whether text is a whole file: its version, its lines and its check value.
bool kst_prog_file_load (kst_prog_t *p, const char *text, size_t len)
 The file as found at start.

Variables

static const char k_head [] = "RCBENCH KST 2\n"
static const char k_head_1 [] = "RCBENCH KST 1\n"

Detailed Description

The programmer's journal file: the text of a write to the servo that survives a restart of the panel, and the parse of it.

See kst_prog.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ crc16()

uint16_t crc16 ( const char * s,
size_t n )
static

The link CRC-16 of n bytes.

Parameters
sThe bytes.
nThe number of bytes.
Returns
The CRC-16 of the bytes at s.

◆ hex()

int hex ( char c)
static

The value of one hexadecimal digit.

Parameters
cThe character.
Returns
The value 0 to 15, or -1 when c is no hexadecimal digit.

◆ kst_prog_file_done()

void kst_prog_file_done ( kst_prog_t * p,
bool ok )

How the write of the text kst_prog_file_take() gave went.

The answer to a write's journal releases that write when the card completed the file and the write's start gate holds as it is now: the port in PROGRAMMING on the write's port, no STOP, the bench not ARMED and ENABLE WRITE TO SERVO on. Otherwise the write ends as one that did not start: nothing goes to the servo, its record is cleared, and the message names the gate that refused it, or KST_PROG_MSG_STORE_FAILED.

Parameters
pThe programmer state.
oktrue when the card completed the file.

◆ kst_prog_file_load()

bool kst_prog_file_load ( kst_prog_t * p,
const char * text,
size_t len )

The file as found at start.

False, with KST_PROG_MSG_FILE_BAD, for a text that is not whole.

Parameters
pThe programmer state.
textThe file text.
lenThe length of the text, in bytes.
Returns
true when the text is a whole valid file.

◆ kst_prog_file_take()

size_t kst_prog_file_take ( kst_prog_t * p,
char * out,
size_t n )

The file text is to be written: fill out and return its length; 0 while nothing is to be written or n is too small.

Parameters
pThe programmer state.
outReceives the text.
nThe size of out, in bytes.
Returns
The number of bytes written to out; 0 when none is wanted.

◆ kst_prog_file_text()

size_t kst_prog_file_text ( const kst_prog_t * p,
char * out,
size_t n )

The text of the state as it is, for a caller that only reads.

Parameters
pThe programmer state.
outReceives the text.
nThe size of out, in bytes.
Returns
The number of bytes written; 0 when out is too small.

◆ kst_prog_file_whole()

bool kst_prog_file_whole ( const char * text,
size_t len )

Whether text is a whole file: its version, its lines and its check value.

Changes nothing and says nothing.

Parameters
textThe file text.
lenThe length of the text, in bytes.
Returns
true when the text parses.

◆ parse()

bool parse ( loaded_t * into,
const char * text,
size_t len )
static

Parses a file text into the loaded state.

Parameters
intoReceives the loaded file.
textThe file text.
lenThe length of the text, in bytes.
Returns
true when the text is a valid file.

◆ put()

char * put ( char * at,
const char * s )
static

Appends a string without its terminator.

Parameters
atWhere the text goes.
sThe text.
Returns
The position after the text.

◆ put_hex()

char * put_hex ( char * at,
unsigned v,
unsigned digits )
static

Appends v as upper-case hexadecimal digits.

Parameters
atWhere the digits go.
vThe value.
digitsThe number of hexadecimal digits written.
Returns
The position after the digits.

◆ put_image()

char * put_image ( char * at,
const char * key,
const kst_image_t * img )
static

Appends a line of a key and the image's registers in hexadecimal.

Parameters
atWhere the line goes.
keyThe key of the line.
imgThe image.
Returns
The position after the line.

◆ take_hex()

long take_hex ( const char * s,
unsigned digits )
static

Reads a number of hexadecimal digits.

digits hexadecimal digits at s; -1 for anything else.

Parameters
sThe text.
digitsThe number of digits to read.
Returns
The value, or -1 for anything else.

◆ take_image()

bool take_image ( const char * s,
size_t left,
const char * key,
kst_image_t * img )
static

"key" + 64 digits + newline at s, left bytes there.

Parameters
sThe text.
leftThe bytes left at s.
keyThe key the line starts with.
imgReceives the image.
Returns
true when the line is read.