Commit graph

218 commits

Author SHA1 Message Date
Simon Ruderich 5fb5a2908d jsonlogger: increase pipe buffer to reduce likelihood of corrupted messages
Our JSON messages can get rather large which can cause a buffer overrun
when the reading program is not scheduled at the same time. When the
kernel returns EAGAIN we abort writing the current JSON message.
However, the unfinished (and thus invalid) JSON message is still in the
pipe and will be processed by the reading program.

Increase the pipe buffer from the default 65536 to reduce the likelihood
of this happening. It's difficult to completely prevent the issue as we
don't want to slow down the main program due to slow logging.
2024-05-28 08:51:56 +02:00
Simon Ruderich 657ac4faa3 test_rx_file: add JSON logging (controllable via JSONLOGGER define) 2024-05-28 08:51:56 +02:00
Thomas Kolb 33df7132ef rx: tag most debug messages with the sample index 2024-05-25 18:24:40 +02:00
Thomas Kolb 5f8346d290 agc: update squelch threshold more often
This fixes the noise level tracking in test cases like the loopback
test where the signal has already ramped up before the first noise level
update.
2024-05-25 18:16:24 +02:00
Thomas Kolb ca241f266b rx: add monotonic sample counter for debug messages 2024-05-25 18:15:23 +02:00
Simon Ruderich 0237ea6494 tests: fix compile 2024-05-09 18:32:51 +02:00
Simon Ruderich a4e55f781b Always NUL-terminate path in jsonlogger_init() 2024-05-09 18:32:26 +02:00
Simon Ruderich f689c4ec15 Fix compiler warnings
- implicit declaration of built-in function 'strncpy'
- control reaches end of non-void function
- assignment to 'void (*)(int,  siginfo_t *, void *)' from incompatible pointer type 'void (*)(int)'
2024-05-09 14:37:39 +02:00
Thomas Kolb a42d795002 Dump debug info from the RX via jsonlogger 2024-05-07 21:40:29 +02:00
Thomas Kolb 5bcd3a6933 jsonlogger: add test file and improve open/close behaviour 2024-05-05 18:40:50 +02:00
Thomas Kolb 251aca7738 Basic implementation of a JSON logger module 2024-05-05 18:09:00 +02:00
Thomas Kolb 033c26bcae preamble: invert symbols to match BPSK convention 2024-04-27 22:42:32 +02:00
Thomas Kolb c6ea578808 sdr: fix loss of samples due to unaligned buffer reads
sdr_rf_to_baseband() processes samples in blocks of size SDR_OVERSAMPLING. If
the total number of samples does not align with this block size, the leftover
samples are lost and phase and timing glitches result.

To mitigate this, sdr_receive() now has an additional parameter that specifies
the alignment of the returned data. The number of samples returned is always a
multiple of this alignment factor. This feature is used to ensure that the
number of returned samples is a multiple of SDR_OVERSAMPLING and therefore no
samples are lost in sdr_rf_to_baseband().

sdr_rf_to_baseband() now has an additional check that makes the function fail
if the alignment is incorrect.
2024-04-27 20:08:04 +02:00
Simon Ruderich a3928d0ad0 Fix compiler warnings
- passing argument 2 of 'crc_generate_key' discards ‘const’ qualifier;
  a bit ugly but signature of crc_generate_key() is wrong
