System

The System module gives access to the internals of the Virtual Machine and access the host computer.

System.cwd

Change working directory for the current task.

System.cwd('/home/user/test');

System.exec

Execute system command, sending optional parameters as array

WARNING : there is no size limit for outputs 'stdout' and 'stderr'

System.exec('/path_to_file/<command>',[ parameters array]);

Function will return JSON object :

{
  'exec' : '/path/to/the/command/',
  'stdout': standard output as text
  'stderr': error output as text
}

Example :

var c = {
    'command' : '/bin/bash', 
    'args' : ['-c','ls']
} ;

var res = System.exec( c );
print( JSON.stringify( res ));

System.GPSAvail

Checks if a GPS positionning device is managed by the VM. Returns true if :
- A GPS device has been declared at startup

bool result = System.GPSAvail() ;

System.GPSConnect

Allows to 'hotplug' a GPS receiver of the VM.

bool result = System.GPSConnect( String device, [optional : baudrate]) ;

Parameters:

  • device: comm port to be used, for example /dev/ttyACM0
  • baudrate : communication speed with the GPS receiver, default value is 9600

Returns true if the GPS has been connected.

Example:

 if( System.GPSAvail() == false ) {
    print('No GPS receiver configured by command line, testing ttyACM0') ;
    if( System.GPSConnect('/dev/ttyACM0') === true ) {
        print('GPS ready');
    } else {
        print('No GPS');
    }
 }

System.GPSValidNMEA

Checks if a GPS positionning device is managed by the VM. Returns true if :

  • A GPS device has been declared at startup
  • The GPS is connected and is sending NMEA frames.
bool result = System.GPSValidNMEA() ;

System.GPSInfos

Returns, if a GPS device is connected and running, the following infos:

  • latitude, longitude, altitude from the last fix report
  • fix status (locked/unlocked)
  • GPS time (seconds after the 01/01/1970)
var mypos = System.GPSInfos();

Function will return JSON object :

{
  'fix' : boolean to indicate if we have a fix or not,
  'latitude_N': latitude in degrees,
  'longitude_E': longitude in degrees,
  'altitude' : altitude in meters,
  'speed_kmh': current estimated speed,
  'travel_angle_north' : current bearing angle,
  'system_time': system time,
  'sys_timestamp' : number of seconds since the 01/01/1970,
  'gps_timestamp' : date and time, as returned by device
}

GPS example

sudo ./sdrvm -g /dev/ttyACM0 -b 19200 -f gps_pos.js
for( ; ; ) {
    if( System.GPSAvail() == false ) {
        print('Run the VM with the -g option');
        exit(0);
    }
    if( System.GPSValidNMEA() == true ) {
        print('GPS now working.');
        break ;
    }
    print("Waiting for NMEA frames to arrive.");
    sleep(1000);    
}
print('GPS ready');
for( ; ; ) {
    var mypos = System.GPSInfos();
    print(JSON.stringify(mypos));
    sleep(1000);
}

System.isMounted

Check if specified path is a mounted filesystem or not.

bool System.isMounted('path');

Example :

if( System.isMounted('/media/disk/04DA-6F70') ) {
    print('search boot');
    createTask('/media/disk/04DA-6F70/boot.js');
}

System.getFreeSpace

Returns the % free in the volume where the given file is located.

number System.getFreeSpace('path');

Example:

var freespace = System.getFreeSpace('/etc/passwd');
if( freespace < 1 ) {
    print('Root filesytem almost full !');
}

System.getRamUSed

Returns the % of system RAM currently used.

number System.getRamUSed();

System.getCpuLoad

Returns the CPU load average over 100 milliseconds.

number System.getCpuLoad();

System.nics

Returns the list of network interfaces available, with their MAC and current IP addresses.

var nics = System.nics() ;

returns an array of JSON objects :

{
    "ip" : string,
    "mac": string,
    "name": string
}

example :

[{"ip":"192.168.10.103","mac":"54:BF:64:73:FD:23","name":"enp0s31f6"}]

System.ps

Get a list of JS tasks which are actually running on the SDR Javascript Virtual Machine

var running_tasks = System.ps();
  • Example, list tasks :
var tasks = System.ps();
print( JSON.stringify( tasks ));

System.kill

Tells a specific running task to stop.

System.kill(task_id);

System.mkFifo

Create a Linux FIFO file.
Function will return a TRUE boolean value if FIFO was yet existing or created just now.

var ok = System.mkFifo('/tmp/data.fifo');

Note : if the FIFO will be used to transfer IQ data to a third-party application through file ( E.G.: IQData.appendToFile(...)), you have to name the fifo file with an additional extension ( .CF16 .CF32).

For more informations, please refer to IQdata object.

  • Example
var ok = System.mkFifo('/tmp/data.fifo.CS16');

System.loadLicense

Load external license file instead of usual default license file 'license.dat' located in app directory.

  • Example
var d=System.loadLicense('/tmp/mylicense.dat');
print(d);

Will return TRUE and display licensing informations if success.
Returns FALSE if license file is not found

System.setLicense

Defines the license with a string constant. Returns true if the license is valid for this system.

  • Example
var ok=System.setLicense('ToYRrOK$vHE$B3Gb3zAOvHGnVb69oCYhVPD0LHt4vmzAGZ3yZGSGJJUvpegsinXtVEIGi1$UV*oT2x*Tne');
if( ok == false ) {
    print('error in license, cannot continue.');
    exit();
}

System.setWebRoot

Defines where the "/" URL path goes in the local filesystem. By default, it is defined in the configuration file ( see WebServer) but can be overriden by this function.

Example:

// Change Web root to local folder
System.setWebRoot( './webpages');

System.getGPUCount

Returns how many GPU devices are available. Return -1 if the GPU support is not enabled.

Example:

var nb = System.getGPUCount();
if( nb == -1 ) {
 print('GPU support not enabled.');
} else {
 print( nb, ' GPU devices detected.');
}

System.setDefaultGPU

Defines the default GPU to be used by the SDRVM. Valid from 0 to System.etGPUCount()-1 .

Will throw an exception if no GPU support or not valid ID.

Last update: August 21, 2023