4 * author: frank zirkelbach (frank.zirkelbach@physik.uni-augsburg.de)
6 * this program tries helping to understand the amorphous depuration
7 * and recrystallization of SiCx while ion implantation at temperatures
8 * below 400 degree celsius.
9 * hopefully the program will simulate the stabilization of the
10 * selforganizing lamella structure in the observed behaviour.
13 * - J. K. N. Lindner. Habil.Schrift, Universitaet Augsburg.
14 * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg.
16 * Copyright (C) 2004 Frank Zirkelbach
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include <sys/types.h>
52 #include "nlsop_general.h"
54 #define LOGFILE "nlsop_gui_logfile"
60 printf("%s -i <ip> -p <port> -l <logfile>\n",prog);
65 * gui internal functions
68 int display_new_line(t_display *display,t_input *input,char *text) {
79 tmp=(unsigned char *)malloc(display->max_x);
80 memset(tmp,0x20,display->max_x);
82 display_line(display,0,0,x,0,'#');
83 display_string(display,x/2-17,1,"nlsop gui (C) 2004 Frank Zirkelbach",35);
84 display_line(display,0,2,x,2,'#');
85 display_line(display,0,y-1,x,y-1,'#');
86 display_string(display,0,y,"prompt: ",8);
87 memcpy(tmp,input->content,input->c_count);
88 display_string(display,8,y,tmp,x-9);
92 for(i=0;i<display->max_y-6;i++) {
93 memcpy(display->screen+ptr,display->screen+ptr+display->max_x,
98 memcpy(display->screen+ptr,text,i);
99 memset(display->screen+ptr+i,0x20,x-i);
102 display_draw(display);
103 display_set_cursor(display,8+input->c_count,y);
108 int send_and_wait_for_answer(t_net *net,t_display *display,t_input *input) {
113 char string[MAX_CONTENT];
117 /* request information */
118 network_send_chan(net,0,&data,sizeof(unsigned char));
120 /* receive information */
121 network_receive_chan(net,0,&data,sizeof(unsigned char));
123 display_new_line(display,input,"no gui info answer, ignored");
127 network_receive_chan(net,0,(unsigned char *)&count,sizeof(int));
128 for(i=0;i<count;i++) {
129 network_receive_chan(net,0,(unsigned char *)&job,sizeof(t_job));
130 snprintf(string,MAX_CONTENT,
131 "channel %d %c => b=%f c=%f s=%f | d: %d %f | %d",
132 job.channel,job.status&IN_WORK?'a':'q',
133 job.info.b,job.info.c,job.info.s,
134 job.info.diff_rate,job.info.dr_ac,job.progress);
135 display_new_line(display,input,string);
138 display_new_line(display,input,"done");
143 int send_job(t_net *net,t_input *input,t_display *display) {
145 char command[MAX_CONTENT];
156 info.diff_rate=DIFF_RATE;
159 info.save_rate=RESAVE;
165 strncpy(command,input->content,MAX_CONTENT);
168 while(strtok(NULL," ")!=NULL) {
171 info.b=atof(command+1);
174 info.c=atof(command+1);
177 info.s=atof(command+1);
180 info.diff_rate=atoi(command+1);
183 info.dr_ac=atof(command+1);
186 info.steps=atoi(command+1);
189 info.cpi=atoi(command+1);
192 info.range=atoi(command+1);
195 info.s_rate=atoi(command+1);
198 info.save_rate=atoi(command+1);
210 display_new_line(display,input,"unknown command");
215 command[0]=GUI_ADDJOB;
216 network_send_chan(net,0,command,1);
218 network_send_chan(net,0,(unsigned char *)&x,sizeof(int));
219 network_send_chan(net,0,(unsigned char *)&y,sizeof(int));
220 network_send_chan(net,0,(unsigned char *)&z,sizeof(int));
222 network_send_chan(net,0,(unsigned char *)&info,sizeof(info));
227 int get_whatever(t_input *input,void *ptr) {
232 display=(t_display *)ptr;
234 last=input->content[input->c_count-1];
236 if((last=='\n')||(last=='\r')) {
237 input->content[input->c_count-1]='\0';
242 display_new_line(display,input,NULL);
247 int nothing(t_event *event,void *allineed) {
252 int get_command(t_event *event,void *allineed) {
257 unsigned int addr[3];
259 memcpy(addr,allineed,3*sizeof(unsigned int));
260 net=(t_net *)addr[0];
261 display=(t_display *)addr[1];
262 input=(t_input *)addr[2];
264 input_get_event(input,get_whatever,display);
266 /* if there was a new line! */
267 if(input->c_count==0) {
268 switch(input->content[0]) {
270 send_and_wait_for_answer(net,display,input);
273 send_job(net,input,display);
276 /* stop everything */
277 event_math(0,event,READ,REMOVE);
278 network_shutdown(net);
279 display_shutdown(display);
280 input_shutdown(input);
284 display_new_line(display,input,"unknown gui command");
296 int main(int argc,char **argv)
313 unsigned int addr[3];
316 allyouneed=(void *)addr;
318 addr[0]=(unsigned int)&net;
319 addr[1]=(unsigned int)&display;
320 addr[2]=(unsigned int)&input;
323 strcpy(logfile,LOGFILE);
324 strcpy(server_ip,"");
327 /* parse/check argv */
328 for(i=1;i<argc;i++) {
329 if(argv[i][0]=='-') {
335 strncpy(server_ip,argv[++i],16);
338 port=atoi(argv[++i]);
341 strncpy(logfile,argv[++i],64);
349 if(!strcmp(server_ip,"")) {
354 if((fd=open(logfile,O_WRONLY|O_CREAT))<0) {
355 printf("unable to open file %s\n",logfile);
360 display_init(&display,fd);
363 input_init(&input,fd);
364 input.mode=CONTENT_BUFFER|ECHO;
365 input_ios_init(&input);
368 event_init(&event,fd);
369 event_set_timeout(&event,0,0);
371 /* user interaction */
372 event_math(0,&event,READ,ADD);
374 display_new_line(&display,&input,"welcome to nlsop gui! :)");
376 /* connect to server */
377 network_init(&net,fd);
378 network_set_connection_info(&net,0,server_ip,port);
379 if(network_connect(&net,0)==N_E_CONNECT) {
380 printf("unable to connect to server, aborting ...\n");
383 network_select(&net,0);
385 display_new_line(&display,&input,"successfully connected to server");
387 /* tell server: i am a client, i may work for you */
389 network_send(net.connection[0].fd,&data,1);
391 display_new_line(&display,&input,"send data to server, waiting for input");
394 event_start(&event,allyouneed,get_command,nothing);