Skip to content

Commit

Permalink
Skip frequency limit checks on request
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
hamarituc committed Jun 15, 2023
1 parent 7c45be5 commit 498408f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ fout1 = fosc / (N1_HS * NC1_LS) = 450.000 Hz ... 808.000 MHz
fout2 = fosc / (N1_HS * NC2_LS) = 450.000 Hz ... 808.000 MHz
```

Frequency Limit
---------------

The datasheet specifies limits for the intermediate frequenciens. However it
was reported, the clock performs well even outside this limits. The parameter
`--ignore-freq-limits` skips the internal checks of these limits whenever a
configuration is written to the device or exported into a file (commands
`modify`, `backup`, `restore`, `analyze`). The limit violations are still shown
in the diagnostic output.

Future plans
------------

Expand Down
54 changes: 43 additions & 11 deletions lbgpsdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,27 @@ def update(self, *args, **kwargs):
self.level = level


def asdict(self):
def asdict(self, ignore_freq_limits = False):
"""
Returns the configuration as a dictionary.
The returned dict can by use a argument for `update()` method to
restore the settings.
The method raises an exception if the configuration is invalid.
The method raises an exception if the configuration is invalid. If
`ignore_freq_limits` is `True`, no error is raised if an intermediate
frequency exceeds the limits specified in the datasheet.
:param ignore_freq_limits: Ignore frequency limits defined in the datasheet.
:type ignore_freq_limits: bool
:raises: :class:`GPSDOConfigurationException`: Invalid configuration
:returns: Configuration
:rtype: dict
"""

freq, errdict, errflag = self.freqplan()
freq, errdict, errflag = self.freqplan(ignore_freq_limits = ignore_freq_limits)
if errflag:
raise GPSDOConfigurationException({ a: v for a, v in errdict.items() if v is not None })

Expand All @@ -276,7 +281,7 @@ def asdict(self):
return configdict


def freqplan(self, modify = False):
def freqplan(self, modify = False, ignore_freq_limits = False):
"""
Returns the frequency plan.
Expand All @@ -300,6 +305,12 @@ def freqplan(self, modify = False):
:param modifiy: Enable output 1.
:type modifiy: bool
If `ignore_freq_limits` is `True`, no error is raised if an
intermediate frequency exceeds the limits specified in the datasheet.
:param ignore_freq_limits: Ignore frequency limits defined in the datasheet.
:type ignore_freq_limits: bool
:raises: :class:`GPSDOConfigurationException`: Invalid configuration
:returns: Frequency plan and error information
Expand Down Expand Up @@ -355,6 +366,8 @@ def freqplan(self, modify = False):
value = freq[attr]
if value is None:
errdict[attr] = "%s undefined." % name
elif ignore_freq_limits:
errdict[attr] = None
elif value < lmin or value > lmax:
errdict[attr] = "%s is %s, but %s." % ( name, self._format_freq(value), msg )
else:
Expand Down Expand Up @@ -845,7 +858,7 @@ def read(self, update = True):
return result


def write(self, overwrite = False):
def write(self, overwrite = False, ignore_freq_limits = False):
"""
Write configuration to the device.
Expand All @@ -861,11 +874,17 @@ def write(self, overwrite = False):
:param overwrite: Force updating the configuration.
:type overwrite: bool
If `ignore_freq_limits` is `True`, no error is raised if an
intermediate frequency exceeds the limits specified in the datasheet.
:param ignore_freq_limits: Ignore frequency limits defined in the datasheet.
:type ignore_freq_limits: bool
:raises: :class:`GPSDOConfigurationException`: Invalid configuration
"""

# Check settings.
freq, errdict, errflag = self.freqplan()
freq, errdict, errflag = self.freqplan(ignore_freq_limits = ignore_freq_limits)

# Dont't upload invalid settings.
if errflag:
Expand Down Expand Up @@ -1028,7 +1047,7 @@ def command_modify(args):
d.update(**parser_get_config(args))
sys.stdout.write(d.infotext(show_status = args.show_status, show_freq = args.show_freq))
if not args.pretend:
d.write()
d.write(ignore_freq_limits = args.ignore_freq_limits)
except GPSDOConfigurationException as e:
sys.stdout.write("Parameter error:\n")
sys.stdout.write(e.errortext())
Expand All @@ -1040,7 +1059,8 @@ def command_backup(args):
try:
d.read()
sys.stdout.write(d.infotext(show_status = args.show_status, show_freq = args.show_freq))
json.dump(d.asdict(), args.output_file, indent = 2)
json.dump(d.asdict(ignore_freq_limits = args.ignore_freq_limits),
args.output_file, indent = 2)
except GPSDOConfigurationException as e:
sys.stdout.write("Parameter error:\n")
sys.stdout.write(e.errortext())
Expand All @@ -1053,7 +1073,7 @@ def command_restore(args):
d.update(**json.load(args.input_file))
sys.stdout.write(d.infotext(show_status = False, show_freq = args.show_freq))
if not args.pretend:
d.write()
d.write(ignore_freq_limits = args.ignore_freq_limits)
except GPSDOConfigurationException as e:
sys.stdout.write("Parameter error:\n")
sys.stdout.write(e.errortext())
Expand All @@ -1080,9 +1100,10 @@ def command_analyze(args):
sys.stdout.write(d.infotext(show_status = False))

if args.output_device:
d.write()
d.write(ignore_freq_limits = args.ignore_freq_limits)
elif args.output_file:
json.dump(d.asdict(), args.output_file, indent = 2)
json.dump(d.asdict(ignore_freq_limits = args.ignore_freq_limits),
args.output_file, indent = 2)

except GPSDOConfigurationException as e:
sys.stdout.write("Parameter error:\n")
Expand Down Expand Up @@ -1287,6 +1308,13 @@ def parser_add_show_freq(p):
help = "Show frequency plan")


def parser_add_ignore_freq_limits(p):
p.add_argument(
'--ignore-freq-limits',
action = 'store_true',
help = "Ignore frequency limits specified in the datasheet")


def parser_get_config(args):
result = {}
for attr in [ 'fin', 'n3', 'n2_hs', 'n2_ls', 'n1_hs', 'nc1_ls', 'nc2_ls', 'skew', 'bw', 'out1', 'out2' ]:
Expand Down Expand Up @@ -1344,6 +1372,7 @@ def parser_get_config(args):
parser_add_show_status(parser_modify)
parser_add_show_freq(parser_modify)
parser_add_config(parser_modify)
parser_add_ignore_freq_limits(parser_modify)
parser_modify.set_defaults(func = command_modify)


Expand All @@ -1355,6 +1384,7 @@ def parser_get_config(args):
parser_add_device(parser_backup)
parser_add_show_status(parser_backup)
parser_add_show_freq(parser_backup)
parser_add_ignore_freq_limits(parser_backup)
parser_add_output(parser_backup, required = True)
parser_backup.set_defaults(func = command_backup)

Expand All @@ -1367,6 +1397,7 @@ def parser_get_config(args):
parser_add_device(parser_restore)
parser_add_pretend(parser_restore)
parser_add_show_freq(parser_restore)
parser_add_ignore_freq_limits(parser_restore)
parser_add_input(parser_restore, required = True)
parser_restore.set_defaults(func = command_restore)

Expand Down Expand Up @@ -1413,6 +1444,7 @@ def parser_get_config(args):
parser_add_multiinput(parser_analyze)
parser_add_multioutput(parser_analyze)
parser_add_config(parser_analyze)
parser_add_ignore_freq_limits(parser_analyze)
parser_analyze.set_defaults(func = command_analyze)


Expand Down

0 comments on commit 498408f

Please sign in to comment.