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

Hitec servo programming protocols: the register models, the parameter table and the write plans. More...

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

Go to the source code of this file.

Data Structures

struct  hitec_image_t
 The registers or cells of one servo, as read. More...
struct  hitec_range_t
 A run of classic cells. More...
struct  hitec_model_t
 What identification found. More...
struct  hitec_param_info_t
 One row of the parameter table. More...
struct  hitec_value_t
 A decoded value and the raw value beside it. More...
struct  hitec_step_t
 One write of a plan. More...
struct  hitec_plan_t
 An ordered list of writes. More...

Macros

#define HITEC_MEM_SIZE   256u
 Bytes of an image: 256 classic cells or 128 D series registers.
#define HITEC_C_SUM_LAST   0x1Cu
#define HITEC_C_FACTORY   0x30u
#define HITEC_C_BLOCK_LEN   0x24u
#define HITEC_C_NAME   0x60u
#define HITEC_C_NAME_LEN   16u
#define HITEC_C_DATE   0x70u
#define HITEC_C_SERIAL   0x80u
#define HITEC_C_SERIAL_LEN   7u
#define HITEC_D_REG_MODEL   0x00u
#define HITEC_D_REG_FACTORY   0x6Eu
#define HITEC_D_REG_SAVE   0x70u
#define HITEC_D_REG_REBOOT   0x46u
#define HITEC_D_FACTORY_KEY   0x0F0Fu
#define HITEC_D_SAVE_KEY   0xFFFFu
#define HITEC_D_POS_MAX   16383u
 Highest D series position; 8192 is the centre.
#define HITEC_LAYOUT_BIT(l)
 The bit of layout l in a parameter row's layout set.
#define HITEC_FS_LIMP   0
#define HITEC_FS_OFF   1
#define HITEC_OVERLOAD_OFF   0
 Overload protection off.
#define HITEC_ADDR_NONE   0xFFu
 No second register or cell.
#define HITEC_D_WRITE_GAP_MS   20u
 Gap from a D series write to the next, the HFP-30's.
#define HITEC_D_SAVE_GAP_MS   100u
 Gap from the save to the reboot, the HFP-30's.
#define HITEC_D_REBOOT_WAIT_MS   1000u
 Wait after the reboot: the servo ignores frames for 1000ms (third-party observation; the HFP-30 reads again after 834.6ms).
#define HITEC_PLAN_MAX   56u
 The longest plan: a classic restore of all 35 writable cells with a balance after each of the 19 settings of cells up to 0x1B, and room for 2 more.

Enumerations

enum  hitec_layout_t { HITEC_LAYOUT_D = 0 , HITEC_LAYOUT_HS5 , HITEC_LAYOUT_HS7 , HITEC_LAYOUT_COUNT }
 Register layouts. More...
enum  hitec_src_t { HITEC_SRC_RCBENCH = 0 , HITEC_SRC_CAPTURED , HITEC_SRC_READ , HITEC_SRC_DOC }
 Where an entry comes from. More...
enum  hitec_model_id_t {
  HITEC_MODEL_NONE = 0 , HITEC_MODEL_D485HW , HITEC_MODEL_D645MW , HITEC_MODEL_D_OTHER ,
  HITEC_MODEL_HS5645MG , HITEC_MODEL_HS5955TG , HITEC_MODEL_HS7955TG , HITEC_MODEL_HS5_OTHER ,
  HITEC_MODEL_HS7_OTHER , HITEC_MODEL_C_OTHER , HITEC_MODEL_COUNT
}
 Models the module knows by name. More...
