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

Limit checks of an edited register image against the servo's limits. More...

#include "kst_limits.h"

Data Structures

struct  values_t
 The fields one image check reads. More...

Functions

static int32_t raw_of (const kst_image_t *img, kst_field_id_t id)
 Raw value of a field as a signed number.
static void load (const kst_image_t *img, values_t *v)
 Read the fields one image check uses into a values_t.
static kst_rules_t when (bool broken, kst_rule_t rule)
 Give the rule bit when a condition holds.
static int32_t distance (int32_t a, int32_t b)
 Absolute difference of two numbers.
static kst_rules_t hard (const kst_image_t *img, const values_t *v)
 Hard rules of one image.
kst_rules_t kst_limits_image (const kst_image_t *img)
 The hard rules an image breaks on its own.
static kst_rules_t access (const kst_image_t *backup, const kst_image_t *target, kst_field_set_t unlocked, kst_field_set_t *refused)
 Access-class rules of an edit.
static kst_rules_t soft (const values_t *b, const values_t *t)
 Soft rules of an edit: changes that move a value the hazardous way.
kst_rules_t kst_limits_edit (const kst_image_t *backup, const kst_image_t *target, kst_field_set_t unlocked, kst_field_set_t *refused)
 The hard and soft rules the image target breaks as an edit of the servo's image backup.

Detailed Description

Limit checks of an edited register image against the servo's limits.

SPDX-License-Identifier: MIT

Function Documentation

◆ kst_limits_edit()

kst_rules_t kst_limits_edit ( const kst_image_t * backup,
const kst_image_t * target,
kst_field_set_t unlocked,
kst_field_set_t * refused )

The hard and soft rules the image target breaks as an edit of the servo's image backup.

unlocked lifts KST_ACCESS_LOCKED for the fields in it. Nothing lifts KST_ACCESS_NEVER; register 01 may follow 02. refused, when not NULL, receives the changed fields that the access class refuses.

A soft rule about a value on its own (KST_S_DUTY_BELOW_HALF and the like) is reported when the edit changes a field the rule reads, not for a state the servo already has.

Parameters
backupImage the edit starts from.
targetImage after the edit.
unlockedFields whose KST_ACCESS_LOCKED is lifted.
refusedReceives the refused fields; may be NULL.
Returns
The hard and soft rules the edit breaks.

◆ kst_limits_image()

kst_rules_t kst_limits_image ( const kst_image_t * img)

The hard rules an image breaks on its own.

Pulse Lower, Upper and Uncontrolled Pos are compared with Neutral in microseconds, because Neutral's unit differs from theirs.

An image in Gyro Servo mode breaks KST_H_GYRO_MODE: the vendor tool halves every microsecond value there, and what a servo does with them is not measured.

Parameters
imgImage to check.
Returns
The hard rules the image breaks; KST_RULES_HARD for NULL.