JSRadio

Warning

The TX feature is available only with a License - Contact us for more details
Otherwise, only reception is possible.

JSRadio object

construct the JSRadio object

  object JSRadio {
     constructor JSRadio(key);
     string getKey();
     bool valid() // true if hw init ok
     bool isAvailable() // true if nothing running on it (another steaming operation)
     bool setExternalClockRef( bool, clock_Hz ); // 
     int getChannelCount();
     dump();

     double getRxCenterFreq() ; // MHz
     bool setRxCenterFreq( freq ); // MHz
     bool setTxCenterFreq( freq ); // MHz
     double getMinRxFreq() ; // MHz
     double getMaxRxFreq() ; // MHz

    // Samplerate management
     int getRxSampleRate();
     bool setRxSampleRate( number ); // Hz

     // Bandwidth management
     int getRxBandwidth(); // Hz
     bool setRxBandwidth( number ) ; // Hz

     // non blocking : returns samples from current rx if receiver already used by another task
     IQData Capture( int samples );

     // Blocking : if device already sampling for another task, the capture will wait
     // availability of the device can be checked before with isAvailable()
     IQData captureSubBand( int samples , OLshift, bw );
     IQData CaptureAllChannels(int samples);
     Array multiCapture( Array definition );

     int getGainStageCount();
     double getMinGain( stage );
     double getMaxGain( stage );
     double setGain( double value, stage );
     double getGain( stage );

     // TX support
     bool hasTX();
     bool txOn();
     bool txOff();
     bool setTxGain( value );
     number getTxGain();
     number getMinTXGain();
     number getMaxTXGain();
     bool txData( IQData samples , nb_repeats);


}

.getKey

Returns the internal unique key (serial number or USB bus id).

.isValid

  • Check if given object is valid
.isValid();

Example:

int('Searching for SoapySDR device...');
var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
if( !rx.isValid()) {
    print('no radio ?');
    exit();
}

.isAvailable()

Returns :

  • True is no other task is currently using this receiver
  • False is the receiver is being used

.setExternalClockRef()

Some receivers (like the BladeRF) can use an external reference clock.

 rx.setExternalClockRef( boolean use_externa_clock , number clock_Hz );

Parameters :

  • boolean use_external_clock : Set to true to use the external clock, if available
  • number clock_Hz : set the external clock frequency in Hz

.getChannelCount()

  • Returns the number of channels available on this device

.dump

Prints on the console details off the JSRadio object, for debug purposes.

Example:

var rx = Soapy.makeDevice( {'query' : 'driver=sdrplay' });
rx.setRxSampleRate( 6e6 ); 
rx.setGain( 10 );
rx.setRxCenterFreq( 98 );
rx.dump();

Will output:

(boot:0)> JSRadio object dump:
(boot:0)>  Hardware name : RSP1A
(boot:0)>  Serial number : 0001
(boot:0)>  RX channels : 1
(boot:0)>  ---------------------
(boot:0)>  RX tunning ranges:
(boot:0)>   RX from 0.001 MHz to 2000.000 MHz
(boot:0)>  ---------------------
(boot:0)>  RX sample rate features :
(boot:0)>   Sampling at 0.062 MSPS
(boot:0)>   Sampling at 0.096 MSPS
(boot:0)>   Sampling at 0.125 MSPS
(boot:0)>   Sampling at 0.192 MSPS
(boot:0)>   Sampling at 0.250 MSPS
(boot:0)>   Sampling at 0.384 MSPS
(boot:0)>   Sampling at 0.500 MSPS
(boot:0)>   Sampling at 0.768 MSPS
(boot:0)>   Sampling at 1.000 MSPS
(boot:0)>   Sampling at 2.000 MSPS
(boot:0)>   Sampling at 2.048 MSPS
(boot:0)>   Sampling at 3.000 MSPS
(boot:0)>   Sampling at 4.000 MSPS
(boot:0)>   Sampling at 5.000 MSPS
(boot:0)>   Sampling at 6.000 MSPS
(boot:0)>   Sampling at 7.000 MSPS
(boot:0)>   Sampling at 8.000 MSPS
(boot:0)>   Sampling at 9.000 MSPS
(boot:0)>   Sampling at 10.000 MSPS
(boot:0)>  ---------------------
(boot:0)>  RX bandwidth features :
(boot:0)>   Bandwidth of 0.200 MHz
(boot:0)>   Bandwidth of 0.300 MHz
(boot:0)>   Bandwidth of 0.600 MHz
(boot:0)>   Bandwidth of 1.536 MHz
(boot:0)>   Bandwidth of 5.000 MHz
(boot:0)>   Bandwidth of 6.000 MHz
(boot:0)>   Bandwidth of 7.000 MHz
(boot:0)>   Bandwidth of 8.000 MHz
(boot:0)>  ---------------------
(boot:0)>  Gain from 0.0 to 48.0
(boot:0)>  ---------------------
(boot:0)> Current configuration:
(boot:0)>  RX center freq : 98.000 MHz
(boot:0)>  RX sample rate : 6.000 MSPS
(boot:0)>  RX bandwidth   : 6.000 MHz
(boot:0)>  RX gain (stage 0) : 10.0

.getRxSampleRate

Get the RX samplerate (Hz)

.getRxSampleRate();

.setRxSampleRate

Define the RX samplerate (Hz)

.setRxSampleRate(sample_rate);

.getRxBandwidth

Get the RX bandwidth (Hz)

.getRxBandwidth();

.setRxBandwidth

Define the RX bandwidth (in Hz) if the receiver has this feature. Use the dump() method to check possible values.

.setRxBandwidth( bandwidth);

.getRxCenterFreq

  • Returns the central frequency (MHz)
.getRxCenterFreq();
var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
print(rx.getMaxRxFreq());
print(rx.getRxCenterFreq());

.getMinRxFreq

  • Returns the minimum allowed frequency for RX (MHz)
.getMinRxFreq();

.getMaxRxFreq

  • Returns the mmaximum allowed allowed frequency for RX (MHz)
.getMaxRxFreq();
  • Example:
var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
print(rx.getMaxRxFreq());

.getGainStageCount

  • Get the amplification stages number
.getGainStageCount()

.getMinGain

  • Get the minimum allowed gain for this device
.getMinGain();

.getMaxGain

  • Get the maximum allowed gain for this device
.getMaxGain();

.setRxCenterFreq

  • Define the center receiving frequency for this radio device (MHz).
.setRxCenterFreq(freq_MHz);

This function will return false when:

  • The radio device is not valid,
  • The given frequency value is out of the possible range.

  • Example :

var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
print("Freq : ",rx.getRxCenterFreq());
print("Listening now on 1090 MHz");
rx.setRxCenterFreq(1090);
print("Freq now : ",rx.getRxCenterFreq());
(boot:0)> Freq : 100.000000
(boot:0)> Listening now on 1090 MHz
(boot:0)> Freq now : 1090.000000

.setTxCenterFreq

  • Defines the center transmitting frequency for this radio device (MHz).
.setTxCenterFreq(freq_MHz);

This function will return false when:

  • The radio device cannot transmit,
  • The given frequency value is out of the possible range.

.setGain

  • Define gain for stage 'stage'
.setGain(gain,stage);
var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
rx.setGain(30,0);

.getGain

.getGain(stage_id);
  • Returns the current gain value
var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
var gain = rx.getGain();
print('Current gain is set to:' + gain );

Example: RX status