enum  hitec_param_t {
  HITEC_P_D_MODEL = 0 , HITEC_P_D_POSITION , HITEC_P_D_ID , HITEC_P_D_DIRECTION ,
  HITEC_P_D_NEUTRAL , HITEC_P_D_LEFT_END , HITEC_P_D_RIGHT_END , HITEC_P_D_DEAD_BAND ,
  HITEC_P_D_SPEED , HITEC_P_D_FAILSAFE , HITEC_P_D_SOFT_START , HITEC_P_D_OVERLOAD ,
  HITEC_P_D_SMART_SENSOR , HITEC_P_D_SENSITIVITY , HITEC_P_D_R04 , HITEC_P_D_R22 ,
  HITEC_P_D_R8A , HITEC_P_D_R8C , HITEC_P_D_RD4 , HITEC_P_D_RD6 ,
  HITEC_P_C_VERSION , HITEC_P_C_DATE , HITEC_P_C_SERIAL , HITEC_P_C_CHECKSUM ,
  HITEC_P_C_DEAD_BAND , HITEC_P_C_SPEED , HITEC_P_C_CENTRE , HITEC_P_C_LEFT_END ,
  HITEC_P_C_RIGHT_END , HITEC_P_C_DIRECTION , HITEC_P_C_FAILSAFE , HITEC_P_C_FS_POSITION ,
  HITEC_P_C_OVERLOAD , HITEC_P_C_RESOLUTION , HITEC_P_COUNT
}
 The parameters of both series. More...
enum  hitec_unit_t {
  HITEC_UNIT_RAW = 0 , HITEC_UNIT_COUNTS , HITEC_UNIT_PERCENT , HITEC_UNIT_STEP ,
  HITEC_UNIT_CHOICE , HITEC_UNIT_FS_US , HITEC_UNIT_OVERLOAD , HITEC_UNIT_QUARTER_US ,
  HITEC_UNIT_DATE , HITEC_UNIT_NUMBER
}
 Unit of a decoded value. More...
enum  hitec_choice_t {
  HITEC_CW = 0 , HITEC_CCW = 1 , HITEC_OFF = 0 , HITEC_ON = 1 ,
  HITEC_RES_NORMAL = 0 , HITEC_RES_HIGH = 1 , HITEC_SUM_BAD = 0 , HITEC_SUM_OK = 1
}
 The values of the CHOICE parameters. More...
enum  hitec_access_t { HITEC_RO = 0 , HITEC_RW }
 Access of a parameter. More...
enum  hitec_get_t { HITEC_GET_OK = 0 , HITEC_GET_RAW , HITEC_GET_UNKNOWN , HITEC_GET_ERR_ARG }
 Result of a decode. More...
enum  hitec_set_t {
  HITEC_SET_OK = 0 , HITEC_SET_ERR_ARG , HITEC_SET_ERR_RO , HITEC_SET_ERR_RANGE ,
  HITEC_SET_ERR_RAW , HITEC_SET_ERR_UNKNOWN , HITEC_SET_ERR_MIRROR , HITEC_SET_ERR_ORDER
}
 Result of an edit. More...
enum  hitec_step_kind_t {
  HITEC_STEP_C_CELL = 0 , HITEC_STEP_C_SUM , HITEC_STEP_D_WRITE , HITEC_STEP_D_SAVE ,
  HITEC_STEP_D_REBOOT
}
 Kind of a write. More...
enum  hitec_plan_result_t { HITEC_PLAN_OK = 0 , HITEC_PLAN_ERR_ARG , HITEC_PLAN_ERR_UNKNOWN }
 Result of planning. More...

Functions

void hitec_image_init (hitec_image_t *img, uint8_t series)
 Empty an image of series: no byte known, no version.
bool hitec_image_put_cell (hitec_image_t *img, uint8_t cell, uint8_t value)
 Store a classic cell as read.
bool hitec_image_put_reg (hitec_image_t *img, uint8_t addr, uint16_t value)
 Store a D series register as read.
bool hitec_image_put_version (hitec_image_t *img, uint8_t version)
 Store the classic reply to the first command (0x67).
bool hitec_image_forget (hitec_image_t *img, uint8_t addr)
 Mark a cell or a D series register as not known: the servo may hold another value than the image.
bool hitec_image_known (const hitec_image_t *img, uint8_t addr)
 True when byte addr was read.
uint8_t hitec_image_cell (const hitec_image_t *img, uint8_t cell)
 A classic cell; 0 for NULL.
uint16_t hitec_image_reg (const hitec_image_t *img, uint8_t addr)
 A D series register; 0 for NULL or an odd address.
const uint8_t * hitec_d_read_list (size_t *n)
 The D series registers a full read takes: the 19 the HFP-30 reads, less 0x6E (write only), plus the model 0x00, the position 0x0C and 0x22.
