📄 rtaicodegen_.sci
字号:
" int *clkptr, int *ordptr, int *ordclk, int *nordcl, double *"+... " rpar, int *ipar, int *funptr, int *funtyp, double"+... " *outtb, int * urg, int *iwa, int *kiwa) ;',70); ' '; cformatline('int '+rdnom+'_initi(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+'_endi(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+'_outtb(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 C2F(putevs)(double *tevts, int *evtspt, int * nevts, int"+... " *pointi, double *told, int *i2, int *ierr);',70); '/* ---- block simulation functions -------*/' ' '];endfunctionfunction Code=make_decl_standalone()//generates procedure declarations//Copyright INRIA//Author : Rachid Djenidi//Modified for RTAI by Paolo Mantegazza (mantegazza@aero.polimi.it)//and Roberto Bucher (roberto.bucher@die.supsi.ch) Code=['/* Code prototype for standalone use */'; '/* Generated by Code_Generation toolbox of Scicos with '+ .. getversion()+' */'; '/* date : '+date(getdate())+' */'; '' cformatline('void '+rdnom+'main1(double *z, double *t, '+.. 'double * rpar, integer *nrpar,integer *ipar,integer *nipar);',70); ''; cformatline('void '+rdnom+'main2(double *z, double *t, '+.. 'double * rpar, integer *nrpar,integer *ipar,integer *nipar) ;',70); ''; cformatline('void '+rdnom+'_init(double *z, double *t, '+.. 'double * rpar, integer *nrpar,integer *ipar,integer *nipar) ;',70); ''; cformatline('void '+rdnom+'_end(double *z, double *t, '+.. 'double * rpar, integer *nrpar,integer *ipar,integer *"+... " nipar) ;',70); '' cformatline('void '+rdnom+'_const_update(double *z, double *t, '+.. 'double * rpar, integer *nrpar,integer *ipar,integer *"+... " nipar) ;',70); '' 'void set_nevprt(int nevprt);']endfunctionfunction Code=make_end()//Copyright INRIA//Author : Rachid Djenidi nordcl=size(ordclk,1); Code=['/*'+part('-',ones(1,40))+' end */ '; 'void ' cformatline(rdnom+'_end(double *z, double *t, double * rpar, '+.. 'integer *nrpar,integer *ipar,integer *nipar)',70); '{']; if size(pointi,1) <> 0 then Code($+1)=' integer pointi[ ]={'+strcat(string(pointi),",")+'};'; else Code($+1)=' integer pointi[1];'; end Code=[Code 'integer nordcl = '+string(nordcl)+';'; '' cformatline(' '+rdnom+'_endi(z, zptr, t, tevts, evtspt, nevts, pointi, '+.. 'outptr, clkptr, ordptr, ordclk, &nordcl, rpar, ipar, '+.. 'rdfunptr, funtyp, &(z['+string(size(z,1))+']), '+.. '(int *)(z+'+string(size(z,1)+size(outtb,1))+'));',70); '} ']; endfunctionfunction Code=make_init()//Copyright INRIA//Author : Rachid Djenidi nordcl=size(ordclk,1); Code=['/*'+part('-',ones(1,40))+' init */ '; 'void ' cformatline(rdnom+'_init(double *z, double *t, double * rpar, '+.. 'integer *nrpar,integer *ipar,integer *nipar)',70); '{']; if size(pointi,1) <> 0 then Code($+1)=' integer pointi[ ]={'+strcat(string(pointi),",")+'};'; else Code($+1)=' integer pointi[1];'; end Code=[Code; 'integer nordcl = '+string(nordcl)+';'; ' /*Block initializations*/' cformatline(' '+rdnom+'_initi(z, zptr, t, tevts, evtspt, nevts, '+.. 'pointi, outptr, clkptr, ordptr, ordclk, &nordcl, rpar, ipar, '+.. 'rdfunptr,funtyp, &(z['+string(size(z,1))+']), '+.. '(int *)(z+'+string(size(z,1)+size(outtb,1))+'));',70); ' /*Constants propagation*/' cformatline(' '+rdnom+'_outtb(z, zptr, t, tevts, evtspt, nevts, '+.. 'pointi, outptr, clkptr, ordptr, ordclk, &nordcl, rpar, ipar, '+.. 'rdfunptr,funtyp, &(z['+string(size(z,1))+']), '+.. '(int *)(z+'+string(size(z,1)+size(outtb,1))+'));',70); '} ']; endfunctionfunction Code=make_main1()//generate code for flag=1 case //Copyright INRIA//Author : Rachid Djenidi nordcl=size(ordclk,1); Code=['/*'+part('-',ones(1,40))+' main1 */ '; 'void ' cformatline(rdnom+'main1(double *z, double *t, double * rpar, '+.. 'integer *nrpar,integer *ipar,integer *nipar)',70); '{']; if size(pointi,1) <> 0 then Code($+1)=' integer pointi[ ]={'+strcat(string(pointi),",")+'};'; else Code($+1)=' integer pointi[1];'; end Code=[Code; 'integer nordcl = '+string(nordcl)+';'; '' cformatline(' '+rdnom+'ddoit1(z, zptr, t, tevts, evtspt, nevts, '+.. 'pointi, outptr, clkptr, ordptr, ordclk, &nordcl, rpar, ipar, '+.. 'rdfunptr, funtyp, &(z['+string(size(z,1))+']), '+.. '(int *)(z+'+string(size(z,1)+size(outtb,1))+'));',70); '} '];endfunctionfunction Code=make_main2()//generate code for flag=2 case//Copyright INRIA//Author : Rachid Djenidi nordcl=size(ordclk,1); Code=['/*'+part('-',ones(1,40))+' main2 */ '; 'void ' cformatline(rdnom+'main2(double *z, double *t, double * rpar, '+.. 'integer *nrpar,integer *ipar,integer *nipar)',70); '{']; if size(pointi,1) <> 0 then Code($+1)=' integer pointi[ ]={'+strcat(string(pointi),",")+'};'; else Code($+1)=' integer pointi[1];'; end Code=[Code; 'integer nordcl = '+string(nordcl)+';'; '' cformatline(' '+rdnom+'ddoit2(z, zptr, t, tevts, evtspt, nevts, '+.. 'pointi, outptr, clkptr, ordptr, ordclk, &nordcl, rpar, '+.. 'ipar, rdfunptr, funtyp, &(z['+string(size(z,1))+']), '+.. '(int *)(z+'+string(size(z,1)+size(outtb,1))+'));',70); '} ']; endfunctionfunction Code=make_outevents()//generates skeleton of external world events handling function z='0' if szclkIN==[] then newszclkIN=0; else newszclkIN=szclkIN; end Code=[ '/*'+part('-',ones(1,40))+' External events handling function */ '; 'void ' rdnom+'_events(int *nevprt,double *t)'; '{' '/* set next event time and associated events ports ' ' * nevprt has binary expression b1..b'+string(newszclkIN)+' where bi is a bit ' ' * bi is set to 1 if an activation is received by port i. Note that' ' * more than one activation can be received simultaneously ' ' * Caution: at least one bi should be equal to one */' '' ' int i,p,b[]={'+strcat(z(ones(1,newszclkIN)),',')+'};' '' '/* this is an example for the activation of events ports */' ' b[0]=1;'] if newszclkIN>1 then for bb=2:newszclkIN Code($+1)=' b['+string(bb-1)+']=1;' end end Code=[Code;' ' '/* definition of the step time */' ' *t = *t + 0.1;' ' ' '/* External events handling process */' ' *nevprt=0;p=1;' ' for (i=0;i<'+string(newszclkIN)+';i++) {' ' *nevprt=*nevprt+b[i]*p;' ' p=p*2;}' '}']endfunctionfunction Code=make_sensor(standalone)// Generating the routine for sensors interfacing//Copyright INRIA//Author : Rachid Djenidi//Modified for RTAI by Roberto Bucher (roberto.bucher@die.supsi.ch) Call=['/*'+part('-',ones(1,40))+' Sensor */ '; 'void '; rdnom+'_sensor(flag,nport,nevprt,t,y,ny)']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' ' * y : the vector outputs value' ' * ny : the output vector size' ' */']dcl=[' integer *flag,*nevprt,*nport;' ' integer *ny;' '' ' double *t, y[];' '{' ' int k;'];if standalone then a_sensor=[' switch (*flag) {' ' case 1 : /* set the ouput value */' ' /* sens_1_input */' ' break;' ' case 2 : /* Update internal discrete state if any */' ' /* sens_1_update */' ' break;' ' case 4 : /* sensor initialisation */' ' /* sens_1_init */' ' break;' ' case 5 : /* sensor ending */' ' /* sens_1_end */' ' break;' ' }']else a_sensor=[]endnc=size(cap,'*')Code=[]if nc==1|~standalone then Code=[Code; Call comments dcl a_sensor '}'];elseif nc>1 then S=' switch (*nport) {' str1='sens_1' for k=1:nc str2='sens_'+string(k) a_sensor=strsubst(a_sensor,str1,str2) str1=str2 S=[S; ' case '+string(k)+' : /* Port number '+string(k)+' ----------*/' ' '+a_sensor ' break;'] end S=[S;' }'] Code=[Code Call comments dcl S '}']endendfunctionfunction Code=make_standalone()//generates code of the standalone simulation procedure//Copyright INRIA//Author : Rachid Djenidi//Modified for RTAI by Paolo Mantegazza (mantegazza@aero.polimi.it)//and Roberto Bucher (roberto.bucher@die.supsi.ch)//Generates simulation routine for standalone simulation iwa=zeros(clkptr($),1),Z=[z;outtb;iwa]';Code=[ '' cformatline('static double z[]={'+strcat(string(Z),',')+'};',70) ''] '' Code=[Code; '/*'+part('-',ones(1,40))+' Lapack messag function */ '; 'void' 'C2F(xerbla)(SRNAME,INFO,L)' 'char *SRNAME;' 'int *INFO;' 'long int L;' '{' 'printf(""** On entry to %s, parameter number %d had an illegal value\n"",SRNAME,*INFO);' '}' '' '#include ""'+rdnom+'_io.c""']endfunctionfunction Code=make_static()//generates static table definitions//Copyright INRIA//Author : Rachid Djenidi z=cpr.state.z; tevts=cpr.state.tevts;evtspt=cpr.state.evtspt; nevts=size(evtspt,1); zptr=cpr.sim.zptr; outptr=cpr.sim.outptr; funtyp=cpr.sim.funtyp; clkptr=cpr.sim.clkptr;ordptr=cpr.sim.ordptr; ordclk=cpr.sim.ordclk;nordcl=size(ordclk,1); funs=cpr.sim.funs; Code= ['/* Table of constant values */ '; ' '; 'static integer totalnevprt; ']; if size(evtspt,1) <> 0 then Code=[Code;cformatline('static integer evtspt[ ]={'+.. strcat(string(evtspt),",")+'};',70)] else Code($+1)='static integer evtspt[1];'; end if size(nevts,1) <> 0 then Code=[Code;cformatline('static integer nevts[ ]={'+.. strcat(string(nevts),",")+'};',70)] else Code($+1)='static integer nevts[1];'; end Code($+1)='static double x[1];'; if size(zptr,1) <> 0 then Code=[Code;cformatline('static integer zptr[ ]={'+.. strcat(string(zptr),",")+'};',70)] else Code($+1)='static integer zptr[1];'; end if size(clkptr,1) <> 0 then Code=[Code;cformatline('static integer clkptr[ ]={'+.. strcat(string(clkptr),",")+'};',70)] else Code($+1)='static integer clkptr[1];'; end if size(ordptr,1) <> 0 then Code=[Code;cformatline('static integer ordptr[ ]={'+.. strcat(string(ordptr),",")+'};',70)] else Code($+1)='static integer ordptr[1];'; end if size(ordclk,1) <> 0 then Code=[Code;cformatline('static integer ordclk[ ]={'+.. strcat(string(ordclk),",")+'};',70)] else Code($+1)='static integer ordclk [1];'; end if size(outptr,1) <> 0 then Code=[Code;cformatline('static integer outptr[ ]={'+.. strcat(string(outptr),",")+'};',70)] else Code($+1)='static integer outptr[1];'; end if size(tevts,1) <> 0 then Code=[Code;cformatline('static double tevts[ ] = {'+.. strcat(string(tevts),",")+'};',70)] else Code($+1)='static double tevts[1];'; end if length(funs) <> 0 then Code=[Code;cformatline('static integer rdfunptr[ ]={'+.. strcat(string(1:length(funs)),",")+'};',70)] else Code($+1)='static integer rdfunptr[1];'; end if size(funtyp,1) <> 0 then Code=[Code;cformatline('static integer funtyp[ ]={'+.. strcat(string(funtyp),",")+'};',70)] else Code($+1)='static integer funtyp[1];'; end Code($+1)='static double w[1];' Code=[Code; 'void set_nevprt(int nevprt)' '{' ' totalnevprt=nevprt;' '}']endfunctionfunction Code=make_static_standalone()//generates static table definitions//Copyright INRIA//Author : Rachid Djenidi// Modified for RTAI by Roberto Bucher (roberto.bucher@die.supsi.ch) rpar=cpr.sim.rpar;ipar=cpr.sim.ipar; nrpar=size(rpar,1);nipar=size(ipar,1); RCode=[];nbrpa=0;strRCode='';lenRCode=[];ntot_r=0; if size(rpar,1) <> 0 then RCode=[RCode;'static double RPAR1[ ] = {']; par_len = length(rpptr)-1; for i=1:par_len if rpptr(i+1)-rpptr(i)>0 then if size(corinv(i),'*')==1 then OO=scs_m.objs(corinv(i)); else path=list('objs'); for l=cpr.corinv(i)(1:$-1),path($+1)=l;path($+1)='model';path($+1)='rpar';path($+1)='objs';end path($+1)=cpr.corinv(i)($); OO=scs_m(path); end aaa=OO.gui;bbb=emptystr(3,1); if and(aaa+bbb~= ['INPUTPORTEVTS'; ... 'OUTPUTPORTEVTS';'EVTGEN_f']) then nbrpa=nbrpa+1; ntot_r = ntot_r + (rpptr(i+1)-rpptr(i)); RCode($+1)='/* Routine name of block: '+strcat(string(cpr.sim.funs(i))); RCode($+1)=' Gui name of block: '+strcat(string(OO.gui)); if stripblanks(OO.model.label)~=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -