Skip to content

Two Profiles #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ const bt_save=document.querySelector("#save");
$(document).ready(function() {
cfg=ipcRenderer.sendSync("get_config", '');

$("#hamlib_host").val(cfg.hamlib_host);
$("#hamlib_port").val(cfg.hamlib_port);
$("#hamlib_ena").prop("checked", cfg.hamlib_ena);
$("#ignore_pwr").prop("checked", cfg.ignore_pwr);

bt_save.addEventListener('click', () => {
cfg=ipcRenderer.sendSync("get_config", '');
cfg.hamlib_host=$("#hamlib_host").val().trim();
cfg.hamlib_port=$("#hamlib_port").val().trim();
cfg.hamlib_ena=$("#hamlib_ena").is(':checked');
cfg.ignore_pwr=$("#ignore_pwr").is(':checked');

if ($("#hamlib_ena").is(':checked') && cfg.flrig_ena){cfg.flrig_ena = false;}
$("#hamlib_host").val(cfg.profiles[cfg.profile].hamlib_host ?? '');
$("#hamlib_port").val(cfg.profiles[cfg.profile].hamlib_port ?? '');
$("#hamlib_ena").prop("checked", cfg.profiles[cfg.profile].hamlib_ena ?? '');
$("#ignore_pwr").prop("checked", cfg.profiles[cfg.profile].ignore_pwr ?? '');

bt_save.addEventListener('click', async () => {
cfg=await ipcRenderer.sendSync("get_config", '');
cfg.profiles[cfg.profile].hamlib_host=$("#hamlib_host").val().trim();
cfg.profiles[cfg.profile].hamlib_port=$("#hamlib_port").val().trim();
cfg.profiles[cfg.profile].hamlib_ena=$("#hamlib_ena").is(':checked');
cfg.profiles[cfg.profile].ignore_pwr=$("#ignore_pwr").is(':checked');

if ($("#hamlib_ena").is(':checked') && cfg.profiles[cfg.profile].flrig_ena){cfg.profiles[cfg.profile].flrig_ena = false;}

x=ipcRenderer.sendSync("set_config", cfg);
// console.log(x);
Expand Down
17 changes: 11 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,23 @@
</div>
<div class="row" id="buttonsRow">
<div class="col">
<div class="mb-3 col-mb-3" style="text-align: left">
<button type="button" class="btn btn-primary" id="save"></i>Save</button>
<div class="mb-4 col-mb-4" style="text-align: left">
<button type="button" class="btn btn-primary" id="save">Save</button>
</div>
</div>
<div class="col">
<div class="mb-3 col-mb-3" style="text-align: center">
<button type="button" class="btn btn-primary" id="test"></i>Test</button>
<div class="mb-4 col-mb-4" style="text-align: left">
<button type="button" class="btn btn-primary" id="toggle" title="change config-profile">1</button>
</div>
</div>
<div class="col">
<div class="mb-3 col-mb-3" style="text-align: right">
<button type="button" class="btn btn-primary" id="quit"></i>Quit</button>
<div class="mb-4 col-mb-4" style="text-align: center">
<button type="button" class="btn btn-primary" id="test">Test</button>
</div>
</div>
<div class="col">
<div class="mb-4 col-mb-4" style="text-align: right">
<button type="button" class="btn btn-primary" id="quit">Quit</button>
</div>
</div>
</div>
Expand Down
43 changes: 26 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function createAdvancedWindow (mainWindow) {
}

ipcMain.on("set_config", async (event,arg) => {
defaultcfg=arg;
defaultcfg=arg;
storage.set('basic', defaultcfg, function(e) {
if (e) throw e;
});
Expand All @@ -107,13 +107,24 @@ ipcMain.on("resize", async (event,arg) => {
});

ipcMain.on("get_config", async (event, arg) => {
const storedcfg = storage.getSync('basic');
for (const key in storedcfg) {
if (storedcfg[key] !== "" && storedcfg[key] !== undefined) {
defaultcfg[key] = storedcfg[key];
}
}
event.returnValue = defaultcfg;
var storedcfg = storage.getSync('basic');
var realcfg={};
if (!(storedcfg.wavelog_url) && !(storedcfg.profiles)) { storedcfg=defaultcfg; } // Old config not present, add default-cfg
if (!(storedcfg.profiles)) { // Old Config without array? Convert it
(realcfg.profiles = realcfg.profiles || []).push(storedcfg);
realcfg.profiles.push(defaultcfg);
realcfg.profile=(storedcfg.profile ?? 0);
} else {
realcfg=storedcfg;
}
if ((arg ?? '') !== '') {
realcfg.profile=arg;
}
defaultcfg=realcfg;
storage.set('basic', realcfg, function(e) { // Store one time
if (e) throw e;
});
event.returnValue = realcfg;
});

ipcMain.on("setCAT", async (event,arg) => {
Expand Down Expand Up @@ -174,7 +185,6 @@ function parseADIF(adifdata) {
function writeADIF(adifObject) {
const { ADIF } = require("tcadif");
var adiWriter = new ADIF(adifObject);
// console.log(adiWriter);
return adiWriter;
}

Expand All @@ -184,7 +194,6 @@ function send2wavelog(o_cfg,adif, dryrun = false) {
clpayload.station_profile_id=o_cfg.wavelog_id.trim();
clpayload.type='adif';
clpayload.string=adif;
// console.log(clpayload);
postData=JSON.stringify(clpayload);
let httpmod='http';
if (o_cfg.wavelog_url.toLowerCase().startsWith('https')) {
Expand Down Expand Up @@ -307,7 +316,7 @@ ports.forEach(port => {
let x={};
try {
outadif=writeADIF(adobject);
plainret=await send2wavelog(defaultcfg,outadif.stringify());
plainret=await send2wavelog(defaultcfg.profiles[defaultcfg.profile ?? 0],outadif.stringify());
x.state=plainret.statusCode;
x.payload = JSON.parse(plainret.resString);
} catch(e) {
Expand Down Expand Up @@ -370,7 +379,7 @@ async function settrx(qrg) {
} else {
to.mode='USB';
}
if (defaultcfg.flrig_ena) {
if (defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_ena) {
postData= '<?xml version="1.0"?>';
postData+='<methodCall><methodName>main.set_frequency</methodName><params><param><value><double>' + to.qrg + '</double></value></param></params></methodCall>';
var options = {
Expand All @@ -380,10 +389,10 @@ async function settrx(qrg) {
'Content-Length': postData.length
}
};
let url="http://"+defaultcfg.flrig_host+':'+defaultcfg.flrig_port+'/';
let url="http://"+defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_host+':'+defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_port+'/';
x=await httpPost(url,options,postData);

if (defaultcfg.wavelog_pmode) {
if (defaultcfg.profiles[defaultcfg.profile ?? 0].wavelog_pmode) {
postData= '<?xml version="1.0"?>';
postData+='<methodCall><methodName>rig.set_modeA</methodName><params><param><value>' + to.mode + '</value></param></params></methodCall>';
var options = {
Expand All @@ -396,10 +405,10 @@ async function settrx(qrg) {
x=await httpPost(url,options,postData);
}
}
if (defaultcfg.hamlib_ena) {
const client = net.createConnection({ host: defaultcfg.flrig_host, port: defaultcfg.flrig_port }, () => {
if (defaultcfg.profiles[defaultcfg.profile ?? 0].hamlib_ena) {
const client = net.createConnection({ host: defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_host, port: defaultcfg.profiles[defaultcfg.profile ?? 0].flrig_port }, () => {
client.write("F " + to.qrg + "\n");
if (defaultcfg.wavelog_pmode) {
if (defaultcfg.profiles[defaultcfg.profile ?? 0].wavelog_pmode) {
client.write("M " + to.mode + "\n-1");
}
client.end();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Gateway for connecting WSJT-* and FLRig to Wavelog",
"keywords": [],
"main": "./main.js",
"version": "1.1.1",
"version": "1.1.2",
"author": "DJ7NT",
"scripts": {
"start": "electron-forge start",
Expand Down
Loading