var rx = Soapy.makeDevice({'query' : 'driver=rtlsdr' }) ;
print('Fmin : ',rx.getMinRxFreq().toFixed(0));
print('Fmax : ',rx.getMaxRxFreq().toFixed(0));
print('Samplerate : ',rx.getRxSampleRate().toFixed(0));
print('RXamp stages : ',rx.getGainStageCount().toFixed(0));
print('Gain Min : ',rx.getMinGain().toFixed(1));
print('Gain Max : ',rx.getMaxGain().toFixed(1));
print('Actual freq : ',rx.getRxCenterFreq().toFixed(0), ' MHz');
exit();
Fmin : 24
Fmax : 1764
SR : 2048000
RXamp stages : 1
Gain Min : 0.0
Gain Max : 49.6
Actual freq : 100MHz
Samplerate : 2048000
exit requested from user

RX (receiving)

.Capture( number_of_samples )

This function turns on the radio, acquires the required number of samples, and returns a IQData object.

Notes:

  • For maximal performances, acquisition is driven by blocks of constant size. The exact number of samples is set to be an integer number of blocks, so the returned object usually contains more samples than requested.
  • The radio device must be available (not streaming) when the capture is requested.
  • It is turned off after the capture.

Example:

var rx = BladeRF.makeDevice( { 'device_name' : 'rx'} ) ;
rx.setRxSampleRate(4e6);
rx.setRxCenterFreq(2410);
rx.setGain( 60 );
var IQ = rx.Capture( 1e6 );

.captureSubBand( number_of_samples , OLshift, bw )

var capture_rx = new JSRadio('my_unique_key');
if( !capture_rx.isValid() ) {
    print('capture radio not found.');
    exit();
}
print('Capture radio ok, Sample rate is :' + capture_rx.getRxSampleRate() / 1e6 + ' MSPS');
capture_rx.setRxCenterFreq( 436.95 );

var IQ = capture_rx.captureSubBand( 100e3, 50e3, 100e3 );
IQ.saveToFile('/tmp/capture.cf32') ;

.multiCapture( array )

var capture_rx = new JSRadio('my_unique_key');
if( !capture_rx.isValid() ) {
    print('capture radio not found.');
    exit();
}

var captures = new Array();
captures.push( {'center_freq_mhz' : 98.0, 'samplerate' : 20e6, 'samples' : 1e6 });
captures.push( {'center_freq_mhz' : 144.0, 'samplerate': 2e6, 'samples' : 1024*256 });
captures.push( {'center_freq_mhz' : 435.0, 'samplerate': 10e6, 'samples' : 1e6 });
var data = radio.multiCapture( sweep );
// data is an array of IQData
for( i=0 ; i < data.length ; i++ ) {
        var IQ = data[i] ;
        IQ.saveToFile('/tmp/capture_'+i+'.cf32')
}

TX (transmitting)

.hasTX

Check if SDR device is able to transmit

.hasTX();

.txOn

Start transmit

.txOn(freq_MHz, SR_Hz);

.txOff

Stops transmitter

.txOff();

.txData

Adds to the TX queue the IQData argument, repeat it repeat_times

.txData( IQData , repeat_times );

.setTxGain

Define TX gain

.setTXGain(gain);

.getTXGain

Get TX gain

.getTXGain();

.getMinTXGain

Get minimum allowed gain for this device

.getMinTXGain();

.getMaxTXGain

Get maximum allowed gain for this device

.getMaxTXGain();

Example

  • Sending tones
var tx = Soapy.makeDevice({'query' : 'driver=plutosdr' }) ;
print('TX : ',tx.hasTX())
print('Gain : ', tx.getTxGain());
var maxgain=tx.getMaxTXGain();
tx.setTxGain( maxgain-10 ); 
print('New gain : ',tx.getTxGain());
tx.txOn( 144, 4e6 ); 
tx.txData( DSP.tone( 440, 10000, 12500 ));
tx.txData( DSP.tone( 880, 15000, 12500 ));
tx.txOff();
  • Console :
    (boot:0)> TX : TRUE
    (boot:0)> Gain : 0.000000
    (boot:0)> New gain : 50.000000


    No running task, ending.
Last update: May 29, 2023