2023-10-03 13:15:17 +00:00
|
|
|
import path from "node:path";
|
|
|
|
import fs from "fs";
|
2023-11-04 02:12:06 +00:00
|
|
|
import { setColormap } from "./waterfallHandler";
|
2023-09-06 10:23:20 +00:00
|
|
|
// pinia store setup
|
2023-10-03 13:15:17 +00:00
|
|
|
import { setActivePinia } from "pinia";
|
|
|
|
import pinia from "../store/index";
|
2023-09-06 10:23:20 +00:00
|
|
|
setActivePinia(pinia);
|
|
|
|
|
2023-10-03 13:15:17 +00:00
|
|
|
import { useSettingsStore } from "../store/settingsStore.js";
|
2023-09-06 10:23:20 +00:00
|
|
|
const settings = useSettingsStore(pinia);
|
2023-11-08 10:24:52 +00:00
|
|
|
|
2023-11-09 13:15:11 +00:00
|
|
|
import { useAudioStore } from "../store/audioStore.js";
|
|
|
|
const audioStore = useAudioStore(pinia);
|
|
|
|
|
2023-11-08 19:19:13 +00:00
|
|
|
import { postToServer, getFromServer } from "./rest.js";
|
2023-11-08 19:18:41 +00:00
|
|
|
|
2023-09-06 10:23:20 +00:00
|
|
|
// ---------------------------------
|
|
|
|
|
2023-10-22 08:12:00 +00:00
|
|
|
console.log(process.env);
|
2023-10-22 09:13:02 +00:00
|
|
|
var appDataFolder = "undefined";
|
2023-10-22 08:12:00 +00:00
|
|
|
if (typeof process.env["APPDATA"] !== "undefined") {
|
2023-10-22 09:13:02 +00:00
|
|
|
appDataFolder = process.env["APPDATA"];
|
2023-10-22 08:12:00 +00:00
|
|
|
console.log(appDataFolder);
|
2023-10-04 21:34:36 +00:00
|
|
|
} else {
|
2023-10-22 08:12:00 +00:00
|
|
|
switch (process.platform) {
|
|
|
|
case "darwin":
|
2023-10-22 09:13:02 +00:00
|
|
|
appDataFolder = process.env["HOME"] + "/Library/Application Support";
|
2023-10-22 08:12:00 +00:00
|
|
|
console.log(appDataFolder);
|
|
|
|
break;
|
|
|
|
case "linux":
|
2023-10-22 09:13:02 +00:00
|
|
|
appDataFolder = process.env["HOME"] + "/.config";
|
2023-10-22 08:12:00 +00:00
|
|
|
console.log(appDataFolder);
|
2023-10-22 09:19:25 +00:00
|
|
|
break;
|
2023-10-22 08:12:00 +00:00
|
|
|
case "win32":
|
2023-10-22 09:13:02 +00:00
|
|
|
appDataFolder = "undefined";
|
2023-10-22 08:12:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
2023-10-22 09:13:02 +00:00
|
|
|
appDataFolder = "undefined";
|
2023-10-22 08:12:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-10-04 21:34:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 10:23:20 +00:00
|
|
|
var configFolder = path.join(appDataFolder, "FreeDATA");
|
|
|
|
var configPath = path.join(configFolder, "config.json");
|
|
|
|
|
2023-10-22 08:12:00 +00:00
|
|
|
console.log(appDataFolder);
|
|
|
|
console.log(configFolder);
|
|
|
|
console.log(configPath);
|
2023-10-04 21:34:36 +00:00
|
|
|
|
2023-09-06 10:23:20 +00:00
|
|
|
// create config folder if not exists
|
|
|
|
if (!fs.existsSync(configFolder)) {
|
|
|
|
fs.mkdirSync(configFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create config file if not exists with defaults
|
2023-11-08 10:24:52 +00:00
|
|
|
const configDefaultSettings = `{
|
|
|
|
"modem_host": "127.0.0.1",
|
|
|
|
"modem_port": 3000,
|
|
|
|
"spectrum": "waterfall",
|
|
|
|
"theme": "default",
|
|
|
|
"screen_height": 430,
|
|
|
|
"screen_width": 1050,
|
|
|
|
"update_channel": "latest",
|
|
|
|
"wftheme": 2,
|
|
|
|
"enable_sys_notification": 1
|
|
|
|
}`;
|
|
|
|
var parsedConfig = JSON.parse(configDefaultSettings);
|
2023-09-06 10:23:20 +00:00
|
|
|
|
|
|
|
if (!fs.existsSync(configPath)) {
|
|
|
|
fs.writeFileSync(configPath, configDefaultSettings);
|
|
|
|
}
|
|
|
|
|
2023-10-03 13:15:17 +00:00
|
|
|
export function loadSettings() {
|
|
|
|
// load settings
|
|
|
|
var config = require(configPath);
|
2023-09-06 12:48:45 +00:00
|
|
|
|
2023-10-03 13:15:17 +00:00
|
|
|
//config validation
|
|
|
|
// check running config against default config.
|
|
|
|
// if parameter not exists, add it to running config to prevent errors
|
|
|
|
console.log("CONFIG VALIDATION ----------------------------- ");
|
2023-09-06 20:20:18 +00:00
|
|
|
|
2023-10-03 13:15:17 +00:00
|
|
|
for (var key in parsedConfig) {
|
|
|
|
if (config.hasOwnProperty(key)) {
|
|
|
|
console.log("FOUND SETTTING [" + key + "]: " + config[key]);
|
2023-09-06 20:20:18 +00:00
|
|
|
} else {
|
2023-10-03 13:15:17 +00:00
|
|
|
console.log("MISSING SETTTING [" + key + "] : " + parsedConfig[key]);
|
|
|
|
config[key] = parsedConfig[key];
|
|
|
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
|
|
}
|
|
|
|
try {
|
2023-11-08 10:25:25 +00:00
|
|
|
if (key == "wftheme") {
|
2023-11-04 02:12:06 +00:00
|
|
|
setColormap(config[key]);
|
|
|
|
}
|
2023-10-03 13:15:17 +00:00
|
|
|
if (key == "mycall") {
|
|
|
|
settings.mycall = config[key].split("-")[0];
|
|
|
|
settings.myssid = config[key].split("-")[1];
|
|
|
|
} else {
|
|
|
|
settings[key] = config[key];
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
2023-09-06 20:20:18 +00:00
|
|
|
}
|
2023-09-06 10:23:20 +00:00
|
|
|
}
|
2023-09-06 12:48:45 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 13:15:17 +00:00
|
|
|
export function saveSettingsToFile() {
|
|
|
|
console.log("save settings to file...");
|
|
|
|
let config = settings.getJSON();
|
|
|
|
console.log(config);
|
|
|
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
|
|
}
|
2023-11-08 10:24:52 +00:00
|
|
|
|
2023-11-08 10:25:25 +00:00
|
|
|
export function processModemConfig(data) {
|
2023-11-08 19:19:13 +00:00
|
|
|
// update our settings from get request
|
|
|
|
// TODO Can we make this more dynamic? Maybe using a settings object?
|
|
|
|
// For now its a hardcoded structure until we found a better way
|
|
|
|
|
|
|
|
console.log(data);
|
2023-11-11 19:28:24 +00:00
|
|
|
// chatGPT function for iterating through all items and asserting them to a function
|
2023-11-11 19:27:54 +00:00
|
|
|
for (const category in data) {
|
|
|
|
if (data.hasOwnProperty(category)) {
|
2023-11-11 19:28:24 +00:00
|
|
|
for (const setting in data[category]) {
|
|
|
|
if (data[category].hasOwnProperty(setting)) {
|
|
|
|
// Create a variable name combining the category and setting name
|
|
|
|
const variableName = setting;
|
|
|
|
// Assign the value to the variable
|
|
|
|
settings[variableName] = data[category][setting];
|
|
|
|
|
|
|
|
console.log(variableName + ": " + settings[variableName]);
|
2023-11-11 19:27:54 +00:00
|
|
|
}
|
2023-11-11 19:28:24 +00:00
|
|
|
}
|
2023-11-11 19:27:54 +00:00
|
|
|
}
|
2023-11-11 19:28:24 +00:00
|
|
|
}
|
2023-11-11 19:27:54 +00:00
|
|
|
|
2023-11-11 19:28:24 +00:00
|
|
|
/*
|
2023-11-08 19:19:13 +00:00
|
|
|
// STATION SETTINGS
|
|
|
|
// Extract the callsign and SSID
|
|
|
|
if (data.STATION.mycall.includes("-")) {
|
|
|
|
const splittedCallsign = data.STATION.mycall.split("-");
|
|
|
|
settings.mycall = splittedCallsign[0]; // The part before the hyphen
|
|
|
|
settings.myssid = parseInt(splittedCallsign[1], 10); // The part after the hyphen, converted to a number
|
|
|
|
} else {
|
|
|
|
settings.mycall = data.STATION.mycall; // Use the original mycall if no SSID is present
|
|
|
|
settings.myssid = 0; // Default SSID if not provided
|
|
|
|
}
|
|
|
|
settings.mygrid = data.STATION.mygrid;
|
|
|
|
|
|
|
|
// ssid list not yet implemented
|
|
|
|
//data.STATION.ssid_list[0];
|
|
|
|
|
|
|
|
// AUDIO SETTINGS
|
|
|
|
settings.auto_tune = data.AUDIO.auto_tune;
|
|
|
|
settings.rx_audio_level = data.AUDIO.rxaudiolevel;
|
|
|
|
settings.tx_audio_level = data.AUDIO.txaudiolevel;
|
2023-11-09 13:15:11 +00:00
|
|
|
settings.rx_audio = data.AUDIO.rx;
|
|
|
|
settings.tx_audio = data.AUDIO.tx;
|
2023-11-08 19:19:13 +00:00
|
|
|
|
|
|
|
// MODEM SETTINGS
|
|
|
|
settings.enable_fft = data.Modem.fft;
|
|
|
|
settings.enable_fsk = data.Modem.fsk;
|
|
|
|
settings.tuning_range_fmin = data.Modem.fmin;
|
|
|
|
settings.tuning_range_fmax = data.Modem.fmax;
|
|
|
|
settings.rx_buffer_size = data.Modem.rx_buffer_size;
|
|
|
|
settings.enable_explorer = data.Modem.explorer;
|
|
|
|
settings.explorer_stats = data.Modem.stats;
|
|
|
|
settings.tx_delay = data.Modem.tx_delay;
|
|
|
|
settings.respond_to_cq = data.Modem.qrv;
|
|
|
|
settings.low_bandwidth_mode = data.Modem.narrowband;
|
|
|
|
|
|
|
|
// HAMLIB SETTINGS
|
|
|
|
settings.hamlib_rigctld_port = data.RADIO.rigctld_port;
|
|
|
|
settings.hamlib_rigctld_ip = data.RADIO.rigctld_ip;
|
|
|
|
settings.radiocontrol = data.RADIO.radiocontrol;
|
|
|
|
|
|
|
|
// TCI SETTINGS
|
|
|
|
settings.tci_ip = data.TCI.ip;
|
|
|
|
settings.tci_port = data.TCI.port;
|
|
|
|
|
|
|
|
// MESH SETTINGS
|
|
|
|
settings.enable_mesh_features = data.MESH.enable_protocol;
|
2023-11-11 19:27:54 +00:00
|
|
|
|
|
|
|
*/
|
2023-11-08 10:25:25 +00:00
|
|
|
}
|
2023-11-08 19:18:41 +00:00
|
|
|
|
2023-11-09 13:15:11 +00:00
|
|
|
export function processModemAudioDevices(data) {
|
2023-11-09 13:15:29 +00:00
|
|
|
console.log(data);
|
|
|
|
audioStore.inputDevices = data["in"];
|
|
|
|
audioStore.outputDevices = data["out"];
|
2023-11-09 13:15:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function processModemSerialDevices(data) {
|
2023-11-09 13:15:29 +00:00
|
|
|
settings.serial_devices = data;
|
2023-11-09 13:15:11 +00:00
|
|
|
}
|
|
|
|
|
2023-11-08 19:19:13 +00:00
|
|
|
export function getModemConfigAsJSON() {
|
|
|
|
// create json output from settings
|
|
|
|
// TODO Can we make this more dynamic? Maybe using a settings object?
|
|
|
|
// For now its a hardcoded structure until we found a better way
|
|
|
|
|
|
|
|
const configData = {
|
|
|
|
AUDIO: {
|
2023-11-11 19:27:54 +00:00
|
|
|
enable_auto_tune: settings.auto_tune,
|
2023-11-11 19:01:15 +00:00
|
|
|
input_device: settings.rx_audio,
|
2023-11-08 19:19:13 +00:00
|
|
|
rxaudiolevel: settings.rx_audio_level,
|
2023-11-11 19:01:15 +00:00
|
|
|
output_device: settings.tx_audio,
|
2023-11-08 19:19:13 +00:00
|
|
|
txaudiolevel: settings.tx_audio_level,
|
2023-11-11 19:01:15 +00:00
|
|
|
//enable_auto_tune: settings.tx_audio_level,
|
2023-11-08 19:19:13 +00:00
|
|
|
},
|
|
|
|
MESH: {
|
|
|
|
enable_protocol: settings.enable_mesh_features,
|
|
|
|
},
|
|
|
|
Modem: {
|
2023-11-11 19:01:15 +00:00
|
|
|
enable_explorer: settings.enable_explorer,
|
|
|
|
enable_fft: settings.enable_fft,
|
|
|
|
tuning_range_fmax: settings.tuning_range_fmax,
|
|
|
|
tuning_range_fmin: settings.tuning_range_fmin,
|
|
|
|
enable_fsk: settings.enable_fsk,
|
|
|
|
enable_low_bandwidth_mode: settings.enable_low_bandwidth_mode,
|
|
|
|
respond_to_cq: settings.respond_to_cq,
|
2023-11-08 19:19:13 +00:00
|
|
|
rx_buffer_size: settings.rx_buffer_size,
|
2023-11-11 19:01:15 +00:00
|
|
|
enable_scatter: "False",
|
|
|
|
enable_stats: settings.explorer_stats,
|
2023-11-08 19:19:13 +00:00
|
|
|
tx_delay: settings.tx_delay,
|
|
|
|
},
|
|
|
|
NETWORK: {
|
|
|
|
modemport: "3000",
|
|
|
|
},
|
|
|
|
RADIO: {
|
|
|
|
radiocontrol: settings.radiocontrol,
|
|
|
|
rigctld_ip: settings.hamlib_rigctld_ip,
|
|
|
|
rigctld_port: settings.hamlib_rigctld_port,
|
|
|
|
},
|
|
|
|
STATION: {
|
|
|
|
mycall: settings.mycall + "-" + settings.myssid,
|
|
|
|
mygrid: settings.mygrid,
|
|
|
|
ssid_list: [],
|
|
|
|
},
|
|
|
|
TCI: {
|
2023-11-11 19:27:54 +00:00
|
|
|
tci_ip: settings.tci_ip,
|
|
|
|
tci_port: settings.tci_port,
|
2023-11-08 19:19:13 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return configData;
|
2023-11-08 19:18:41 +00:00
|
|
|
}
|