const hitec_range_t * hitec_c_read_ranges (size_t *n)
 The classic cells a full read takes: 0x00 to 0x23, the factory block 0x30 to 0x53, the name 0x60 to 0x6F, the date 0x70 to 0x73 and the serial 0x80 to 0x87, 100 cells.
uint8_t hitec_c_eeprom_sum (const hitec_image_t *img)
 Sum of classic cells 0x00 to 0x1C modulo 256; 0 is a good image.
uint8_t hitec_c_balance (const hitec_image_t *img)
 The value of cell 0x1C that makes cells 0x00 to 0x1C sum to 0.
bool hitec_c_rebalance (hitec_image_t *img)
 Write the balance into cell 0x1C of a classic draft.
bool hitec_d_mirror (uint16_t pos, uint16_t *out)
 A D series position mirrored by a direction change: 16384 less the position, as the HFP-30 writes it.
uint8_t hitec_layout_series (uint8_t layout)
 The series of a layout.
bool hitec_identify (const hitec_image_t *img, hitec_model_t *out)
 Identify the model from a read image.
const char * hitec_model_name (uint8_t model)
 The model's name as Hitec writes it, "D485HW", "HS-5645MG"; "" for the OTHER and NONE models.
const hitec_param_info_t * hitec_param (uint8_t layout, uint8_t id)
 The row of id for layout; NULL when the layout has no such parameter.
hitec_get_t hitec_param_get (const hitec_image_t *img, uint8_t layout, uint8_t id, hitec_value_t *out)
 Decode a parameter.
hitec_set_t hitec_param_set (hitec_image_t *img, uint8_t layout, uint8_t id, int32_t value)
 Edit a draft: encode value and write its side effects.
bool hitec_param_ok (uint8_t layout, uint8_t id, int32_t value)
 True when value is a value an edit of id takes.
int32_t hitec_param_clamp (uint8_t layout, uint8_t id, int32_t value)
 The nearest value an edit of id takes.
bool hitec_c_factory (hitec_image_t *img)
 Classic factory reset on a draft: cells 0x00 to 0x23 from the factory block 0x30 to 0x53, then the balance.
bool hitec_writable (uint8_t series, uint8_t addr)
 True when a plan writes addr of series.
hitec_plan_result_t hitec_plan (const hitec_image_t *from, const hitec_image_t *to, hitec_plan_t *out)
 The writes that take a servo from image from to to.
void hitec_d_factory_plan (hitec_plan_t *out)
 The D series factory reset: 0x6E = 0x0F0F, save, reboot, as the HFP-30 writes it.

Detailed Description

Hitec servo programming protocols: the register models, the parameter table and the write plans.

Implements the register models of Hitec servos. Hitec is a name or trademark of its owner; it is used here only to say which servos this module works with (README.md, "Legal notice and disclaimer").

Two models share one image type (hitec_image_t, 256 bytes):

  • Classic, the HS-5xxx and HS-7xxx servos: 256 EEPROM cells of 8 bits. A two-cell value is stored high byte first. Cells 0x00 to 0x1C sum to 0 modulo 256; cell 0x1C is the balance. 0x30 to 0x53 hold the factory block in the layout of 0x00 to 0x23, 0x60 to 0x6F the model name in ASCII.
  • D series: registers of 16 bits at even addresses 0x00 to 0xFE, the low byte at the even address. A write takes effect in the servo's RAM; a save (0x70 = 0xFFFF) stores it, and a reboot (0x46 = 1) restarts the servo with it.

The image stores raw values. A parameter (hitec_param_t) is decoded from the image and encoded into it with the encoding the vendor programmers use: the HFP-30 for the D series, measured on a D485HW; the HPP-21 Plus for classic servos, measured on an HS-5645MG and an HS-7955TG. A raw value that fits no encoding is shown raw; an edit replaces it with a value of the table, and only a restore writes the raw value back. Every value is an integer in the unit of its hitec_unit_t; no floating point is used.

An edit (hitec_param_set()) changes a draft image as the vendor programmer changes the servo, with the side effects it writes: the D series direction mirrors the neutral and both end points; the classic centre resets both end points; the classic direction swaps the end points and takes the fail-safe position from the factory block. A plan (hitec_plan()) lists the writes that take a servo from its read image to the draft, in the vendor programmer's order, with the classic checksum write and the D series save and reboot.

