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

Reading a board drawing. More...

#include "link_drawing.h"
#include <stddef.h>
#include <string.h>

Functions

static uint16_t u16_at (const uint8_t *p)
 Read a 16-bit little-endian value.
static void pad_of (const uint8_t *p, link_draw_pad_t *out)
 Decode one pad record from its 8 bytes.
static void shape_of (const uint8_t *p, link_draw_shape_t *out)
 Decode one shape record from its 12 bytes.
static bool within (int32_t lo, int32_t hi, uint16_t limit)
 [lo, hi] lies inside [0, limit]: no part of it past either edge.
static bool pad_ok (const link_drawing_t *d, const link_draw_pad_t *p)
 Test a pad record against the format and the outline.
static bool shape_ok (const link_drawing_t *d, const link_draw_shape_t *s)
 Test a shape record against the format and the outline.
static bool refuse (link_drawing_t *out, const char **why, const char *reason)
 Zero the output, record the reason and report failure.
bool link_drawing_parse (link_drawing_t *out, const uint8_t *data, uint32_t bytes, const char **why)
 Check bytes of data whole and describe them in out.
bool link_drawing_pad_at (const link_drawing_t *d, uint8_t i, link_draw_pad_t *out)
 Pad record i, 0 to pads - 1, in the order the drawing lists them.
bool link_drawing_find_pad (const link_drawing_t *d, uint8_t pad, link_draw_pad_t *out)
 The record of pad number pad.
bool link_drawing_shape_at (const link_drawing_t *d, uint16_t i, link_draw_shape_t *out)
 Shape record i, 0 to shapes - 1, in drawing order.

Detailed Description

Reading a board drawing.

See link_drawing.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ link_drawing_find_pad()

bool link_drawing_find_pad ( const link_drawing_t * d,
uint8_t pad,
link_draw_pad_t * out )

The record of pad number pad.

False when the drawing has none.

Parameters
dThe parsed drawing.
padThe pad number, 1 to 63.
outReceives the record; may be NULL.
Returns
true when the drawing has the pad, else false.

◆ link_drawing_pad_at()

bool link_drawing_pad_at ( const link_drawing_t * d,
uint8_t i,
link_draw_pad_t * out )

Pad record i, 0 to pads - 1, in the order the drawing lists them.

Parameters
dThe parsed drawing.
iIndex of the record, 0 to pads - 1.
outReceives the record.
Returns
true when i is in range, else false.

◆ link_drawing_parse()

bool link_drawing_parse ( link_drawing_t * out,
const uint8_t * data,
uint32_t bytes,
const char ** why )

Check bytes of data whole and describe them in out.

False, with out zeroed, when anything is out of place; why (may be NULL) then names the first thing found, for a log line, and is never left pointing at nothing.

Parameters
outReceives the description; zeroed on failure.
dataThe drawing bytes.
bytesLength of data in bytes.
whyReceives the reason text on failure; may be NULL.
Returns
true when the drawing is whole and in order, else false.

◆ link_drawing_shape_at()

bool link_drawing_shape_at ( const link_drawing_t * d,
uint16_t i,
link_draw_shape_t * out )

Shape record i, 0 to shapes - 1, in drawing order.

Parameters
dThe parsed drawing.
iIndex of the record, 0 to shapes - 1.
outReceives the record.
Returns
true when i is in range, else false.

◆ pad_of()

void pad_of ( const uint8_t * p,
link_draw_pad_t * out )
static

Decode one pad record from its 8 bytes.

Parameters
pThe record's bytes.
outReceives the decoded pad.

◆ pad_ok()

bool pad_ok ( const link_drawing_t * d,
const link_draw_pad_t * p )
static

Test a pad record against the format and the outline.

Parameters
dThe parsed drawing, for the outline and ring radius.
pThe pad to test.
Returns
true when the pad number, kind, value, flags and ring fit.

◆ refuse()

bool refuse ( link_drawing_t * out,
const char ** why,
const char * reason )
static

Zero the output, record the reason and report failure.

Parameters
outThe drawing to zero.
whyReceives reason when not NULL.
reasonThe text of the first fault found.
Returns
false.

◆ shape_of()

void shape_of ( const uint8_t * p,
link_draw_shape_t * out )
static

Decode one shape record from its 12 bytes.

Parameters
pThe record's bytes.
outReceives the decoded shape.

◆ shape_ok()

bool shape_ok ( const link_drawing_t * d,
const link_draw_shape_t * s )
static

Test a shape record against the format and the outline.

Parameters
dThe parsed drawing, for the outline.
sThe shape to test.
Returns
true when the shape's kind and fields fit the format and lie inside the outline.

◆ u16_at()

uint16_t u16_at ( const uint8_t * p)
static

Read a 16-bit little-endian value.

Parameters
pThe two bytes, low byte first.
Returns
The value.

◆ within()

bool within ( int32_t lo,
int32_t hi,
uint16_t limit )
static

[lo, hi] lies inside [0, limit]: no part of it past either edge.

In 32 bits, so lo - r below zero is a negative number and not a wrap.

Parameters
loLower end of the interval, in 0.01mm.
hiUpper end of the interval, in 0.01mm.
limitThe outline's width or height, in 0.01mm.
Returns
true when 0 <= lo and hi <= limit.