ka9q-python 3.26.2__py3-none-any.whl → 3.29.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ka9q/cli.py +0 -2
- ka9q/compat.py +1 -1
- ka9q/control.py +65 -17
- ka9q/multi_stream.py +60 -22
- ka9q/resequencer.py +403 -159
- ka9q/spectrum_stream.py +35 -3
- ka9q/status.py +25 -6
- ka9q/stream.py +49 -21
- ka9q/stream_quality.py +9 -2
- ka9q/tui.py +0 -2
- ka9q/types.py +11 -3
- {ka9q_python-3.26.2.dist-info → ka9q_python-3.29.0.dist-info}/METADATA +6 -1
- ka9q_python-3.29.0.dist-info/RECORD +30 -0
- ka9q_python-3.26.2.dist-info/RECORD +0 -30
- {ka9q_python-3.26.2.dist-info → ka9q_python-3.29.0.dist-info}/WHEEL +0 -0
- {ka9q_python-3.26.2.dist-info → ka9q_python-3.29.0.dist-info}/entry_points.txt +0 -0
- {ka9q_python-3.26.2.dist-info → ka9q_python-3.29.0.dist-info}/licenses/LICENSE +0 -0
- {ka9q_python-3.26.2.dist-info → ka9q_python-3.29.0.dist-info}/top_level.txt +0 -0
ka9q/cli.py
CHANGED
|
@@ -54,8 +54,6 @@ def _render_status_text(st: ChannelStatus) -> str:
|
|
|
54
54
|
L.append(f" First LO: {_fmt_hz(st.first_lo)} lock={fe.lock}")
|
|
55
55
|
L.append(f" Second LO: {_fmt_hz(st.second_lo)}")
|
|
56
56
|
L.append(f" Shift: {_fmt_hz(st.shift)}")
|
|
57
|
-
if st.doppler:
|
|
58
|
-
L.append(f" Doppler: {_fmt_hz(st.doppler)} @ {st.doppler_rate} Hz/s")
|
|
59
57
|
L.append(f" Filter: {_fmt_hz(st.low_edge)} .. {_fmt_hz(st.high_edge)} (β={st.kaiser_beta})")
|
|
60
58
|
L.append(f" FE filter: {_fmt_hz(fe.fe_low_edge)} .. {_fmt_hz(fe.fe_high_edge)}")
|
|
61
59
|
L.append("")
|
ka9q/compat.py
CHANGED
ka9q/control.py
CHANGED
|
@@ -23,7 +23,9 @@ PARAMETERS:
|
|
|
23
23
|
import socket
|
|
24
24
|
import select
|
|
25
25
|
import struct
|
|
26
|
+
import math
|
|
26
27
|
import secrets
|
|
28
|
+
import warnings
|
|
27
29
|
import logging
|
|
28
30
|
import threading
|
|
29
31
|
import hashlib
|
|
@@ -2624,32 +2626,68 @@ class RadiodControl:
|
|
|
2624
2626
|
logger.info("Metrics reset")
|
|
2625
2627
|
|
|
2626
2628
|
def set_doppler(self, ssrc: int, doppler_hz: float = 0.0, doppler_rate_hz_per_sec: float = 0.0):
|
|
2629
|
+
"""Retired: radiod dropped DOPPLER_FREQUENCY/_RATE in ka9q 64938af7.
|
|
2630
|
+
|
|
2631
|
+
Use :meth:`set_sweep`. Sends nothing.
|
|
2627
2632
|
"""
|
|
2628
|
-
|
|
2629
|
-
|
|
2633
|
+
warnings.warn("set_doppler is retired; radiod dropped DOPPLER (ka9q 64938af7); use set_sweep",
|
|
2634
|
+
DeprecationWarning, stacklevel=2)
|
|
2635
|
+
raise RuntimeError("radiod dropped DOPPLER (ka9q 64938af7); use set_sweep")
|
|
2636
|
+
|
|
2637
|
+
def set_sweep(self, ssrc: int, rate_hz_per_s: float, period_s: float,
|
|
2638
|
+
duration_s: Optional[float] = None, start_s: float = 0.0) -> None:
|
|
2639
|
+
"""
|
|
2640
|
+
Command a linear sweep (dechirp) on a linear-demod channel.
|
|
2641
|
+
|
|
2642
|
+
Sends all four sweep TLVs, zeros explicit, so a command always
|
|
2643
|
+
replaces the whole sweep. radiod checks the merged settings after
|
|
2644
|
+
each command and refuses (logs, leaves the channel unswept) a rate
|
|
2645
|
+
without a period, duration > period, or an NCO-limit violation.
|
|
2646
|
+
|
|
2630
2647
|
Args:
|
|
2631
2648
|
ssrc: SSRC of the channel
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2649
|
+
rate_hz_per_s: sweep rate, Hz/s, signed (positive = up); 0 = no sweep
|
|
2650
|
+
period_s: sweep period in seconds (required for a nonzero rate)
|
|
2651
|
+
duration_s: seconds of each period that sweep (default: whole period)
|
|
2652
|
+
start_s: offset added to the sweep time base, seconds (default 0)
|
|
2653
|
+
|
|
2654
|
+
Raises:
|
|
2655
|
+
ValidationError: non-finite value; rate != 0 without
|
|
2656
|
+
0 < period <= 1e6 s; duration outside [0, period]
|
|
2657
|
+
|
|
2658
|
+
Note: SWEEP_EPOCH_SAMPLE/FRAC (217/216), which radiod reports, are
|
|
2659
|
+
provisional until Phil assigns final numbers.
|
|
2638
2660
|
"""
|
|
2639
2661
|
_validate_ssrc(ssrc)
|
|
2640
|
-
|
|
2662
|
+
if duration_s is None:
|
|
2663
|
+
duration_s = period_s
|
|
2664
|
+
for nm, v in (("rate", rate_hz_per_s), ("period", period_s),
|
|
2665
|
+
("duration", duration_s), ("start", start_s)):
|
|
2666
|
+
if not isinstance(v, (int, float)) or isinstance(v, bool) or not math.isfinite(v):
|
|
2667
|
+
raise ValidationError(f"Sweep {nm} must be a finite number, got {v!r}")
|
|
2668
|
+
if rate_hz_per_s != 0 and not (0 < period_s <= 1e6):
|
|
2669
|
+
raise ValidationError(
|
|
2670
|
+
f"Sweep period must satisfy 0 < period <= 1e6 s with a nonzero rate, got {period_s}")
|
|
2671
|
+
if period_s < 0 or period_s > 1e6:
|
|
2672
|
+
raise ValidationError(f"Sweep period out of range [0, 1e6] s: {period_s}")
|
|
2673
|
+
if not (0 <= duration_s <= period_s):
|
|
2674
|
+
raise ValidationError(
|
|
2675
|
+
f"Sweep duration must satisfy 0 <= duration <= period ({period_s}), got {duration_s}")
|
|
2676
|
+
|
|
2641
2677
|
cmdbuffer = bytearray()
|
|
2642
2678
|
cmdbuffer.append(CMD)
|
|
2643
|
-
|
|
2644
|
-
encode_double(cmdbuffer, StatusType.
|
|
2645
|
-
encode_double(cmdbuffer, StatusType.
|
|
2679
|
+
encode_double(cmdbuffer, StatusType.SWEEP_RATE, float(rate_hz_per_s))
|
|
2680
|
+
encode_double(cmdbuffer, StatusType.SWEEP_DURATION, float(duration_s))
|
|
2681
|
+
encode_double(cmdbuffer, StatusType.SWEEP_PERIOD, float(period_s))
|
|
2682
|
+
encode_double(cmdbuffer, StatusType.SWEEP_START, float(start_s))
|
|
2646
2683
|
encode_int(cmdbuffer, StatusType.OUTPUT_SSRC, ssrc)
|
|
2647
2684
|
encode_int(cmdbuffer, StatusType.COMMAND_TAG, secrets.randbits(31))
|
|
2648
2685
|
encode_eol(cmdbuffer)
|
|
2649
|
-
|
|
2650
|
-
logger.info(f"Setting
|
|
2686
|
+
|
|
2687
|
+
logger.info(f"Setting sweep for SSRC {ssrc}: rate={rate_hz_per_s} Hz/s, "
|
|
2688
|
+
f"period={period_s} s, duration={duration_s} s, start={start_s} s")
|
|
2651
2689
|
self.send_command(cmdbuffer)
|
|
2652
|
-
|
|
2690
|
+
|
|
2653
2691
|
def set_pll(self, ssrc: int, enable: bool, bandwidth_hz: Optional[float] = None, square: bool = False):
|
|
2654
2692
|
"""
|
|
2655
2693
|
Configure PLL (Phase-Locked Loop) for carrier tracking in linear modes
|
|
@@ -3062,7 +3100,8 @@ class RadiodControl:
|
|
|
3062
3100
|
window_type: Optional[int] = None, avg: Optional[int] = None,
|
|
3063
3101
|
overlap: Optional[float] = None, base: Optional[float] = None,
|
|
3064
3102
|
step: Optional[float] = None, demod_type: Optional[int] = None,
|
|
3065
|
-
frequency_hz: Optional[float] = None
|
|
3103
|
+
frequency_hz: Optional[float] = None,
|
|
3104
|
+
lifetime: Optional[int] = None):
|
|
3066
3105
|
"""
|
|
3067
3106
|
Configure spectrum analyzer mode parameters.
|
|
3068
3107
|
|
|
@@ -3091,6 +3130,10 @@ class RadiodControl:
|
|
|
3091
3130
|
DemodType.SPECT_DEMOD or SPECT2_DEMOD) so a spectrum
|
|
3092
3131
|
channel can be created/retargeted with one command.
|
|
3093
3132
|
frequency_hz: Optional center frequency to set in the same packet.
|
|
3133
|
+
lifetime: Optional LIFETIME in radiod frames (~50/s), sent in the
|
|
3134
|
+
same packet; 0 = infinite. radiod never reaps a 0 Hz
|
|
3135
|
+
spectrum channel without one, so a client that dies before
|
|
3136
|
+
removing its channel leaks it. See set_channel_lifetime.
|
|
3094
3137
|
|
|
3095
3138
|
Example:
|
|
3096
3139
|
>>> control.set_spectrum(ssrc=12345, bin_bw_hz=100, bin_count=512,
|
|
@@ -3146,6 +3189,11 @@ class RadiodControl:
|
|
|
3146
3189
|
encode_float(cmdbuffer, StatusType.SPECTRUM_BASE, base)
|
|
3147
3190
|
if step is not None:
|
|
3148
3191
|
encode_float(cmdbuffer, StatusType.SPECTRUM_STEP, step)
|
|
3192
|
+
if lifetime is not None:
|
|
3193
|
+
if not isinstance(lifetime, int) or lifetime < 0:
|
|
3194
|
+
raise ValidationError(
|
|
3195
|
+
f"lifetime must be an int >= 0 (frames), got {lifetime!r}")
|
|
3196
|
+
encode_int(cmdbuffer, StatusType.LIFETIME, lifetime)
|
|
3149
3197
|
|
|
3150
3198
|
encode_int(cmdbuffer, StatusType.OUTPUT_SSRC, ssrc)
|
|
3151
3199
|
encode_int(cmdbuffer, StatusType.COMMAND_TAG, secrets.randbits(31))
|
|
@@ -3155,7 +3203,7 @@ class RadiodControl:
|
|
|
3155
3203
|
f"Setting spectrum for SSRC {ssrc}: bw={bin_bw_hz} Hz, "
|
|
3156
3204
|
f"bins={bin_count}, crossover={crossover_hz} Hz, "
|
|
3157
3205
|
f"window={window_type}, avg={avg}, overlap={overlap}, "
|
|
3158
|
-
f"base={base}, step={step}"
|
|
3206
|
+
f"base={base}, step={step}, lifetime={lifetime}"
|
|
3159
3207
|
)
|
|
3160
3208
|
self.send_command(cmdbuffer)
|
|
3161
3209
|
|
ka9q/multi_stream.py
CHANGED
|
@@ -83,6 +83,10 @@ class _ChannelSlot:
|
|
|
83
83
|
pending_rtp_start: object = None # first-sample RTP of the pending batch
|
|
84
84
|
deliver_interval: int = 10
|
|
85
85
|
last_packet_time: float = 0.0
|
|
86
|
+
# Time of the last resequencer OUTPUT. Packets can keep arriving while
|
|
87
|
+
# nothing comes out (a wedged resequencer); raw receipt alone would
|
|
88
|
+
# call that slot healthy.
|
|
89
|
+
last_output_time: float = 0.0
|
|
86
90
|
dropped: bool = False
|
|
87
91
|
first_rtp_timestamp: Optional[int] = None
|
|
88
92
|
lifetime: Optional[int] = None
|
|
@@ -392,11 +396,15 @@ class MultiStream:
|
|
|
392
396
|
# Flush all resequencers
|
|
393
397
|
for ssrc, slot in self._slots.items():
|
|
394
398
|
try:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
slot.
|
|
399
|
-
self.
|
|
399
|
+
# flush() stops before a STREAM_INTERRUPTION; each further
|
|
400
|
+
# call returns the next chunk, routed like live output.
|
|
401
|
+
for _ in range(len(slot.resequencer.buffer) + 1):
|
|
402
|
+
final_samples, final_gaps = slot.resequencer.flush()
|
|
403
|
+
self._route_output(slot, final_samples, final_gaps)
|
|
404
|
+
if not slot.resequencer.pending:
|
|
405
|
+
break
|
|
406
|
+
# Deliver the pending batch even when flush added nothing.
|
|
407
|
+
self._deliver(slot)
|
|
400
408
|
except Exception:
|
|
401
409
|
pass
|
|
402
410
|
|
|
@@ -487,6 +495,10 @@ class MultiStream:
|
|
|
487
495
|
continue
|
|
488
496
|
|
|
489
497
|
slot.last_packet_time = time.time()
|
|
498
|
+
# The first packet arms the output timer too, so a slot whose
|
|
499
|
+
# packets arrive but never come out still trips it.
|
|
500
|
+
if slot.last_output_time == 0.0:
|
|
501
|
+
slot.last_output_time = slot.last_packet_time
|
|
490
502
|
slot.quality.rtp_packets_received += 1
|
|
491
503
|
|
|
492
504
|
if slot.first_rtp_timestamp is None:
|
|
@@ -523,22 +535,37 @@ class MultiStream:
|
|
|
523
535
|
wallclock=wallclock,
|
|
524
536
|
)
|
|
525
537
|
output, gaps = slot.resequencer.process_packet(packet)
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
538
|
+
self._route_output(slot, output, gaps)
|
|
539
|
+
|
|
540
|
+
def _route_output(self, slot: _ChannelSlot, output, gaps) -> None:
|
|
541
|
+
"""Accumulate one resequencer emission into the slot's batch."""
|
|
542
|
+
if output is not None and len(output) > 0 and any(
|
|
543
|
+
g.source is GapSource.STREAM_INTERRUPTION for g in gaps):
|
|
544
|
+
# The resequencer could not fill this gap, and the chunk opens
|
|
545
|
+
# at the post-gap packet. Deliver what came before as its own
|
|
546
|
+
# batch, then re-base the anchor so that first_rtp_timestamp +
|
|
547
|
+
# total_samples_delivered still names the next sample's RTP.
|
|
548
|
+
self._deliver(slot)
|
|
549
|
+
rebased = (slot.resequencer.last_chunk_rtp_start
|
|
550
|
+
- slot.quality.total_samples_delivered) & 0xFFFFFFFF
|
|
551
|
+
slot.first_rtp_timestamp = rebased
|
|
552
|
+
slot.quality.first_rtp_timestamp = rebased
|
|
553
|
+
|
|
554
|
+
# Harvest gaps unconditionally, even from a call that produced no
|
|
555
|
+
# output; collecting only inside the branch below once discarded a
|
|
556
|
+
# radiod zero-block marker, and the stall went silent one layer
|
|
557
|
+
# further up.
|
|
558
|
+
slot.gap_buffer.extend(gaps)
|
|
559
|
+
|
|
560
|
+
if output is not None and len(output) > 0:
|
|
561
|
+
slot.last_output_time = time.time()
|
|
562
|
+
if not slot.sample_buffer:
|
|
563
|
+
slot.pending_rtp_start = slot.resequencer.last_chunk_rtp_start
|
|
564
|
+
slot.sample_buffer.append(output)
|
|
565
|
+
slot.packets_since_delivery += 1
|
|
566
|
+
|
|
567
|
+
if slot.packets_since_delivery >= slot.deliver_interval:
|
|
568
|
+
self._deliver(slot)
|
|
542
569
|
|
|
543
570
|
# ── encoding verification ──
|
|
544
571
|
|
|
@@ -662,7 +689,9 @@ class MultiStream:
|
|
|
662
689
|
slot.quality.delivered_rtp_start = slot.pending_rtp_start
|
|
663
690
|
|
|
664
691
|
try:
|
|
665
|
-
slot
|
|
692
|
+
# A copy: the slot's quality keeps changing (an interruption
|
|
693
|
+
# re-bases first_rtp_timestamp right after this delivery).
|
|
694
|
+
slot.on_samples(combined, slot.quality.copy())
|
|
666
695
|
except Exception:
|
|
667
696
|
logger.exception(
|
|
668
697
|
f"MultiStream: callback error for SSRC {slot.channel_info.ssrc}"
|
|
@@ -696,6 +725,14 @@ class MultiStream:
|
|
|
696
725
|
f"No packets for {silence:.1f}s "
|
|
697
726
|
f"(timeout: {self._drop_timeout_sec}s)",
|
|
698
727
|
)
|
|
728
|
+
elif (slot.last_output_time > 0 and
|
|
729
|
+
now - slot.last_output_time > self._drop_timeout_sec):
|
|
730
|
+
self._handle_drop(
|
|
731
|
+
ssrc, slot,
|
|
732
|
+
f"packets arriving but no output for "
|
|
733
|
+
f"{now - slot.last_output_time:.1f}s "
|
|
734
|
+
f"(timeout: {self._drop_timeout_sec}s)",
|
|
735
|
+
)
|
|
699
736
|
elif self._gap_storm(slot, check_interval):
|
|
700
737
|
self._handle_drop(
|
|
701
738
|
ssrc, slot,
|
|
@@ -772,6 +809,7 @@ class MultiStream:
|
|
|
772
809
|
slot.packets_since_delivery = 0
|
|
773
810
|
slot.last_gaps = 0
|
|
774
811
|
slot.gap_storm_secs = 0.0
|
|
812
|
+
slot.last_output_time = 0.0
|
|
775
813
|
|
|
776
814
|
logger.info(
|
|
777
815
|
f"MultiStream: {slot.frequency_hz/1e6:.3f} MHz restored "
|