/* Copyright (c) 2023-forever Douglas Malnati. All rights reserved. See the /faq/tos page for details. (If this generated header is stamped on a file which is a 3rd party file or under a different license or copyright, then ignore this copyright statement and use that file's terms.) */ import { CandidateFilterBase } from './CandidateFilterBase.js'; import { NonRejectedOnlyFilter } from './WsprMessageCandidate.js'; import { CodecHeartbeat } from './CodecHeartbeat.js'; import { WSPR } from '/js/WSPR.js'; /////////////////////////////////////////////////////////////////////////// // // Candidate Filter - Heartbeat // // Reject Heartbeat messages whose stated intended TX frequency does not // match the searched-for channel frequency. /////////////////////////////////////////////////////////////////////////// export class CandidateFilterHeartbeat extends CandidateFilterBase { constructor(t, band, channel) { super("Heartbeat", t); this.band = band; this.channel = channel; this.codecHeartbeat = new CodecHeartbeat(); } OnFilterStart() { this.t.Event(`CandidateFilterHeartbeat Start`); } OnFilterEnd() { this.t.Event(`CandidateFilterHeartbeat End`); } FilterWindowAlgorithm(msgListList) { if (this.channel == "") { return; } let searchedFreqHz = WSPR.GetChannelDetails(this.band, this.channel).freq; for (let slot = 0; slot < 5; ++slot) { for (let msg of NonRejectedOnlyFilter(msgListList[slot])) { if (!msg.IsTelemetryExtended()) { continue; } let codec = msg.GetCodec(); if (!this.codecHeartbeat.IsCodecHeartbeat(codec)) { continue; } let intendedFreqHz = this.codecHeartbeat.DecodeTxFreqHzFromBand( this.band, codec.GetTxFreqHzIdx(), ); if (intendedFreqHz !== searchedFreqHz) { msg.Reject( this.type, `Heartbeat intended frequency (${intendedFreqHz}) does not match searched channel frequency (${searchedFreqHz}).` ); } else if (msg.IsCandidate()) { msg.Confirm( this.type, `Heartbeat matches searched channel frequency (${searchedFreqHz}).` ); } } } } }