@jtarrio/webrtlsdr 0.0.1
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.
- package/LICENSE +203 -0
- package/README.md +69 -0
- package/dist/audio/player.d.ts +24 -0
- package/dist/audio/player.d.ts.map +1 -0
- package/dist/audio/player.js +68 -0
- package/dist/audio/player.js.map +1 -0
- package/dist/demod/demodulator.d.ts +59 -0
- package/dist/demod/demodulator.d.ts.map +1 -0
- package/dist/demod/demodulator.js +150 -0
- package/dist/demod/demodulator.js.map +1 -0
- package/dist/demod/sample-counter.d.ts +18 -0
- package/dist/demod/sample-counter.d.ts.map +1 -0
- package/dist/demod/sample-counter.js +43 -0
- package/dist/demod/sample-counter.js.map +1 -0
- package/dist/demod/scheme-am.d.ts +32 -0
- package/dist/demod/scheme-am.d.ts.map +1 -0
- package/dist/demod/scheme-am.js +75 -0
- package/dist/demod/scheme-am.js.map +1 -0
- package/dist/demod/scheme-cw.d.ts +22 -0
- package/dist/demod/scheme-cw.d.ts.map +1 -0
- package/dist/demod/scheme-cw.js +68 -0
- package/dist/demod/scheme-cw.js.map +1 -0
- package/dist/demod/scheme-nbfm.d.ts +32 -0
- package/dist/demod/scheme-nbfm.d.ts.map +1 -0
- package/dist/demod/scheme-nbfm.js +76 -0
- package/dist/demod/scheme-nbfm.js.map +1 -0
- package/dist/demod/scheme-ssb.d.ts +33 -0
- package/dist/demod/scheme-ssb.d.ts.map +1 -0
- package/dist/demod/scheme-ssb.js +75 -0
- package/dist/demod/scheme-ssb.js.map +1 -0
- package/dist/demod/scheme-wbfm.d.ts +38 -0
- package/dist/demod/scheme-wbfm.d.ts.map +1 -0
- package/dist/demod/scheme-wbfm.js +106 -0
- package/dist/demod/scheme-wbfm.js.map +1 -0
- package/dist/demod/scheme.d.ts +78 -0
- package/dist/demod/scheme.d.ts.map +1 -0
- package/dist/demod/scheme.js +96 -0
- package/dist/demod/scheme.js.map +1 -0
- package/dist/demod/spectrum.d.ts +18 -0
- package/dist/demod/spectrum.d.ts.map +1 -0
- package/dist/demod/spectrum.js +76 -0
- package/dist/demod/spectrum.js.map +1 -0
- package/dist/dsp/buffers.d.ts +72 -0
- package/dist/dsp/buffers.d.ts.map +1 -0
- package/dist/dsp/buffers.js +109 -0
- package/dist/dsp/buffers.js.map +1 -0
- package/dist/dsp/coefficients.d.ts +22 -0
- package/dist/dsp/coefficients.d.ts.map +1 -0
- package/dist/dsp/coefficients.js +77 -0
- package/dist/dsp/coefficients.js.map +1 -0
- package/dist/dsp/converters.d.ts +15 -0
- package/dist/dsp/converters.d.ts.map +1 -0
- package/dist/dsp/converters.js +43 -0
- package/dist/dsp/converters.js.map +1 -0
- package/dist/dsp/demodulators.d.ts +72 -0
- package/dist/dsp/demodulators.d.ts.map +1 -0
- package/dist/dsp/demodulators.js +245 -0
- package/dist/dsp/demodulators.js.map +1 -0
- package/dist/dsp/fft.d.ts +53 -0
- package/dist/dsp/fft.d.ts.map +1 -0
- package/dist/dsp/fft.js +175 -0
- package/dist/dsp/fft.js.map +1 -0
- package/dist/dsp/filters.d.ts +91 -0
- package/dist/dsp/filters.d.ts.map +1 -0
- package/dist/dsp/filters.js +250 -0
- package/dist/dsp/filters.js.map +1 -0
- package/dist/dsp/power.d.ts +2 -0
- package/dist/dsp/power.d.ts.map +1 -0
- package/dist/dsp/power.js +10 -0
- package/dist/dsp/power.js.map +1 -0
- package/dist/dsp/resamplers.d.ts +33 -0
- package/dist/dsp/resamplers.d.ts.map +1 -0
- package/dist/dsp/resamplers.js +91 -0
- package/dist/dsp/resamplers.js.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -0
- package/dist/radio/msgqueue.d.ts +23 -0
- package/dist/radio/msgqueue.d.ts.map +1 -0
- package/dist/radio/msgqueue.js +52 -0
- package/dist/radio/msgqueue.js.map +1 -0
- package/dist/radio/radio.d.ts +81 -0
- package/dist/radio/radio.d.ts.map +1 -0
- package/dist/radio/radio.js +305 -0
- package/dist/radio/radio.js.map +1 -0
- package/dist/radio/sample_receiver.d.ts +11 -0
- package/dist/radio/sample_receiver.d.ts.map +1 -0
- package/dist/radio/sample_receiver.js +49 -0
- package/dist/radio/sample_receiver.js.map +1 -0
- package/dist/rtlsdr/r820t.d.ts +18 -0
- package/dist/rtlsdr/r820t.d.ts.map +1 -0
- package/dist/rtlsdr/r820t.js +39 -0
- package/dist/rtlsdr/r820t.js.map +1 -0
- package/dist/rtlsdr/r828d.d.ts +28 -0
- package/dist/rtlsdr/r828d.d.ts.map +1 -0
- package/dist/rtlsdr/r828d.js +120 -0
- package/dist/rtlsdr/r828d.js.map +1 -0
- package/dist/rtlsdr/r8xx.d.ts +90 -0
- package/dist/rtlsdr/r8xx.d.ts.map +1 -0
- package/dist/rtlsdr/r8xx.js +468 -0
- package/dist/rtlsdr/r8xx.js.map +1 -0
- package/dist/rtlsdr/rtl2832u.d.ts +74 -0
- package/dist/rtlsdr/rtl2832u.d.ts.map +1 -0
- package/dist/rtlsdr/rtl2832u.js +342 -0
- package/dist/rtlsdr/rtl2832u.js.map +1 -0
- package/dist/rtlsdr/rtlcom.d.ts +144 -0
- package/dist/rtlsdr/rtlcom.d.ts.map +1 -0
- package/dist/rtlsdr/rtlcom.js +299 -0
- package/dist/rtlsdr/rtlcom.js.map +1 -0
- package/dist/rtlsdr/rtldevice.d.ts +53 -0
- package/dist/rtlsdr/rtldevice.d.ts.map +1 -0
- package/dist/rtlsdr/rtldevice.js +24 -0
- package/dist/rtlsdr/rtldevice.js.map +1 -0
- package/dist/rtlsdr/tuner.d.ts +20 -0
- package/dist/rtlsdr/tuner.d.ts.map +1 -0
- package/dist/rtlsdr/tuner.js +15 -0
- package/dist/rtlsdr/tuner.js.map +1 -0
- package/package.json +20 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// Copyright 2024 Jacobo Tarrio Barreiro. All rights reserved.
|
|
2
|
+
// Copyright 2013 Google Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
import { RadioError, RadioErrorType } from "../errors";
|
|
16
|
+
import { R820T } from "./r820t";
|
|
17
|
+
import { R828D } from "./r828d";
|
|
18
|
+
import { RtlCom } from "./rtlcom";
|
|
19
|
+
import { DirectSampling, } from "./rtldevice";
|
|
20
|
+
/** Known RTL2832 devices. */
|
|
21
|
+
const TUNERS = [
|
|
22
|
+
{ vendorId: 0x0bda, productId: 0x2832 },
|
|
23
|
+
{ vendorId: 0x0bda, productId: 0x2838 },
|
|
24
|
+
];
|
|
25
|
+
/** Class that returns an open RTL2832U device. */
|
|
26
|
+
export class RTL2832U_Provider {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.device = undefined;
|
|
29
|
+
}
|
|
30
|
+
device;
|
|
31
|
+
async get() {
|
|
32
|
+
if (this.device === undefined) {
|
|
33
|
+
this.device = await this.getDevice();
|
|
34
|
+
}
|
|
35
|
+
await this.device.open();
|
|
36
|
+
return RTL2832U.open(this.device);
|
|
37
|
+
}
|
|
38
|
+
async getDevice() {
|
|
39
|
+
if (navigator.usb === undefined) {
|
|
40
|
+
throw new RadioError(`This browser does not support the HTML5 USB API`, RadioErrorType.NoUsbSupport);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
return navigator.usb.requestDevice({ filters: TUNERS });
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw new RadioError(`No device was selected`, RadioErrorType.NoDeviceSelected, { cause: e });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Operations on the RTL2832U demodulator. */
|
|
51
|
+
export class RTL2832U {
|
|
52
|
+
com;
|
|
53
|
+
tuner;
|
|
54
|
+
/** Frequency of the oscillator crystal. */
|
|
55
|
+
static XTAL_FREQ = 28800000;
|
|
56
|
+
/** The number of bytes for each sample. */
|
|
57
|
+
static BYTES_PER_SAMPLE = 2;
|
|
58
|
+
constructor(com, tuner) {
|
|
59
|
+
this.com = com;
|
|
60
|
+
this.tuner = tuner;
|
|
61
|
+
this.centerFrequency = 0;
|
|
62
|
+
this.ppm = 0;
|
|
63
|
+
this.gain = null;
|
|
64
|
+
this.directSamplingMethod = DirectSampling.Off;
|
|
65
|
+
this.directSampling = DirectSampling.Off;
|
|
66
|
+
this.biasTeeEnabled = false;
|
|
67
|
+
}
|
|
68
|
+
centerFrequency;
|
|
69
|
+
ppm;
|
|
70
|
+
gain;
|
|
71
|
+
directSamplingMethod;
|
|
72
|
+
directSampling;
|
|
73
|
+
biasTeeEnabled;
|
|
74
|
+
/**
|
|
75
|
+
* Initializes the demodulator.
|
|
76
|
+
* @param device The USB device.
|
|
77
|
+
*/
|
|
78
|
+
static async open(device) {
|
|
79
|
+
let com = new RtlCom(device);
|
|
80
|
+
await com.claimInterface();
|
|
81
|
+
await RTL2832U._init(com);
|
|
82
|
+
let tuner = await RTL2832U._findTuner(com);
|
|
83
|
+
let rtl = new RTL2832U(com, tuner);
|
|
84
|
+
await rtl.setGain(rtl.gain);
|
|
85
|
+
await rtl.setFrequencyCorrection(rtl.ppm);
|
|
86
|
+
return rtl;
|
|
87
|
+
}
|
|
88
|
+
static async _init(com) {
|
|
89
|
+
// USB_SYSCTL [0] DMA enable [3] Full packet mode [10] SIE normal state
|
|
90
|
+
await com.setUsbReg(0x2000, 0b00001001, 1);
|
|
91
|
+
// USB_EPA_MAXPKT [10:0] Max packet size = 0x200 bytes
|
|
92
|
+
await com.setUsbReg(0x2158, 0x0200, 2);
|
|
93
|
+
// USB_EPA_CTL [4] Stall endpoint [9] FIFO reset.
|
|
94
|
+
await com.setUsbReg(0x2148, 0b0000001000010000, 2);
|
|
95
|
+
// DEMOD_CTL1 -- something to do with IR remote wakeup
|
|
96
|
+
await com.setSysReg(0x300b, 0b00100010);
|
|
97
|
+
// DEMOD_CTL [3] ADC_Q enable [5] Release reset [6] ADC_I enable [7] PLL enable
|
|
98
|
+
await com.setSysReg(0x3000, 0b11101000);
|
|
99
|
+
// ? reset demodulator
|
|
100
|
+
await com.setDemodReg(1, 0x01, 0b00010100, 1);
|
|
101
|
+
await com.setDemodReg(1, 0x01, 0b00010000, 1);
|
|
102
|
+
// [0] spectrum not inverted [1] adjacent channel rejection disabled
|
|
103
|
+
await com.setDemodReg(1, 0x15, 0b00000000, 1);
|
|
104
|
+
// Carrier frequency offset [21:0] set to 0
|
|
105
|
+
await com.setDemodReg(1, 0x16, 0x00, 1);
|
|
106
|
+
await com.setDemodReg(1, 0x17, 0x00, 1);
|
|
107
|
+
await com.setDemodReg(1, 0x18, 0x00, 1);
|
|
108
|
+
// IF frequency registers [21:0] set to 0
|
|
109
|
+
await com.setDemodReg(1, 0x19, 0x00, 1);
|
|
110
|
+
await com.setDemodReg(1, 0x1a, 0x00, 1);
|
|
111
|
+
await com.setDemodReg(1, 0x1b, 0x00, 1);
|
|
112
|
+
// LPF coefficients
|
|
113
|
+
await com.setDemodReg(1, 0x1c, 0xca, 1);
|
|
114
|
+
await com.setDemodReg(1, 0x1d, 0xdc, 1);
|
|
115
|
+
await com.setDemodReg(1, 0x1e, 0xd7, 1);
|
|
116
|
+
await com.setDemodReg(1, 0x1f, 0xd8, 1);
|
|
117
|
+
await com.setDemodReg(1, 0x20, 0xe0, 1);
|
|
118
|
+
await com.setDemodReg(1, 0x21, 0xf2, 1);
|
|
119
|
+
await com.setDemodReg(1, 0x22, 0x0e, 1);
|
|
120
|
+
await com.setDemodReg(1, 0x23, 0x35, 1);
|
|
121
|
+
await com.setDemodReg(1, 0x24, 0x06, 1);
|
|
122
|
+
await com.setDemodReg(1, 0x25, 0x50, 1);
|
|
123
|
+
await com.setDemodReg(1, 0x26, 0x9c, 1);
|
|
124
|
+
await com.setDemodReg(1, 0x27, 0x0d, 1);
|
|
125
|
+
await com.setDemodReg(1, 0x28, 0x71, 1);
|
|
126
|
+
await com.setDemodReg(1, 0x29, 0x11, 1);
|
|
127
|
+
await com.setDemodReg(1, 0x2a, 0x14, 1);
|
|
128
|
+
await com.setDemodReg(1, 0x2b, 0x71, 1);
|
|
129
|
+
await com.setDemodReg(1, 0x2c, 0x74, 1);
|
|
130
|
+
await com.setDemodReg(1, 0x2d, 0x19, 1);
|
|
131
|
+
await com.setDemodReg(1, 0x2e, 0x41, 1);
|
|
132
|
+
await com.setDemodReg(1, 0x2f, 0xa5, 1);
|
|
133
|
+
// ? claimed to be enable SDR, [5] disable DAGC
|
|
134
|
+
await com.setDemodReg(0, 0x19, 0b00000101, 1);
|
|
135
|
+
// ? claimed to be initialize finite-state machine
|
|
136
|
+
await com.setDemodReg(1, 0x93, 0b11110000, 1);
|
|
137
|
+
await com.setDemodReg(1, 0x94, 0b00001111, 1);
|
|
138
|
+
// [0] disable DAGC
|
|
139
|
+
await com.setDemodReg(1, 0x11, 0b00000000, 1);
|
|
140
|
+
// [4:1] set AGC loop gain to 0
|
|
141
|
+
await com.setDemodReg(1, 0x04, 0b00000000, 1);
|
|
142
|
+
// [5] pass error packets [6] reject matched PID
|
|
143
|
+
await com.setDemodReg(0, 0x61, 0b01100000, 1);
|
|
144
|
+
// [5:4] default ADC_I, ADC_Q datapath
|
|
145
|
+
await com.setDemodReg(0, 0x06, 0b10000000, 1);
|
|
146
|
+
// [0] enable zero-IF input
|
|
147
|
+
await com.setDemodReg(1, 0xb1, 0b00011011, 1);
|
|
148
|
+
// ? claimed to be disable output on TP_CK0
|
|
149
|
+
await com.setDemodReg(0, 0x0d, 0b10000011, 1);
|
|
150
|
+
}
|
|
151
|
+
/** Finds the tuner that's connected to this demodulator and returns the appropriate instance. */
|
|
152
|
+
static async _findTuner(com) {
|
|
153
|
+
let tuner = await R820T.maybeInit(com);
|
|
154
|
+
if (tuner === null)
|
|
155
|
+
tuner = await R828D.maybeInit(com);
|
|
156
|
+
if (tuner === null) {
|
|
157
|
+
await com.releaseInterface();
|
|
158
|
+
throw new RadioError("Sorry, your USB dongle has an unsupported tuner chip.", RadioErrorType.UnsupportedDevice);
|
|
159
|
+
}
|
|
160
|
+
return tuner;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Set the sample rate.
|
|
164
|
+
* @param rate The sample rate, in samples/sec.
|
|
165
|
+
* @returns a promise that resolves to the sample rate that was actually set.
|
|
166
|
+
*/
|
|
167
|
+
async setSampleRate(rate) {
|
|
168
|
+
let ratio = Math.floor((this._getXtalFrequency() * (1 << 22)) / rate);
|
|
169
|
+
ratio &= 0x0ffffffc;
|
|
170
|
+
let realRate = Math.floor((this._getXtalFrequency() * (1 << 22)) / ratio);
|
|
171
|
+
// [27:2] set resample ratio
|
|
172
|
+
await this.com.setDemodReg(1, 0x9f, (ratio >> 16) & 0xffff, 2);
|
|
173
|
+
await this.com.setDemodReg(1, 0xa1, ratio & 0xffff, 2);
|
|
174
|
+
await this._resetDemodulator();
|
|
175
|
+
return realRate;
|
|
176
|
+
}
|
|
177
|
+
async setFrequencyCorrection(ppm) {
|
|
178
|
+
this.ppm = ppm;
|
|
179
|
+
let ppmOffset = -1 * Math.floor((this.ppm * (1 << 24)) / 1000000);
|
|
180
|
+
// [13:0] sampling frequency offset
|
|
181
|
+
await this.com.setDemodReg(1, 0x3e, (ppmOffset >> 8) & 0x3f, 1);
|
|
182
|
+
await this.com.setDemodReg(1, 0x3f, ppmOffset & 0xff, 1);
|
|
183
|
+
let xtalFrequency = this._getXtalFrequency();
|
|
184
|
+
this.tuner.setXtalFrequency(xtalFrequency);
|
|
185
|
+
let ifFreq = this.tuner.getIntermediateFrequency();
|
|
186
|
+
if (ifFreq != 0) {
|
|
187
|
+
await this._setIfFrequency(ifFreq);
|
|
188
|
+
}
|
|
189
|
+
if (this.centerFrequency != 0) {
|
|
190
|
+
await this.setCenterFrequency(this.centerFrequency);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async _setIfFrequency(ifFreq) {
|
|
194
|
+
let xtalFrequency = this._getXtalFrequency();
|
|
195
|
+
let multiplier = -1 * Math.floor((ifFreq * (1 << 22)) / xtalFrequency);
|
|
196
|
+
// [21:0] set IF frequency
|
|
197
|
+
await this.com.setDemodReg(1, 0x19, (multiplier >> 16) & 0x3f, 1);
|
|
198
|
+
await this.com.setDemodReg(1, 0x1a, (multiplier >> 8) & 0xff, 1);
|
|
199
|
+
await this.com.setDemodReg(1, 0x1b, multiplier & 0xff, 1);
|
|
200
|
+
return Math.floor((-1 * multiplier * xtalFrequency) / (1 << 22));
|
|
201
|
+
}
|
|
202
|
+
getFrequencyCorrection() {
|
|
203
|
+
return this.ppm;
|
|
204
|
+
}
|
|
205
|
+
async setGain(gain) {
|
|
206
|
+
this.gain = gain;
|
|
207
|
+
await this.com.openI2C();
|
|
208
|
+
if (this.directSampling) {
|
|
209
|
+
this._enableRtlAgc(gain == null);
|
|
210
|
+
}
|
|
211
|
+
else if (this.gain === null) {
|
|
212
|
+
await this.tuner.setAutoGain();
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
await this.tuner.setManualGain(this.gain);
|
|
216
|
+
}
|
|
217
|
+
await this.com.closeI2C();
|
|
218
|
+
}
|
|
219
|
+
getGain() {
|
|
220
|
+
return this.gain;
|
|
221
|
+
}
|
|
222
|
+
async enableBiasTee(enabled) {
|
|
223
|
+
this.biasTeeEnabled = enabled;
|
|
224
|
+
await this.com.setGpioOutput(0);
|
|
225
|
+
await this.com.setGpioBit(0, enabled ? 1 : 0);
|
|
226
|
+
}
|
|
227
|
+
isBiasTeeEnabled() {
|
|
228
|
+
return this.biasTeeEnabled;
|
|
229
|
+
}
|
|
230
|
+
async _enableRtlAgc(enable) {
|
|
231
|
+
await this.com.setDemodReg(0, 0x19, enable ? 0x25 : 0x05, 1);
|
|
232
|
+
}
|
|
233
|
+
_getXtalFrequency() {
|
|
234
|
+
return Math.floor(RTL2832U.XTAL_FREQ * (1 + this.ppm / 1000000));
|
|
235
|
+
}
|
|
236
|
+
/** Resets the demodulator. */
|
|
237
|
+
async _resetDemodulator() {
|
|
238
|
+
// ? reset demodulator
|
|
239
|
+
await this.com.setDemodReg(1, 0x01, 0b00010100, 1);
|
|
240
|
+
await this.com.setDemodReg(1, 0x01, 0b00010000, 1);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Tunes the device to the given frequency.
|
|
244
|
+
* @param freq The frequency to tune to, in Hertz.
|
|
245
|
+
* @returns a promise that resolves to the actual tuned frequency.
|
|
246
|
+
*/
|
|
247
|
+
async setCenterFrequency(freq) {
|
|
248
|
+
await this._maybeSetDirectSampling(freq);
|
|
249
|
+
let actualFreq;
|
|
250
|
+
if (this.directSampling) {
|
|
251
|
+
actualFreq = this._setIfFrequency(freq);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
await this.com.openI2C();
|
|
255
|
+
actualFreq = await this.tuner.setFrequency(freq);
|
|
256
|
+
await this.com.closeI2C();
|
|
257
|
+
}
|
|
258
|
+
this.centerFrequency = freq;
|
|
259
|
+
return actualFreq;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Sets the method used for direct sampling mode, or disables it.
|
|
263
|
+
* If enabled, the radio will enter direct sampling mode for low frequencies.
|
|
264
|
+
*/
|
|
265
|
+
async setDirectSamplingMethod(method) {
|
|
266
|
+
if (this.directSamplingMethod == method)
|
|
267
|
+
return;
|
|
268
|
+
this.directSamplingMethod = method;
|
|
269
|
+
if (this.centerFrequency != 0) {
|
|
270
|
+
await this.setCenterFrequency(this.centerFrequency);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/** Returns the current direct sampling method. */
|
|
274
|
+
getDirectSamplingMethod() {
|
|
275
|
+
return this.directSamplingMethod;
|
|
276
|
+
}
|
|
277
|
+
async _maybeSetDirectSampling(frequency) {
|
|
278
|
+
let lowFrequency = frequency < this.tuner.getMinimumFrequency();
|
|
279
|
+
let method = lowFrequency ? this.directSamplingMethod : DirectSampling.Off;
|
|
280
|
+
if (this.directSampling == method)
|
|
281
|
+
return;
|
|
282
|
+
const tunerWasOn = this.directSampling == DirectSampling.Off;
|
|
283
|
+
const useDirectSampling = method != DirectSampling.Off;
|
|
284
|
+
this.directSampling = method;
|
|
285
|
+
if (useDirectSampling) {
|
|
286
|
+
if (tunerWasOn) {
|
|
287
|
+
await this.com.openI2C();
|
|
288
|
+
await this.tuner.close();
|
|
289
|
+
await this.com.closeI2C();
|
|
290
|
+
}
|
|
291
|
+
// [0] disable zero-IF input
|
|
292
|
+
await this.com.setDemodReg(1, 0xb1, 0b00011010, 1);
|
|
293
|
+
// [0] non-inverted spectrum
|
|
294
|
+
await this.com.setDemodReg(1, 0x15, 0b00000000, 1);
|
|
295
|
+
// [5:4] exchange ADC_I, ADC_Q datapath if Q channel is selected
|
|
296
|
+
let regValue = method == DirectSampling.I ? 0b10000000 : 0b10010000;
|
|
297
|
+
await this.com.setDemodReg(0, 0x06, regValue, 1);
|
|
298
|
+
await this._enableRtlAgc(true);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
await this.com.openI2C();
|
|
302
|
+
await this.tuner.open();
|
|
303
|
+
await this.com.closeI2C();
|
|
304
|
+
let ifFreq = this.tuner.getIntermediateFrequency();
|
|
305
|
+
if (ifFreq != 0) {
|
|
306
|
+
await this._setIfFrequency(ifFreq);
|
|
307
|
+
}
|
|
308
|
+
// [0] inverted spectrum
|
|
309
|
+
await this.com.setDemodReg(1, 0x15, 0b00000001, 1);
|
|
310
|
+
// [5:4] default ADC_I, ADC_Q datapath
|
|
311
|
+
await this.com.setDemodReg(0, 0x06, 0b10000000, 1);
|
|
312
|
+
await this._enableRtlAgc(false);
|
|
313
|
+
await this.setGain(this.getGain());
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** Resets the sample buffer. Call this before starting to read samples. */
|
|
317
|
+
async resetBuffer() {
|
|
318
|
+
// USB_EPA_CTL [4] Stall endpoint [9] FIFO reset.
|
|
319
|
+
await this.com.setUsbReg(0x2148, 0b0000001000010000, 2);
|
|
320
|
+
await this.com.setUsbReg(0x2148, 0x0000, 2);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Reads a block of samples off the device.
|
|
324
|
+
* @param length The number of samples to read.
|
|
325
|
+
* @returns a promise that resolves to a SampleBlock.
|
|
326
|
+
*/
|
|
327
|
+
async readSamples(length) {
|
|
328
|
+
const data = await this.com.getSamples(length * RTL2832U.BYTES_PER_SAMPLE);
|
|
329
|
+
const frequency = this.centerFrequency;
|
|
330
|
+
const directSampling = this.directSampling != DirectSampling.Off;
|
|
331
|
+
return { frequency, directSampling, data };
|
|
332
|
+
}
|
|
333
|
+
/** Stops the demodulator. */
|
|
334
|
+
async close() {
|
|
335
|
+
await this.com.openI2C();
|
|
336
|
+
await this.tuner.close();
|
|
337
|
+
await this.com.closeI2C();
|
|
338
|
+
await this.com.releaseInterface();
|
|
339
|
+
await this.com.close();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=rtl2832u.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rtl2832u.js","sourceRoot":"","sources":["../../src/rtlsdr/rtl2832u.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,kDAAkD;AAClD,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,UAAU,E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E,CAAC;QACzB,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/** Low-level communications with the RTL2832U-base dongle. */
|
|
2
|
+
export declare class RtlCom {
|
|
3
|
+
constructor(device: USBDevice);
|
|
4
|
+
private device;
|
|
5
|
+
/** Set in the control messages' index field for write operations. */
|
|
6
|
+
private static WRITE_FLAG;
|
|
7
|
+
/** Claims the USB control interface. */
|
|
8
|
+
claimInterface(): Promise<void>;
|
|
9
|
+
/** Releases the USB control interface. */
|
|
10
|
+
releaseInterface(): Promise<void>;
|
|
11
|
+
/** Returns branding information. */
|
|
12
|
+
getBranding(): {
|
|
13
|
+
manufacturer?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Writes to a USB control register.
|
|
18
|
+
* @param address The register's address.
|
|
19
|
+
* @param value The value to write.
|
|
20
|
+
* @param length The number of bytes this value uses.
|
|
21
|
+
*/
|
|
22
|
+
setUsbReg(address: number, value: number, length: number): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Writes to a 8051 system register.
|
|
25
|
+
* @param address The register's address.
|
|
26
|
+
* @param value The value to write.
|
|
27
|
+
*/
|
|
28
|
+
setSysReg(address: number, value: number): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Reads from a 8051 system register.
|
|
31
|
+
* @param address The register's address.
|
|
32
|
+
* @returns The value that was read.
|
|
33
|
+
*/
|
|
34
|
+
getSysReg(address: number): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Writes a value into a demodulator register.
|
|
37
|
+
* @param page The register page number.
|
|
38
|
+
* @param addr The register's address.
|
|
39
|
+
* @param value The value to write.
|
|
40
|
+
* @param len The width in bytes of this value.
|
|
41
|
+
* @returns a promise that resolves the value that was read back from the register.
|
|
42
|
+
*/
|
|
43
|
+
setDemodReg(page: number, addr: number, value: number, len: number): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Reads a value from an I2C register.
|
|
46
|
+
* @param addr The device's address.
|
|
47
|
+
* @param reg The register number.
|
|
48
|
+
* @returns a promise that resolves to the value in the register.
|
|
49
|
+
*/
|
|
50
|
+
getI2CReg(addr: number, reg: number): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Writes a value to an I2C register.
|
|
53
|
+
* @param addr The device's address.
|
|
54
|
+
* @param reg The register number.
|
|
55
|
+
* @param value The value to write.
|
|
56
|
+
*/
|
|
57
|
+
setI2CReg(addr: number, reg: number, value: number): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Reads a buffer from an I2C register.
|
|
60
|
+
* @param addr The device's address.
|
|
61
|
+
* @param reg The register number.
|
|
62
|
+
* @param len The number of bytes to read.
|
|
63
|
+
* @returns a promise that resolves to the read buffer.
|
|
64
|
+
*/
|
|
65
|
+
getI2CRegBuffer(addr: number, reg: number, len: number): Promise<ArrayBuffer>;
|
|
66
|
+
setGpioOutput(gpio: number): Promise<void>;
|
|
67
|
+
setGpioBit(gpio: number, val: number): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Does a bulk transfer from the device.
|
|
70
|
+
* @param length The number of bytes to read.
|
|
71
|
+
* @returns a promise that resolves to the data that was read.
|
|
72
|
+
*/
|
|
73
|
+
getSamples(length: number): Promise<ArrayBuffer>;
|
|
74
|
+
/**
|
|
75
|
+
* Opens the I2C repeater.
|
|
76
|
+
* To avoid interference, the tuner is usually disconnected from the I2C bus.
|
|
77
|
+
* With the repeater open, the tuner can receive I2C messages.
|
|
78
|
+
*/
|
|
79
|
+
openI2C(): Promise<void>;
|
|
80
|
+
/** Closes the I2C repeater. */
|
|
81
|
+
closeI2C(): Promise<void>;
|
|
82
|
+
/** Closes the connection. */
|
|
83
|
+
close(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Writes a value into a dongle's register.
|
|
86
|
+
* @param block The register's block number.
|
|
87
|
+
* @param reg The register number.
|
|
88
|
+
* @param value The value to write.
|
|
89
|
+
* @param length The width in bytes of this value.
|
|
90
|
+
*/
|
|
91
|
+
private _setReg;
|
|
92
|
+
/**
|
|
93
|
+
* Reads a value from a dongle's register.
|
|
94
|
+
* @param block The register's block number.
|
|
95
|
+
* @param reg The register number.
|
|
96
|
+
* @param length The width in bytes of the value to read.
|
|
97
|
+
* @returns a promise that resolves to the decoded value.
|
|
98
|
+
*/
|
|
99
|
+
private _getReg;
|
|
100
|
+
/**
|
|
101
|
+
* Writes a buffer into a dongle's register.
|
|
102
|
+
* @param block The register's block number.
|
|
103
|
+
* @param reg The register number.
|
|
104
|
+
* @param buffer The buffer to write.
|
|
105
|
+
*/
|
|
106
|
+
private _setRegBuffer;
|
|
107
|
+
/**
|
|
108
|
+
* Reads a buffer from a dongle's register.
|
|
109
|
+
* @param block The register's block number.
|
|
110
|
+
* @param reg The register number.
|
|
111
|
+
* @param length The length in bytes of the buffer to read.
|
|
112
|
+
* @returns a Promise that resolves to the read buffer.
|
|
113
|
+
*/
|
|
114
|
+
private _getRegBuffer;
|
|
115
|
+
/**
|
|
116
|
+
* Decodes a buffer as a little-endian number.
|
|
117
|
+
* @param buffer The buffer to decode.
|
|
118
|
+
* @returns The decoded number.
|
|
119
|
+
*/
|
|
120
|
+
private _bufferToNumber;
|
|
121
|
+
/**
|
|
122
|
+
* Encodes a number into a buffer.
|
|
123
|
+
* @param value The number to encode.
|
|
124
|
+
* @param len The number of bytes to encode into.
|
|
125
|
+
* @param opt_bigEndian Whether to use a big-endian encoding.
|
|
126
|
+
*/
|
|
127
|
+
private _numberToBuffer;
|
|
128
|
+
/**
|
|
129
|
+
* Sends a USB control message to read from the device.
|
|
130
|
+
* @param value The value field of the control message.
|
|
131
|
+
* @param index The index field of the control message.
|
|
132
|
+
* @param length The number of bytes to read.
|
|
133
|
+
* @returns a promise that resolves to the read buffer.
|
|
134
|
+
*/
|
|
135
|
+
private _readCtrlMsg;
|
|
136
|
+
/**
|
|
137
|
+
* Sends a USB control message to write to the device.
|
|
138
|
+
* @param value The value field of the control message.
|
|
139
|
+
* @param index The index field of the control message.
|
|
140
|
+
* @param buffer The buffer to write to the device.
|
|
141
|
+
*/
|
|
142
|
+
private _writeCtrlMsg;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=rtlcom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rtlcom.d.ts","sourceRoot":"","sources":["../../src/rtlsdr/rtlcom.ts"],"names":[],"mappings":"AAiBA,8DAA8D;AAC9D,qBAAa,MAAM;gBACL,MAAM,EAAE,SAAS;IAI7B,OAAO,CAAC,MAAM,CAAY;IAE1B,qEAAqE;IACrE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAQ;IAEjC,wCAAwC;IAClC,cAAc;IAYpB,0CAA0C;IACpC,gBAAgB;IAItB,oCAAoC;IACpC,WAAW,IAAI;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAOxD;;;;;OAKG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAI9D;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI9C;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjD;;;;;;;OAOG;IACG,WAAW,CACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC;IASlB;;;;;OAKG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,G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