Every table row says where its encoding comes from (hitec_src_t). The module identifies the model from the read data (hitec_identify()); a model other than the measured ones takes its series' layout.

The module has no hardware access, no heap and no global or static mutable state, and includes nothing outside the C standard headers and this folder.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ HITEC_C_BLOCK_LEN

#define HITEC_C_BLOCK_LEN   0x24u

cells of a block: 0x00 to 0x23

◆ HITEC_C_DATE

#define HITEC_C_DATE   0x70u

day, month, year high, year low

◆ HITEC_C_FACTORY

#define HITEC_C_FACTORY   0x30u

first cell of the factory block

◆ HITEC_C_NAME

#define HITEC_C_NAME   0x60u

first cell of the model name

◆ HITEC_C_NAME_LEN

#define HITEC_C_NAME_LEN   16u

cells of the model name

◆ HITEC_C_SERIAL

#define HITEC_C_SERIAL   0x80u

7 ASCII digits

◆ HITEC_C_SERIAL_LEN

#define HITEC_C_SERIAL_LEN   7u

digits of the serial

◆ HITEC_C_SUM_LAST

#define HITEC_C_SUM_LAST   0x1Cu

last cell of the checksum, the balance

◆ HITEC_D_FACTORY_KEY

#define HITEC_D_FACTORY_KEY   0x0F0Fu

the value of a factory reset

◆ HITEC_D_REG_FACTORY

#define HITEC_D_REG_FACTORY   0x6Eu

0x0F0F restores the factory values

◆ HITEC_D_REG_MODEL

#define HITEC_D_REG_MODEL   0x00u

model number

◆ HITEC_D_REG_REBOOT

#define HITEC_D_REG_REBOOT   0x46u

1 restarts the servo

◆ HITEC_D_REG_SAVE

#define HITEC_D_REG_SAVE   0x70u

0xFFFF stores the registers

◆ HITEC_D_SAVE_KEY

#define HITEC_D_SAVE_KEY   0xFFFFu

the value of a save

◆ HITEC_FS_LIMP

#define HITEC_FS_LIMP   0

D series fail-safe: no torque on signal loss

◆ HITEC_FS_OFF

#define HITEC_FS_OFF   1

D series fail-safe: off

◆ HITEC_LAYOUT_BIT

#define HITEC_LAYOUT_BIT ( l)
Value:
((uint8_t)(1u << (l)))

The bit of layout l in a parameter row's layout set.

Enumeration Type Documentation

◆ hitec_access_t

Access of a parameter.

Enumerator
HITEC_RO 

read only

HITEC_RW 

an edit may change it

◆ hitec_choice_t

The values of the CHOICE parameters.

Enumerator
HITEC_CW 

direction: clockwise

HITEC_CCW 

direction: counterclockwise

HITEC_OFF 

smart sensor, fail-safe: off

HITEC_ON 

smart sensor, fail-safe: on

HITEC_RES_NORMAL 

resolution Normal

HITEC_RES_HIGH 

resolution High

HITEC_SUM_BAD 

checksum: cells 0x00 to 0x1C do not sum to 0

HITEC_SUM_OK 

checksum: they do

◆ hitec_get_t

Result of a decode.

Enumerator
HITEC_GET_OK 

value is the decoded value

HITEC_GET_RAW 

the stored value fits no encoding: value is the raw value; an edit sets a table value

HITEC_GET_UNKNOWN 

a byte the decode needs was not read

HITEC_GET_ERR_ARG 

NULL, a parameter the layout lacks, an image of the other series

◆ hitec_layout_t

Register layouts.

A layout fixes which parameters a servo has and how they are encoded.

Enumerator
HITEC_LAYOUT_D 

D series, measured on a D485HW

HITEC_LAYOUT_HS5 

HS-5xxx, measured on an HS-5645MG

HITEC_LAYOUT_HS7 

HS-7xxx, measured on an HS-7955TG

◆ hitec_model_id_t

Models the module knows by name.

Enumerator
HITEC_MODEL_NONE 

what identification reads is not known

HITEC_MODEL_D485HW 

