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

The write side of the programmer for servos by Hitec: the draft and its edits, the soft rules and their confirmations, the write switch, the writes, and the record of a write. See hitec_prog.h. More...

#include "hitec_prog.h"
#include <string.h>
#include "hitec_prog_int.h"

Functions

static hitec_prog_msg_id_t say (hitec_prog_t *p, hitec_prog_msg_id_t id, unsigned arg)
 Say message id with one argument.
const hitec_image_t * hitec_prog_draft (const hitec_prog_t *p)
 The draft: the servo read with the edits; NULL with no servo read.
bool hitec_prog_can_edit (const hitec_prog_t *p)
 Whether an edit is taken now: the port held and idle, the servo in programming mode and read, the port not stopped.
bool hitec_prog_editable (const hitec_prog_t *p, uint8_t id)
 Whether parameter id of the servo's layout takes an edit.
bool hitec_prog_differs (const hitec_prog_t *p, const hitec_image_t *img, uint8_t id)
 Whether parameter id differs in img from the servo read: in its decoded value or in its stored value.
static unsigned differing (const hitec_prog_t *p, const hitec_image_t *img)
 The parameters in which img differs from the servo read.
unsigned hitec_prog_changes (const hitec_prog_t *p)
 The writable parameters in which the draft differs from the servo read.
bool hitec_prog_sum_bad (const hitec_prog_t *p)
 Whether the classic servo read has cells 0x00 to 0x1C that do not sum to 0.
bool hitec_prog_first_done (const hitec_prog_t *p)
 Whether the first write of this CONNECT has gone out.
bool hitec_prog_write_progress (const hitec_prog_t *p, unsigned *done, unsigned *total, uint8_t *kind)
 The progress of the running write.
static int32_t mag (int32_t v)
 The absolute value of v.
uint16_t hitec_prog_rules (const hitec_prog_t *p, uint8_t id, int32_t value)
 The soft rules value of parameter id breaks against the servo read.
static bool covered (const hitec_prog_t *p, uint8_t id, int32_t value)
 Whether a confirmation covers value of id: the value confirmed, or one on its side of the servo's value and no further from it.
static hitec_prog_msg_id_t edit_gate (const hitec_prog_t *p)
 Why an edit is not taken now.
static hitec_prog_edit_t trial (hitec_prog_t *p, uint8_t id, int32_t value, hitec_image_t *out)
 Take value of id into a copy of the draft.
hitec_prog_edit_t hitec_prog_edit (hitec_prog_t *p, uint8_t id, int32_t value)
 Edit the draft: value in the unit of parameter id.
uint16_t hitec_prog_pending (const hitec_prog_t *p, uint8_t *id, int32_t *value)
 The edit that waits for a confirmation.
hitec_prog_edit_t hitec_prog_confirm (hitec_prog_t *p)
 Take the edit that waits: its rules are confirmed for its value.
void hitec_prog_cancel (hitec_prog_t *p)
 Drop the edit that waits; the draft stays as it was.
static void unconfirm (hitec_prog_t *p)
 Every confirmation ends, and the edit that waits.
void hitec_prog_discard (hitec_prog_t *p)
 DISCARD EDITS: the draft is the servo read again, and every confirmation ends.
hitec_prog_msg_id_t hitec_prog_write_enable (hitec_prog_t *p, bool on)
 ENABLE WRITE TO SERVO.
bool hitec_prog_write_on (const hitec_prog_t *p)
 Whether ENABLE WRITE TO SERVO is on.
hitec_prog_msg_id_t hitec_prog_write_gate (const hitec_prog_t *p, uint8_t kind)
 Why a write of kind is not taken now, the switch included.
static void file_due (hitec_prog_t *p)
 The record's text is due on the card.
static void rec_clear (hitec_prog_t *p)
 The record ends: the write it stood for is verified, or nothing of it was sent.
static void not_sent (hitec_prog_t *p, hitec_ses_t r)
 A write that ended before a step reached the servo: the record goes with it, a RESTORE's excepted, and the switch goes off.
static void go (hitec_prog_t *p)
 The write goes out: its plan, step by step.
