skyspy: fix whitespace, counting time with sat view should now work

master
Pavel Machek 2024-12-03 14:02:02 +01:00
parent 7161aac53e
commit e78f566e96
1 changed files with 51 additions and 49 deletions

View File

@ -630,15 +630,15 @@ let sky = {
return this.sats.slice(0, this.snum).sort((a, b) => b.snr - a.snr); return this.sats.slice(0, this.snum).sort((a, b) => b.snr - a.snr);
}, },
getSatSNR: function(n) { /* Get n-th strongest sat */ getSatSNR: function(n) { /* Get n-th strongest sat */
if (n <= 0 || n > this.sats.length) if (n <= 0 || n > this.sats.length)
return -1; return -1;
// Sort the satellites by snr in descending order // Sort the satellites by snr in descending order
let sortedSats = this.snrSort(); let sortedSats = this.snrSort();
// Return the SNR of the n-th strongest satellite // Return the SNR of the n-th strongest satellite
return sortedSats[n - 1].snr; return sortedSats[n - 1].snr;
}, },
qualest: function() { qualest: function() {
// Sort the satellites by snr in descending order // Sort the satellites by snr in descending order
let sortedSats = this.snrSort(); let sortedSats = this.snrSort();
@ -653,60 +653,62 @@ let sky = {
}, },
satVisibility: [], satVisibility: [],
trackSatelliteVisibility: function() { trackSatelliteVisibility: function() {
const threshold = this.snrLim; // SNR threshold const threshold = this.snrLim; // SNR threshold
const now = getTime(); const now = getTime();
let newVisibility = []; let newVisibility = [];
//this.satVisibility = []; //this.satVisibility = [];
for (let i = 0; i < this.snum; i++) { for (let i = 0; i < this.snum; i++) {
let sat = this.sats[i]; let sat = this.sats[i];
let existingSat = this.satVisibility[sat.id]; let existingSat = this.satVisibility[sat.id];
if (sat.snr >= threshold) { if (sat.snr >= threshold) {
if (!existingSat) { if (!existingSat) {
// New satellite starts visibility // New satellite starts visibility
newVisibility[sat.id] = { start: now, visible: true }; newVisibility[sat.id] = { start: now, visible: true };
} else } else
newVisibility[sat.id] = this.satVisibility[sat.id]; newVisibility[sat.id] = this.satVisibility[sat.id];
}
} }
} this.satVisibility = newVisibility;
this.satVisibility = newVisibility; },
},
getnthLowestStartTimeSat: function(n) { getnthLowestStartTimeSat: function(n) {
// Collect all satellites from visibility // Collect all satellites from visibility
let satellites = Object.values(this.satVisibility); let satellites = Object.values(this.satVisibility);
// Ensure we have at least 5 satellites // Ensure we have at least 5 satellites
if (satellites.length < n) if (satellites.length < n)
return -1; return -1;
// Sort satellites by start time in ascending order // Sort satellites by start time in ascending order
satellites.sort((a, b) => a.start - b.start); satellites.sort((a, b) => a.start - b.start);
// Return the satellite with the 5th lowest start time // Return the satellite with the 5th lowest start time
return satellites[n-1]; // 0-based index, so 5th is index 4 return satellites[n-1]; // 0-based index, so 5th is index 4
}, },
goodest: function () { goodest: function () {
let s = this.getnthLowestStartTimeSat(5); let s = this.getnthLowestStartTimeSat(5);
let t = getTime() - s; if (s==-1)
return "none";
let t = getTime() - s.start;
return "" + t; return "" + t;
}, },
messageEnd: function() { messageEnd: function() {
this.old_msg = this.msg; this.old_msg = this.msg;
this.msg = {}; this.msg = {};
this.msg.gp = {}; this.msg.gp = {};
this.msg.bd = {}; this.msg.bd = {};
this.msg.gl = {}; this.msg.gl = {};
this.drawSats(this.sats); this.drawSats(this.sats);
let r = this.qualest(); let r = this.qualest();
let r1 = this.goodest(); let r1 = this.goodest();
print(r, r1, this.old_msg.hdop, this.old_msg.quality); print(r, r1, this.old_msg.hdop, this.old_msg.quality);
ui.drawMsg(r + "\n" + r1 + "\n" + this.old_msg.hdop + "\n" + this.old_msg.quality); ui.drawMsg(r + "\n" + r1 + "\n" + this.old_msg.hdop + "\n" + this.old_msg.quality);
this.trackSatelliteVisibility(); this.trackSatelliteVisibility();
//print(this.sats); //print(this.sats);
if (this.sats_used < 5) if (this.sats_used < 5)
this.sky_start = getTime(); this.sky_start = getTime();
this.snum = 0; this.snum = 0;
this.sats = []; this.sats = [];
this.sats_used = 0; this.sats_used = 0;
}, },
parseRaw: function(msg, lost) { parseRaw: function(msg, lost) {