From 0a338519552006bdc7fd80d34edcf786848529b2 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Sat, 14 Oct 2023 17:09:25 +0100 Subject: [PATCH] Kryoflux: Allow sample clock rate to be specified when generating stream files For example, 72MHz rate: gw read name/00.0.raw::sck=72m --- src/greaseweazle/image/kryoflux.py | 32 +++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/greaseweazle/image/kryoflux.py b/src/greaseweazle/image/kryoflux.py index 35ef95c6..2461fba9 100644 --- a/src/greaseweazle/image/kryoflux.py +++ b/src/greaseweazle/image/kryoflux.py @@ -11,7 +11,7 @@ from greaseweazle import __version__ from greaseweazle import error from greaseweazle.flux import Flux -from .image import Image, OptDict +from .image import Image, ImageOpts, OptDict def_mck = 18432000 * 73 / 14 / 2 def_sck = def_mck / 2 @@ -31,6 +31,31 @@ class OOB: KFInfo = 4 EOF = 13 +class KFOpts(ImageOpts): + """sck: Sample clock to use for flux timings. + Suffix 'm' for MHz. For example: sck=72m + """ + + w_settings = [ 'sck' ] + + def __init__(self) -> None: + self._sck: float = def_sck + + @property + def sck(self) -> float: + return self._sck + @sck.setter + def sck(self, sck: str): + factor = 1e0 + if sck.lower().endswith('m'): + sck = sck[:-1] + factor = 1e6 + try: + self._sck = float(sck) * factor + except ValueError: + raise error.Fatal("Kryoflux: Bad sck value: '%s'\n" % sck) + + class KryoFlux(Image): def __init__(self, name: str, _fmt) -> None: @@ -44,6 +69,7 @@ def __init__(self, name: str, _fmt) -> None: assert m is not None # mypy self.basename = name[:m.start()] self.filename = name + self.opts = KFOpts() @classmethod @@ -67,7 +93,7 @@ def get_track(self, cyl, side): # Parse the index-pulse stream positions and KFInfo blocks. index, idx = [], 0 - sck, ick = def_sck, def_sck/8 + sck, ick = self.opts.sck, self.opts.sck/8 while idx < len(dat): op = dat[idx] if op == Op.OOB: @@ -198,7 +224,7 @@ def emit(f): check_index(f) flux = track.flux() - sck = def_sck + sck = self.opts.sck # HxC crashes or fails to load non-index-cued stream files. # So let's give it what it wants.