Resolve the CHANGELOG conflict, and fix the EVK1029 shared-memory input
on top of the merge:
- In shared-memory mode, Evk1029SignalSource is real-time and cannot
wait, so the deterministic mode refuses it and the Signal Conditioner
no longer plans it as an unthrottled replay. Read
shm_stop_on_buffer_overflow only on Linux, avoiding an unused variable
warning elsewhere.
- Stopping the receiver no longer hangs when EVK1029_CtrlApp is idle,
has crashed or has been restarted. ReadBlock() waits at most 100 ms at
a time, RawStreamReader::read() then returns to its caller (see
end_of_stream()), and Evk1029Source releases a decode worker waiting
for data when GNU Radio stops the flowgraph. The stream ends if the
producer publishes nothing for SignalSource.shm_stall_timeout_s
seconds (default 5, 0 waits forever).
- request_stop() bumps data_event before waking the reader, and
ReadBlock() takes its snapshot of data_event before checking the stop
flag, the ring and the stream state, so that no wake-up is lost.
- Count overflows and producer silence from the first sample read, not
from the attach: nothing reads the ring while the flowgraph is built,
so shm_stop_on_buffer_overflow=true stopped the receiver at startup.
Update the CHANGELOG entry with the actual parameter names and the new
shm_stall_timeout_s parameter.
Extend the change of the previous merge to the remaining tracking
blocks: kf_tracking and gps_l1_ca_gaussian_tracking_cc (binary dump and
.mat file; records grow from 96 to 100 bytes), and the GPS L1 C/A and
Galileo E1 TCP connector and GPS L1 C/A GPU blocks (records grow from 88
to 92 bytes). The Galileo E1 TCP connector block accumulated the carrier
phase in a float, which is now a double.
Update the KF readers in utils/matlab and utils/python accordingly.
Tracking_Dump_Reader now takes the record layout, since the FPGA and
Gaussian tests read dumps that lack the TOW and WN fields (and, for the
Gaussian block, have the carrier noise variance in place of the code
frequency rate) with the dll_pll_veml_tracking layout.
Add a CHANGELOG entry.
Resolve the conflicts with the deterministic processing mode: keep the
deterministic loss-of-lock dispatch together with the "forced" suffix in
the loss-of-lock log line, and convert the two deterministic telemetry
fault paths in dll_pll_veml_tracking and kf_tracking, which still forced
the loss of lock by writing 200000 into the carrier lock fail counter,
to d_force_loss_of_lock.
Remove the conflict markers left in docs/CHANGELOG.md by the merge of
the deterministic branch, and add a CHANGELOG entry for this fix.
Add a deterministic processing mode for recorded signals
Processing the same file twice was not repeatable, even with
Acquisition_XX.blocking=true: the control thread started searches,
assigned satellites and applied channel events at whatever sample
each block had reached, and the PVT and observables applied each
other's messages whenever they arrived.
With GNSS-SDR.deterministic=true (default: false), events and
messages carry the sample at which they happened, the control
thread handles channel events in sample order, and their effects
take place a fixed lookahead later (deterministic_lookahead_ms,
default 100 ms). A gate at the Signal Conditioner output keeps the
stream within that horizon, blocks take their stamped messages at
the start of each work call, maintenance runs on signal time
(deterministic_tick_ms), and the receiver stops once the whole
input has reached the PVT. Dumps, RINEX, NMEA, KML, GPX and GeoJSON
outputs are then bit-identical from run to run on the same machine
(same FFTW wisdom and VOLK configuration), whatever the CPU load.
Supported: all file sources (throttled or not, including LabSat,
EVK1029 and ION), all acquisitions except assisted and FPGA, and
the DLL/PLL VEML, KF and Gaussian trackers. Live front ends, HAS
and NTRIP corrections, strict OSNMA, Galileo E6 with the TOW map,
GNSS assistance and visibility-aware search are refused.
carlesfernandez's review of this PR (gnss-sdr/gnss-sdr#1154) raised several
issues. This addresses all but the DCO/signing requirement (handled
separately via rebase) and the GPL licensing question on shm_ring.h (his
call, not mine to answer in code):
- Build: shared_memory_stream_reader.cc/shm_ring.h are now gated to Linux
only (CMAKE_SYSTEM_NAME), matching the EVK1029_SHM_INPUT compile
definition the adapter checks before including/constructing
SharedMemoryStreamReader; an unavailable shared_memory input now throws
std::invalid_argument instead of failing to build.
- librt is linked on glibc < 2.34, same as core_receiver already does for
its own shm_open use.
- ReadBlock() now treats StreamState::Error as terminal (it previously
blocked forever), and rejects a length prefix larger than the block can
hold instead of reading past it (reproduced his reported 64 MiB ASan
overread).
- An unrecognized SignalSource.input value now throws instead of silently
falling back to file mode; enable_throttle_control is ignored with a
warning in shared_memory mode.
- Dangling references to the (not-in-repo) spec doc removed; diagnostics
moved from std::cout to LOG(INFO)/LOG(WARNING); added the missing
gnss_sdr_make_unique.h include; fixed the clang-tidy violations he listed
(brace-less ifs, long -> int64_t).
Backpressure and loss detection redesigned per further discussion: the SHM
ring's WriteBlock() blocks (not drops) a full ring, so a stalled GNSS-SDR
consumer backs up through EVK1029_CtrlApp's own buffering instead of ever
reaching the USB/target side -- the target must never see an overflow
condition from this path. Real, unrecoverable loss is instead detected on
EVK1029_CtrlApp's side via the existing IF_TO_AXIS hardware overflow flag
(now also polled during SHM streaming, not just recording) and surfaced
through the ring's Header as overflow_event_count (protocol bumped to v3).
It's a count of occurrences, not bytes -- the hardware only latches a
sticky bit -- so SharedMemoryStreamReader can't zero-fill a known gap; it
either stops the stream (new SignalSource.shm_stop_on_buffer_overflow,
default false) or logs and continues, leaving the sample count to jump in
place.
Also fixes request_stop() not waking a blocked read(): setting the stop
flag alone doesn't wake a ReadBlock() already asleep in FUTEX_WAIT on
data_event, so Evk1029Source's join() of the decode-ahead thread could hang
on shutdown with an idle producer -- the same class of bug his review
caught elsewhere, found while re-checking this change for others like it.
Verified with standalone tests (plain and under AddressSanitizer), not
just a clean build: round-trip, terminal Error, corrupted-length
rejection, WriteBlock's blocking-plus-abortFlag-wake behavior, overflow
detection (both log-and-continue and stop-on-overflow), and request_stop()
unblocking a waiting read(). Full gnss-sdr build (including install/)
clean throughout.
Signed-off-by: joebre <joel.brenner@saphyrion.ch>
First step of EVK1029_shared_memory_input_spec(2).md on the GNSS-SDR side:
Evk1029Source now reads raw bytes through a RawStreamReader interface
instead of owning an ifstream directly, so the exact same OBA-decode/FIR/
CUDA pipeline can run against either a recorded capture file or a live
shared-memory stream from EVK1029_CtrlApp.
- raw_stream_reader.h: the interface (read(), request_stop()).
- file_stream_reader.{h,cc}: wraps the original file-reading behavior
(open, optional word-aligned seek, buffered read) verbatim.
- shm_ring.h: verbatim copy of EVK1029_CtrlApp's evk1029/shm_ring.hpp wire
protocol -- the two repos build completely separately; only the struct
layout and kMagic/kVersion need to match, since both sides mmap the same
region. Keep both copies in sync if the format ever changes.
- shared_memory_stream_reader.{h,cc}: attaches to the ring (retrying up to
30s if the producer hasn't started yet -- a late producer is recoverable,
not a hard failure like a missing file), bridges SHM block granularity
into read()'s byte-stream semantics, EOF on Stopped/EndOfStream with the
ring drained. Wakes a producer that might be stuck waiting for space on
destruction.
- Evk1029Source's destructor now calls reader_->request_stop() before
joining the decode-ahead thread -- that thread's read() can block
indefinitely on a live stream, so without this the join could hang
forever on shutdown (a no-op for FileStreamReader, which never blocks).
- evk1029_signal_source.cc: new SignalSource.input=file|shared_memory
(default file, every existing config keeps working untouched) and
.shm_name config keys.
Verified: file-mode regression (same capture file, full GPS+Galileo
tracking lock, unchanged from before this refactor) and a synthetic
SHM-mode smoke test (sustained attach/read/EOF/shutdown with no real
hardware). Confirmed on real hardware: EVK1029_CtrlApp's live SHM stream
reaches a real position fix through this path.
Signed-off-by: joebre <joel.brenner@saphyrion.ch>
The Monitor is fed from the Observables, which since ed5a75e31 fill
channels without a valid time reference with their latest tracking
data. That never worked in Galileo E6-only configurations: the GPS L1
C/A, GPS L5, Galileo, BeiDou D1/D2 and BeiDou B1C telemetry decoders
produced no output until they decoded the time of week, so the
Observables never received E6 tracking data. The GLONASS, GPS L2C,
BeiDou B2a and SBAS decoders already forwarded every symbol with
Flag_valid_word unset; now all telemetry decoders do. Dumps,
telemetry_to_trk and nav-data monitor messages are still issued only
with a valid time of week.
The tracking-only entries also had fs set to 0, which gnss-sdr-monitor
takes as an empty channel, hiding SBAS channels. fs is now kept, with
the validity flags still unset; the PVT only uses observations with
Flag_valid_pseudorange.
As a side effect, the secondary-band acquisition assistance can use a
primary-band channel as soon as its tracking locks, instead of after
its time of week is decoded. The Galileo F/NAV test sink now records
the first item with a valid word.
Alternative to PR #1122, without new options or changes to tracking
and to the PVT time-of-week reset handling. Related to #1018.
log_data() in dll_pll_veml_tracking and dll_pll_veml_tracking_fpga casts
d_acc_carrier_phase_rad, a double, to float before writing it to the
binary dump, and save_matfile() reads it back as a float. The
accumulated phase grows by 2*pi times the Doppler shift every second
(about 31400 rad/s at 5 kHz), so it reaches 1e6 rad after about 30 s of
tracking at 5 kHz, or under 3 minutes at 1 kHz. The float spacing is
0.0625 rad at 1e6 rad, 0.25 rad at 3e6 rad and 1 rad at 1e7 rad. At
3e6 rad, for instance, the phase difference between two 1 ms epochs of
the dump is only known to within +/-0.25 rad, about 40 Hz in frequency
terms. The phase used by the receiver (Gnss_Synchro::Carrier_phase_rads)
is a double and is not affected; only the dump is.
Write the field as a double, and read it back as a double in
save_matfile(), so that the .mat file also holds a double.
This changes the dump record layout. The field keeps its position but
grows from 4 to 8 bytes, so a record is now 112 bytes long in
dll_pll_veml_tracking (it was 108) and 100 bytes long in
dll_pll_veml_tracking_fpga (it was 96). The readers of this format are
updated accordingly: Tracking_Dump_Reader, used by the unit tests, and
dll_pll_veml_read_tracking_dump in utils/matlab and utils/python.
Signed-off-by: ObvMamut <obvmamut@proton.me>
Two fail-safes in the tracking blocks force a loss of lock: the bit or
secondary code synchronization time limit
(bit_synchronization_time_limit_s), and the telemetry fault message sent
by the telemetry decoders. Both did it by writing a large value into
d_carrier_lock_fail_counter (300000 and 200000, respectively) and
relying on the lock check to find it above max_carrier_lock_fail. When
max_carrier_lock_fail is configured above those values, neither
fail-safe drops the channel: unless the lock detectors drop it for
other reasons, a channel that never achieves bit synchronization keeps
tracking past the time limit, and a channel whose telemetry decoder
reports a fault keeps tracking.
Replace the magic counter values with a d_force_loss_of_lock flag. Both
fail-safes set it, cn0_and_tracking_lock_status() declares the loss of
lock when it is set, whatever the lock fail counters, and it is cleared
when the loss of lock is declared and when a new tracking attempt
starts. The loss-of-lock log line now says when the loss was forced,
since the counter values no longer show it.
The same change is applied to dll_pll_veml_tracking,
dll_pll_veml_tracking_fpga and kf_tracking, the three blocks that used
this pattern.
Add two tests to trk_test that set max_carrier_lock_fail = 1000000 and
check that a telemetry fault and the synchronization time limit still
drop the channel.
Signed-off-by: ObvMamut <obvmamut@proton.me>
A one-code-period PCPS window starts at an arbitrary code phase, so a
secondary-code or data sign transition at the code epoch inside it
splits the correlation peak up to +-0.74/T away from the true Doppler.
For GPS L5 (the I5 NH10 code changes sign at 6 of every 10 epochs),
about 40 % of the acquisitions started tracking 250-900 Hz off. The
1 ms Costas loop then either held a false lock at exactly +-500 Hz
(lock test 0.97, C/N0 3.9 dB low, secondary-code sync impossible)
until bit_synchronization_time_limit_s, or never locked and lost lock
a few seconds after pull-in.
After a positive decision, refine_doppler() despreads the dwells with
the replica aligned to the detected code epoch, scores the two sides
of the epoch under both sign hypotheses (summed non-coherently over
dwells), and re-estimates the Doppler over +-1/T around the grid peak.
It only runs on positive acquisitions, so its cost is negligible, also
with the CUDA grid. It applies to every pcps_acquisition search over
one code period without bit_transition_flag. The new
Acquisition_XX.refine_doppler parameter (default true) disables it.
With -DENABLE_CUDA=ON, band<n>_cuda=true computes that band's
frequency-translating FIR (complex composite taps applied to the real
capture) on an NVIDIA GPU through the new CudaDdcEngine, instead of on
a CPU worker thread. As with the CUDA acquisition engine, the public
interface has no CUDA types and hides the implementation behind a
PIMPL. Each band falls back to the CPU, with a warning in the log, if
its engine cannot be created or a GPU call fails. Builds without CUDA,
and bands without the flag, are unchanged.
Taken from PR #1144, plus:
- Report the CUDA status per band with LOG instead of std::cout/cerr
- Check cudaGetLastError() after the kernel launch, so a failed launch
is not mistaken for valid output
- Select the engine's device in set_taps(), compute() and the
destructor, since compute() runs on the band worker threads
- Build the engine only with both ENABLE_CUDA and ENABLE_EVK1029
With enable_freq_xlating=true, Evk1029Source translates, filters and
decimates each band itself and exposes one gr_complex output port per
band, so Bypass Signal Conditioners can connect the channels straight
to the source. Each band's FIR runs on its own worker thread, and the
next chunk of the capture is decoded while the current one is filtered.
Per-band filter design: band<n>_IF, _decimation_factor, _bw, _tw,
_window, _attenuation_dB and _kaiser_beta.
Taken from PR #1143 without its SignalConditioner Bypass commits (next
already provides Bypass), plus:
- Center shorter band filters on the longest one, so every band has the
same group delay (mismatched tap counts biased pseudoranges between
bands by up to km)
- Fix source dump in fused mode: one gr_complex file per band (_ch<n>)
- Reject unequal or non-positive band decimation factors
- Build with GNU Radio < 3.9 (firdes window type) and VOLK < 2.5
(rotator), use volk_gnsssdr::vector
- Link Gnuradio::filter privately and only with ENABLE_EVK1029
- Start worker threads after the capture file is opened
With blocking=false and max_dwells > 1, copy the whole integration window
into a per-block buffer, so that general_work() keeps consuming input while
the worker integrates. The shared conditioner buffer no longer holds back
every channel during a search.
- set_history() keeps the last window readable, so a search starts as soon
as one new dwell arrives. Dwell offsets in the window follow the
dwell-residual skip, and the sample stamp is the end of the window (the
end of the first dwell while the window starts at stream index 0).
- The buffer is allocated at the first search and freed on a positive
acquisition or when the channel is deactivated.
- Deactivation stops the worker and drops the search, so the next
activation starts a new one. stop() replaces the destructor wait.
- Idle input is consumed in one call per wakeup, keeping the history.
Based on #1108 by Vladislav P.
Replace the fixed 20 ms limit on SignalConditioner.batch_size_ms and
max_batch_latency_ms. A configured batch is accepted if it is no longer
than the automatic one (min(10 ms, observable_interval_ms)), or if the
buffer it needs (whole batches, with room for one on top of the largest
reader window) fits the alignment budget: the signal time channels can
trail the receiver clock before the observables miss epochs. Batches
are also limited to 4 MiB, since GNU Radio allocates two of them on
each side of the batching block.
At observable_interval_ms=20 and 4 MSps gr_complex this allows about
90 ms instead of 20 ms. At 5 ms it now rejects batches that the old
limit let through. In automatic mode, an explicit max_batch_latency_ms
sets the batch size, so that batch gets the same check. Defaults are
unchanged.
add_obs_sat_record_line() formatted every observable group (pseudorange,
carrier phase, Doppler, CN0) unconditionally, even for the placeholder
Gnss_Synchro{} slot get_constellation_observables_map() creates for a
signal with no valid observation for a given satellite (e.g. untracked,
or simply a frequency that satellite doesn't transmit, such as a GPS
PRN5/PRN7 which has an L5 slot but only tracks/transmits L1). That
placeholder is all-zero, so it printed as a formatted "0.000" value with
a Signal Strength Indicator floored to its minimum class (1), which
reads as a real but degraded observation rather than "no data".
Per RINEX 3/4, an unavailable observation must be a fully blank field,
not a zero value. Gate the formatter on Flag_valid_pseudorange, which
already reliably distinguishes a real observable (set true by the
Observables block) from the placeholder (defaults false) -- write 64
spaces instead when false.
Select batch targets from sample rate, latency and memory limits, and
consumer buffer requirements. Replace eligible pass-through stages before
channel fan-out without machine-specific profiles or configuration edits.
Preserve samples and tags across partial batches, deadlines, and EOF.
Handle conditioned output ports consistently and clean up stream and
message connections on disconnect or connection failure.
GPS L5 is pre-operational, and the L5 health bit of CNAV message type 10 (IS-GPS-200N 30.3.3.1.1.2) is broadcast as "unhealthy" on every SV. As a result, every GPS L5 signal was reported with healthy = false in the monitor_pvt tracked_satellites list, and "not used for navigation" was printed for every GPS satellite. Neither affected the PVT solution: CNAV L2C/L5/J5 observables are not gated on these bits (the L5 exclusion was dropped in v0.0.17), and the CNAV ephemeris handed to RTKLIB carries no svh. GPS L5 now reports the LNAV SV health of the same satellite; GPS L2C and QZSS L5 keep the CNAV bits; and the console message is replaced by a LOG(INFO) line.
Rtklib_Solver::get_broadcast_signal_health() excluded these signals from
the fix based on CNAV message type 10's per-carrier L1/L2/L5 health bit
alone. Per IS-GPS-200N 30.3.3.1.1.2, that bit is only meaningful together
with the SV's LNAV configuration code (20.3.3.5.1.4), which this receiver
does not track; the spec's own instruction for a receiver in that position
is to assume every signal is available on every SV.
Confirmed this was excluding real, operational satellites: cross-checked
the adjacent Transmission Week Number field against ground truth (computed
expected GPS week for the capture date, matched exactly), ruling out a
decode/bit-offset bug. L2C/L5/J5 now fall through to the same SV-wide
health source L1 C/A already uses. Also removes the now-misleading
"not used for navigation" message tied to the same bit.
Tested against real EVK1029 hardware captures; GPS L5 satellites now
report correctly instead of being universally flagged unhealthy.
d_samples_to_consume (pcps_acquisition_adapter.cc) is floor(sampled_ms *
samples_per_ms), truncating to an integer. When the configured internal_fs_sps
does not divide evenly into a dwell (any decimation ratio leaving a fractional
number of samples per dwell), every dwell is silently shorter than the true
dwell length by a fixed residual, and that residual compounds linearly across
non-coherent dwells: the true code epoch drifts within the accumulation grid
instead of landing on the same index every time, and the sample stamp handed
to tracking drifts out of sync with it. Tracking then reconstructs the wrong
code phase at pull-in. Only shows up for short, high-chip-rate codes (Galileo
E5a, GPS L5) accumulated over several dwells -- low chip rate codes (GPS L1,
Galileo E1) absorb the same absolute drift as a much smaller fraction of a
chip.
Fix: keep each dwell's FFT/correlation window at the existing fixed
d_samples_to_consume size (so none of the buffer/FFT-plan sizing set up at
construction needs to change), but let the actual stream consumption between
dwells track the true dwell boundary with a standard DDA/Bresenham
accumulator -- skip one extra sample (discarded, never buffered) whenever the
accumulated residual reaches a full sample. This keeps every dwell's window
within half a sample of the true boundary permanently, so the drift this fix
is about never accumulates in the first place. The residual itself is
computed once, in the constructor, directly from the integer resampled_fs
(not through the lossy intermediate float samples_per_ms), and is always in
[0, 1) by construction, so there is no signed/unsigned wraparound risk.
This lives entirely in the sample-consumption state machine in general_work(),
upstream of doppler_grid_cpu()/doppler_grid_cuda()/update_synchro(), so CUDA
builds and bit_transition_flag mode need no special-casing -- they share the
same corrected consumption automatically. It is also correct for
coherent_integration_time_ms spanning more than one code period, since the
residual is derived from the same sampled_ms used for d_samples_to_consume,
not from a single code period.
A no-op whenever samples_per_code is already an integer (any internal_fs_sps
dividing evenly into one dwell): the residual is then exactly 0, so the skip
counter never fires.
Verified against a real EVK1029 dual-band capture (Galileo E1+E5a, GPS
L1+L5): the untouched case (samples/dwell already integer) stayed at ~2
spurious loss-of-lock events per 90s; a case with 0.5 samples/dwell of
truncation error went from 50+ loss-of-lock events per 4 minutes (tracking's
own frequency-error-reduction diagnostic scan showing no discernible
correlation peak at all) down to 1 event per ~41s -- the same order as the
untouched case -- with sharp, correct correlation peaks and CN0 estimates
jumping from ~20-30 dB-Hz (meaningless, noise-floor) to ~42-52 dB-Hz (genuine
lock).