Merge pull request #1582 from kb-light/radioapi

[WIP] Unify radio API
pull/1624/head
Peter Goodhall 2022-09-30 15:47:30 +01:00 zatwierdzone przez GitHub
commit dd1e224d7f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 210 dodań i 238 usunięć

1
.gitignore vendored
Wyświetl plik

@ -15,3 +15,4 @@
.DS_Store
sync.sh
*.p12
*.swp

Wyświetl plik

@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 99;
$config['migration_version'] = 101;
/*
|--------------------------------------------------------------------------

Wyświetl plik

@ -48,17 +48,23 @@
{
echo "<tr>";
echo "<td>".$row->radio."</td>";
if($row->frequency != "0" && $row->frequency != NULL) {
if (empty($row->frequency) || $row->frequency == "0") {
echo "<td>- / -</td>";
} elseif (empty($row->frequency_rx) || $row->frequency_rx == "0") {
echo "<td>".$this->frequency->hz_to_mhz($row->frequency)."</td>";
} else {
echo "<td>".$this->frequency->hz_to_mhz($row->downlink_freq)." / ".$this->frequency->hz_to_mhz($row->uplink_freq)."</td>";
echo "<td>".$this->frequency->hz_to_mhz($row->frequency_rx)." / ".$this->frequency->hz_to_mhz($row->frequency)."</td>";
}
if($row->mode != "non" && $row->mode != NULL) {
if (empty($row->mode) || $row->mode == "non") {
echo "<td>N/A</td>";
} elseif (empty($row->mode_rx) || $row->mode_rx == "non") {
echo "<td>".$row->mode."</td>";
} else {
echo "<td>".$row->downlink_mode." / ".$row->uplink_mode."</td>";
echo "<td>".$row->mode_rx." / ".$row->mode."</td>";
}
$phpdate = strtotime($row->timestamp);
echo "<td>".date('H:i:s d-m-y', $phpdate)."</td>" ;
echo "<td><a href=\"".site_url('radio/delete')."/".$row->id."\" class=\"btn btn-danger\"> <i class=\"fas fa-trash-alt\"></i> Delete</a></td>" ;
@ -86,24 +92,23 @@
foreach ($query->result() as $row)
{
$frequency = $row->frequency;
if($row->prop_mode == "SAT") {
$uplink_freq = $row->uplink_freq;
$downlink_freq = $row->downlink_freq;
$frequency_rx = $row->frequency_rx;
$power = $row->power;
$power = $row->power;
$prop_mode = $row->prop_mode;
$prop_mode = $row->prop_mode;
// Check Mode
if(strtoupper($row->uplink_mode) == "FMN"){
$mode = "FM";
} else {
$mode = strtoupper($row->uplink_mode);
}
// Check Mode
$mode = strtoupper($row->mode);
if ($mode == "FMN") {
$mode = "FM";
}
if ($row->prop_mode == "SAT") {
// Get Satellite Name
if($row->sat_name == "AO-07") {
if ($row->sat_name == "AO-07") {
$sat_name = "AO-7";
} elseif ($row->sat_name == "LILACSAT") {
$sat_name = "CAS-3H";
@ -112,27 +117,17 @@
}
// Get Satellite Mode
$uplink_mode = $this->get_mode_designator($row->uplink_freq);
$downlink_mode = $this->get_mode_designator($row->downlink_freq);
$sat_mode_uplink = $this->get_mode_designator($row->frequency);
$sat_mode_downlink = $this->get_mode_designator($row->frequency_rx);
if ($uplink_mode != "" && $downlink_mode != "") {
$sat_mode = $uplink_mode."/".$downlink_mode;
}
} else {
$frequency = $row->frequency;
$power = $row->power;
$prop_mode = $row->prop_mode;
// Check Mode
if(strtoupper($row->mode) == "FMN"){
$mode = "FM";
if (empty($sat_mode_uplink)) {
$sat_mode = "";
} elseif ($sat_mode_uplink !== $sat_mode_downlink) {
$sat_mode = $sat_mode_uplink."/".$sat_mode_downlink;
} else {
$mode = strtoupper($row->mode);
$sat_mode = $sat_mode_uplink;
}
} else {
$sat_name = "";
$sat_mode = "";
}
@ -149,29 +144,18 @@
$updated_at = $minutes;
// Return Json data
if ($prop_mode == "SAT") {
echo json_encode(array(
"uplink_freq" => $uplink_freq,
"downlink_freq" => $downlink_freq,
"mode" => $mode,
"satmode" => $sat_mode,
"satname" => $sat_name,
"power" => $power,
"prop_mode" => $prop_mode,
"updated_minutes_ago" => $updated_at,
), JSON_PRETTY_PRINT);
} else {
echo json_encode(array(
"frequency" => $frequency,
"mode" => $mode,
"power" => $power,
"prop_mode" => $prop_mode,
"updated_minutes_ago" => $updated_at,
), JSON_PRETTY_PRINT);
}
echo json_encode(array(
"frequency" => $frequency,
"frequency_rx" => $frequency_rx,
"mode" => $mode,
"satmode" => $sat_mode,
"satname" => $sat_name,
"power" => $power,
"prop_mode" => $prop_mode,
"updated_minutes_ago" => $updated_at,
), JSON_PRETTY_PRINT);
}
}
}
function get_mode_designator($frequency)

Wyświetl plik

@ -0,0 +1,52 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
Update CAT table
*/
class Migration_update_cat_table extends CI_Migration {
public function up()
{
if ($this->db->table_exists('cat')) {
if ($this->db->field_exists('uplink_freq', 'cat')) {
$this->dbforge->drop_column('cat', 'uplink_freq');
}
if ($this->db->field_exists('uplink_mode', 'cat')) {
$this->dbforge->drop_column('cat', 'uplink_mode');
}
if ($this->db->field_exists('downlink_freq', 'cat')) {
$this->db->query("ALTER TABLE cat RENAME COLUMN downlink_freq TO frequency_rx");
}
if ($this->db->field_exists('downlink_mode', 'cat')) {
$this->db->query("ALTER TABLE cat RENAME COLUMN downlink_mode TO mode_rx");
}
}
}
public function down()
{
if ($this->db->table_exists('cat')) {
if ($this->db->field_exists('frequency_rx', 'cat')) {
$this->db->query("ALTER TABLE cat RENAME COLUMN frequency_rx TO downlink_freq");
}
if ($this->db->field_exists('mode_rx', 'cat')) {
$this->db->query("ALTER TABLE cat RENAME COLUMN mode_rx TO downlink_mode");
}
if (!$this->db->field_exists('uplink_freq', 'cat')) {
$fields = array(
'uplink_freq bigint(13) DEFAULT NULL AFTER `downlink_freq`',
);
$this->dbforge->add_column('cat', $fields);
}
if (!$this->db->field_exists('uplink_mode', 'cat')) {
$fields = array(
'uplink_mode varchar(255) DEFAULT NULL AFTER `downlink_mode`',
);
$this->dbforge->add_column('cat', $fields);
}
}
}
}

