From c5323f8d5470f86a77c2b0f449fff62b1f3aba5c Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 14 Jan 2021 00:12:53 +0100 Subject: [PATCH] validate start_freq, use center_freq if invalid --- htdocs/lib/DemodulatorPanel.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/htdocs/lib/DemodulatorPanel.js b/htdocs/lib/DemodulatorPanel.js index 2cdca68..b98044b 100644 --- a/htdocs/lib/DemodulatorPanel.js +++ b/htdocs/lib/DemodulatorPanel.js @@ -181,7 +181,7 @@ DemodulatorPanel.prototype.collectParams = function() { squelch_level: -150, mod: 'nfm' } - return $.extend(new Object(), defaults, this.initialParams, this.transformHashParams(this.parseHash())); + return $.extend(new Object(), defaults, this.validateInitialParams(this.initialParams), this.transformHashParams(this.parseHash())); }; DemodulatorPanel.prototype.startDemodulator = function() { @@ -287,7 +287,7 @@ DemodulatorPanel.prototype.validateHash = function(params) { var self = this; params = Object.keys(params).filter(function(key) { if (key == 'freq' || key == 'mod' || key == 'secondary_mod' || key == 'sql') { - return params.freq && Math.abs(params.freq - self.center_freq) < bandwidth / 2; + return params.freq && Math.abs(params.freq - self.center_freq) <= bandwidth / 2; } return true; }).reduce(function(p, key) { @@ -303,6 +303,17 @@ DemodulatorPanel.prototype.validateHash = function(params) { return params; }; +DemodulatorPanel.prototype.validateInitialParams = function(params) { + return Object.fromEntries( + Object.entries(params).filter(function(a) { + if (a[0] == "offset_frequency") { + return Math.abs(a[1]) <= bandwidth / 2; + } + return true; + }) + ); +}; + DemodulatorPanel.prototype.updateHash = function() { var demod = this.getDemodulator(); if (!demod) return;