2025-10-02 14:19:39 +01:00
|
|
|
<?php
|
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
class Dxcluster extends CI_Controller {
|
|
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
$this->load->model('user_model');
|
|
|
|
|
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function index()
|
|
|
|
|
{
|
|
|
|
|
$data['page_title'] = "DX Cluster Spots";
|
|
|
|
|
|
2025-10-02 21:43:35 +01:00
|
|
|
/// Load layout
|
|
|
|
|
|
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
|
$this->load->view('dxcluster/index', $data);
|
|
|
|
|
$this->load->view('interface_assets/footer');
|
2025-10-02 14:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bandmap()
|
|
|
|
|
{
|
2025-10-02 17:40:49 +01:00
|
|
|
$this->load->model('bands');
|
|
|
|
|
|
2025-10-02 14:19:39 +01:00
|
|
|
$data['page_title'] = "DX Cluster Bandmap";
|
2025-10-04 23:05:20 +01:00
|
|
|
$data['bands'] = $this->bands->get_user_bands_for_bandmap($includeall = true);
|
2025-10-02 14:19:39 +01:00
|
|
|
|
2025-10-02 17:40:49 +01:00
|
|
|
$this->load->view('dxcluster/bandmap', $data);
|
2025-10-02 14:19:39 +01:00
|
|
|
|
|
|
|
|
}
|
2025-10-04 13:34:42 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* QSY radio to frequency from bandmap spot
|
|
|
|
|
* POST /dxcluster/qsy
|
|
|
|
|
*/
|
|
|
|
|
public function qsy() {
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
|
|
$this->load->model('cat');
|
|
|
|
|
|
|
|
|
|
// Get JSON input
|
|
|
|
|
$input = json_decode(file_get_contents("php://input"), true);
|
|
|
|
|
|
|
|
|
|
if (!isset($input['radio_id']) || !isset($input['frequency'])) {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Missing radio_id or frequency']);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$radio_id = $input['radio_id'];
|
|
|
|
|
$frequency = $input['frequency'];
|
|
|
|
|
$mode = isset($input['mode']) ? $input['mode'] : null;
|
|
|
|
|
|
|
|
|
|
// Validate that the radio belongs to the current user
|
|
|
|
|
$radios = $this->cat->radios()->result();
|
|
|
|
|
$radio_found = false;
|
|
|
|
|
foreach ($radios as $radio) {
|
|
|
|
|
if ($radio->id == $radio_id) {
|
|
|
|
|
$radio_found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$radio_found) {
|
|
|
|
|
http_response_code(403);
|
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Invalid radio selected']);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert MHz to Hz for storage
|
|
|
|
|
$frequency_hz = floatval($frequency) * 1000000;
|
|
|
|
|
|
|
|
|
|
// Prepare command data
|
|
|
|
|
$command_data = array(
|
|
|
|
|
'radio_id' => $radio_id,
|
|
|
|
|
'user_id' => $this->session->userdata('user_id'),
|
|
|
|
|
'station_id' => $this->session->userdata('active_station_profile'),
|
|
|
|
|
'command_type' => 'SET_FREQ',
|
|
|
|
|
'frequency' => $frequency_hz,
|
|
|
|
|
'expires_at' => date('Y-m-d H:i:s', strtotime('+30 minutes'))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add mode command if provided
|
|
|
|
|
$freq_command_id = $this->cat->queue_command($command_data);
|
|
|
|
|
$mode_command_id = null;
|
|
|
|
|
|
2025-10-04 14:06:19 +01:00
|
|
|
// Debug logging
|
|
|
|
|
log_message('debug', "QSY: Mode parameter received: '" . var_export($mode, true) . "'");
|
|
|
|
|
log_message('debug', "QSY: Mode empty check: " . (empty($mode) ? 'true' : 'false'));
|
|
|
|
|
|
2025-10-04 13:34:42 +01:00
|
|
|
if (!empty($mode)) {
|
|
|
|
|
$mode_command = array(
|
|
|
|
|
'radio_id' => $radio_id,
|
|
|
|
|
'user_id' => $this->session->userdata('user_id'),
|
|
|
|
|
'station_id' => $this->session->userdata('active_station_profile'),
|
|
|
|
|
'command_type' => 'SET_MODE',
|
|
|
|
|
'mode' => $mode,
|
|
|
|
|
'expires_at' => date('Y-m-d H:i:s', strtotime('+30 minutes'))
|
|
|
|
|
);
|
|
|
|
|
|
2025-10-04 14:06:19 +01:00
|
|
|
log_message('debug', "QSY: Creating SET_MODE command: " . json_encode($mode_command));
|
2025-10-04 13:34:42 +01:00
|
|
|
$mode_command_id = $this->cat->queue_command($mode_command);
|
2025-10-04 14:06:19 +01:00
|
|
|
log_message('debug', "QSY: SET_MODE command ID: " . var_export($mode_command_id, true));
|
|
|
|
|
} else {
|
|
|
|
|
log_message('debug', "QSY: No mode provided or mode is empty");
|
2025-10-04 13:34:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($freq_command_id) {
|
|
|
|
|
echo json_encode([
|
|
|
|
|
'success' => true,
|
|
|
|
|
'message' => 'QSY command sent to radio',
|
|
|
|
|
'frequency' => $frequency,
|
|
|
|
|
'frequency_hz' => $frequency_hz,
|
|
|
|
|
'mode' => $mode,
|
|
|
|
|
'freq_command_id' => $freq_command_id,
|
|
|
|
|
'mode_command_id' => $mode_command_id
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
http_response_code(500);
|
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Failed to queue QSY command']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-02 14:19:39 +01:00
|
|
|
}
|