Scripting is an easy way to set a default configuration for the Cloud SDR nodes. Scripts are not only providing configuration capabilities, they can also be used as regular programs that can be run on any remote node and do signal processing, satellite tracking, recoding, playback, hardware management…

Scripts can also be used to run periodic tasks.

A script is a code snippet that interacts with the configuration, processing or more generally the behavior of the system. As a very short example, here is a typical boot script for SDRNode :

function boot() {
	var sources = GetSources(); 
	// sources contains now the list of local hardware devices
	 for( i=0 ; i < sources.length ; i++ ) {
		var sourceDef = sources[i] ;
		print( '--------------------------------------');
		print( 'Unique identifier : ' + i + ' UID=' + sourceDef.UID );
		print( 'Source ' + i + ' name=' + sourceDef.name );
		print( ' Center Frequency =' + sourceDef.center + ' MHz');
		print( ' Tunable from ' + sourceDef.fmin + ' MHz to ' + sourceDef.fmax + ' MHz' );
		print( ' Current sampling rate : ' + sourceDef.sr/1000 + ' KHz' ) ;
		
		
		// sourceDef.name = hardware name reported by driver
		if( sourceDef.name == 'RTL820T') {
			var rtlsdr = new RFSource( sourceDef.UID ) ;
			// set sampling rate
			rtlsdr.setSampleRate( 2048000 );   
			rtlsdr.setRxGain( 0, 12 ) ; // set a default gain
			print('dongle gain set');
			
			// first published stream : not compressed at 100 KHz
			// bandwidth = 100k * 8 bytes / samples= 800 Ko/seconds
                       // This stream is published under the name 'HD'
			var streamDef = createStream( sourceDef.UID, 100e3, 'HD' ) ; 
			var rx820 = new RFSource( streamDef.UID ); 		
			rx820.setCompressionType(0) ; // [0] = no compression
			rx820.setPublic(true); // anybody can connect
			
			// another compressed stream with bandwidth = 50k 
                       // requires approx  2 bytes per samples, gives around 100 Ko/seconds on network
			var streamDefc = createStream( sourceDef.UID, 50e3, 'Compressed' ) ;
			var rx820c = new RFSource( streamDefc.UID ); 	
			rx820c.setCompressionType(3);  // [3] = compression max
		}
}

This example shows how the script sets locally the behavior or capabilities of the SDR node. This example script is typically loaded at boot time and configures the published streams from the node. It first obtains the list of connected devices using the GetSources() function. Then, it loops through each source and defines what should be done. In this example, if a RTL820T USB receiver is connected it does the following :

  1. Configure the SDR sampling rate to 2048 KHz ( with setSampleRate( 2048000 ) ),
  2. Set first stage gain to 12 dB ( with setRxGain( 0, 12 ) );
  3. Creates a channel of 100 KHz called 'HD' ( createStream( sourceDef.UID, 100e3, 'HD' ) );
  4. Declares no compression for this IQ stream,
  5. Creates a second channel of 50 KHz called 'Compressed'.

Connecting to this remote SDR Node with the gkSDR client is quite then easy :

Once the desired stream selected, it may be used as a if it was coming from a local hardware device.

Scripts can be fetched from different locations :

  1. Locally, they are available in local file system,
  2. Remotely, available through HTTP from a remote Web server,
  3. Remotely, pushed to SDR Node for execution through the API.

Local scripts can be used as object libraries or called on demand. For example previous boot script example loads different configuration routines by doing :

load('scripts/rx.js');
load('scripts/streams.js');

Local or remote scripts can be used the same way. A remote script can be downloaded just by specifying its HTTP URL :

load('http://myserver.com/scripts/rx.js');
load('http://myserver.com/scripts/streams.js');

loading a script does the following :

  • complete syntax test of the whole code. In case of error, the code is not executed,
  • the JavaScript interpreter merges then loaded code with current environment.

For example; lets consider the following scenario :

  • a remote server defines a list of frequencies to be scanned.
  • This list is offered through a public web server.

The following code snippet is an example of returned code to set frequency list :

frequency[0] = 13.128;
frequency[1] = 14.120;
frequency[2] = 22.010;

Base code in SDR Node does not contain whole list of frequencies but gets them from the remote web server :

var frequency ;
var i;
// at that step the frequency variable is empty
if( load('http://remoteserver.com/frequencies.php') ) {
// now the remote code has initialized the frequency list, we can go
  for( i=0 ; i < frequency.length ; i++ ) {
       var f = frequency[i];
       rx.setFrequency( f ) ;
       ...
  }
}