register 0x00 reads 34485

HITEC_MODEL_D645MW 

register 0x00 reads 34645 (third-party)

HITEC_MODEL_D_OTHER 

any other D series number

HITEC_MODEL_HS5645MG 

name HS5645MG

HITEC_MODEL_HS5955TG 

name HS5955TG

HITEC_MODEL_HS7955TG 

name HS7955

HITEC_MODEL_HS5_OTHER 

another name starting HS5

HITEC_MODEL_HS7_OTHER 

another name starting HS7

HITEC_MODEL_C_OTHER 

any other name; the HS-5xxx layout

◆ hitec_param_t

The parameters of both series.

Enumerator
HITEC_P_D_MODEL 

0x00, model number, read only

HITEC_P_D_POSITION 

0x0C, read only

HITEC_P_D_ID 

0x32

HITEC_P_D_DIRECTION 

0x5E; mirrors 0xC2, 0xB2, 0xB0

HITEC_P_D_NEUTRAL 

0xC2

HITEC_P_D_LEFT_END 

0xB2

HITEC_P_D_RIGHT_END 

0xB0

HITEC_P_D_DEAD_BAND 

0x4E

HITEC_P_D_SPEED 

0x54

HITEC_P_D_FAILSAFE 

0x4C

HITEC_P_D_SOFT_START 

0x60

HITEC_P_D_OVERLOAD 

0x9C

HITEC_P_D_SMART_SENSOR 

0x6C and 0x44

HITEC_P_D_SENSITIVITY 

0x64, read only

HITEC_P_D_R04 

0x04, meaning not known, read only

HITEC_P_D_R22 

0x22, meaning not known, read only

HITEC_P_D_R8A 

0x8A, the smart sensor's off value

HITEC_P_D_R8C 

0x8C, the smart sensor's off value

HITEC_P_D_RD4 

0xD4, meaning not known, read only

HITEC_P_D_RD6 

0xD6, meaning not known, read only

HITEC_P_C_VERSION 

the reply to 0x67, read only

HITEC_P_C_DATE 

0x70 to 0x73, read only

HITEC_P_C_SERIAL 

0x80 to 0x86, read only

HITEC_P_C_CHECKSUM 

0x00 to 0x1C sum to 0, read only

HITEC_P_C_DEAD_BAND 

0x02

HITEC_P_C_SPEED 

0x06

HITEC_P_C_CENTRE 

0x07 and 0x08; resets 0x13, 0x14

HITEC_P_C_LEFT_END 

0x14 on a CW servo, 0x13 on a CCW one

HITEC_P_C_RIGHT_END 

0x13 on a CW servo, 0x14 on a CCW one

HITEC_P_C_DIRECTION 

0x1B bit 0; swaps 0x13, 0x14

HITEC_P_C_FAILSAFE 

0x1B bit 1

HITEC_P_C_FS_POSITION 

0x19 and 0x1A

HITEC_P_C_OVERLOAD 

HS-5xxx 0x20, HS-7xxx 0x21

HITEC_P_C_RESOLUTION 

0x22, HS-7xxx, read only

◆ hitec_plan_result_t

Result of planning.

Enumerator
HITEC_PLAN_OK 

out holds the writes; none when equal

HITEC_PLAN_ERR_ARG 

NULL, or the two images of other series

HITEC_PLAN_ERR_UNKNOWN 

a byte a write needs was not read

◆ hitec_set_t

Result of an edit.

Enumerator
HITEC_SET_OK 

stored, side effects included

HITEC_SET_ERR_ARG 

NULL, a parameter the layout lacks, an image of the other series

HITEC_SET_ERR_RO 

a read-only parameter

HITEC_SET_ERR_RANGE 

a value no step of the encoding gives

HITEC_SET_ERR_RAW 

D series: a position edit beside a position above 16383, and smart sensor off with 0x8A = 0x8C = 0, which reads as on.

HITEC_SET_ERR_UNKNOWN 

a byte the edit reads or writes was not read

HITEC_SET_ERR_MIRROR 

D direction: a position the mirror leaves

HITEC_SET_ERR_ORDER 

D: left end, neutral, right end not ascending

◆ hitec_src_t

Where an entry comes from.

A parameter row's mark refers to the measured servo of its layout: the D485HW, the HS-5645MG or the HS-7955TG. A model's mark says what is measured on that model.

Enumerator
HITEC_SRC_RCBENCH 

Written through the rcbench IOmcu and read back.

HITEC_SRC_CAPTURED 

A vendor programmer's writes captured on the wire.

HITEC_SRC_READ 

Read from a servo; no write recorded.

HITEC_SRC_DOC 

Documentation only: Hitec's D series manual, community documents, third-party observations.

◆ hitec_step_kind_t

Kind of a write.

Enumerator
HITEC_STEP_C_CELL 

classic write EEPROM: addr, value

HITEC_STEP_C_SUM 

classic write of 0x1C, the balance

HITEC_STEP_D_WRITE 

D series register write

HITEC_STEP_D_SAVE 

D series 0x70 = 0xFFFF

HITEC_STEP_D_REBOOT 

D series 0x46 = 1

◆ hitec_unit_t

Unit of a decoded value.

Enumerator
HITEC_UNIT_RAW 

the stored value, no unit known

HITEC_UNIT_COUNTS 

D series position, 8192 the centre

HITEC_UNIT_PERCENT 

1%

HITEC_UNIT_STEP 

a dead band step, 1 to 5

HITEC_UNIT_CHOICE 

an index; hitec_choice_t names them

HITEC_UNIT_FS_US 

0 limp, 1 off, else a position in us

HITEC_UNIT_OVERLOAD 

0 off, else the percent

HITEC_UNIT_QUARTER_US 

0.25us: 6000 is 1500us

HITEC_UNIT_DATE 

year x 10000 + month x 100 + day

HITEC_UNIT_NUMBER 

a decimal number read from digits

Function Documentation

◆ hitec_c_balance()

uint8_t hitec_c_balance ( const hitec_image_t * img)

The value of cell 0x1C that makes cells 0x00 to 0x1C sum to 0.

Parameters
imgClassic image; NULL gives 0.
Returns
0 less the sum of cells 0x00 to 0x1B, modulo 256.

◆ hitec_c_eeprom_sum()

uint8_t hitec_c_eeprom_sum ( const hitec_image_t * img)

Sum of classic cells 0x00 to 0x1C modulo 256; 0 is a good image.

Parameters
imgClassic image; NULL gives 0.
Returns
The sum.

◆ hitec_c_factory()

bool hitec_c_factory ( hitec_image_t * img)

Classic factory reset on a draft: cells 0x00 to 0x23 from the factory block 0x30 to 0x53, then the balance.

Parameters
imgClassic draft.
Returns
false, and no change, for NULL, a D series image or a cell of either block not known.

◆ hitec_c_read_ranges()

const hitec_range_t * hitec_c_read_ranges ( size_t * n)

The classic cells a full read takes: 0x00 to 0x23, the factory block 0x30 to 0x53, the name 0x60 to 0x6F, the date 0x70 to 0x73 and the serial 0x80 to 0x87, 100 cells.

Parameters
nReceives the count of runs, 5; may be NULL.
Returns
The runs, ascending.

◆ hitec_c_rebalance()

bool hitec_c_rebalance ( hitec_image_t * img)

Write the balance into cell 0x1C of a classic draft.

Parameters
imgClassic image.
Returns
false, and no change, for NULL, a D series image or a cell of 0x00 to 0x1B not known.

◆ hitec_d_factory_plan()

void hitec_d_factory_plan ( hitec_plan_t * out)

The D series factory reset: 0x6E = 0x0F0F, save, reboot, as the HFP-30 writes it.

Parameters
outReceives the plan; NULL does nothing.

◆ hitec_d_mirror()

bool hitec_d_mirror ( uint16_t pos,
uint16_t * out )

A D series position mirrored by a direction change: 16384 less the position, as the HFP-30 writes it.

Parameters
posPosition, 1 to HITEC_D_POS_MAX.
outReceives the mirrored position.
Returns
false for 0, a position above HITEC_D_POS_MAX and a NULL out: the mirror would leave the range.

◆ hitec_d_read_list()

const uint8_t * hitec_d_read_list ( size_t * n)