- variable 'linearized_history' set but not used
- typedef is unused
- superfluous arguments to DEBUG_LOG() and fprintf()
- implicit declaration of function 'memset'
- unused arguments
2024-04-27 12:22:33 +02:00
Simon Ruderich b3ceb50b23 Fix one-byte buffer-overflow in layer1_rx_process() 2024-04-27 12:17:58 +02:00
Thomas Kolb c250944d79 transmission: fix ramp-down length calculation 2024-04-26 22:40:41 +02:00
Thomas Kolb e22b9ed4c5 rx: fix squelch level tracking
Thanks to rudi_s for reporting this.
2024-04-26 21:50:07 +02:00
Thomas Kolb d3b0ac1e0a rx: signal busy as long as squelch is open 2024-04-26 21:47:41 +02:00
Thomas Kolb 90ed7dc0a8 Re-add accidentally removed constants 2024-04-20 01:31:21 +02:00
Simon Ruderich 2768e21849 test_rx_file: set nco frequency 2024-04-20 01:14:17 +02:00
Simon Ruderich 79fc1c4f59 utils: fix numpy deprecation warnings 2024-04-20 01:14:17 +02:00
Thomas Kolb 7d1a927425 Calculate HackRF center frequency correctly 2024-04-20 01:07:21 +02:00
Thomas Kolb 32632914df Prevent TX exception in QPSK mode
QPSK-modulated packets require more samples, which must be available in the TX
buffer. Therefore we increase the required free space.
2024-04-20 01:04:13 +02:00
Thomas Kolb 11f19c03a0 Fix TX handling for multiple packets
- (only) time-based end-of-transmission tracking
  - removed tx_done flag
  - count zero-buffers correctly in time-tracking
  - add 10 ms of headroom so the transmission does not stop before buffer was
    completely transmitted (race condition)
  - fix race condition with tx_start_time in sdr_start_tx()
- simplified packet queuing (no chunking)
- read multiple packets before starting transmission (to fill buffers initially)

Thanks to rudi_s!
2024-04-20 00:55:39 +02:00
Thomas Kolb 1f5f922cdf Adjust squelch level and rampup 2024-04-12 21:50:49 +02:00
Thomas Kolb 91db4e1f75 rx: implement squelch + symsync reset
Whenever the squelch opens, the symsync is reset to prevent lock-up in
that module due to noise.
2024-04-08 22:03:09 +02:00
Thomas Kolb 4b46d87edb Add missing variable declaration 2024-03-31 22:26:34 +02:00
Thomas Kolb 93fd8aebbc Lock TX to RX frequency for clients
Central nodes (“base stations”) do no longer do coarse frequency estimation,
but do only use the preamble + PLL for fine offset tracking.
2024-03-31 22:23:04 +02:00
Thomas Kolb 4f4128fbd3 test: fixed build errors 2024-03-31 18:01:00 +02:00
Thomas Kolb 8441b12fbd rx: delay frequency estimation until history was fully refreshed 2024-03-30 22:10:13 +01:00
Thomas Kolb 171a4a369c rx: fix header checksum verification 2024-03-30 22:07:08 +01:00
Thomas Kolb 79d7f74dfc rx: use different PLL BW for header and data 2024-03-30 22:06:13 +01:00
Thomas Kolb bbf7bcf2f0 test/freq_est: add channel simulation 2024-03-30 22:05:02 +01:00
Thomas Kolb 66c88bf889 Improvements to debug scripts 2024-03-30 22:04:26 +01:00
Thomas Kolb d9707ac4a9 test: add test_rx_file 2024-03-30 21:56:00 +01:00
Thomas Kolb dd5712eada Add options parsing module 2024-03-30 21:51:27 +01:00
Thomas Kolb 07555edfdf Add CRC8 to the header
This should prevent wrong decodings of modcod and packet length, which may disrupt decoding of directly following packets.
2024-01-07 00:02:26 +01:00
Thomas Kolb 16aa2ce92c correlator: improved phase estimation
The phase is now calculated based on the preamble correlation directly instead
of the method of the frequency estimator.
2024-01-06 23:54:41 +01:00
Thomas Kolb ef25ca2388 Enable Hamming 8/4 code for the header 2024-01-05 21:29:41 +01:00
Thomas Kolb 84c172abc7 Fixed iterative frequency refinement; count header errors 2024-01-05 21:28:38 +01:00
Thomas Kolb 3a4be428b5 sdr: stop reading packets if the TX buffer is too full 2024-01-05 14:13:11 +01:00
Thomas Kolb e807f0617b rx: skip zero-length packets
If passed on, these cause a segmentation fault in the channel decoder. As
zero-length packets currently make no real sense in this protocol, they are
ignored now.
2024-01-05 13:49:50 +01:00
Thomas Kolb a6f12d876b sdr: fixed RX sample data conversion 2024-01-05 13:48:41 +01:00
Thomas Kolb be5fa06950 Handle SIGTERM and SIGINT for graceful shutdown 2024-01-03 22:03:19 +01:00
Thomas Kolb ee63483b8f sdr: scale sample for HackRF API 2024-01-03 17:41:35 +01:00
Thomas Kolb ac087634dd sdr: ensure that all samples were transmitted before TX is stopped
This is done by tracking the time that the transmitter must stay on based on
the number of samples to be transmitted and the sampling rate.
2024-01-03 17:32:51 +01:00
Thomas Kolb 8689ed5b27 Use fsleep instead of nanosleep 2024-01-03 17:29:51 +01:00
Thomas Kolb fb9c26ccd5 make.sh: allow passing parameters to make 2024-01-03 17:29:05 +01:00
Thomas Kolb 5564f1751a Fixed TX gain setting 2024-01-03 17:04:47 +01:00
Thomas Kolb c9d53ed96e Ensure that buffer is full when transmission starts 2024-01-03 00:33:54 +01:00
Thomas Kolb 628659511c sdr: properly flush the transmit buffers 2024-01-03 00:25:55 +01:00
Thomas Kolb 497498acd2 rx: fix overflow in symbol buffer 2024-01-03 00:01:27 +01:00
Thomas Kolb ef0fad4335 Improved handling of up- and downsampling 2024-01-02 23:49:55 +01:00
Thomas Kolb d55e3ab902 sdr: release buffered data; set sampling rate 2024-01-02 23:25:14 +01:00
Thomas Kolb 2b741acd8a Use libhackrf directly (not tested yet) 2024-01-02 22:49:16 +01:00
Thomas Kolb 7995f5bef0 Print RX stats periodically instead of debug logging 2024-01-02 19:04:19 +01:00
Thomas Kolb 112a8a1215 Improved logging and soapy stream handling 2023-05-20 22:01:26 +02:00
Thomas Kolb 2b078a4147 Settings updated: 2 Msps, 10 ms TX backoff 2023-05-20 21:59:40 +02:00
Thomas Kolb a6530da0d0 make.sh: set build type to RelWithDebInfo 2023-05-20 21:58:16 +02:00
Thomas Kolb f5a367464f Optimized one-shot frequency synchronization
- Ramp-up length increased to 128 symbols (here is room for
  improvement!)
