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

The text of the Hitec programmer's record of a write, and its parse. See hitec_card.h. More...

#include "hitec_card.h"
#include <string.h>
#include "link_crc.h"

Data Structures

struct  reader_t
 The text being read: where it is and where its body ends. More...

Macros

#define CHECK_LEN   11u
 The check line's length: "check=" 4 digits and the newline.
#define PIN_LAST   47u
 The highest GPIO of the IOmcu.

Functions

unsigned hitec_card_addrs (uint8_t series, uint8_t out[HITEC_C_BLOCK_LEN])
 The addresses a record holds for series.
static char * put (char *at, const char *s)
 Append s without its terminator.
static char * put_hex (char *at, unsigned v, unsigned digits)
 Append v as digits upper-case hexadecimal digits.
static char * put_image (char *at, const char *key, uint8_t series, const hitec_image_t *img)
 Append the line key with the record's addresses of img.
size_t hitec_card_text (const hitec_card_record_t *r, char *out, size_t n)
 The text of r, or of no record for NULL.
static long take_hex (const char *s, unsigned digits)
 The value of digits upper-case hexadecimal digits at s.
static const char * take_line (reader_t *r, const char *key, unsigned digits, long *v)
 Take the line "@p key + @p digits digits + newline".
static bool take_image (reader_t *r, const char *key, uint8_t series, hitec_image_t *img)
 Take an image line into img.
hitec_card_result_t hitec_card_parse (const char *text, size_t len, hitec_card_record_t *out)
 Parse a text.

Variables

static const char k_head [] = "RCBENCH HITEC 1\n"
 The first line.

Detailed Description

The text of the Hitec programmer's record of a write, and its parse. See hitec_card.h.

Hitec is a name or trademark of its owner; it is used here only to say which servos this module works with.

SPDX-License-Identifier: MIT

Function Documentation

◆ hitec_card_addrs()

unsigned hitec_card_addrs ( uint8_t series,
uint8_t out[HITEC_C_BLOCK_LEN] )

The addresses a record holds for series.

Parameters
serieshitec_family_t.
outReceives up to 36 addresses, ascending.
Returns
The count: 36 classic cells, 21 D series registers.

◆ hitec_card_parse()

hitec_card_result_t hitec_card_parse ( const char * text,
size_t len,
hitec_card_record_t * out )

Parse a text.

A record's images know the addresses hitec_card_addrs() names, nothing else. A pin above 47 reads as HITEC_CARD_NO_PIN.

Parameters
textThe text; it need not be terminated.
lenIts length in bytes.
outReceives the record on HITEC_CARD_OK; untouched otherwise.
Returns
A hitec_card_result_t.

◆ hitec_card_text()

size_t hitec_card_text ( const hitec_card_record_t * r,
char * out,
size_t n )

The text of r, or of no record for NULL.

Only the addresses hitec_card_addrs() names are written; a byte that is not known is written as its value all the same.

Parameters
rThe record; NULL for a text without one.
outReceives the text, terminated.
nBytes at out, HITEC_CARD_TEXT_MAX or more.
Returns
The length without the terminator; 0 when n is too small, r names a series other than classic and D, or a port above 15.

◆ put()

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

Append s without its terminator.

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

◆ put_hex()

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

Append v as digits upper-case hexadecimal digits.

Parameters
atWhere they go.
vThe value.
digitsThe count.
Returns
The position after them.

◆ put_image()

char * put_image ( char * at,
const char * key,
uint8_t series,
const hitec_image_t * img )
static

Append the line key with the record's addresses of img.

Parameters
atWhere it goes.
key"before=" or "target=".
serieshitec_family_t.
imgThe image.
Returns
The position after the line.

◆ take_hex()

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

The value of digits upper-case hexadecimal digits at s.

Parameters
sThe digits.
digitsTheir count, at most 4.
Returns
The value; -1 for a character that is no such digit.

◆ take_image()

bool take_image ( reader_t * r,
const char * key,
uint8_t series,
hitec_image_t * img )
static

Take an image line into img.

Parameters
rThe reader.
key"before=" or "target=".
serieshitec_family_t.
imgReceives the addresses, known; emptied first.
Returns
false when the line is not there.

◆ take_line()

const char * take_line ( reader_t * r,
const char * key,
unsigned digits,
long * v )
static

Take the line "@p key + @p digits digits + newline".

Parameters
rThe reader.
keyThe key.
digitsThe digits.
vReceives their value, for at most 4 digits; NULL to keep the place only.
Returns
The line's first digit; NULL when it is not there.