JSTask

A JTask is an independant instance of the Virtual Machine. Internally, it is executed by a separate thread and handles its own heap. Local variables are not exposed to other tasks (see Shared Maps to share data between tasks ).

Note:
A running script is a Task object.

exit

  • Exit from current task
exit();

include

  • Includes a Javascript file to the actual one.
  • URL may be used instead of local path
include('/home/scripts/example/plotlib.js');
include('http://mywebsite:8081/scripts/plotlib.js');

print

  • Send a text to the script standard output.
  print( param1, param2, ... , paramN );

example :

print('Hello world');

Note about format:

if 'param' is an Object, the Virtual Machine tries to convert it to JSON and displays it as : Object[] : { ... }*

getTID

  • Returns the current task unique id (TaskID)
getTID();
  • Example
var tid=getTID();
print(JSON.stringify(tid));

argc

  • Returns the number of arguments passed when the task was created
var count=argc();

argv

  • Get one specific parameter passed when the task was created
variable = argv(x);
  • Example : get first parameter:
var my_first_parameter=argv(0);
print(my_first_parameter);

sleep

  • Pause task (in milliseconds). Internally, the thread running the task VM checks if the task is requested to end (through the kill function).
sleep(millis);

getRunningTime

  • Returns running time in milliseconds since the starting on the task.
var running_time = getRunningTime();

timestamp

  • Returns the system timestamp: time elapsed since 01/01/1970 in milliseconds.
var unix_time = timestamp();

createTask

  • Create a task from a script file, using optional parameters

Important : Parameters are strings.

int task_id = createTask(filename, [optional : parameter1, parameter2, ....] );
Notes:
filename can be a string pointing to a local file, * filename can be a valid URL (starting with http*)

Examples:

// Create task
var tid = createTask('/home/use/sdr4space/examples/record_signal.js','one parameter');
// Create task
var tid = createTask('http://myremote:port/record_signal.js','one parameter');

waitTask

Wait for a specific task to end. Actual running task is suspended until the given task (parameter) has ended.

     waitTask( ID );

It is possible to retrieve the list of running tasks in the SDRVM by using the System module

example :

// Create task
var tid = createTask('/home/use/sdr4space/examples/record_signal.js','one parameter');
// now wait for end
waitTask( tid );
print('Task has finished');

isTaskRunning

Check if a task is still running in the virtual machine.

     bool task_is_still_alive = isTaskRunning( ID );
Last update: November 19, 2023