THE PROTOCOL ASTP
1. INTRODUCTION ASTP (AudeLA Scripting Transfer Protocol) is a protocol of communication that permits execution through the AudeLA system of Tcl scripts from any program (this one can be written in C, in Basic, in Java, etc.). This documentation applies therefore to the programmers. The ASTP protocol is simple to understand and to implement, also, even though you are not practiced in programming, you should not have much difficulty to benefit from advantages of AudeLA in your own realizations. For example, a practical idea is to conceive the user-interface then in Visual Basic, an extremely intuitive and effective programming environment, to use AudeLA for everything that concerns the functions of calculation, the piloting of cameras, the management of an observatory, the Ethernet communication, etc. ASTP adds a considerable power to your processing
and acquisition programs. Indeed, you cannot only throw some Tcl
scripts (one of the available most powerful script languages today),
but you benefit in addition to the numerous written function scripts
to come from the AudeLA system (LIBTT, LIBMC, LIBQM,..). The diversity
of these scripts permits to construct by you even an almost infinite
number of macro-functions. You dream of a function that doesn't
exist in any software: you have all the basis blocks to construct
it very simply (a word processor such as WordPad is sufficient!).
And if you lack a basis block, the AudeLA system is sufficiently
open so that you can add this block there while using your preferred
low-level language: C, C++, Pascal, etc. (for an introduction to
the construction of an Audela library click here).
AudeLA, Tcl and ASTP permits to write the applications that exchange themselves very well between users, including on different exploitation systems (Windows, Linux, Unix, Mac, etc.). This easiness of exchange are not the least of the advantages of the system: that guarantee a continuous development, strong evolution and the constitution of a help network if you are in difficulty. Let's underline that it is otherwise possible to exploit the power of AudeLA without writing the least line of code while using the dedicated programs, for example Aud'Ace (Aud'Ace is writed entirely in Tcl/Tk, see To be concrete we are going to describe in
these pages how the ASTP protocol is implanted in the image processing
software IRIS. 2. THE PROTOCOL ASTP The protocol between the client software (your software) and AudeLA is based on the exchange of files on the hard disk. The efficiency of the method in terms of communication speed is not exceptional, but against the technique is easy to implement, it is very portable and reliable. We should note that the relative slowness of the protocol (in the present version 1) is not a true handicap if one considers that ASTP permits to execute the powerful scripts that have a large autonomy in relation to the program calling. For example, you can start a script that pilots the telescope and the camera in unison in order to achieve a mosaic of a part of the sky, an operation that can take several score of minutes, that is to say that a lot longer length than the time of communication between the user and Audela. Here is the progress stage by stage of the
execution of a script from the client software: 2.1. Stage 1 The user of the software decides to run a script since a command line, a menu, a dialog box... To this stage it is necessary that the user provided the name of the script file as well as the entry parameters of this script. Let's suppose for example that the wished operation either to add a constant to all pixels of a sequence of pictures. The script that achieves it has for name offset2.tcl. The script is programmed in such a way that it waits for three parameters. In the order: (1) the generic name of the pictures, (2) the constant to add to the pixels (a substraction if the constant is negative), (3) the number of pictures in the sequence. So for example one wishes to treat the I1, I2, I3 pictures, as there adding the constant 500, the 3 parameters will be respectively: I 500 3 When one uses IRIS a script is run from a command given on the console. The key word of the command is TCL. The syntax is: TCL SCRIPT ARG1 ARG2 ARG3 ARG4.... SCRIPT is the name of the Tcl file (on the disk this file to still the .tcl extension but it is not necessary to specify this extension in command line) ARG1, ARG2,... are the arguments (or input parameters) of the function contained in the script file. IRIS (version 3) accepts until 12 parameters. Thus, while taking our example of the calculation of the offset of a pictures sequence, the user will enter the following order: TCL OFFSET2 I 500
3 2.2. Stage 2 As soon as the user validated the order, the
client software writes on the disk a file that is merely a small
Tcl script. This file contains the functions that permit to synchronize
the user with the Audela system, as well as the name of the script
that one wishes to execute (the name of his file disk ) and the
list of the parameters. This script that writes by the user is always
called exchange.tcl in the ASTP protocol. 2.3. Stage 3 The client software executed under the shape of a shell programs it audela.exe. In other words, your program does an operation that consists in throwing a new program, here audela.exe. So audela.exe is executed as is, he throws the script Tcl audela.tcl automatically (this script it always finds in the same index that audela.exe, in general the index binwin if you installed in the Audelas rules). But here, the client software makes so that audela.exe throws the exchange.tcl script. So that so be it audela.exe can be thrown with a particular flag, the - File flag. In the case present audela.exe will be thrown of the following manner: AUDELA - FILE EXCHANGE.TCL 2.4. Stage 4 Now, audela.exe took the hand. He/it throws the exchange.tcl script that executes itself then. Of the the beginning of exchange.tcl this one uses the service of the procedures that is in the astp.tcl script. This script is part of the protocol and must always be copied in the index of the hard disk that contains your own library of scripts. The role of exchange.tcl is essentially to recover the parameters entered then by the user to throw the script that is going to use them. 2.5. Stage 5 The user's script executes itself then. He/it can use the set of the libraries written for Audela. In our example it is the offset2.tcl script that executes itself to this stage. 2.6. Stage 6 To the term of the execution of the user's script the hand is given back to exchange.tcl. This one writes then on the hard disk two files: (1) a result.txt file that possesses two lines of text. The first contains either the NOERROR text, either the ERROR text according to whether script of the user doesn't have or produced a mistake. The second line contains a text that can be exploited by the client software. In the case of IRIS this line is displayed in the console to the fence of the execution of the TCL order. (2) a signal.txt file that means to the user that the execution of the exchange.tcl script is finished. The existence of the signal.txt file (a file empties in fact) is supervised permanently by the client software in order to identify the end of execution of the script and so to be able to pass to something else. There is several ways to manage this waiting, for either example while using a simple infinite buckle that will stop at the time of the apparition of the signal.txt file, either while managing a mechanism of thread or timer that gives to the user the feeling to work with a multitask system (however it is necessary to underline that in the present version of ASTP it is delicate to exploit the multitask dimension of Audela, but this point is to the survey). 2.7. Stage 7 The control comes back to the user. This one possibly displays the content of the file result.txt /or produces an error screen provoked at the time of the progress of the script. To note a particularity of ASTP: the exchange.tcl file exploits the picture situated in the users random-access memory (tampon picture principal) under the shape of a file picture disk having for #0.fit name. This file, in the FITS format, is a copy of the current picture in memory. It is exploited by exchange.tcl in order to reflect the operations of treatment pictures done in the user's script and that would apply normally to the picture in memory if a requirement of an internal function to the user. When the user takes the control, the #0.fit file can be reread, stocked in the tampon picture principal and displayed on the screen (it is that that makes IRIS). 3. THE SCRIPT EXCHANGE.TCL The listing shows the content typical of the exchange.tcl script below. This example treats the case of the use of the offset2.tcl script. #--- functions
of initialization--- #--- functions
of Client transfer -> Tcl--- #--- function
of execution--- #--- functions
of Tcl transfer -> User--- #--- function
of termination--- Here are the operations that exchange.tcl achieves. First of all exchange.tcl loads the astp.tcl file, that contains the utilitarian procedures that manage the ASTP protocol. The path that permits to localize the astp.tcl file (in this example c:/script /) is defined by the user of your program (in IRIS, it this fact in the category Script path of it limps of Settings dialogue, to see farther). It is possible to put the scripts where good seems you, but it is important that your index of script contains the astp.tcl script. The installation of Audela placed a copy of this one in the subdirectory astp of the index of installation of Audela. For example, if the path of installation of Audela is c:\audela \, then a copy of astp is located in the index c:\audela\astp \. A buffer picture is created then and the procedure astp_buf_load loads the file picture #0 in this buffer. The localization of the #0.fit file is defined in IRIS by the index of work (category Working path in it limps of Settings dialogue). In the example, the index of work is c:\iris \. The procedure astp_param_in decodes the parameters given out by the client program. We have here 5 parameters. The two first are obligatory. The first is the path of the work index, the second is the path permitting to arrive to the audela.exe program and the Audelas bookstores (here c:\audela3\binwin \). To note that in these explanations we don't make a distinction between the character slash (/) and the anti - slash character (\), that are functionally equivalent. However the Tcl language only tolerates the slash (compatibility with the world UNIX), from where the manner to write the paths in exchange.tcl. The procedure astp_source executes offset2.tcl script then (note that it is located in the index c:/script /). Once the progress of the offset2.tcl script finished, exchange.tcl writes the file result (result.txt) on the disk and protects the content of the buffer picture in the #0.fit file. Finally, the signal.txt file is created to indicate to the client program that the set of the procedure is finished (this file is located in the index containing the scripts. The order Tcl exit closes the Tcl session. The copy of screen below watch the labels of Settings dialogue of corresponding IRIS to the parameters of our example.
4. ASTP AND IRIS We have since the call of a Tcl script in the software IRIS (from the version 3) this fact since the line orders whose syntax is: TCL SCRIPT ARG1 ARG2 ARG3.... SCRIPT is the name of a file of Tcl script ARG1, ARG2,... are the arguments (or parameters of entry) of the function contained in the file of script. IRIS is written in C with the environment of Visual programming C++ 6.0 of Microsoft. The implementation of the ASTP protocol holds in only one routine that has for name exe__tcl. The complete code of this routine is given below. This code will be described step-by-step in the continuation. / * * * * * * * * * * * * *
* * * * * * * * * * * * * EXE_TCL * * * * * * * * * * * * * * *
* * * * * * * * * * * * / strcpy(audela_path,ini.audela_path);
/ / path of the index audela / / change the
anti - slash in slash strcpy(image_path,ini.path);
len=(int)strlen(script_path);
sprintf(binwin_path,
" %sbinwin / " ,audela_path);
/ / path of the index binwin / / synthesis
of the line of argument of the order / / created
a new picture in memory if him there some to not already one
/ / safeguard
of the buffer memory / / writing
of the exchange.tcl file write_file (#---
functions of intialisation--- " ,dest); write_file (#---
functions of Client transfer -> Tcl--- " ,dest);
write_file (#---
function of execution--- " ,dest); write_file (#---
functions of Tcl transfer -> User--- " ,dest);
write_file (#---
function of termination--- " ,dest); fflush(dest);
remove(signal_file); hwnd=GetDesktopWindow
(); do {} while(access(signal_file,1)==-1); / / loads the
file picture of exchange in memory / / displays
the picture / / reads the
file result / / flag of
mistake / / reading
of the line of parameters in return of the script fclose(fp);
The first left from the code starts by declarations of variables. / * * * * * * * * * * * * *
* * * * * * * * * * * * * EXE_TCL * * * * * * * * * * * * * * *
* * * * * * * * * * * * / It is necessary to note the arguments of the function C exe_tcl:
The following part of the code calculates the necessary index path to the working of the ASTP protocol. The variable ini.audela_path is internal to IRIS. She/it contains the path that brings to the audela.exe program. His/her/its content reflects the zone of dialogue precisely Audela script of it limps Settings of IRIS (applicable since the menu Spins this program). The variable internal ini.script_path designates the index in which is situated your library of script (this variable reflects the content of the text zone Script path of it limps of Settings dialogue). Finally the variable ini.path contains the path of the work index (zone of text Working path in it limps Settings). strcpy(audela_path,ini.audela_path);
/ / path of the index audela / / change the anti - slash
in slash strcpy(image_path,ini.path);
len=(int)strlen(script_path);
sprintf(binwin_path, "
%sbinwin / " ,audela_path); / / path
of the index binwin One notices that in this code the anti - slash of the paths is replaced often by slash, a necessary operation when the path is used to the very breast of the script (compatibility with the world UNIX). Comes then the generation of the line of argument of the function named Tcl. The first two argument of this line is always respectively the path designating the index of work (it is the index containing the pictures to treat) and the path of the index that contains the audela.exe program (as well as the scripts of extensions as libtt.dll or libqm.dll). One finds the arguments then actual of the script. In the example of the offset2.tcl script, this line of order would contain something as " c:/image / c:/audela/binwin / I 200 5 ". Note that the parameters must be separated by at least a space. / / synthesis of the line of
argument of the order In IRIS, if a picture is already in memory (it is displayed then also to the screen) it is protected on the disk under the #0.fit name (attention, you must have selected the FITS format in it tabs of Settings dialogue). If there are not any pictures in memory whereas you wish to execute a script, the operation is possible, but IRIS only created for you a minuscule picture containing that of the zeros with help the function interns IRIS newimage (arbitrarily this picture has a size of 10x10 pixels). The function save_picture, intern to IRIS, do the actual safeguard of the picture in memory in a FITS file. / / created a new picture in
memory if him there some to not already one / / safeguard of the buffer
memory Comes then the writing lign offs after line of the file of exchange Tcl exchange.tcl (the function write_file is internal to IRIS and do the actual writing of a line in a file text). The function msg is internal to IRIS and return an adequate mistake message if a problem presents itself. / / writing of the exchange.tcl
file write_file (#--- functions
of intialisation--- " ,dest); Before starting the audela.exe program one erases the signal.txt file: remove(signal_file); The audela.exe program is executed then while using the ShellExecute function of the Windows API. The variable cmdline contains the argument of audela.exe. hwnd=GetDesktopWindow ();
IRIS then in waiting gets the writing of the signal.txt file by the exchange.tcl script. This buckle infinity is very poor because it blocks the working of IRIS so much that the progress of the script is not finished. It is possible to make a better environment for Windows, but as is, the process functions. do {} while(access(signal_file,1)==-1); Once the script finished its work, one loads in memory the content of the #0.fit file (function load_picture of IRIS), then one displays this picture (function view). / / loads the file picture
of exchange in memory / / displays the picture
The routine exe_tcl ends by the reading of the two lines that is in the result.txt file. A possible mistake at the time of the progress of the script is treated to this level. The second line is a text that is displayed on the console of IRIS (this text is possibly a message of mistake automatically generated by Tcl, what facilitates the rest the writing of the scripts considerably). 5. EXAMPLES OF SCRIPTS Here are some elementary scripts that can be called in the context of the ASTP protocol. 5.1. Calculation of the Julian day This small script returns in the console of IRIS the Julian day for one date entered by the user. This script uses the function qm_jd that is implemented in the LIBQM script. #jd
#--- conversion
of the ASTPS parameters in clear language #--- possible
bookstore loading #--- body of
the script #--- value back
The script starts while placing the parameters of entry in variables to the explicit names. The parameters are stocked automatically in a picture having for name astp (). Notice that the first two parameters contain the paths of the work index and the path of the index containing the script. The LIBQM.DLL script is charged then in memory. The function actual qm_jd is thrown then. The result returned in the variable has. The last line synthesizes a clear message that is sent to the user through the result.txt file. It is the content of this line that is displayed in the console. To use this tag copy the command in an index file of your choice (c:\script \ for example) also think about additionally adding to the astp.tcl file also. In the made for example console (the first parameter of jd.tcl is the year, the second the month and finally the day): TCL JD 2000 10 13.566 The picture shows the console of IRIS below in this situation: 5.2. Addition of a constant to a sequence of pictures Here is the content of the offset2.tcl script that already acted us as example. Here one uses an elementary function of the LIBQM script again: the function qm_offset that adds a constant to a picture situated in the definite buffer 0 by the Audela system. #offset2
#--- conversion
of the ASTPS parameters in clear language #--- loading
of the bookstores #--- body of
the script #--- parameter
of exit This script is very similar to jd.tcl. One notes here in more that the management of the sequence of pictures is done by a clamp written in Tcl. It lets glimpse the manner of which it is possible to conceive complex scripts while using a simple word processor and a minimum of knowledge of the Tcl language. 5.3. Addition of a constant to the picture in memory The following script is simple because it does the treatment on the picture in memory of the client software (while using the file #0.fit intermediate). #offset
#--- conversion
of the ASTPS parameters in clear language #--- possible
bookstore loading #--- conversion
of the ASTPS parameters in clear language #--- value back
One can note that it is possible to use a function of calculation different of the one that is in LIBQM. For example, if you want to exploit the equivalent function in LIBTT, the script will be then: #offset
#--- conversion
of the ASTPS parameters in clear language #--- conversion
of the ASTPS parameters in clear language #--- value back
The offset procedure is defined in astp.tcl from the functions of basis of LIBTT. Seen since the interface of IRIS, this script executes itself of the following manner: 6. DOWNLOADING To download astp.tcl and the scripts of examples, click here. Click here for going to LIBQM page |
|