The D series registers a full read takes: the 19 the HFP-30 reads, less 0x6E (write only), plus the model 0x00, the position 0x0C and 0x22.

Parameters
nReceives the count, 21; may be NULL.
Returns
The addresses, ascending.

◆ hitec_identify()

bool hitec_identify ( const hitec_image_t * img,
hitec_model_t * out )

Identify the model from a read image.

D series: register 0x00. Classic: the name cells 0x60 to 0x6F. The classic version byte is not used.

Parameters
imgRead image.
outReceives the model; on false its model is HITEC_MODEL_NONE.
Returns
false for NULL and for an image without the data read.

◆ hitec_image_cell()

uint8_t hitec_image_cell ( const hitec_image_t * img,
uint8_t cell )

A classic cell; 0 for NULL.

Parameters
imgImage.
cellCell address.
Returns
The cell's value.

◆ hitec_image_forget()

bool hitec_image_forget ( hitec_image_t * img,
uint8_t addr )

Mark a cell or a D series register as not known: the servo may hold another value than the image.

The bytes keep their values; decodes and plans that need them fail with an UNKNOWN code until they are stored again.

Parameters
imgImage.
addrClassic cell, or the even address of a D series register.
Returns
false, and no change, for NULL or an odd D series address.

◆ hitec_image_init()

void hitec_image_init ( hitec_image_t * img,
uint8_t series )

Empty an image of series: no byte known, no version.

Parameters
imgImage to empty; NULL does nothing.
serieshitec_family_t of the servo.

◆ hitec_image_known()

bool hitec_image_known ( const hitec_image_t * img,
uint8_t addr )

True when byte addr was read.

Parameters
imgImage; NULL gives false.
addrCell, or the even address of a D series register.
Returns
true when the byte is known.

◆ hitec_image_put_cell()

bool hitec_image_put_cell ( hitec_image_t * img,
uint8_t cell,
uint8_t value )

Store a classic cell as read.

Parameters
imgClassic image.
cellCell address.
valueValue read.
Returns
false, and no change, for NULL or a D series image.

◆ hitec_image_put_reg()

bool hitec_image_put_reg ( hitec_image_t * img,
uint8_t addr,
uint16_t value )

Store a D series register as read.

Parameters
imgD series image.
addrRegister address, even.
valueValue read.
Returns
false, and no change, for NULL, a classic image or an odd address.

◆ hitec_image_put_version()

bool hitec_image_put_version ( hitec_image_t * img,
uint8_t version )

Store the classic reply to the first command (0x67).

Parameters
imgClassic image.
versionFirst byte of the reply.
Returns
false, and no change, for NULL or a D series image.

◆ hitec_image_reg()

uint16_t hitec_image_reg ( const hitec_image_t * img,
uint8_t addr )

A D series register; 0 for NULL or an odd address.

Parameters
imgImage.
addrRegister address.
Returns
The register's value.

◆ hitec_layout_series()

uint8_t hitec_layout_series ( uint8_t layout)

The series of a layout.

Parameters
layouthitec_layout_t.
Returns
HITEC_D or HITEC_CLASSIC; HITEC_CLASSIC for an unknown layout.

◆ hitec_model_name()

const char * hitec_model_name ( uint8_t model)

The model's name as Hitec writes it, "D485HW", "HS-5645MG"; "" for the OTHER and NONE models.

Parameters
modelhitec_model_id_t.
Returns
The name.

◆ hitec_param()

const hitec_param_info_t * hitec_param ( uint8_t layout,
uint8_t id )

The row of id for layout; NULL when the layout has no such parameter.

Parameters
layouthitec_layout_t.
idhitec_param_t.
Returns
The table row, or NULL.

◆ hitec_param_clamp()

int32_t hitec_param_clamp ( uint8_t layout,
uint8_t id,
int32_t value )

The nearest value an edit of id takes.

Clamped to the row's limits, then to the nearest step from min, a tie going up. FS_US keeps HITEC_FS_LIMP and HITEC_FS_OFF, takes a value under 0 as HITEC_FS_LIMP and a position under min as min. A read-only or unknown parameter gives value unchanged.

Parameters
layouthitec_layout_t.
idhitec_param_t.
valueValue in the row's unit.
Returns
The clamped value.