- Try to detect the frequency once during ramp-up. To do so, every
  second symbol is inverted (to remove the +/-1 symbol toggling) and the
  phase difference between neigboring resulting symbols is checked. When
  it is low enough for all symbols, the frequency is estimated and
  corrected. When frequency estimation was done, it is not retried for a
  number of incoming symbols in order to allow the timing estimator to
  converge again.
- This approach was verified in a simulated loopback test with frequency
  offset and AWGN.
2023-05-17 22:28:18 +02:00
Thomas Kolb b5bae84994 utils: new and improved plotting scripts 2023-05-17 22:27:40 +02:00
Thomas Kolb a7db93ab9e Added test for frequency estimator 2023-05-17 22:26:46 +02:00
Thomas Kolb e42602633e freq_est: implement L&R-based symbol-independent frequency estimation
The RX chain uses this to acquire an initial estimate of the carrier frequency. The estimate is adjusted on every incoming symbol until a preamble is found.
2023-05-14 15:53:14 +02:00
Thomas Kolb 3b7628882c utils: open output file in binary mode 2023-05-12 13:49:20 +02:00
Thomas Kolb d17b7b3309 RX: added some asserts 2023-05-12 13:48:18 +02:00
Thomas Kolb afb25a69d8 Use dynamic linking for liquid-dsp again 2023-05-12 13:47:05 +02:00
Thomas Kolb 7d5b67a257 Add layer 1 software loopback test 2023-05-12 13:46:02 +02:00
Thomas Kolb c8e0516e80 Implement time-based carrier sensing
In the following events, the modem cannot switch to transmit mode for the
given time:

