Shepherd-Core - Waveform Decoder

Note

TODO: WORK IN PROGRESS

Example

from pathlib import Path
from timeit import timeit

from shepherd_core import logger
from shepherd_core.decoder_waveform import Uart

# file captured with logic analyzer, 15.5k events (2700 symbols, 61 lines)
trace = Path(__file__).parent / "uart_raw2.csv"
uwd = Uart(trace)

sym = uwd.get_symbols()
lne = uwd.get_lines()
txt = uwd.get_text()
logger.info(txt)

do_analysis = False
if do_analysis:
    l0 = timeit("Uart(trace)", globals=globals(), number=1000)
    l1 = timeit("uwd.get_symbols(force_redo=True)", globals=globals(), number=100)
    l2 = timeit("uwd.get_lines(force_redo=True)", globals=globals(), number=1000)
    l3 = timeit("uwd.get_text(force_redo=True)", globals=globals(), number=1000)
    print("t_init\t", l0)
    print("t_symb\t", l1 * 10)
    print("t_line\t", l2)
    print("t_text\t", l3)
    # Results:
    # t_init  5.8   [ms/run]
    # t_symb  70.4  [!!!!!]
    # t_line  3.9
    # t_text  0.1

Source

UART

class shepherd_core.decoder_waveform.Uart(content: Path | ndarray, baud_rate: int | None = None, frame_length: int | None = 8, inversion: bool | None = None, parity: Parity | None = Parity.no, bit_order: BitOrder | None = BitOrder.lsb)

Specialized UART decoder.

detect_baud_rate() int

Analyze the smallest step.

detect_dataframe_length() int

Try to determine length of dataframe.

Algo will look for longest pauses & accumulate steps until a state with uneven step-size is found.

detect_half_stop() bool

Look into the spacing between time-steps to determine use of half stop.

detect_inversion() bool

Analyze bit-state during long pauses (unchanged states).

  • pause should be HIGH for non-inverted mode (default)

  • assumes max frame size of 64 bit + x for safety

get_lines(*, force_redo: bool = False) ndarray

Timestamped symbols to line, cut at r, rn or n.

get_symbols(*, force_redo: bool = False) ndarray

Extract symbols from events.

Ways to detect EOF: - long pause on HIGH - off_tick pause on high - bit_pos > max

# TODO:
  • slowest FN -> speedup with numba or parallelization?

  • dset could be divided (long pauses) and threaded for speedup.

get_text(*, force_redo: bool = False) str

Remove timestamps and just return the whole string.