static hitec_prog_msg_id_t start (hitec_prog_t *p, uint8_t kind, const hitec_image_t *target)
 Start a write of kind to target.
hitec_prog_msg_id_t hitec_prog_write (hitec_prog_t *p)
 WRITE n VALUES: the draft to the servo, then its read-back.
hitec_prog_msg_id_t hitec_prog_repair (hitec_prog_t *p)
 REPAIR: the classic balance 0x1C alone, then the read-back.
static bool compared (uint8_t series, uint8_t addr)
 The addresses a write and the record compare: what a plan writes, without the classic balance.
static unsigned at (const hitec_image_t *img, uint8_t addr)
 The value at addr of img in its series' width.
bool hitec_prog_restore_image (const hitec_prog_t *p, hitec_image_t *out)
 The image RESTORE writes: the servo read with the record's values before the write.
hitec_prog_msg_id_t hitec_prog_restore (hitec_prog_t *p)
 RESTORE: the values before the recorded write back to the servo, as a write; the record stays until it ends verified.
static unsigned diff_count (const hitec_prog_t *p)
 How many addresses the read-back found different.
void hpw_write_done (hitec_prog_t *p, hitec_ses_t r)
 A write operation ended with r.
bool hitec_prog_record (const hitec_prog_t *p)
 Whether a record of a write stands.
hitec_prog_rec_t hitec_prog_record_verdict (const hitec_prog_t *p)
 What the last servo read holds of the record.
static hitec_prog_rec_t verdict (const hitec_prog_t *p)
 What the servo read holds of the record.
static void rec_compare (hitec_prog_t *p)
 Compare the servo read with the record and say what it holds.
hitec_prog_msg_id_t hitec_prog_forget (hitec_prog_t *p)
 FORGET: discard the record without a write.
bool hitec_prog_file_due (const hitec_prog_t *p)
 Whether the record's text is to go to the card.
size_t hitec_prog_file_take (hitec_prog_t *p, char *out, size_t n)
 The record's text for the card: fill out and return its length; 0 while none is due, no card is mounted or n is under HITEC_CARD_TEXT_MAX.
void hitec_prog_file_done (hitec_prog_t *p, bool ok)
 How the card took the text hitec_prog_file_take() gave.
bool hitec_prog_file_load (hitec_prog_t *p, const char *text, size_t len)
 The record's text as the card held it at the start.
void hpw_connect (hitec_prog_t *p)
 A CONNECT starts: the switch off, the edits and the confirmations gone; the record stays.
void hpw_off (hitec_prog_t *p)
 The write switch goes off: a LEAVE, a lost link, a stop.
void hpw_read_done (hitec_prog_t *p, bool had, const hitec_image_t *was)
 A full read ended well: the draft is the servo again, the switch goes off when the servo changed, and a record stands against it.
void hpw_tick (hitec_prog_t *p)
 Every feed: a stop switches the switch off, and a write that waits for the card gives up after HITEC_PROG_CARD_MS.
bool hpw_abort (hitec_prog_t *p)
 ABORT of a write that waits for the card: nothing was written.

Detailed Description

The write side of the programmer for servos by Hitec: the draft and its edits, the soft rules and their confirmations, the write switch, the writes, and the record of a write. See hitec_prog.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

◆ at()

unsigned at ( const hitec_image_t * img,
uint8_t addr )
static

The value at addr of img in its series' width.

Parameters
imgThe image.
addrThe address.
Returns
The cell or the register.

◆ compared()

bool compared ( uint8_t series,
uint8_t addr )
static

The addresses a write and the record compare: what a plan writes, without the classic balance.

Parameters
serieshitec_family_t.
addrThe address.
Returns
true when compared.

◆ covered()

bool covered ( const hitec_prog_t * p,
uint8_t id,
int32_t value )
static

Whether a confirmation covers value of id: the value confirmed, or one on its side of the servo's value and no further from it.

Parameters
pThe programmer.
idhitec_param_t.
valueThe value.
Returns
true when no new confirmation is needed.

◆ diff_count()

unsigned diff_count ( const hitec_prog_t * p)
static

How many addresses the read-back found different.

