|
9 | 9 | // Shorthand for document.querySelector. |
10 | 10 | var cfg={}; |
11 | 11 | var active_cfg=0; |
| 12 | +var trxpoll=undefined; |
12 | 13 |
|
13 | 14 | const {ipcRenderer} = require('electron') |
14 | 15 | const net = require('net'); |
@@ -39,7 +40,6 @@ $(document).ready(function() { |
39 | 40 | $("#test").removeClass('btn-success'); |
40 | 41 | $("#test").removeClass('btn-danger'); |
41 | 42 | $("#test").addClass('btn-primary'); |
42 | | - getsettrx(); |
43 | 43 | }); |
44 | 44 |
|
45 | 45 | bt_save.addEventListener('click', async () => { |
@@ -98,16 +98,6 @@ $(document).ready(function() { |
98 | 98 | getStations(); |
99 | 99 | }); |
100 | 100 |
|
101 | | - getsettrx(); |
102 | | - |
103 | | - $("#flrig_ena").on( "click",async function() { |
104 | | - await getsettrx(); |
105 | | - }); |
106 | | - |
107 | | - $("#hamlib_ena").on( "click",async function() { |
108 | | - await getsettrx(); |
109 | | - }); |
110 | | - |
111 | 101 | setInterval(updateUtcTime, 1000); |
112 | 102 | window.onload = updateUtcTime; |
113 | 103 |
|
@@ -143,9 +133,11 @@ async function load_config() { |
143 | 133 | if (cfg.profiles[active_cfg].wavelog_key != "" && cfg.profiles[active_cfg].wavelog_url != "") { |
144 | 134 | getStations(); |
145 | 135 | } |
146 | | - |
147 | | - |
| 136 | + if (trxpoll === undefined) { |
| 137 | + getsettrx(); |
| 138 | + } |
148 | 139 | } |
| 140 | + |
149 | 141 | function resizeme(size) { |
150 | 142 | x=(ipcRenderer.sendSync("resize", size)) |
151 | 143 | return x; |
@@ -191,22 +183,26 @@ async function get_trx() { |
191 | 183 |
|
192 | 184 | async function getInfo(which) { |
193 | 185 | if (cfg.profiles[active_cfg].flrig_ena){ |
194 | | - const response = await fetch( |
195 | | - "http://"+$("#flrig_host").val()+':'+$("#flrig_port").val(), { |
196 | | - method: 'POST', |
197 | | - // mode: 'no-cors', |
198 | | - headers: { |
199 | | - 'Accept': 'application/json, application/xml, text/plain, text/html, *.*', |
200 | | - 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' |
201 | | - }, |
202 | | - body: '<?xml version="1.0"?><methodCall><methodName>'+which+'</methodName></methodCall>' |
203 | | - } |
204 | | - ); |
205 | | - const data = await response.text(); |
206 | | - var parser = new DOMParser(); |
207 | | - var xmlDoc = parser.parseFromString(data, "text/xml"); |
208 | | - var qrgplain = xmlDoc.getElementsByTagName("value")[0].textContent; |
209 | | - return qrgplain; |
| 186 | + try { |
| 187 | + const response = await fetch( |
| 188 | + "http://"+$("#flrig_host").val()+':'+$("#flrig_port").val(), { |
| 189 | + method: 'POST', |
| 190 | + // mode: 'no-cors', |
| 191 | + headers: { |
| 192 | + 'Accept': 'application/json, application/xml, text/plain, text/html, *.*', |
| 193 | + 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' |
| 194 | + }, |
| 195 | + body: '<?xml version="1.0"?><methodCall><methodName>'+which+'</methodName></methodCall>', |
| 196 | + } |
| 197 | + ); |
| 198 | + const data = await response.text(); |
| 199 | + var parser = new DOMParser(); |
| 200 | + var xmlDoc = parser.parseFromString(data, "text/xml"); |
| 201 | + var qrgplain = xmlDoc.getElementsByTagName("value")[0].textContent; |
| 202 | + return qrgplain; |
| 203 | + } catch (e) { |
| 204 | + return ''; |
| 205 | + } |
210 | 206 | } |
211 | 207 | if (cfg.profiles[active_cfg].hamlib_ena) { |
212 | 208 | var commands = {"rig.get_vfo": "f", "rig.get_mode": "m", "rig.get_ptt": 0, "rig.get_power": 0, "rig.get_split": 0, "rig.get_vfoB": 0, "rig.get_modeB": 0}; |
@@ -237,11 +233,12 @@ async function getInfo(which) { |
237 | 233 |
|
238 | 234 | async function getsettrx() { |
239 | 235 | if ($("#flrig_ena").is(':checked') || cfg.profiles[active_cfg].hamlib_ena) { |
| 236 | + console.log('Polling TRX '+trxpoll); |
240 | 237 | x=get_trx(); |
241 | | - setTimeout(() => { |
242 | | - getsettrx(); |
243 | | - }, 1000); |
244 | 238 | } |
| 239 | + trxpoll = setTimeout(() => { |
| 240 | + getsettrx(); |
| 241 | + }, 1000); |
245 | 242 | } |
246 | 243 |
|
247 | 244 | const isDeepEqual = (object1, object2) => { |
|
0 commit comments