◆ hitec_param_get()

hitec_get_t hitec_param_get ( const hitec_image_t * img,
uint8_t layout,
uint8_t id,
hitec_value_t * out )

Decode a parameter.

Parameters
imgImage.
layouthitec_layout_t of the servo.
idhitec_param_t.
outReceives the value; zero on HITEC_GET_UNKNOWN and on an error.
Returns
A hitec_get_t.

◆ hitec_param_ok()

bool hitec_param_ok ( uint8_t layout,
uint8_t id,
int32_t value )

True when value is a value an edit of id takes.

Parameters
layouthitec_layout_t.
idhitec_param_t.
valueValue in the row's unit.
Returns
true for a writable parameter and a value inside its limits on its step.

◆ hitec_param_set()

hitec_set_t hitec_param_set ( hitec_image_t * img,
uint8_t layout,
uint8_t id,
int32_t value )

Edit a draft: encode value and write its side effects.

A value equal to the decoded one changes nothing, side effects included. A stored value that fits no encoding is replaced by the table value of value, with the side effects; no edit writes a raw value. Side effects, as the vendor programmers write them:

D direction 0xC2, 0xB2, 0xB0 mirrored (hitec_d_mirror()), 0xB2 from 0xB0 and 0xB0 from 0xB2; from a 0x5E that is neither 0 nor 1 the present direction is not known, and 0x5E is written alone D smart sensor on: 0x6C = 0x44 = 0; off: 0x6C = 0x8A, 0x44 = 0x8C C centre 0x13 = 0x14 = 0x10 C direction 0x13 and 0x14 swapped, 0x19 and 0x1A from 0x49 and 0x4A C fail-safe position 0x1B bit 1 set C overload HS-5xxx 0x21 = 0xFF, HS-7xxx 0x20 = 0x00

A classic edit writes the balance into 0x1C. A D series neutral or end point keeps left end < neutral < right end.

Parameters
imgDraft image.
layouthitec_layout_t of the servo.
idhitec_param_t.
valueValue in the row's unit.
Returns
A hitec_set_t; on an error the draft is unchanged.

◆ hitec_plan()

hitec_plan_result_t hitec_plan ( const hitec_image_t * from,
const hitec_image_t * to,
hitec_plan_t * out )

The writes that take a servo from image from to to.

Only writable addresses (hitec_writable()) are compared; a difference anywhere else is not written.

Classic, in the order of the HPP-21 Plus's operations: cells 0x00 to 0x06, the pairs 0x07/08 to 0x11/12, 0x13, 0x14, the pairs 0x15/16 to 0x19/1A, 0x1B, 0x1D, the pairs 0x1E/1F and 0x20/21, 0x22, 0x23. A setting with a changed cell writes all its cells; a setting of cells up to 0x1B is followed by a write of the balance to 0x1C. Cells above 0x1C get no balance. When from has a bad checksum and no setting up to 0x1B changes, one balance write ends the plan.

D series, by setting, each with the registers the HFP-30 writes for it: ID 0x32; direction 0xC2, 0xB2, 0xB0, 0x4C, 0x5E, and 0x5E alone when from holds a 0x5E that is neither 0 nor 1; neutral 0xC2; left end 0xB2; right end 0xB0; dead band 0x4E; speed 0x54; fail-safe 0x4C; soft start 0x60; overload protection 0x9C, 0x9A = 3, 0x98 = 200; smart sensor 0x72 = 0x4E54, 0x6C, 0x44. A register already written with the same value is not written again. A register the plan does not write need not be known. The save and the reboot end a plan with a write.

Parameters
fromImage the servo holds.
toDraft.
outReceives the plan; empty on an error.
Returns
A hitec_plan_result_t.

◆ hitec_writable()

bool hitec_writable ( uint8_t series,
uint8_t addr )

True when a plan writes addr of series.

Classic: cells 0x00 to 0x23 but 0x1C, which the balance writes. D series: 0x32, 0x44, 0x4C, 0x4E, 0x54, 0x5E, 0x60, 0x6C, 0x9C, 0xB0, 0xB2, 0xC2.

Parameters
serieshitec_family_t.
addrCell or register.
Returns
true when a plan writes it.