Parameters
pThe programmer.
Returns
The count.

◆ differing()

unsigned differing ( const hitec_prog_t * p,
const hitec_image_t * img )
static

The parameters in which img differs from the servo read.

Parameters
pThe programmer.
imgThe image.
Returns
The count.

◆ edit_gate()

hitec_prog_msg_id_t edit_gate ( const hitec_prog_t * p)
static

Why an edit is not taken now.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it is.

◆ file_due()

void file_due ( hitec_prog_t * p)
static

The record's text is due on the card.

Parameters
pThe programmer.

◆ go()

void go ( hitec_prog_t * p)
static

The write goes out: its plan, step by step.

Parameters
pThe programmer.

◆ hitec_prog_can_edit()

bool hitec_prog_can_edit ( const hitec_prog_t * p)

Whether an edit is taken now: the port held and idle, the servo in programming mode and read, the port not stopped.

Parameters
pThe programmer.
Returns
true when it is.

◆ hitec_prog_cancel()

void hitec_prog_cancel ( hitec_prog_t * p)

Drop the edit that waits; the draft stays as it was.

Parameters
pThe programmer.

◆ hitec_prog_changes()

unsigned hitec_prog_changes ( const hitec_prog_t * p)

The writable parameters in which the draft differs from the servo read.

Parameters
pThe programmer.
Returns
The count; 0 with no servo read.

◆ hitec_prog_confirm()

hitec_prog_edit_t hitec_prog_confirm ( hitec_prog_t * p)

Take the edit that waits: its rules are confirmed for its value.

Parameters
pThe programmer.
Returns
What the edit came to; HITEC_PROG_EDIT_REFUSED with none waiting.

◆ hitec_prog_differs()

bool hitec_prog_differs ( const hitec_prog_t * p,
const hitec_image_t * img,
uint8_t id )

Whether parameter id differs in img from the servo read: in its decoded value or in its stored value.

Parameters
pThe programmer.
imgThe image; the draft for NULL.
idhitec_param_t.
Returns
true when it differs.

◆ hitec_prog_discard()

void hitec_prog_discard ( hitec_prog_t * p)

DISCARD EDITS: the draft is the servo read again, and every confirmation ends.

Parameters
pThe programmer.

◆ hitec_prog_draft()

const hitec_image_t * hitec_prog_draft ( const hitec_prog_t * p)

The draft: the servo read with the edits; NULL with no servo read.

Parameters
pThe programmer.
Returns
The draft.

◆ hitec_prog_edit()

hitec_prog_edit_t hitec_prog_edit ( hitec_prog_t * p,
uint8_t id,
int32_t value )

Edit the draft: value in the unit of parameter id.

A value equal to the draft's changes nothing. A value hitec_param_set() refuses is refused (HITEC_PROG_MSG_EDIT_REFUSED, arg its hitec_set_t). A value that breaks a soft rule not confirmed for it waits: hitec_prog_pending() names it, hitec_prog_confirm() takes it, hitec_prog_cancel() drops it.

Parameters
pThe programmer.
idhitec_param_t.
valueThe value.
Returns
What the edit came to.

◆ hitec_prog_editable()

bool hitec_prog_editable ( const hitec_prog_t * p,
uint8_t id )

Whether parameter id of the servo's layout takes an edit.

Parameters
pThe programmer.
idhitec_param_t.
Returns
true for a writable parameter of the layout.

◆ hitec_prog_file_done()

void hitec_prog_file_done ( hitec_prog_t * p,
bool ok )

How the card took the text hitec_prog_file_take() gave.

Only the answer to the text that holds the record of the write waiting in HITEC_PROG_RECORDING releases that write, or ends it when the card refused the text. The answer to a text taken before that write began, the record of an aborted or timed-out write or the text that clears a record, only frees the card for the next text.

Parameters
pThe programmer.
oktrue when the card holds it whole.

◆ hitec_prog_file_due()

bool hitec_prog_file_due ( const hitec_prog_t * p)

Whether the record's text is to go to the card.

Parameters
pThe programmer.
Returns
true while one is due and none is out.

◆ hitec_prog_file_load()

