/* 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 { CodecHeartbeat } from './CodecHeartbeat.js'; export class ColumnBuilderHeartbeat { constructor() { this.codecHeartbeat = new CodecHeartbeat(); } MatchWindow(slotMsgList) { return this.HasAnyHeartbeat(slotMsgList); } GetColNameList() { return [ "TxFreqHzIdx", "UptimeMinutes", "GpsLockType", "GpsTryLockSeconds", "GpsSatsInViewCount", ]; } GetColMetaDataList() { return [ { rangeMin: 0, rangeMax: 200 }, { rangeMin: 0, rangeMax: 1440 }, { rangeMin: 0, rangeMax: 2 }, { rangeMin: 0, rangeMax: 1200 }, { rangeMin: 0, rangeMax: 50 }, ]; } GetValListForWindow(slotMsgList) { let msg = this.GetLatestHeartbeat(slotMsgList); if (!msg) { return [null, null, null, null, null]; } let codec = msg.GetCodec(); return [ codec.GetTxFreqHzIdx(), codec.GetUptimeMinutes(), codec.GetGpsLockTypeEnum(), codec.GetGpsTryLockSeconds(), codec.GetGpsSatsInViewCount(), ]; } GetLatestHeartbeat(slotMsgList) { if (!Array.isArray(slotMsgList) || slotMsgList.length == 0) { return null; } for (let slot = slotMsgList.length - 1; slot >= 0; --slot) { let msg = slotMsgList[slot]; if (!msg?.IsTelemetryExtended?.()) { continue; } if (this.codecHeartbeat.IsCodecHeartbeat(msg.GetCodec?.())) { return msg; } } return null; } HasAnyHeartbeat(slotMsgList) { if (!Array.isArray(slotMsgList) || slotMsgList.length == 0) { return false; } for (let slot = slotMsgList.length - 1; slot >= 0; --slot) { if (this.IsHeartbeatMsg(slotMsgList[slot])) { return true; } } return false; } IsHeartbeatMsg(msg) { if (!msg?.IsTelemetryExtended?.()) { return false; } return this.codecHeartbeat.IsCodecHeartbeat(msg.GetCodec?.()); } }