- after a preamble has been received, for 500 ms
- after a packet has been successfully decoded, for 1 ms
- after receive mode was initially enabled, for 500 ms

Note that the times are that long to work around the RX/TX switching of
the hackrf and can be hopefully reduced to <10 milliseconds in a later
version.
2022-05-07 21:17:53 +02:00
Thomas Kolb 886a78018f RX: write correct sample rate to debug file 2022-05-07 20:13:01 +02:00
Thomas Kolb b2d6c713e1 Briefly start in TX mode to ensure correct RX frequency
Obviously SoapyHackRF does not set the correct RX frequency on startup.
This is a crude but effective workaround.
2022-05-07 20:12:03 +02:00
Thomas Kolb ec99cedaf4 rx: improvements made during on-air testing
- limit frequency adjustment range
- pre-filter the baseband signal to remove out-of-band interference
- reset the frequency acquisition periodically (every 30s) if no preamble is found
2022-04-10 21:58:32 +02:00
Thomas Kolb 2d0bf7eeda sdr: fixed enumeration output 2022-04-08 16:17:17 +02:00
Thomas Kolb 96f10f7fb6 sdr: add gain configuration 2022-04-08 16:17:00 +02:00
Thomas Kolb 715cda83a8 RX: process samples in larger chunks 2022-04-07 21:17:37 +02:00
Thomas Kolb 3e74093fc7 Retry transmitting zeros 2022-04-07 20:58:08 +02:00
Thomas Kolb 31475907d3 Switch to IPv6 2022-04-07 20:44:07 +02:00
Thomas Kolb bfe27d3ead Added script for setting up the tun device 2022-04-07 20:34:21 +02:00
Thomas Kolb 47fc177e87 Reorganize Soapy stream management; flush tx buffer 2022-04-03 18:11:52 +02:00
Thomas Kolb 152d2f02f6 Basic transmitter-only main loop 2022-03-05 21:38:05 +01:00
Thomas Kolb 3bc1d9625f sdr: various fixes; use Kaiser filter for resampling 2022-03-05 21:37:33 +01:00
Thomas Kolb 85663d5304 Added SDR abstraction layer 2022-03-03 22:19:03 +01:00
Thomas Kolb 88145d74ba rx: added function to determine whether rx is busy 2022-03-01 21:51:41 +01:00
Thomas Kolb 45156e64a0 Show packets as hexdump instead of text 2022-02-27 22:01:51 +01:00
Thomas Kolb 9817896914 rx: make receiver more robust 2022-02-27 21:25:33 +01:00
Thomas Kolb 934b18e382 Integrate TUN device interface
Packets are now read from the TUN device and transmitted. The signal
goes through a channel emulator and is then received + decoded. If
decoding is successful, the result is written back to the TUN device
(which does not make much sense, but works for testing).