bool hitec_prog_file_load ( hitec_prog_t * p,
const char * text,
size_t len )

The record's text as the card held it at the start.

Parameters
pThe programmer.
textThe text.
lenIts length in bytes.
Returns
false, with HITEC_PROG_MSG_RECORD_BAD, for a text that does not parse.

◆ hitec_prog_file_take()

size_t hitec_prog_file_take ( hitec_prog_t * p,
char * out,
size_t n )

The record's text for the card: fill out and return its length; 0 while none is due, no card is mounted or n is under HITEC_CARD_TEXT_MAX.

Parameters
pThe programmer.
outReceives the text.
nBytes at out.
Returns
The length.

◆ hitec_prog_first_done()

bool hitec_prog_first_done ( const hitec_prog_t * p)

Whether the first write of this CONNECT has gone out.

Parameters
pThe programmer.
Returns
true after it.

◆ hitec_prog_forget()

hitec_prog_msg_id_t hitec_prog_forget ( hitec_prog_t * p)

FORGET: discard the record without a write.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when taken; BUSY while a write runs.

◆ hitec_prog_pending()

uint16_t hitec_prog_pending ( const hitec_prog_t * p,
uint8_t * id,
int32_t * value )

The edit that waits for a confirmation.

Parameters
pThe programmer.
idReceives its hitec_param_t; may be NULL.
valueReceives its value; may be NULL.
Returns
Its rule set; 0 with none waiting.

◆ hitec_prog_record()

bool hitec_prog_record ( const hitec_prog_t * p)

Whether a record of a write stands.

Parameters
pThe programmer.
Returns
true when one does.

◆ hitec_prog_record_verdict()

hitec_prog_rec_t hitec_prog_record_verdict ( const hitec_prog_t * p)

What the last servo read holds of the record.

Parameters
pThe programmer.
Returns
hitec_prog_rec_t; HITEC_PROG_REC_NONE while not compared.

◆ hitec_prog_repair()

hitec_prog_msg_id_t hitec_prog_repair ( hitec_prog_t * p)

REPAIR: the classic balance 0x1C alone, then the read-back.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_restore()

hitec_prog_msg_id_t hitec_prog_restore ( hitec_prog_t * p)

RESTORE: the values before the recorded write back to the servo, as a write; the record stays until it ends verified.

Taken once the servo read is compared and is not another servo.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_restore_image()

bool hitec_prog_restore_image ( const hitec_prog_t * p,
hitec_image_t * out )

The image RESTORE writes: the servo read with the record's values before the write.

Parameters
pThe programmer.
outReceives it.
Returns
false with no record or no servo read.

◆ hitec_prog_rules()

uint16_t hitec_prog_rules ( const hitec_prog_t * p,
uint8_t id,
int32_t value )

The soft rules value of parameter id breaks against the servo read.

Parameters
pThe programmer.
idhitec_param_t.
valueThe value.
Returns
The rule set; 0 with no servo read.

◆ hitec_prog_sum_bad()

bool hitec_prog_sum_bad ( const hitec_prog_t * p)

Whether the classic servo read has cells 0x00 to 0x1C that do not sum to 0.

Parameters
pThe programmer.
Returns
true when REPAIR has something to write.

◆ hitec_prog_write()

hitec_prog_msg_id_t hitec_prog_write ( hitec_prog_t * p)

WRITE n VALUES: the draft to the servo, then its read-back.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_write_enable()

hitec_prog_msg_id_t hitec_prog_write_enable ( hitec_prog_t * p,
bool on )

ENABLE WRITE TO SERVO.

Off is always taken. On needs the state hitec_prog_can_edit() needs, a SAFE bench and no STOP latched.

Parameters
pThe programmer.
onThe switch.
Returns
HITEC_PROG_MSG_NONE when taken, else the message said.

◆ hitec_prog_write_gate()

hitec_prog_msg_id_t hitec_prog_write_gate ( const hitec_prog_t * p,
uint8_t kind )

Why a write of kind is not taken now, the switch included.

Parameters
pThe programmer.
kindhitec_prog_wr_t.
Returns
HITEC_PROG_MSG_NONE when it is taken, else the reason.

