From 9940c7772cc63e37c540b31ab87e9eafab353cbd Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 23 Oct 2025 09:39:41 +0000 Subject: [PATCH 01/12] Reformat CAT Function for better readability --- application/views/interface_assets/footer.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index d0ac6b6ae4..96c13aee78 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1411,7 +1411,7 @@ function toggleGridsquares(bool) { $(".radio_login_error" ).remove(); } cat2UI($('#frequency'),data.frequency,false,true,function(d){ - $('#frequency').trigger('change'); + $('#frequency').trigger('change'); if ($("#band").val() != frequencyToBand(d)) { $("#band").val(frequencyToBand(d)).trigger('change'); // Let's only change if we really have a different band! } @@ -1436,7 +1436,7 @@ function toggleGridsquares(bool) { } } else { $(".radio_timeout_error" ).remove(); - separator = ''; + separator = ''; text = '' + separator + 'TX: ' + data.frequency_formatted; if(data.mode != null) { text = text + separator + data.mode; @@ -1444,20 +1444,20 @@ function toggleGridsquares(bool) { if(data.power != null && data.power != 0) { text = text + separator + data.power+' W'; } - complementary_info = [] - if(data.prop_mode != null && data.prop_mode != '') { - if (data.prop_mode == 'SAT') { - complementary_info.push(data.prop_mode + ' ' + data.satname); - } else { - complementary_info.push(data.prop_mode); - } - } + complementary_info = [] + if(data.prop_mode != null && data.prop_mode != '') { + if (data.prop_mode == 'SAT') { + complementary_info.push(data.prop_mode + ' ' + data.satname); + } else { + complementary_info.push(data.prop_mode); + } + } if(data.frequency_rx != null && data.frequency_rx != 0) { - complementary_info.push('RX: ' + data.frequency_rx_formatted); + complementary_info.push('RX: ' + data.frequency_rx_formatted); } if( complementary_info.length > 0) { - text = text + separator + '(' + complementary_info.join(separator) + ')'; - } + text = text + separator + '(' + complementary_info.join(separator) + ')'; + } if (! $('#radio_cat_state').length) { $('#radio_status').prepend(''); } else { @@ -1486,7 +1486,7 @@ function toggleGridsquares(bool) { $("#band_rx").val(""); $("#selectPropagation").val($("#selectPropagation option:first").val()); $(".radio_timeout_error" ).remove(); - $(".radio_cat_state" ).remove(); + $(".radio_cat_state" ).remove(); } }); }); From 0435c73f5ed1bdde03f2fc933880ea9ae662afb3 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 23 Oct 2025 09:49:29 +0000 Subject: [PATCH 02/12] More structure for CAT Update // decouple a bit more --- application/views/interface_assets/footer.php | 140 +++++++++--------- 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 96c13aee78..7552ce1317 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1366,24 +1366,81 @@ function toggleGridsquares(bool) { From e5b4c9c87f875551300d45e4263f3e65a268fea2 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 23 Oct 2025 11:51:05 +0000 Subject: [PATCH 04/12] Fix formatting for RX (when using split) --- application/views/interface_assets/footer.php | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index b2d6455fdb..8aa9443075 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1444,6 +1444,21 @@ function handleWebSocketData(data) { } } + function format_frequency(freq) { + const qrgunit = localStorage.getItem('qrgunit_' + $('#band').val()); + let frequency_formatted=null; + if (qrgunit == 'Hz') { + frequency_formatted=freq; + } else if (qrgunit == 'kHz') { + frequency_formatted=(freq / 1000); + } else if (qrgunit == 'MHz') { + frequency_formatted=(freq / 1000000); + } else if (qrgunit == 'GHz') { + frequency_formatted=(freq / 1000000000); + } + return frequency_formatted+''+qrgunit; + } + function updateCATui(data) { cat2UI($('#frequency'),data.frequency,false,true,function(d){ $('#frequency').trigger('change'); @@ -1474,17 +1489,7 @@ function updateCATui(data) { separator = ''; if (!(data.frequency_formatted)) { - let qrgunit = localStorage.getItem('qrgunit_' + $('#band').val()); - if (qrgunit == 'Hz') { - data.frequency_formatted=data.frequency; - } else if (qrgunit == 'kHz') { - data.frequency_formatted=(data.frequency / 1000); - } else if (qrgunit == 'MHz') { - data.frequency_formatted=(data.frequency / 1000000); - } else if (qrgunit == 'GHz') { - data.frequency_formatted=(data.frequency / 1000000000); - } - data.frequency_formatted=data.frequency_formatted+''+qrgunit; + data.frequency_formatted=format_frequency(data.frequency); } if (data.frequency_formatted) { @@ -1506,6 +1511,7 @@ function updateCATui(data) { } } if(data.frequency_rx != null && data.frequency_rx != 0) { + data.frequency_rx_formatted=format_frequency(data.frequency_rx); complementary_info.push('RX: ' + data.frequency_rx_formatted); } if( complementary_info.length > 0) { From d5499ab422b730a643cb86911a70ac4e642b2664 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 23 Oct 2025 16:22:54 +0000 Subject: [PATCH 05/12] Prepare Bandmaplist for Websocket --- assets/js/sections/bandmap_list.js | 169 +++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 47 deletions(-) diff --git a/assets/js/sections/bandmap_list.js b/assets/js/sections/bandmap_list.js index 748f427572..8df7b7ebf7 100644 --- a/assets/js/sections/bandmap_list.js +++ b/assets/js/sections/bandmap_list.js @@ -306,65 +306,140 @@ $(function() { } }); + let websocket = null; + let reconnectAttempts = 0; + let websocketEnabled = false; + let CATInterval=null; var CatCallbackURL = "http://127.0.0.1:54321"; - var updateFromCAT = function() { - - if($('select.radios option:selected').val() != '0') { - radioID = $('select.radios option:selected').val(); - $.getJSON( base_url+"index.php/radio/json/" + radioID, function( data ) { - if (data.error) { - if (data.error == 'not_logged_in') { - $(".radio_cat_state" ).remove(); - if($('.radio_login_error').length == 0) { - $('.messages').prepend(''); - } - } - // Put future Errorhandling here - } else { - if($('.radio_login_error').length != 0) { - $(".radio_login_error" ).remove(); + function initializeWebSocketConnection() { + try { + websocket = new WebSocket('ws://localhost:54322'); + websocket.onopen = function(event) { + reconnectAttempts = 0; + websocketEnabled = true; + }; + websocket.onmessage = function(event) { + try { + const data = JSON.parse(event.data); + handleWebSocketData(data); + } catch (error) { } - var band = frequencyToBand(data.frequency); - CatCallbackURL=data.cat_url; - if (band !== $("#band").val()) { - $("#band").val(band); - $("#band").trigger("change"); + }; + websocket.onerror = function(error) { + websocketEnabled=false; + }; + websocket.onclose = function(event) { + websocketEnabled = false; + + if (reconnectAttempts < 5) { + setTimeout(() => { + reconnectAttempts++; + initializeWebSocketConnection(); + }, 2000 * reconnectAttempts); + } else { + $(".radio_cat_state" ).remove(); + $('#radio_status').html(''); + websocketEnabled = false; } + }; + } catch (error) { + websocketEnabled=false; + } + } - var minutes = Math.floor(cat_timeout_interval / 60); + function handleWebSocketData(data) { + // Handle welcome message + if (data.type === 'welcome') { + return; + } + // Handle radio status updates + if (data.type === 'radio_status' && data.radio && ($(".radios option:selected").val() == 'ws')) { + data.updated_minutes_ago = Math.floor((Date.now() - data.timestamp) / 60000); + // Cache the radio data + updateCATui(data); + } + } - if(data.updated_minutes_ago > minutes) { - $(".radio_cat_state" ).remove(); - if($('.radio_timeout_error').length == 0) { - $('.messages').prepend(''); - } else { - $('.radio_timeout_error').html('Radio connection timed-out: ' + $('select.radios option:selected').text() + ' data is ' + data.updated_minutes_ago + ' minutes old.'); + + $( "#radio" ).change(function() { + if (CATInterval) { // We've a change - stop polling if active + clearInterval(CATInterval); + CATInterval=null; + } + if (websocket) { // close possible websocket connection + websocket.close(); + websocketEnabled = false; + } + if ($("#radio option:selected").val() == '0') { + $(".radio_cat_state" ).remove(); + } else if ($("#radio option:selected").val() == 'ws') { + initializeWebSocketConnection(); + } else { + // Update frequency every three second + CATInterval=setInterval(updateFromCAT, 3000); + } + }); + + function updateCATui(data) { + const band = frequencyToBand(data.frequency); + CatCallbackURL=data.cat_url; + if (band !== $("#band").val()) { + $("#band").val(band); + $("#band").trigger("change"); + } + + const minutes = Math.floor(cat_timeout_interval / 60); + + if(data.updated_minutes_ago > minutes) { + $(".radio_cat_state" ).remove(); + if($('.radio_timeout_error').length == 0) { + $('.messages').prepend(''); + } else { + $('.radio_timeout_error').html('Radio connection timed-out: ' + $('select.radios option:selected').text() + ' data is ' + data.updated_minutes_ago + ' minutes old.'); + } + } else { + $(".radio_timeout_error" ).remove(); + text = 'TX: '+(Math.round(parseInt(data.frequency)/100)/10000).toFixed(4)+' MHz'; + highlight_current_qrg((parseInt(data.frequency))/1000); + if(data.mode != null) { + text = text+''+data.mode; + } + if(data.power != null && data.power != 0) { + text = text+''+data.power+' W'; + } + if (! $('#radio_cat_state').length) { + $('.messages').prepend(''); + } else { + $('#radio_cat_state').html(text); + } + } + } + + var updateFromCAT = function() { + if($('select.radios option:selected').val() != '0') { + radioID = $('select.radios option:selected').val(); + $.getJSON( base_url+"index.php/radio/json/" + radioID, function( data ) { + + if (data.error) { + if (data.error == 'not_logged_in') { + $(".radio_cat_state" ).remove(); + if($('.radio_login_error').length == 0) { + $('.messages').prepend(''); + } } + // Put future Errorhandling here } else { - $(".radio_timeout_error" ).remove(); - text = 'TX: '+(Math.round(parseInt(data.frequency)/100)/10000).toFixed(4)+' MHz'; - highlight_current_qrg((parseInt(data.frequency))/1000); - if(data.mode != null) { - text = text+''+data.mode; - } - if(data.power != null && data.power != 0) { - text = text+''+data.power+' W'; - } - if (! $('#radio_cat_state').length) { - $('.messages').prepend(''); - } else { - $('#radio_cat_state').html(text); + if($('.radio_login_error').length != 0) { + $(".radio_login_error" ).remove(); } + updateCATui(data); } - } - }); - } -}; + }); + } + }; $.fn.dataTable.moment(custom_date_format + ' HH:mm'); -// Update frequency every three second -setInterval(updateFromCAT, 3000); // If a radios selected from drop down select radio update. $('.radios').change(updateFromCAT); From 837a02fb01e868d555785e39e946f183b8a76513 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 23 Oct 2025 16:23:21 +0000 Subject: [PATCH 06/12] JS at View --- application/views/interface_assets/footer.php | 2 +- application/views/qso/index.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 8aa9443075..3daa1ea5f2 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1418,7 +1418,7 @@ function handleWebSocketData(data) { } // Handle radio status updates - if (data.type === 'radio_status' && data.radio) { + if (data.type === 'radio_status' && data.radio && ($(".radios option:selected").val() == 'ws')) { data.updated_minutes_ago = Math.floor((Date.now() - data.timestamp) / 60000); // Cache the radio data updateCATui(data); diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 0fb78d697f..08cd269ce1 100644 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -350,6 +350,7 @@ + result() as $row) { ?>