Unfortunately, there still seems to be a problem in the receiver: packet
loss is very high even at extremely high SNRs.
2022-02-27 20:21:14 +01:00
Thomas Kolb 890baf577f Moved config.h to src/ top level 2022-02-27 18:41:16 +01:00
Thomas Kolb 8a8ddc5ea3 rx: integrate AGC 2022-02-27 16:59:14 +01:00
Thomas Kolb a60b8b1f87 Moved results.h to src/ top level 2022-02-27 16:02:51 +01:00
Thomas Kolb 1787d0d351 layer1: implement per-packet modulation/coding
This allows a higher layer to adjust data rate based on the current
channel conditions. For example, the SNR could be measured and if it
becomes too low for the current modulation/code, a lower-order
modulation or stronger code could be used.
2022-02-17 21:39:18 +01:00
Thomas Kolb 0ed7109335 Clean up debug output 2022-02-16 21:46:56 +01:00
Thomas Kolb 876bafd6f9 Moved receiver to separate module 2022-02-16 20:52:46 +01:00
Thomas Kolb a5634ed736 Move the transmission chain to a separate "tx" module 2022-02-13 21:29:35 +01:00
Thomas Kolb 97772fa12b Removed unused packet_demod 2022-02-13 20:06:14 +01:00
Thomas Kolb 513a399ae4 Refactoring: moved layer1-related stuff to subdirectory 2022-02-13 20:05:47 +01:00
Thomas Kolb a124c04021 plot_spectrum: ensure that the t and f array sizes match 2022-02-13 19:54:07 +01:00
Thomas Kolb 89f04b3ad0 plot_constellation: added guard lines 2022-02-13 19:53:17 +01:00
Thomas Kolb eb3fc5f9c7 Use data whitening 2022-02-12 22:06:49 +01:00
Thomas Kolb 87b844a2da Implement CRC check and phase tracking 2022-02-12 21:58:53 +01:00
Thomas Kolb 947615f5cd First complete RX chain
Decoding of the test message works down to ~10 dB SNR.

Still missing:
- Phase tracking during header and payload.
- CRC calculation and check.
- Data whitening.
2022-02-11 17:56:26 +01:00
Thomas Kolb 042c05f9f3 Decode the received header 2022-02-10 22:33:51 +01:00
Thomas Kolb f2c95a125d Use new frequency+phase estimation method for preamble 2022-02-06 18:04:31 +01:00
Thomas Kolb 8060137c1d Move frequency estimation to separate module 2022-02-05 20:33:56 +01:00
Thomas Kolb 465d9a1c26 main: restructure state management; evaluate a found preamble 2022-02-03 22:18:24 +01:00
Thomas Kolb 423f1d6416 correlator: added functions for phase and frequency estimation 2022-02-03 22:17:37 +01:00
Thomas Kolb c17c7e060f Integrate preamble search 2022-02-01 21:35:43 +01:00
Thomas Kolb b6713909f7 Make initial frequency sync much faster
The NCO frequency is now only adjusted every 8 symbols. That means that
the frequency error over the last 8 symbols before the adjustment is
(almost) constant, giving a good estimation result. Therefore, the
adjustment factor can be much larger than previously, leading to faster
acquisition time.
2022-01-30 20:23:41 +01:00
Thomas Kolb c1dd039d6b First shot at frequency synchronization
Supports only the BPSK part so far (ramp-up, preamble).
2022-01-30 20:05:20 +01:00
Thomas Kolb 09465591ed Added symsync to the receiver chain 2022-01-29 22:37:55 +01:00
Thomas Kolb f983635c14 Fixed output size of transmission_filter_packet() 2022-01-29 22:14:25 +01:00
Thomas Kolb d522a1d6bd Implemented pulse shaping
The pulse shaper currently uses an RRC filter with beta=0.2.
2022-01-29 22:05:17 +01:00
Thomas Kolb a6fed80149 Added script for plotting the spectrum of signal dumps 2022-01-29 22:03:51 +01:00
Thomas Kolb a1f62a3b0a packet_mod: implement FEC and modulation for the header 2022-01-23 16:28:53 +01:00
Thomas Kolb 9a1107ff38 Added correlator + small test program 2022-01-22 22:42:05 +01:00
Thomas Kolb 6c21618f1f Document the packet_mod interface 2021-10-17 22:51:10 +02:00
Thomas Kolb 62ff2938ac Some python debug plot scripts 2021-10-17 19:46:30 +02:00
Thomas Kolb 874d8d5073 Fixed the modulator + test demodulation 2021-10-17 19:45:54 +02:00
Thomas Kolb 9ba470adeb Initial implementation of packet modulation
Not really tested yet…
2021-10-17 19:26:38 +02:00
Thomas Kolb 0b237a47cb Initial commit: infrastructure 2021-10-17 19:25:42 +02:00