◆ hitec_prog_write_on()

bool hitec_prog_write_on ( const hitec_prog_t * p)

Whether ENABLE WRITE TO SERVO is on.

Parameters
pThe programmer.
Returns
true when on.

◆ hitec_prog_write_progress()

bool hitec_prog_write_progress ( const hitec_prog_t * p,
unsigned * done,
unsigned * total,
uint8_t * kind )

The progress of the running write.

Parameters
pThe programmer.
doneReceives the plan's steps done.
totalReceives its steps.
kindReceives the hitec_step_kind_t of the step out; 0xFF in the read-back.
Returns
true while a write runs.

◆ hpw_abort()

bool hpw_abort ( hitec_prog_t * p)

ABORT of a write that waits for the card: nothing was written.

Parameters
pThe programmer.
Returns
true when one waited.

◆ hpw_connect()

void hpw_connect ( hitec_prog_t * p)

A CONNECT starts: the switch off, the edits and the confirmations gone; the record stays.

Parameters
pThe programmer.

◆ hpw_off()

void hpw_off ( hitec_prog_t * p)

The write switch goes off: a LEAVE, a lost link, a stop.

Parameters
pThe programmer.

◆ hpw_read_done()

void hpw_read_done ( hitec_prog_t * p,
bool had,
const hitec_image_t * was )

A full read ended well: the draft is the servo again, the switch goes off when the servo changed, and a record stands against it.

Parameters
pThe programmer.
hadA servo was read before.
wasWhat that read found; NULL with none.

◆ hpw_tick()

void hpw_tick ( hitec_prog_t * p)

Every feed: a stop switches the switch off, and a write that waits for the card gives up after HITEC_PROG_CARD_MS.

Parameters
pThe programmer.

◆ hpw_write_done()

void hpw_write_done ( hitec_prog_t * p,
hitec_ses_t r )

A write operation ended with r.

Parameters
pThe programmer.
rIts result.

◆ mag()

int32_t mag ( int32_t v)
static

The absolute value of v.

Parameters
vThe value.
Returns
|v|.

◆ not_sent()

void not_sent ( hitec_prog_t * p,
hitec_ses_t r )
static

A write that ended before a step reached the servo: the record goes with it, a RESTORE's excepted, and the switch goes off.

Parameters
pThe programmer.
rThe session's result.

◆ rec_clear()

void rec_clear ( hitec_prog_t * p)
static

The record ends: the write it stood for is verified, or nothing of it was sent.

Parameters
pThe programmer.

◆ rec_compare()

void rec_compare ( hitec_prog_t * p)
static

Compare the servo read with the record and say what it holds.

Parameters
pThe programmer.

◆ say()

hitec_prog_msg_id_t say ( hitec_prog_t * p,
hitec_prog_msg_id_t id,
unsigned arg )
static

Say message id with one argument.

Parameters
pThe programmer.
idhitec_prog_msg_id_t.
argIts argument.
Returns
id.

◆ start()

hitec_prog_msg_id_t start ( hitec_prog_t * p,
uint8_t kind,
const hitec_image_t * target )
static

Start a write of kind to target.

Parameters
pThe programmer.
kindhitec_prog_wr_t.
targetWhat the servo is to hold.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ trial()

hitec_prog_edit_t trial ( hitec_prog_t * p,
uint8_t id,
int32_t value,
hitec_image_t * out )
static

Take value of id into a copy of the draft.

Parameters
pThe programmer.
idhitec_param_t.
valueThe value.
outReceives the draft with the edit.
Returns
HITEC_PROG_EDIT_OK, or HITEC_PROG_EDIT_REFUSED with its message.

◆ unconfirm()

void unconfirm ( hitec_prog_t * p)
static

Every confirmation ends, and the edit that waits.

Parameters
pThe programmer.

◆ verdict()

hitec_prog_rec_t verdict ( const hitec_prog_t * p)
static

What the servo read holds of the record.

Another series, another port or another D series model is another servo, and so is an address that holds neither the value before the write nor the value the write was to leave.

Parameters
pThe programmer.
Returns
hitec_prog_rec_t.