Feat/api tornado
Created by: samartse
The REST API for pymepix library (implemented using tornado web): Implemented as an additional feature. The pymepix should be started as:
pymepix-acq api-service -i 192.168.x.x -g 3
whrere -g is optional, default is 3 for timepix 3 camera generation.
In order to check if the server is online the endpoint '/' could be used like:
curl -X GET "http://localhost:8080/"; echo
The result from request:
"{"message": "Online"}"
Now, starting the camera using curl commands for http requests:
curl -X POST "http://localhost:8080/tpxmethod" -d '{"func_name": "start"}' ; echo
here, 8080 is the default port where rest server is running. In this case the endpoint "tpxmethod" is used to call function "start".
Next, start the acquisition:
curl -X POST "http://localhost:8080/tpxmethod" -d '{"func_name": "start_recording", "path":"/home/username/data_record.raw"}' ; echo
the 'start_recording' function is called, in addition to dictionary key 'func_name' corresponding to the name of the function, the parameters to function are added ("path"), the paramters are named, should correspond to the signature of the function.
In the same way, acquisition could be stopped:
curl -X POST "http://localhost:8080/tpxmethod" -d '{"func_name": "stop_recording"}' ; echo
and after that, camera may be stopped:
curl -X POST "http://localhost:8080/tpxmethod" -d '{"func_name": "stop"}' ; echo
The result from http request is the result from function call, which must be json serializable.
In order to change the property of the camera like biasVoltage, another endpoint should be used:
curl -X GET "http://localhost:8080/tpxproperty" -d 'param_name=biasVoltage' ; echo
The name of property of the class pymepix_connection should under variable 'param_name'
In order to change the value of property:
curl -X POST "http://localhost:8080/tpxproperty" -d '{"biasVoltage":60}' ; echo
In this case, the dictionary is sent, the dict contains the pairs 'variable name': value. Several pairs can be sent. The complicated field of pymepix_class or also its subclasses are possble to modify, using 'complex' paths to variable like:
curl -X GET "http://localhost:8080/tpxproperty" -d 'param_name=[0]._acq_running' ; echo
In this case it accesses the timepixdevice class (always 0 index) and reads its internal property '_acq_running'. The only requirements that the call to funcions/properties must be json serializable. If something is required to be called/accessed which is not json serializable, then refactoring of the library code may be required.
There is also implemented the REST API endpoing fot the postprocessing:
curl -X GET "http://localhost:8080/postprocess" -d '{"input_file_name":"input_file_name_path", "output_file":"output_file_path", "number_processes":n, "timewalk_file":"timewalk_file_path", "cent_timewalk_file":"cent_timewalk_file_path", "camera_generation":3}'
where "input_file_name_path"/"output_file_path" path to input/output file, n is a number of processes for centroid calculator, "timewalk_file_path" and "cent_timewalk_file" are timewalk file and centroid timewalk files respectivelly, "camera_generation" is the camera generation number (default 3).