Merge pull request #1804 from int2001/autofill_az_ele_qso

Autofill az ele qso
This commit is contained in:
Joerg (DJ7NT)
2025-03-28 09:10:33 +01:00
committed by GitHub
5 changed files with 93 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ class QSO extends CI_Controller {
public function index() {
$this->load->model('cat');
$this->load->library('qra');
$this->load->model('stations');
$this->load->model('logbook_model');
$this->load->model('user_model');
@@ -41,6 +42,7 @@ class QSO extends CI_Controller {
$data['iota'] = $this->logbook_model->fetchIota();
$data['modes'] = $this->modes->active();
$data['bands'] = $this->bands->get_user_bands_for_qso_entry();
[$data['lat'], $data['lng']] = $this->qra->qra2latlong($this->stations->gridsquare_from_station($this->stations->find_active()));
$data['user_default_band'] = $this->session->userdata('user_default_band');
$data['sat_active'] = array_search("SAT", $this->bands->get_user_bands(), true);
@@ -607,8 +609,10 @@ class QSO extends CI_Controller {
public function get_station_power() {
$this->load->model('stations');
$this->load->library('qra');
$stationProfile = $this->input->post('stationProfile', TRUE);
$data = array('station_power' => $this->stations->get_station_power($stationProfile));
[$data['lat'], $data['lng']] = $this->qra->qra2latlong($this->stations->gridsquare_from_station($stationProfile));
header('Content-Type: application/json');
echo json_encode($data);

View File

@@ -1060,6 +1060,7 @@ $($('#callsign')).on('keypress',function(e) {
<?php if ($this->uri->segment(1) == "qso") { ?>
<script src="<?php echo base_url() ;?>assets/js/sections/qso.js"></script>
<script src="<?php echo base_url() ;?>assets/js/sections/satellite_functions.js"></script>
<script src="<?php echo base_url() ;?>assets/js/bootstrap-multiselect.js"></script>
<?php if ($this->session->userdata('isWinkeyEnabled')) { ?>
<script src="<?php echo base_url() ;?>assets/js/winkey.js"></script>

View File

@@ -8,6 +8,7 @@
var lang_dxccsummary_for = "<?= __("DXCC Summary for "); ?>";
var lang_lotw_upload_day_ago = "<?= __("LoTW User. Last upload was 1 day ago."); ?>";
var lang_lotw_upload_days_ago = "<?= __("LoTW User. Last upload was %x days ago."); ?>"; // due to the way the string is built (PHP to JS), %x is replaced with the number of days
var latlng=[<?php echo $lat.','.$lng;?>];
</script>
<div class="row qsopane">
@@ -601,7 +602,7 @@
<div class="mb-3">
<label for="ant_el"><?= __("Antenna Elevation (°)"); ?></label>
<input type="number" inputmode="decimal" step="0.1" min="0" max="90" class="form-control" id="ant_el" name="ant_el" />
<input type="number" inputmode="decimal" step="0.1" min="-5" max="90" class="form-control" id="ant_el" name="ant_el" />
<small id="elHelp" class="form-text text-muted"><?= __("Antenna elevation in decimal degrees."); ?></small>
</div>
</div>

View File

@@ -75,4 +75,4 @@
$('#redirect_message').html('<?= __("The data was redirected. You can close this window."); ?>');
window.close();
}
</script>
</script>

View File

@@ -39,6 +39,8 @@ $('#stationProfile').on('change', function () {
data: { 'stationProfile': stationProfile },
success: function (res) {
$('#transmit_power').val(res.station_power);
latlng=[res.lat,res.lng];
$("#sat_name").change();
},
error: function () {
$('#transmit_power').val('');
@@ -217,6 +219,9 @@ $(document).on("click", "#fav_del", function (event) {
$(document).on("click", "#fav_recall", function (event) {
$('#sat_name').val(favs[this.innerText].sat_name);
if (favs[this.innerText].sat_name) {
$("#sat_name").change();
}
$('#sat_mode').val(favs[this.innerText].sat_mode);
$('#band_rx').val(favs[this.innerText].band_rx);
$('#band').val(favs[this.innerText].band);
@@ -324,9 +329,87 @@ $("#sat_name").on('change', function () {
if (sat == "") {
$("#sat_mode").val("");
$("#selectPropagation").val("");
stop_az_ele_ticker();
} else {
get_tles();
}
});
var satupdater;
function stop_az_ele_ticker() {
if (satupdater) {
clearInterval(satupdater);
}
$("#ant_az").val('');
$("#ant_el").val('');
}
function start_az_ele_ticker(tle) {
const lines = tle.tle.trim().split('\n');
// Initialize a satellite record
var satrec = satellite.twoline2satrec(lines[0], lines[1]);
// Define the observer's location in radians
var observerGd = {
longitude: satellite.degreesToRadians(latlng[1]),
latitude: satellite.degreesToRadians(latlng[0]),
height: 0.370
};
function updateAzEl() {
let dateParts=$('#start_date').val().split("-");
let timeParts=$("#start_time").val().split(":");
try {
var time = new Date(Date.UTC(
parseInt(dateParts[2]),parseInt(dateParts[1])-1,parseInt(dateParts[0]),
parseInt(timeParts[0]),parseInt(timeParts[1]),(parseInt(timeParts[2] ?? 0))
));
if (isNaN(time.getTime())) {
throw new Error("Invalid date");
}
var positionAndVelocity = satellite.propagate(satrec, time);
var gmst = satellite.gstime(time);
var positionEcf = satellite.eciToEcf(positionAndVelocity.position, gmst);
var observerEcf = satellite.geodeticToEcf(observerGd);
var lookAngles = satellite.ecfToLookAngles(observerGd, positionEcf);
let az=(satellite.radiansToDegrees(lookAngles.azimuth).toFixed(2));
let el=(satellite.radiansToDegrees(lookAngles.elevation).toFixed(2));
$("#ant_az").val(parseFloat(az).toFixed(1));
$("#ant_el").val(parseFloat(el).toFixed(1));
} catch(e) {
$("#ant_az").val('');
$("#ant_el").val('');
}
}
satupdater=setInterval(updateAzEl, 1000);
}
function get_tles() {
stop_az_ele_ticker();
$.ajax({
url: base_url + 'index.php/satellite/get_tle',
type: 'post',
data: {
sat: $("#sat_name").val(),
},
success: function (data) {
if (data !== null) {
start_az_ele_ticker(data);
}
},
error: function (data) {
console.log('Something went wrong while trying to fetch TLE for sat: '+$("#sat_name"));
},
});
}
if ($("#sat_name").val() !== '') {
get_tles();
}
$('#stateDropdown').on('change', function () {
var state = $("#stateDropdown option:selected").text();
if (state != "") {
@@ -516,6 +599,7 @@ function reset_to_default() {
$("#sat_mode").val("");
$("#ant_az").val("");
$("#ant_el").val("");
stop_az_ele_ticker();
}
/* Function: reset_fields is used to reset the fields on the QSO page */
@@ -1268,6 +1352,7 @@ $('#band').on('change', function () {
$("#sat_mode").val("");
set_qrg();
$("#callsign").blur();
stop_az_ele_ticker();
});
/* On Key up Calculate Bearing and Distance */