mirror of
https://github.com/smittix/intercept.git
synced 2026-07-25 01:08:11 -07:00
Add rtl_tcp (remote SDR) support v1.1.0
Features: - Add rtl_tcp support for pager and sensor decoding - Connect to remote RTL-SDR via rtl_tcp server - New UI toggle and host:port inputs in sidebar - Supports rtl_fm and rtl_433 with remote devices - Add remote dump1090 support for ADS-B tracking - Connect to dump1090 SBS output on remote machine - New "Remote" checkbox with host:port in ADS-B dashboard Backend changes: - Add rtl_tcp_host/port fields to SDRDevice dataclass - Add is_network property for detecting remote devices - Update RTLSDRCommandBuilder to use rtl_tcp:host:port format - Add create_network_device() to SDRFactory - Add validate_rtl_tcp_host/port validation functions - Update pager, sensor, and adsb routes to accept remote params Note: dump1090 doesn't support rtl_tcp directly - use remote dump1090's SBS output (port 30003) for remote ADS-B tracking.
This commit is contained in:
@@ -7,7 +7,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Application version
|
# Application version
|
||||||
VERSION = "1.0.0"
|
VERSION = "1.1.0"
|
||||||
|
|
||||||
|
|
||||||
def _get_env(key: str, default: str) -> str:
|
def _get_env(key: str, default: str) -> str:
|
||||||
|
|||||||
+23
-1
@@ -16,7 +16,10 @@ from flask import Blueprint, jsonify, request, Response, render_template
|
|||||||
|
|
||||||
import app as app_module
|
import app as app_module
|
||||||
from utils.logging import adsb_logger as logger
|
from utils.logging import adsb_logger as logger
|
||||||
from utils.validation import validate_device_index, validate_gain
|
from utils.validation import (
|
||||||
|
validate_device_index, validate_gain,
|
||||||
|
validate_rtl_tcp_host, validate_rtl_tcp_port
|
||||||
|
)
|
||||||
from utils.sse import format_sse
|
from utils.sse import format_sse
|
||||||
from utils.sdr import SDRFactory, SDRType
|
from utils.sdr import SDRFactory, SDRType
|
||||||
|
|
||||||
@@ -238,6 +241,25 @@ def start_adsb():
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return jsonify({'status': 'error', 'message': str(e)}), 400
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
|
|
||||||
|
# Check for remote SBS connection (e.g., remote dump1090)
|
||||||
|
remote_sbs_host = data.get('remote_sbs_host')
|
||||||
|
remote_sbs_port = data.get('remote_sbs_port', 30003)
|
||||||
|
|
||||||
|
if remote_sbs_host:
|
||||||
|
# Validate and connect to remote dump1090 SBS output
|
||||||
|
try:
|
||||||
|
remote_sbs_host = validate_rtl_tcp_host(remote_sbs_host)
|
||||||
|
remote_sbs_port = validate_rtl_tcp_port(remote_sbs_port)
|
||||||
|
except ValueError as e:
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
|
|
||||||
|
remote_addr = f"{remote_sbs_host}:{remote_sbs_port}"
|
||||||
|
logger.info(f"Connecting to remote dump1090 SBS at {remote_addr}")
|
||||||
|
adsb_using_service = True
|
||||||
|
thread = threading.Thread(target=parse_sbs_stream, args=(remote_addr,), daemon=True)
|
||||||
|
thread.start()
|
||||||
|
return jsonify({'status': 'started', 'message': f'Connected to remote dump1090 at {remote_addr}'})
|
||||||
|
|
||||||
# Check if dump1090 is already running externally (e.g., user started it manually)
|
# Check if dump1090 is already running externally (e.g., user started it manually)
|
||||||
existing_service = check_dump1090_service()
|
existing_service = check_dump1090_service()
|
||||||
if existing_service:
|
if existing_service:
|
||||||
|
|||||||
+23
-4
@@ -18,7 +18,10 @@ from flask import Blueprint, jsonify, request, Response
|
|||||||
|
|
||||||
import app as app_module
|
import app as app_module
|
||||||
from utils.logging import pager_logger as logger
|
from utils.logging import pager_logger as logger
|
||||||
from utils.validation import validate_frequency, validate_device_index, validate_gain, validate_ppm
|
from utils.validation import (
|
||||||
|
validate_frequency, validate_device_index, validate_gain, validate_ppm,
|
||||||
|
validate_rtl_tcp_host, validate_rtl_tcp_port
|
||||||
|
)
|
||||||
from utils.sse import format_sse
|
from utils.sse import format_sse
|
||||||
from utils.process import safe_terminate, register_process
|
from utils.process import safe_terminate, register_process
|
||||||
from utils.sdr import SDRFactory, SDRType, SDRValidationError
|
from utils.sdr import SDRFactory, SDRType, SDRValidationError
|
||||||
@@ -209,9 +212,25 @@ def start_decoding() -> Response:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
sdr_type = SDRType.RTL_SDR
|
sdr_type = SDRType.RTL_SDR
|
||||||
|
|
||||||
# Create device object and get command builder
|
# Check for rtl_tcp (remote SDR) connection
|
||||||
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
|
rtl_tcp_host = data.get('rtl_tcp_host')
|
||||||
builder = SDRFactory.get_builder(sdr_type)
|
rtl_tcp_port = data.get('rtl_tcp_port', 1234)
|
||||||
|
|
||||||
|
if rtl_tcp_host:
|
||||||
|
# Validate and create network device
|
||||||
|
try:
|
||||||
|
rtl_tcp_host = validate_rtl_tcp_host(rtl_tcp_host)
|
||||||
|
rtl_tcp_port = validate_rtl_tcp_port(rtl_tcp_port)
|
||||||
|
except ValueError as e:
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
|
|
||||||
|
sdr_device = SDRFactory.create_network_device(rtl_tcp_host, rtl_tcp_port)
|
||||||
|
logger.info(f"Using remote SDR: rtl_tcp://{rtl_tcp_host}:{rtl_tcp_port}")
|
||||||
|
else:
|
||||||
|
# Create local device object
|
||||||
|
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
|
||||||
|
|
||||||
|
builder = SDRFactory.get_builder(sdr_device.sdr_type)
|
||||||
|
|
||||||
# Build FM demodulation command
|
# Build FM demodulation command
|
||||||
rtl_cmd = builder.build_fm_demod_command(
|
rtl_cmd = builder.build_fm_demod_command(
|
||||||
|
|||||||
+23
-4
@@ -14,7 +14,10 @@ from flask import Blueprint, jsonify, request, Response
|
|||||||
|
|
||||||
import app as app_module
|
import app as app_module
|
||||||
from utils.logging import sensor_logger as logger
|
from utils.logging import sensor_logger as logger
|
||||||
from utils.validation import validate_frequency, validate_device_index, validate_gain, validate_ppm
|
from utils.validation import (
|
||||||
|
validate_frequency, validate_device_index, validate_gain, validate_ppm,
|
||||||
|
validate_rtl_tcp_host, validate_rtl_tcp_port
|
||||||
|
)
|
||||||
from utils.sse import format_sse
|
from utils.sse import format_sse
|
||||||
from utils.process import safe_terminate, register_process
|
from utils.process import safe_terminate, register_process
|
||||||
from utils.sdr import SDRFactory, SDRType
|
from utils.sdr import SDRFactory, SDRType
|
||||||
@@ -90,9 +93,25 @@ def start_sensor() -> Response:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
sdr_type = SDRType.RTL_SDR
|
sdr_type = SDRType.RTL_SDR
|
||||||
|
|
||||||
# Create device object and get command builder
|
# Check for rtl_tcp (remote SDR) connection
|
||||||
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
|
rtl_tcp_host = data.get('rtl_tcp_host')
|
||||||
builder = SDRFactory.get_builder(sdr_type)
|
rtl_tcp_port = data.get('rtl_tcp_port', 1234)
|
||||||
|
|
||||||
|
if rtl_tcp_host:
|
||||||
|
# Validate and create network device
|
||||||
|
try:
|
||||||
|
rtl_tcp_host = validate_rtl_tcp_host(rtl_tcp_host)
|
||||||
|
rtl_tcp_port = validate_rtl_tcp_port(rtl_tcp_port)
|
||||||
|
except ValueError as e:
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
|
|
||||||
|
sdr_device = SDRFactory.create_network_device(rtl_tcp_host, rtl_tcp_port)
|
||||||
|
logger.info(f"Using remote SDR: rtl_tcp://{rtl_tcp_host}:{rtl_tcp_port}")
|
||||||
|
else:
|
||||||
|
# Create local device object
|
||||||
|
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
|
||||||
|
|
||||||
|
builder = SDRFactory.get_builder(sdr_device.sdr_type)
|
||||||
|
|
||||||
# Build ISM band decoder command
|
# Build ISM band decoder command
|
||||||
cmd = builder.build_ism_command(
|
cmd = builder.build_ism_command(
|
||||||
|
|||||||
@@ -159,6 +159,17 @@
|
|||||||
<button class="gps-btn gps-connect-btn" onclick="startGpsDongle()">Connect</button>
|
<button class="gps-btn gps-connect-btn" onclick="startGpsDongle()">Connect</button>
|
||||||
<button class="gps-btn gps-disconnect-btn" onclick="stopGpsDongle()" style="display: none; background: rgba(255,0,0,0.2); border-color: #ff4444;">Stop</button>
|
<button class="gps-btn gps-disconnect-btn" onclick="stopGpsDongle()" style="display: none; background: rgba(255,0,0,0.2); border-color: #ff4444;">Stop</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label style="display: flex; align-items: center; gap: 4px; font-size: 10px; cursor: pointer;">
|
||||||
|
<input type="checkbox" id="useRemoteDump1090" onchange="toggleRemoteDump1090()">
|
||||||
|
<span>Remote</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="control-group remote-dump1090-controls" style="display: none;">
|
||||||
|
<input type="text" id="remoteSbsHost" placeholder="Host" style="width: 90px; font-size: 10px;">
|
||||||
|
<span style="color: #666;">:</span>
|
||||||
|
<input type="number" id="remoteSbsPort" value="30003" min="1" max="65535" style="width: 55px; font-size: 10px;">
|
||||||
|
</div>
|
||||||
<button class="start-btn" id="startBtn" onclick="toggleTracking()">START</button>
|
<button class="start-btn" id="startBtn" onclick="toggleTracking()">START</button>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -1054,15 +1065,47 @@
|
|||||||
// ============================================
|
// ============================================
|
||||||
// TRACKING CONTROL
|
// TRACKING CONTROL
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
|
function toggleRemoteDump1090() {
|
||||||
|
const useRemote = document.getElementById('useRemoteDump1090').checked;
|
||||||
|
const controls = document.querySelector('.remote-dump1090-controls');
|
||||||
|
controls.style.display = useRemote ? 'flex' : 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRemoteDump1090Config() {
|
||||||
|
const useRemote = document.getElementById('useRemoteDump1090').checked;
|
||||||
|
if (!useRemote) return null;
|
||||||
|
|
||||||
|
const host = document.getElementById('remoteSbsHost').value.trim();
|
||||||
|
const port = parseInt(document.getElementById('remoteSbsPort').value) || 30003;
|
||||||
|
|
||||||
|
if (!host) {
|
||||||
|
alert('Please enter remote dump1090 host address');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { host, port };
|
||||||
|
}
|
||||||
|
|
||||||
async function toggleTracking() {
|
async function toggleTracking() {
|
||||||
const btn = document.getElementById('startBtn');
|
const btn = document.getElementById('startBtn');
|
||||||
|
|
||||||
if (!isTracking) {
|
if (!isTracking) {
|
||||||
|
// Check for remote dump1090 config
|
||||||
|
const remoteConfig = getRemoteDump1090Config();
|
||||||
|
if (remoteConfig === false) return;
|
||||||
|
|
||||||
|
const requestBody = {};
|
||||||
|
if (remoteConfig) {
|
||||||
|
requestBody.remote_sbs_host = remoteConfig.host;
|
||||||
|
requestBody.remote_sbs_port = remoteConfig.port;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/adsb/start', {
|
const response = await fetch('/adsb/start', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({})
|
body: JSON.stringify(requestBody)
|
||||||
});
|
});
|
||||||
|
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
|
|||||||
@@ -298,6 +298,29 @@
|
|||||||
<button class="preset-btn" onclick="refreshDevices()" style="width: 100%;">
|
<button class="preset-btn" onclick="refreshDevices()" style="width: 100%;">
|
||||||
Refresh Devices
|
Refresh Devices
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<!-- Remote SDR (rtl_tcp) -->
|
||||||
|
<div class="form-group" style="margin-top: 10px;">
|
||||||
|
<label style="display: flex; align-items: center; gap: 8px; cursor: pointer;">
|
||||||
|
<input type="checkbox" id="useRemoteSDR" onchange="toggleRemoteSDR()">
|
||||||
|
<span style="font-size: 11px; color: #888;">Use Remote SDR (rtl_tcp)</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div id="remoteSDRConfig" style="display: none; margin-bottom: 10px;">
|
||||||
|
<div class="form-group">
|
||||||
|
<label style="font-size: 11px; color: #888;">Host</label>
|
||||||
|
<input type="text" id="rtlTcpHost" placeholder="192.168.1.100" style="width: 100%;">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label style="font-size: 11px; color: #888;">Port</label>
|
||||||
|
<input type="number" id="rtlTcpPort" value="1234" min="1" max="65535" style="width: 100%;">
|
||||||
|
</div>
|
||||||
|
<div class="info-text" style="font-size: 10px; color: #666; margin-top: 4px;">
|
||||||
|
Connect to rtl_tcp server on remote machine.<br>
|
||||||
|
Start server with: <code style="color: #00d4ff;">rtl_tcp -a 0.0.0.0</code>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="toolStatusPager" class="info-text tool-status-section" style="display: grid; grid-template-columns: auto auto; gap: 4px 8px; align-items: center;">
|
<div id="toolStatusPager" class="info-text tool-status-section" style="display: grid; grid-template-columns: auto auto; gap: 4px 8px; align-items: center;">
|
||||||
<span>rtl_fm:</span><span class="tool-status {{ 'ok' if tools.rtl_fm else 'missing' }}">{{ 'OK' if tools.rtl_fm else 'Missing' }}</span>
|
<span>rtl_fm:</span><span class="tool-status {{ 'ok' if tools.rtl_fm else 'missing' }}">{{ 'OK' if tools.rtl_fm else 'Missing' }}</span>
|
||||||
<span>multimon-ng:</span><span class="tool-status {{ 'ok' if tools.multimon else 'missing' }}">{{ 'OK' if tools.multimon else 'Missing' }}</span>
|
<span>multimon-ng:</span><span class="tool-status {{ 'ok' if tools.multimon else 'missing' }}">{{ 'OK' if tools.multimon else 'Missing' }}</span>
|
||||||
@@ -1918,6 +1941,10 @@
|
|||||||
const ppm = document.getElementById('sensorPpm').value;
|
const ppm = document.getElementById('sensorPpm').value;
|
||||||
const device = getSelectedDevice();
|
const device = getSelectedDevice();
|
||||||
|
|
||||||
|
// Check for remote SDR
|
||||||
|
const remoteConfig = getRemoteSDRConfig();
|
||||||
|
if (remoteConfig === false) return; // Validation failed
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
frequency: freq,
|
frequency: freq,
|
||||||
gain: gain,
|
gain: gain,
|
||||||
@@ -1926,6 +1953,12 @@
|
|||||||
sdr_type: getSelectedSDRType()
|
sdr_type: getSelectedSDRType()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add rtl_tcp params if using remote SDR
|
||||||
|
if (remoteConfig) {
|
||||||
|
config.rtl_tcp_host = remoteConfig.host;
|
||||||
|
config.rtl_tcp_port = remoteConfig.port;
|
||||||
|
}
|
||||||
|
|
||||||
fetch('/start_sensor', {
|
fetch('/start_sensor', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
@@ -2403,6 +2436,35 @@
|
|||||||
return document.getElementById('sdrTypeSelect').value;
|
return document.getElementById('sdrTypeSelect').value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleRemoteSDR() {
|
||||||
|
const useRemote = document.getElementById('useRemoteSDR').checked;
|
||||||
|
const configDiv = document.getElementById('remoteSDRConfig');
|
||||||
|
const localControls = document.querySelectorAll('#sdrTypeSelect, #deviceSelect');
|
||||||
|
|
||||||
|
configDiv.style.display = useRemote ? 'block' : 'none';
|
||||||
|
|
||||||
|
// Dim local device controls when using remote
|
||||||
|
localControls.forEach(el => {
|
||||||
|
el.style.opacity = useRemote ? '0.5' : '1';
|
||||||
|
el.disabled = useRemote;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRemoteSDRConfig() {
|
||||||
|
const useRemote = document.getElementById('useRemoteSDR').checked;
|
||||||
|
if (!useRemote) return null;
|
||||||
|
|
||||||
|
const host = document.getElementById('rtlTcpHost').value.trim();
|
||||||
|
const port = parseInt(document.getElementById('rtlTcpPort').value) || 1234;
|
||||||
|
|
||||||
|
if (!host) {
|
||||||
|
alert('Please enter rtl_tcp host address');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { host, port };
|
||||||
|
}
|
||||||
|
|
||||||
function getSelectedProtocols() {
|
function getSelectedProtocols() {
|
||||||
const protocols = [];
|
const protocols = [];
|
||||||
if (document.getElementById('proto_pocsag512').checked) protocols.push('POCSAG512');
|
if (document.getElementById('proto_pocsag512').checked) protocols.push('POCSAG512');
|
||||||
@@ -2425,6 +2487,10 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for remote SDR
|
||||||
|
const remoteConfig = getRemoteSDRConfig();
|
||||||
|
if (remoteConfig === false) return; // Validation failed
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
frequency: freq,
|
frequency: freq,
|
||||||
gain: gain,
|
gain: gain,
|
||||||
@@ -2435,6 +2501,12 @@
|
|||||||
protocols: protocols
|
protocols: protocols
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add rtl_tcp params if using remote SDR
|
||||||
|
if (remoteConfig) {
|
||||||
|
config.rtl_tcp_host = remoteConfig.host;
|
||||||
|
config.rtl_tcp_port = remoteConfig.port;
|
||||||
|
}
|
||||||
|
|
||||||
fetch('/start', {
|
fetch('/start', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ from .validation import (
|
|||||||
validate_longitude,
|
validate_longitude,
|
||||||
validate_frequency,
|
validate_frequency,
|
||||||
validate_device_index,
|
validate_device_index,
|
||||||
|
validate_rtl_tcp_host,
|
||||||
|
validate_rtl_tcp_port,
|
||||||
validate_gain,
|
validate_gain,
|
||||||
validate_ppm,
|
validate_ppm,
|
||||||
validate_hours,
|
validate_hours,
|
||||||
|
|||||||
@@ -172,6 +172,34 @@ class SDRFactory:
|
|||||||
capabilities=caps
|
capabilities=caps
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_network_device(
|
||||||
|
cls,
|
||||||
|
host: str,
|
||||||
|
port: int = 1234
|
||||||
|
) -> SDRDevice:
|
||||||
|
"""
|
||||||
|
Create a network device for rtl_tcp connection.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host: rtl_tcp server hostname or IP address
|
||||||
|
port: rtl_tcp server port (default 1234)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
SDRDevice configured for rtl_tcp connection
|
||||||
|
"""
|
||||||
|
caps = cls.get_capabilities(SDRType.RTL_SDR)
|
||||||
|
return SDRDevice(
|
||||||
|
sdr_type=SDRType.RTL_SDR,
|
||||||
|
index=0,
|
||||||
|
name=f'{host}:{port}',
|
||||||
|
serial='rtl_tcp',
|
||||||
|
driver='rtl_tcp',
|
||||||
|
capabilities=caps,
|
||||||
|
rtl_tcp_host=host,
|
||||||
|
rtl_tcp_port=port
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Export commonly used items at package level
|
# Export commonly used items at package level
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
|||||||
+13
-1
@@ -46,15 +46,23 @@ class SDRDevice:
|
|||||||
serial: str
|
serial: str
|
||||||
driver: str # e.g., "rtlsdr", "lime", "hackrf"
|
driver: str # e.g., "rtlsdr", "lime", "hackrf"
|
||||||
capabilities: SDRCapabilities
|
capabilities: SDRCapabilities
|
||||||
|
rtl_tcp_host: Optional[str] = None # Remote rtl_tcp server host
|
||||||
|
rtl_tcp_port: Optional[int] = None # Remote rtl_tcp server port
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_network(self) -> bool:
|
||||||
|
"""Check if this is a network/remote device."""
|
||||||
|
return self.rtl_tcp_host is not None
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
"""Convert to dictionary for JSON serialization."""
|
"""Convert to dictionary for JSON serialization."""
|
||||||
return {
|
result = {
|
||||||
'index': self.index,
|
'index': self.index,
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
'serial': self.serial,
|
'serial': self.serial,
|
||||||
'sdr_type': self.sdr_type.value,
|
'sdr_type': self.sdr_type.value,
|
||||||
'driver': self.driver,
|
'driver': self.driver,
|
||||||
|
'is_network': self.is_network,
|
||||||
'capabilities': {
|
'capabilities': {
|
||||||
'freq_min_mhz': self.capabilities.freq_min_mhz,
|
'freq_min_mhz': self.capabilities.freq_min_mhz,
|
||||||
'freq_max_mhz': self.capabilities.freq_max_mhz,
|
'freq_max_mhz': self.capabilities.freq_max_mhz,
|
||||||
@@ -66,6 +74,10 @@ class SDRDevice:
|
|||||||
'tx_capable': self.capabilities.tx_capable,
|
'tx_capable': self.capabilities.tx_capable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if self.is_network:
|
||||||
|
result['rtl_tcp_host'] = self.rtl_tcp_host
|
||||||
|
result['rtl_tcp_port'] = self.rtl_tcp_port
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class CommandBuilder(ABC):
|
class CommandBuilder(ABC):
|
||||||
|
|||||||
+24
-4
@@ -27,6 +27,16 @@ class RTLSDRCommandBuilder(CommandBuilder):
|
|||||||
tx_capable=False
|
tx_capable=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _get_device_arg(self, device: SDRDevice) -> str:
|
||||||
|
"""Get device argument for rtl_* tools.
|
||||||
|
|
||||||
|
Returns rtl_tcp connection string for network devices,
|
||||||
|
or device index for local devices.
|
||||||
|
"""
|
||||||
|
if device.is_network:
|
||||||
|
return f"rtl_tcp:{device.rtl_tcp_host}:{device.rtl_tcp_port}"
|
||||||
|
return str(device.index)
|
||||||
|
|
||||||
def build_fm_demod_command(
|
def build_fm_demod_command(
|
||||||
self,
|
self,
|
||||||
device: SDRDevice,
|
device: SDRDevice,
|
||||||
@@ -40,11 +50,11 @@ class RTLSDRCommandBuilder(CommandBuilder):
|
|||||||
"""
|
"""
|
||||||
Build rtl_fm command for FM demodulation.
|
Build rtl_fm command for FM demodulation.
|
||||||
|
|
||||||
Used for pager decoding.
|
Used for pager decoding. Supports local devices and rtl_tcp connections.
|
||||||
"""
|
"""
|
||||||
cmd = [
|
cmd = [
|
||||||
'rtl_fm',
|
'rtl_fm',
|
||||||
'-d', str(device.index),
|
'-d', self._get_device_arg(device),
|
||||||
'-f', f'{frequency_mhz}M',
|
'-f', f'{frequency_mhz}M',
|
||||||
'-M', modulation,
|
'-M', modulation,
|
||||||
'-s', str(sample_rate),
|
'-s', str(sample_rate),
|
||||||
@@ -73,7 +83,17 @@ class RTLSDRCommandBuilder(CommandBuilder):
|
|||||||
Build dump1090 command for ADS-B decoding.
|
Build dump1090 command for ADS-B decoding.
|
||||||
|
|
||||||
Uses dump1090 with network output for SBS data streaming.
|
Uses dump1090 with network output for SBS data streaming.
|
||||||
|
|
||||||
|
Note: dump1090 does not support rtl_tcp. For remote SDR, connect to
|
||||||
|
a remote dump1090's SBS output (port 30003) instead.
|
||||||
"""
|
"""
|
||||||
|
if device.is_network:
|
||||||
|
raise ValueError(
|
||||||
|
"dump1090 does not support rtl_tcp. "
|
||||||
|
"For remote ADS-B, run dump1090 on the remote machine and "
|
||||||
|
"connect to its SBS output (port 30003)."
|
||||||
|
)
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
'dump1090',
|
'dump1090',
|
||||||
'--net',
|
'--net',
|
||||||
@@ -96,11 +116,11 @@ class RTLSDRCommandBuilder(CommandBuilder):
|
|||||||
"""
|
"""
|
||||||
Build rtl_433 command for ISM band sensor decoding.
|
Build rtl_433 command for ISM band sensor decoding.
|
||||||
|
|
||||||
Outputs JSON for easy parsing.
|
Outputs JSON for easy parsing. Supports local devices and rtl_tcp connections.
|
||||||
"""
|
"""
|
||||||
cmd = [
|
cmd = [
|
||||||
'rtl_433',
|
'rtl_433',
|
||||||
'-d', str(device.index),
|
'-d', self._get_device_arg(device),
|
||||||
'-f', f'{frequency_mhz}M',
|
'-f', f'{frequency_mhz}M',
|
||||||
'-F', 'json'
|
'-F', 'json'
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -66,6 +66,32 @@ def validate_device_index(device: Any) -> int:
|
|||||||
raise ValueError(f"Invalid device index: {device}") from e
|
raise ValueError(f"Invalid device index: {device}") from e
|
||||||
|
|
||||||
|
|
||||||
|
def validate_rtl_tcp_host(host: Any) -> str:
|
||||||
|
"""Validate and return rtl_tcp server hostname or IP address."""
|
||||||
|
if not host or not isinstance(host, str):
|
||||||
|
raise ValueError("rtl_tcp host is required")
|
||||||
|
host = host.strip()
|
||||||
|
if not host:
|
||||||
|
raise ValueError("rtl_tcp host cannot be empty")
|
||||||
|
# Allow alphanumeric, dots, hyphens (valid for hostnames and IPs)
|
||||||
|
if not re.match(r'^[a-zA-Z0-9][a-zA-Z0-9.\-]*$', host):
|
||||||
|
raise ValueError(f"Invalid rtl_tcp host: {host}")
|
||||||
|
if len(host) > 253:
|
||||||
|
raise ValueError("rtl_tcp host too long")
|
||||||
|
return host
|
||||||
|
|
||||||
|
|
||||||
|
def validate_rtl_tcp_port(port: Any) -> int:
|
||||||
|
"""Validate and return rtl_tcp server port."""
|
||||||
|
try:
|
||||||
|
port_int = int(port)
|
||||||
|
if not 1 <= port_int <= 65535:
|
||||||
|
raise ValueError(f"Port must be between 1 and 65535, got {port_int}")
|
||||||
|
return port_int
|
||||||
|
except (ValueError, TypeError) as e:
|
||||||
|
raise ValueError(f"Invalid rtl_tcp port: {port}") from e
|
||||||
|
|
||||||
|
|
||||||
def validate_gain(gain: Any) -> float:
|
def validate_gain(gain: Any) -> float:
|
||||||
"""Validate and return gain value."""
|
"""Validate and return gain value."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user