Wyświetl plik

@ -0,0 +1,45 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
Restore initial field settings for frequency as it
broke with commit f6feea5
*/
class Migration_make_frequency_bigint_again extends CI_Migration {
public function up()
{
if ($this->db->table_exists('cat')) {
if ($this->db->field_exists('frequency', 'cat')) {
$fields = array(
'frequency' => array(
'name' => 'frequency',
'type' => 'BIGINT',
'null' => TRUE,
'default' => NULL,
),
);
$this->dbforge->modify_column('cat', $fields);
}
}
}
public function down()
{
if ($this->db->table_exists('cat')) {
if ($this->db->field_exists('frequency', 'cat')) {
$fields = array(
'frequency' => array(
'name' => 'frequency',
'type' => 'VARCHAR(10)',
'null' => TRUE,
'default' => NULL,
),
);
$this->dbforge->modify_column('cat', $fields);
}
}
}
}

Wyświetl plik

@ -4,168 +4,70 @@
function update($result, $user_id) {
if ($result['timestamp'] != "") {
$timestamp = gmdate("Y-m-d H:i:s");
$timestamp = gmdate("Y-m-d H:i:s");
if (isset($result['prop_mode'])) {
$prop_mode = $result['prop_mode'];
// For backward compatibility, SatPC32 does not set propergation mode
} else if (isset($result['sat_name'])) {
$prop_mode = "SAT";
} else {
$timestamp = gmdate("Y-m-d H:i:s");
$prop_mode = NULL;
}
$this->db->where('radio', $result['radio']);
$this->db->where('user_id', $user_id);
$query = $this->db->get('cat');
// Let's keep uplink_freq, downlink_freq, uplink_mode and downlink_mode for backward compatibility
$data = array(
'prop_mode' => $prop_mode,
'power' => $result['power'] ?? NULL,
'sat_name' => $result['sat_name'] ?? NULL,
'timestamp' => $timestamp,
);
if (isset($result['frequency']) && $result['frequency'] != "NULL") {
$data['frequency'] = $result['frequency'];
} else {
$data['frequency'] = $result['uplink_freq'];
}
if (isset($result['mode']) && $result['mode'] != "NULL") {
$data['mode'] = $result['mode'];
} else {
$data['mode'] = $result['uplink_mode'];
}
if (isset($result['frequency_rx'])) {
$data['frequency_rx'] = $result['frequency_rx'];
} else if (isset($result['downlink_freq'])) {
$data['frequency_rx'] = $result['downlink_freq'];
} else {
$data['frequency_rx'] = NULL;
}
if (isset($result['mode_rx'])) {
$data['mode_rx'] = $result['mode_rx'];
} else if (isset($result['downlink_freq'])) {
$data['mode_rx'] = $result['downlink_mode'];
} else {
$data['mode_rx'] = NULL;
}
if ($query->num_rows() > 0)
{
if($result['radio'] == "SatPC32") {
// Update the record
foreach ($query->result() as $row)
{
$radio_id = $row->id;
// Update the record
foreach ($query->result() as $row)
{
$radio_id = $row->id;
$data = array(
'sat_name' => $result['sat_name'],
'downlink_freq' => $result['downlink_freq'],
'uplink_freq' => $result['uplink_freq'],
'downlink_mode' => $result['downlink_mode'],
'uplink_mode' => $result['uplink_mode'],
'prop_mode' => 'SAT',
'timestamp' => $timestamp,
);
$this->db->where('id', $radio_id);
$this->db->where('user_id', $user_id);
$this->db->update('cat', $data);
}
} else if($result['radio'] == "CloudLogCATQt") {
// Update the record
foreach ($query->result() as $row)
{
$radio_id = $row->id;
if ($result['prop_mode'] == "SAT") {
$data = array(
'sat_name' => $result['sat_name'],
'prop_mode' => $result['prop_mode'],
'mode' => NULL,
'frequency' => NULL,
'downlink_freq' => $result['downlink_freq'],
'uplink_freq' => $result['uplink_freq'],
'downlink_mode' => $result['downlink_mode'],
'uplink_mode' => $result['uplink_mode'],
'timestamp' => $timestamp,
);
if (isset($result['power'])) {
$data['power'] = $result['power'];
}
} else {
$data = array(
'prop_mode' => $result['prop_mode'],
'mode' => $result['mode'],
'frequency' => $result['frequency'],
'downlink_freq' => NULL,
'downlink_mode' => NULL,
'uplink_freq' => NULL,
'uplink_mode' => NULL,
'timestamp' => $timestamp,
);
if (isset($result['power'])) {
$data['power'] = $result['power'];
}
}
$this->db->where('id', $radio_id);
$this->db->where('user_id', $user_id);
$this->db->update('cat', $data);
}
} else {
// Update the record
foreach ($query->result() as $row)
{
$radio_id = $row->id;
$data = array(
'frequency' => $result['frequency'],
'mode' => $result['mode'],
'timestamp' => $timestamp,
);
if (isset($result['power'])) {
$data['power'] = $result['power'];
}
$this->db->where('id', $radio_id);
$this->db->where('user_id', $user_id);
$this->db->update('cat', $data);
}
$this->db->where('id', $radio_id);
$this->db->where('user_id', $user_id);
$this->db->update('cat', $data);
}
} else {
// Add a new record
if($result['radio'] == "SatPC32") {
$data = array(
'radio' => $result['radio'],
'frequency' => $result['frequency'],
'mode' => $result['mode'],
'sat_name' => $result['sat_name'],
'downlink_freq' => $result['downlink_freq'],
'uplink_freq' => $result['uplink_freq'],
'downlink_mode' => $result['downlink_mode'],
'uplink_mode' => $result['uplink_mode'],
'prop_mode' => 'SAT',
'user_id' => $user_id,
'timestamp' => $timestamp,
);
} else if($result['radio'] == "CloudLogCATQt") {
if ($result['prop_mode'] == "SAT") {
$data = array(
'radio' => $result['radio'],
'sat_name' => $result['sat_name'],
'prop_mode' => $result['prop_mode'],
'mode' => NULL,
'frequency' => NULL,
'downlink_freq' => $result['downlink_freq'],
'uplink_freq' => $result['uplink_freq'],
'downlink_mode' => $result['downlink_mode'],
'uplink_mode' => $result['uplink_mode'],
'user_id' => $user_id,
'timestamp' => $timestamp,
);
if (isset($result['power'])) {
$data['power'] = $result['power'];
}
} else {
$data = array(
'radio' => $result['radio'],
'prop_mode' => $result['prop_mode'],
'mode' => $result['mode'],
'frequency' => $result['frequency'],
'downlink_freq' => NULL,
'downlink_mode' => NULL,
'uplink_freq' => NULL,
'uplink_mode' => NULL,
'user_id' => $user_id,
'timestamp' => $timestamp,
);
if (isset($result['power'])) {
$data['power'] = $result['power'];
}
}
} else {
$data = array(
'radio' => $result['radio'],
'frequency' => $result['frequency'],
'mode' => $result['mode'],
'timestamp' => $timestamp,
'user_id' => $user_id,
);
if (isset($result['power'])) {
$data['power'] = $result['power'];
}
}
$data['radio'] = $result['radio'];
$data['user_id'] = $user_id;
$this->db->insert('cat', $data);
}
}

Wyświetl plik

@ -143,7 +143,7 @@ function echoQrbCalcLink($mygrid, $grid, $vucc) {
<tr>
<td><?php echo $row['radio']; ?></td>
<td>
<?php if($row['radio'] == "SatPC32" || $row['radio'] == "CloudLogCATQt") { ?>
<?php if($row['prop_mode'] == 'SAT') { ?>
<?php echo $row['sat_name']; ?>
<?php } else { ?>
<?php echo $this->frequency->hz_to_mhz($row['frequency']); ?> (<?php echo $row['mode']; ?>)

Wyświetl plik

@ -1160,33 +1160,25 @@ $(document).on('keypress',function(e) {
</script>
<script>
// Javascript for controlling rig frequency.
var updateFromCAT = function() {
// Javascript for controlling rig frequency.
var updateFromCAT = function() {
if($('select.radios option:selected').val() != '0') {
radioID = $('select.radios option:selected').val();
$.getJSON( "radio/json/" + radioID, function( data ) {
/* {
"uplink_freq": "2400210000",
"downlink_freq": "10489710000",
"frequency": "2400210000",
"frequency_rx": "10489710000",
"mode": "SSB",
"satmode": "",
"satname": "ES'HAIL-2"
"satmode": "S/X",
"satname": "QO-100"
"power": "20"
"prop_mode": "SAT"
} */
if (data.prop_mode == "SAT")
//if (data.uplink_freq != "")
{
$('#frequency').val(data.uplink_freq);
$("#band").val(frequencyToBand(data.uplink_freq));
} else {
$('#frequency').val(data.frequency);
$("#band").val(frequencyToBand(data.frequency));
}
if (data.downlink_freq != "")
{
$('#frequency_rx').val(data.downlink_freq);
$("#band_rx").val(frequencyToBand(data.downlink_freq));
$('#frequency').val(data.frequency);
$("#band").val(frequencyToBand(data.frequency));
if (data.frequency_rx != "") {
$('#frequency_rx').val(data.frequency_rx);
$("#band_rx").val(frequencyToBand(data.frequency_rx));
}
old_mode = $(".mode").val();
@ -1203,18 +1195,18 @@ $(document).on('keypress',function(e) {
}
$("#selectPropagation").val(data.prop_mode);
// Display CAT Timeout warnng based on the figure given in the config file
var minutes = Math.floor(<?php echo $this->optionslib->get_option('cat_timeout_interval'); ?> / 60);
// Display CAT Timeout warning based on the figure given in the config file
var minutes = Math.floor(<?php echo $this->optionslib->get_option('cat_timeout_interval'); ?> / 60);
if(data.updated_minutes_ago > minutes) {
if($('.radio_timeout_error').length == 0) {
$('.qso_panel').prepend('<div class="alert alert-danger radio_timeout_error" role="alert">Radio connection timed-out: ' + $('select.radios option:selected').text() + ' data is ' + data.updated_minutes_ago + ' minutes old.</div>');
} else {
$('.radio_timeout_error').text('Radio connection timed-out: ' + $('select.radios option:selected').text() + ' data is ' + data.updated_minutes_ago + ' minutes old.');
}
if(data.updated_minutes_ago > minutes) {
if($('.radio_timeout_error').length == 0) {
$('.qso_panel').prepend('<div class="alert alert-danger radio_timeout_error" role="alert">Radio connection timed-out: ' + $('select.radios option:selected').text() + ' data is ' + data.updated_minutes_ago + ' minutes old.</div>');
} else {
$(".radio_timeout_error" ).remove();
$('.radio_timeout_error').text('Radio connection timed-out: ' + $('select.radios option:selected').text() + ' data is ' + data.updated_minutes_ago + ' minutes old.');
}
} else {
$(".radio_timeout_error" ).remove();
}
});
}
@ -1226,21 +1218,17 @@ $(document).on('keypress',function(e) {
// If a radios selected from drop down select radio update.
$('.radios').change(updateFromCAT);
// If radio isn't SatPC32 or CloudLogCATQt clear sat_name and sat_mode
// If no radio is selected clear data
$( ".radios" ).change(function() {
if ($(".radios option:selected").text() != "SatPC32" && $(".radios option:selected").text() != "CloudLogCATQt") {
if ($(".radios option:selected").val() == 0) {
$("#sat_name").val("");
$("#sat_mode").val("");
$("#frequency").val("");
$("#frequency_rx").val("");
$("#band_rx").val("");
$("#selectPropagation").val($("#selectPropagation option:first").val());
}
if ($(".radios option:selected").text() == "None") {
$(".radio_timeout_error" ).remove();
}
});
</script>