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

The card's side of the programmer for servos by Hitec: the text of the record of a write, which survives a restart of the panel, and its parse. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "hitec_reg.h"

Go to the source code of this file.

Data Structures

struct  hitec_card_record_t
 A record of a write. More...

Macros

#define HITEC_CARD_RECORD   "HITEC"
 The record's base name in CARD_HITEC_CONF: HITEC.TXT, and HITEC.NEW while it is written.
#define HITEC_CARD_TEXT_MAX   256u
 The text's size, with its terminator: a D series record takes 234 bytes.
#define HITEC_CARD_NO_PIN   0xFFu
 A pin that is not known.

Enumerations

enum  hitec_card_result_t {
  HITEC_CARD_OK = 0 , HITEC_CARD_NONE , HITEC_CARD_ERR_HEADER , HITEC_CARD_ERR_TRUNCATED ,
  HITEC_CARD_ERR_CHECK , HITEC_CARD_ERR_FIELD
}
 What a parse found. More...

Functions

unsigned hitec_card_addrs (uint8_t series, uint8_t out[HITEC_C_BLOCK_LEN])
 The addresses a record holds for series.
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.
hitec_card_result_t hitec_card_parse (const char *text, size_t len, hitec_card_record_t *out)
 Parse a text.

Detailed Description

The card's side of the programmer for servos by Hitec: the text of the record of a write, which survives a restart of the panel, and its parse.

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

Before the first step of a write, hitec_prog.h records the servo's values, the values the write is to leave, the series, the port and the GPIO that port drives. With a card mounted the record goes to BENCH/HITEC/CONF/HITEC.TXT (CARD_HITEC_CONF) and is read again at the panel's next start. A write that ends verified clears it: the text then holds no record.

The record holds the addresses a write can change: classic cells 0x00 to 0x23 (hitec_writable() and the balance 0x1C), and the 21 D series registers of a full read (hitec_d_read_list()). The text, at most HITEC_CARD_TEXT_MAX bytes with its terminator, X a hexadecimal digit:

RCBENCH HITEC 1 series=C or D the series of the write port=X the programming port, from 0 pin=XX its GPIO, FF not known before=XX... classic: 36 cells of 2 digits; D target=XX... series: 21 registers of 4 digits, high digit first check=XXXX link_crc() of the bytes before

A text with no record is the first line and the check line. The digits are upper case. A text that does not end with its check line, whose check does not match, or whose lines are not these, is refused whole.

Pure C, no heap, no card access: the caller writes and reads the bytes.

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ hitec_card_result_t

What a parse found.

Enumerator
HITEC_CARD_OK 

a record

HITEC_CARD_NONE 

a whole text that holds no record

HITEC_CARD_ERR_HEADER 

not "RCBENCH HITEC 1"

HITEC_CARD_ERR_TRUNCATED 

no check line at its end

HITEC_CARD_ERR_CHECK 

the check does not match

HITEC_CARD_ERR_FIELD 

a line that is not the one due

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.