1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

TX ID Algorithm tweaks and config options

Fix bug when TX ERP is 1W and allow user choice of algorithms in webserver config
This commit is contained in:
Adam Wisher
2025-04-21 08:22:36 +01:00
parent ea3b0d8ced
commit 2cd2cf5cf1
3 changed files with 36 additions and 4 deletions

View File

@@ -30,7 +30,8 @@ let serverConfig = {
],
defaultTheme: "theme1",
bgImage: "",
rdsMode: false
rdsMode: false,
txIdAlgorithm: 0
},
xdrd: {
wirelessConnection: true,

View File

@@ -12,6 +12,21 @@ var currentRdsPs = '';
const usStatesGeoJsonUrl = "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json";
let usStatesGeoJson = null; // To cache the GeoJSON data for US states
// Get weighting values based on algorithm setting.
// Defaults = algorithm 1
let weightedErp = 10;
let weightedDist = 400;
const algorithms = [
[10, 400],
[30, 500]
];
const algoSetting = parseInt(serverConfig.webserver.txIdAlgorithm);
if (typeof algorithms[algoSetting] !== 'undefined') {
weightedErp = algorithms[algoSetting][0];
weightedDist = algorithms[algoSetting][1];
}
// Load the US states GeoJSON data
async function loadUsStatesGeoJson() {
if (!usStatesGeoJson) {
@@ -121,8 +136,14 @@ async function processData(data, piCode, rdsPs) {
weightDistance = Math.abs(distance.distanceKm - 1500);
}
let erp = station.erp && station.erp > 0 ? station.erp : 1;
let extraWeight = erp >= 10 && distance.distanceKm <= 400 ? 0.3 : 0;
const score = ((10 * Math.log10(erp * 1000)) / weightDistance) + extraWeight;
let extraWeight = erp >= weightedErp && distance.distanceKm <= weightedDist ? 0.3 : 0;
let score = 0;
// If ERP is 1W, use a simpler formula to avoid zero-scoring.
if (erp === 0.001) {
score = erp / distance.distanceKm;
} else {
score = ((10 * Math.log10(erp * 1000)) / weightDistance) + extraWeight;
}
if (score > maxScore) {
maxScore = score;
txAzimuth = distance.azimuth;
@@ -247,4 +268,4 @@ function deg2rad(deg) {
module.exports = {
fetchTx
};
};