validate start_freq, use center_freq if invalid

This commit is contained in:
Jakob Ketterl 2021-01-14 00:12:53 +01:00
parent 7f3071336b
commit c5323f8d54

View File

@ -181,7 +181,7 @@ DemodulatorPanel.prototype.collectParams = function() {
squelch_level: -150, squelch_level: -150,
mod: 'nfm' 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() { DemodulatorPanel.prototype.startDemodulator = function() {
@ -287,7 +287,7 @@ DemodulatorPanel.prototype.validateHash = function(params) {
var self = this; var self = this;
params = Object.keys(params).filter(function(key) { params = Object.keys(params).filter(function(key) {
if (key == 'freq' || key == 'mod' || key == 'secondary_mod' || key == 'sql') { 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; return true;
}).reduce(function(p, key) { }).reduce(function(p, key) {
@ -303,6 +303,17 @@ DemodulatorPanel.prototype.validateHash = function(params) {
return 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() { DemodulatorPanel.prototype.updateHash = function() {
var demod = this.getDemodulator(); var demod = this.getDemodulator();
if (!demod) return; if (!demod) return;