Packet
softlora.packet
Packet result type and SNR estimation for the LoRa receiver.
Packet
dataclass
A single decoded LoRa packet.
ok is True whenever the payload was demodulated and decoded without
raising (crc_valid may still be False for a corrupted payload). On a
hard failure ok is False and error holds the reason.
Sample positions (sample_start, payload_start, sample_end) are
counts at the decoder bandwidth rate (bw samples/second). They are
absolute within the recording for :meth:LoRaDecoder.decode_iq,
:meth:LoRaDecoder.decode_file and :meth:LoRaDecoder.decode_stream, and
relative to the input buffer for a direct :meth:LoRaDecoder.decode
call.
Source code in softlora/packet.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
__repr__()
Unambiguous one-line summary, used when packets appear in a
list/log; :meth:__str__ provides the full detail table.
__str__()
Human-readable detail table for a decoded packet.
print(packet) renders the packet as an aligned key: value
table with the full payload hex (wrapped at 32 bytes per line) and
the full payload text. A failed decode prints a one-line error
instead. For a compact one-line form see :meth:__repr__.
Source code in softlora/packet.py
to_dict()
Plain JSON-serializable dict (numpy arrays converted to lists).
Source code in softlora/packet.py
estimate_snr(signal, downchirp, N, start_sample=0, num_syms=8, guard=3)
Estimate per-sample SNR (dB) from demodulated preamble upchirps.
The signal is assumed frequency-corrected so that every preamble upchirp
dechirps to the same FFT bin. With per-sample signal power Ps and
noise power Pn, the dechirped FFT concentrates the signal into one bin
of power Ps * N**2 while the noise spreads N * Pn per bin, so
Ps / Pn = peak_power / (N * median_noise_power).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
ndarray
|
Frequency-corrected complex baseband signal at fs = BW. |
required |
downchirp
|
ndarray
|
N-sample reference downchirp. |
required |
N
|
int
|
Samples per symbol (2**sf). |
required |
start_sample
|
int
|
Sample index of the first preamble symbol. |
0
|
num_syms
|
int
|
Number of preamble symbols to average (capped at 8). |
8
|
guard
|
int
|
Bins around the peak excluded from the noise estimate. |
3
|
Returns:
| Type | Description |
|---|---|
float or None
|
SNR estimate in dB, or None if no valid window was available. |