⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtaicodegen_.sci

📁 rtai-3.1-test3的源代码(Real-Time Application Interface )
💻 SCI
📖 第 1 页 / 共 5 页
字号:
	make_end();	make_const_update();	c_make_doit1();	c_make_doit2();	c_make_outtb();	c_make_initi();	c_make_endi()]  	  ierr=execstr('mputl(Code,rpat+''/''+rdnom+''.c'')','errcatch')  if ierr<>0 then    message(lasterror())    ok=%f    return  end  if FCode<>[] then    ierr=execstr('mputl(FCode,rpat+''/''+rdnom+''f.f'')','errcatch')    if ierr<>0 then      message(lasterror())      ok=%f      return    end  end  Code=['#include '"'+SCI+'/routines/machine.h'"';	make_actuator(%t);	make_sensor(%t);        make_upar_update()]  ierr=execstr('mputl(Code,rpat+''/''+rdnom+''_void_io.c'')','errcatch')  if ierr<>0 then    message(lasterror())    ok=%f    return  end     Code=['#include '"'+SCI+'/routines/machine.h'"';	make_decl_standalone()	make_static_standalone()        make_standalone()]  ierr=execstr('mputl(Code,rpat+''/''+rdnom+''_standalone.c'')','errcatch')  if ierr<>0 then    message(lasterror())    ok=%f    return  end  endfunctionfunction ok=gen_gui();//creates the Scicos GUI function associated with the new block//Copyright INRIA//Author : Rachid Djenidi  clkinput=ones(clkIN)';  Code=['function [x,y,typ]='+rdnom+'_c(job,arg1,arg2)';	'// Copyright INRIA';	'x=[];y=[];typ=[];';	'select job';	'case ''plot'' then';	'  standard_draw(arg1)';	'case ''getinputs'' then';	'  [x,y,typ]=standard_inputs(arg1)';	'case ''getoutputs'' then';	'  [x,y,typ]=standard_outputs(arg1)';	'case ''getorigin'' then';	'  [x,y]=standard_origin(arg1)';	'case ''set'' then';	'  x=arg1;';	'  graphics=arg1.graphics;label=graphics.exprs';	'  model=arg1.model;';	'case ''define'' then'	'  '+sci2exp(capt(:,3),'in',70); //input ports sizes	'  '+sci2exp(actt(:,3),'out',70); //output ports sizes	'  '+sci2exp(z,'z',70); //initial state	'  '+sci2exp(outtb,'outtb',70); //initial link values	'  iwa=zeros('+string(clkptr($))+',1)';	'  Z=[z;outtb;iwa]';        '  '+sci2exp(cpr.sim.rpar,'rpar',70); //real parameters        '  '+sci2exp(cpr.sim.ipar,'ipar',70);//integer parameters	'  '+sci2exp(clkinput,'clkinput',70);	'  model=scicos_model(sim=list('''+rdnom+''',1),in=in,out=out,..'	'          evtin=clkinput,dstate=Z,rpar=rpar,ipar=ipar,..'	'          blocktype=''c'',dep_ut=[%t %f])'	'  label=string(in)';	'  gr_i=''xstringb(orig(1),orig(2),'''''+rdnom+''''',sz(1),..'	'         sz(2),''''fill'''')''';	'  x=standard_define([2 2],model,label,gr_i)';	'end'        'endfunction'];  //Create file  ierr=execstr('mputl(Code,rpat+''/''+rdnom+''_c.sci'')','errcatch')  if ierr<>0 then    message(lasterror())    ok=%f  endendfunctionfunction ok=gen_loader()//generates the Scilab script for defining the newly created block//into Scilab.   SCode=['//exec file used to load the ""compiled"" block into Scilab'	 'rdnom='+sci2exp(rdnom);	 '// get the absolute path of this loader file' 	 'DIR=get_absolute_file_path(rdnom+''_loader.sce'')'	 'Makename = DIR+rdnom+''_Makefile'';'	 'select COMPILER'	 'case ''VC++''   then '	 '  Makename = strsubst(Makename,''/'',''\'')+''.mak'';'	 'case ''ABSOFT'' then '	 '  Makename = strsubst(Makename,''/'',''\'')+''.amk'';'	 'end'	 '//unlink if necessary'	 '[a,b]=c_link(rdnom); while a ;ulink(b);[a,b]=c_link(rdnom);end';	 'libn=ilib_compile('+sci2exp('lib'+rdnom)+',Makename)';	 'if MSDOS then'	 '  fileso=strsubst(libn,''/'',''\'')';	 'else'	 '  fileso=strsubst(libn,''\'',''/'')';	 'end';	 'link(fileso,rdnom,''c'')';	 '//load the gui function';	 'getf(DIR+''/''+rdnom+''_c.sci'');']  ierr=execstr('mputl(SCode,rpat+''/''+rdnom+''_loader.sce'')','errcatch')  if ierr<>0 then    message(lasterror())    ok=%f    return  endendfunctionfunction Makename=gen_make(name,files,libs,Makename)//Modified for RTAI by Roberto Bucher (roberto.bucher@die.supsi.ch)  if getenv('WIN32','NO')=='OK' then    Makename=gen_make_win32(name,files,libs)  else    Makename=gen_make_unix(name,files,libs)  endendfunctionfunction Makename=gen_make_unix(name,files,libs,Makename)  //   "OBJSSTAN="+strcat(strsubst(files,'_void_io','_standalone')+'.o',' ...  //		')+' '+rdnom+'_act_sens_events.o'  T=["# generated by builder.sce: Please do not edit this file"     "# ------------------------------------------------------"     ""     "RTAIDIR = $(shell rtai-config --prefix)"     "SCIDIR = "+SCI     ""     "MODEL = "+name     "OBJS = "+strcat(files+'.o',' ')           "OBJSSTAN = "+strcat(strsubst(files,name+'_void_io','rtmain')+'.o',' ')     ""     "SCILIBS = $(SCIDIR)/libs/scicos.a $(SCIDIR)/libs/lapack.a "+..     "$(SCIDIR)/libs/poly.a $(SCIDIR)/libs/calelm.a "+..     "$(SCIDIR)/libs/blas.a $(SCIDIR)/libs/lapack.a"     "LIBRARY = lib$(MODEL)"     "OTHERLIBS = "+libs     "ULIBRARY = $(RTAIDIR)/lib/libsciblk.a $(RTAIDIR)/lib/liblxrt.a"     ""     "include $(SCIDIR)/Makefile.incl";     "CFLAGS = $(CC_OPTIONS) -O2 -I$(SCIDIR)/routines -I$(RTAIDIR)/include -I$(RTAIDIR)/include/scicos -DMODEL=$(MODEL)"     "FFLAGS = $(FC_OPTIONS) -I$(SCIDIR)/routines/"      "include $(SCIDIR)/config/Makeso.incl"     ""     "rtmain.c: $(RTAIDIR)/share/rtai/scicos/rtmain.c $(MODEL).c $(MODEL)_io.c"     ascii(9)+"cp $< ."     ""     name+"_standalone: $(OBJSSTAN) $(ULIBRARY)"      ascii(9)+"gcc -static -o $@  $(OBJSSTAN) $(SCILIBS) $(ULIBRARY) -lpthread -lm"];  mputl(T,Makename)endfunction//     "OBJSSTAN="+strcat(strsubst(files,'_void_io','_standalone')+'.o',' ') function Makename=gen_make_win32(name,files,libs,Makename)WSCI=strsubst(SCI,'/','\') //  "OBJSSTAN="+strcat(strsubst(files,'_void_io','_standalone')+'.obj',' ')+' '+rdnom+'_act_sens_events.obj'  T=["# generated by builder.sce: Please do not edit this file"     "# ------------------------------------------------------"     "SHELL = /bin/sh"     "SCIDIR = "+SCI     "SCIDIR1 = "+WSCI     "SCILIBS = """+WSCI+"\bin\LibScilab.lib"""     "LIBRARY = lib"+name     "OBJS = "+strcat(files+'.obj',' ')     "OBJSSTAN="+rdnom+'.obj '+rdnom+'_standalone.obj '+rdnom+'_act_sens_events.obj'     "OTHERLIBS = "+libs     ""     "DUMPEXTS="""+WSCI+"\bin\dumpexts"""     "SCIIMPLIB="""+WSCI+"\bin\LibScilab.lib"""     ""     "all::"     "CC=cl"     "LINKER=link"     "LINKER_FLAGS=/NOLOGO /machine:ix86"     "INCLUDES=-I"""+WSCI+"\routines\f2c"""      "CC_COMMON=-D__MSC__ -DWIN32 -c -DSTRICT -nologo $(INCLUDES)"      "CC_OPTIONS = $(CC_COMMON) -Od  -GB -Gd -W3"     "CC_LDFLAGS = "     "CFLAGS = $(CC_OPTIONS) -DFORDLL -I"""+WSCI+"\routines"""     "FFLAGS = $(FC_OPTIONS) -DFORDLL -I"""+WSCI+"\routines"""     ""     "all :: $(LIBRARY).dll"     " "     "$(LIBRARY).dll: $(OBJS)"     ascii(9)+"@echo Creation of dll $(LIBRARY).dll and import lib from ..."     ascii(9)+"@echo $(OBJS)"     ascii(9)+"@$(DUMPEXTS) -o ""$*.def"" ""$*.dll"" $**"     ascii(9)+"@$(LINKER) $(LINKER_FLAGS) $(OBJS) $(SCIIMPLIB) $(XLIBSBIN) $(TERMCAPLIB) /nologo /dll /out:""$*.dll"" /implib:""$*.ilib"" /def:""$*.def"""      ".c.obj:"     ascii(9)+"@echo ------------- Compile file $< --------------"     ascii(9)+"$(CC) $(CFLAGS) $< "     ".f.obj:"     ascii(9)+"@echo ----------- Compile file $*.f (using f2c) -------------"     ascii(9)+"@"""+WSCI+"\bin\f2c.exe"" $(FFLAGS) $*.f "     ascii(9)+"@$(CC) $(CFLAGS) $*.c "     ascii(9)+"@del $*.c "     "clean::"     ascii(9)+"@del *.CKP "     ascii(9)+"@del *.ln "     ascii(9)+"@del *.BAK "     ascii(9)+"@del *.bak "     ascii(9)+"@del *.def"     ascii(9)+"@del *.dll"     ascii(9)+"@del *.exp"     ascii(9)+"@del *.ilib"     ascii(9)+"@del errs"      ascii(9)+"@del *~ "     ascii(9)+"@del *.obj"     ascii(9)+"@del .emacs_* "     ascii(9)+"@del tags "     ascii(9)+"@del tags "     ascii(9)+"@del TAGS "     ascii(9)+"@del make.log "     ""     "distclean:: clean "     " "     "standalone: $(OBJSSTAN) $(OTHERLIBS) "      ascii(9)+"$(LINKER) $(LINKER_FLAGS)  $(OBJSSTAN) $(OTHERLIBS) $(SCILIBS)  /out:standalone.exe "]  select COMPILER;    case 'VC++'   then     makename = strsubst(Makename,'/','\')+'.mak'    case 'ABSOFT' then     makename = strsubst(Makename,'/','\')+'.amk'  end  mputl(T,makename)   endfunctionfunction Code=make_actuator(standalone)// Generating the routine for actuators interfacing//Copyright INRIA//Author : Rachid Djenidi//Modified for RTAI by Roberto Bucher (roberto.bucher@die.supsi.ch)  Call=['/*'+part('-',ones(1,40))+' Actuators */ ';      'void ';      rdnom+'_actuator(flag,nport,nevprt,t,u,nu)']comments=['     /*'	  '      * To be customized for standalone execution';	  '      * flag  : specifies the action to be done'	  '      * nport : specifies the  index of the Super Bloc '	  '      *         regular input (The input ports are numbered '	  '      *         from the top to the bottom ) '	  '      * nevprt: indicates if an activation had been received'	  '      *         0 = no activation'	  '      *         1 = activation'	  '      * t     : the current time value'	  '      * u     : the vector inputs value'	  '      * nu    : the input  vector size'	  '      */']dcl=['     integer *flag,*nevprt,*nport;'     '     integer *nu;'     ''     '     double  *t, u[];'     '{'     '  int k;'];if standalone then  a_actuator=['  /* skeleton to be customized */'              '  switch (*flag) {'              '  case 2 : '              '    if(*nevprt>0) {/* get the input value */'              '       /* att_1_output */'              '    } '              '    break;'              '  case 4 : /* actuator initialisation */'              '    /* att_1_init */'              '    break;'              '  case 5 : /* actuator ending */'              '    /* att_1_end */'              '    break;'              '  }']else a_actuator=[]endnc=size(act,'*')Code=[]if nc==1|~standalone then  Code=[Call	comments	dcl	a_actuator	'}']elseif nc>1 then  S='  switch (*nport) {'  str1='att_1'  for k=1:nc    str2='att_'+string(k)    a_actuator=strsubst(a_actuator,str1,str2)    str1=str2    S=[S;       '  case '+string(k)+' :/* Port number '+string(k)+' ----------*/'       '  '+a_actuator       '  break;']  end  S=[S;'  }']    Code=[Code	Call	comments	dcl	S	'}']endendfunctionfunction Code=make_computational()//generates the scicos computational function associated with the block//Copyright INRIA//Author : Rachid Djenidinin=size(capt,1);if nin>0 then In='u'+string(1:nin);else In=[];endnout= size(actt,1);if nout then Out='y'+string(1:nout);else Out=[];end//function arg listArgs=['flag','nevprt','t','xd','x','nx','z','nz','tvec','ntvec','rpar',..      'nrpar','ipar','nipar']if In<>[]  then Args=[Args matrix([In ;'n'+In ],1,-1)],endif Out<>[] then Args=[Args matrix([Out;'n'+Out],1,-1)],end//integer argumentsIargs='*'+[Args([1 2 6 8 10 12:14])];if In<>[]  then Iargs=[Iargs '*n'+In] ,endif Out<>[] then Iargs=[Iargs '*n'+Out],end//double precision argumentsDargs='*'+[Args([3 4 5 7 9 11]),In,Out];Code=['/*'+part('-',ones(1,40))+' Block Computational function */ ';      'int ';      cformatline(rdnom+'('+strcat(Args,' ,')+')',70)      ''      cformatline('  integer '+strcat(Iargs,' ,')+';',70)      cformatline('  double  '+strcat(Dargs,' ,')+';' ,70)      ''      '{'      '  /*  block_outtb is catenated at the end of z*/'      '  double* block_outtb = z+'+string(nztotal)+';'      ''];     //copy inputsCode=[Code;      '  /*Copy inputs in the block outtb */'];for i=1:size(capt,1)   ni=capt(i,3) // dimension of ith input  Code=[Code;        '  block_outtb['+string(capt(i,2)-1+(0:ni-1)')+'] = u'+..	              string(capt(i,4))+'['+string(0:ni-1)'+'];';]endCode=[Code;      '   set_nevprt(*nevprt);';      ' '      '  if (*flag == 1) { /* update outputs */';      '    '+rdnom+'main1(z,t,rpar,nrpar,ipar,nipar);';      '  } ';      '  else if (*flag == 2) { /* update discrete states */';      '    '+rdnom+'main2(z,t,rpar,nrpar,ipar,nipar);';      '  } ';      '  else if (*flag == 4) { /* initialisation */';      '    '+rdnom+'_init(z,t,rpar,nrpar,ipar,nipar);';      '  } ';      '  else if (*flag == 5) { /* ending */';      '    '+rdnom+'_end(z,t,rpar,nrpar,ipar,nipar);';      '  } '];	                    //copy outputsfor i=1:size(actt,1)  ni=actt(i,3) // dimension of ith output  Code=[Code;	'  y'+string(actt(i,4))+'['+string(0:ni-1)'+'] =  block_outtb['+..                            string(actt(i,2)-1+(0:ni-1)')+'];']end//Assemble the codeCode=[Code;      '  return 0;'      ''      '} /* '+rdnom+' */']endfunctionfunction Code=make_decl()//generates  procedure declarations//Copyright INRIA//Author : Rachid Djenidi  Code=['/* SCILAB Computational function  */';	'/*     Copyright INRIA */';	'/*     Generated by Code_Generation toolbox of Scicos with '+ ..	getversion()+' */';	'/*     date : '+date(getdate())+' */';	''	'#include <stdio.h>';	'#include <string.h>';	'#include '"'+SCI+'/routines/machine.h'"';	'#include '"'+SCI+'/routines/sun/link.h'"';	'#include '"'+SCI+'/routines/scicos/scicos.h'"';	' ';	cformatline('void '+rdnom+'main1(double *z, double *t, '+..		    'double * rpar, int *nrpar, int *ipar, int *nipar);',70);	' ';	cformatline('void '+rdnom+'main2(double *z, double *t, '+..		    'double * rpar, int *nrpar, int *ipar, int *nipar) ;',70);	' ';	cformatline('void '+rdnom+'_init(double *z, double *t, '+..		    'double * rpar, int *nrpar, int *ipar, int *nipar) ;',70);	' ';	cformatline('void '+rdnom+'_end(double *z, double *t, '+..		    'double * rpar, int *nrpar, int *ipar, int *nipar) ;',70);	' ';	'int '+rdnom+'()  ;';	' ';	cformatline('int '+rdnom+'ddoit1(double *z, int * zptr, double *t, double"+...		    " *tevts, int *evtspt, int * nevts, int *pointi, int * outptr,"+...		    " int *clkptr, int *ordptr, int *ordclk, int *nordcl, double *"+...		    " rpar, int *ipar, int *funptr, int *funtyp, double *outtb, int"+...		    " *iwa)  ;',70);	' ';	cformatline('int '+rdnom+'ddoit2(double *z, int * zptr, double *t, double"+...		    " *tevts, int *evtspt, int * nevts, int *pointi, int * outptr,"+...		    " int *clkptr, int *ordptr, int *ordclk, int *nordcl, double *"+...		    " rpar, int *ipar, int *funptr, int *funtyp, double *outtb, int"+...		    " *iwa)  ;',70);	' ';	cformatline('int '+rdnom+'edoit1(double *z, int * zptr, double *t, double"+...		    " *tevts, int *evtspt, int * nevts, int *pointi, int * outptr,"+...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -