static void init(scicos_block *block) { char name[7]; int nch = GetNin(block); int nt = nch+1; MBX *mbx; rtRegisterScope(Getint8OparPtrs(block,1), (char**)&block->oparptr[1], nch); get_a_name(TargetMbxID,name); mbx = (MBX *) RT_typed_named_mbx_init(0,0,name,(MBX_RTAI_SCOPE_SIZE/(nt*sizeof(double)))*(nt*sizeof(double)),FIFO_Q); if(mbx == NULL) { fprintf(stderr, "Cannot init mailbox\n"); exit_on_error(); } *(block->work) = mbx; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void logic(scicos_block *block, int flag) { char *u = NULL, *y = NULL; char inp, num; int i = 0, nin = 0, nout = 0, mo = 0; char *opar = NULL; nin = GetNin(block); nout = GetNout(block); opar = Getint8OparPtrs(block, 1); mo = GetOparSize(block, 1, 1); if (flag == 1) { num = 0; for (i = 0; i < nin; i++) { u = Getint8InPortPtrs(block, i + 1); inp = *u; if (inp > 0) { inp = 1; } else { inp = 0; } inp = inp << i; num = num + inp; } for (i = 0; i < nout; i++) { y = Getint8OutPortPtrs(block, i + 1); *y = *(opar + num + i * mo); } } if (flag == 6) { u = Getint8InPortPtrs(block, 1); for (i = 0; i < nout; i++) { y = Getint8OutPortPtrs(block, i + 1); *y = *u; } } }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void gainblk_i8e(scicos_block *block, int flag) { if ((flag == 1) | (flag == 6)) { int i = 0, j = 0, l = 0, ji = 0, jl = 0, il = 0; char *u = NULL, *y = NULL; int mu = 0, ny = 0, my = 0, mo = 0, no = 0; char *opar = NULL; double k = 0., D = 0. , C = 0.; mo = GetOparSize(block, 1, 1); no = GetOparSize(block, 1, 2); mu = GetInPortRows(block, 1); my = GetOutPortRows(block, 1); ny = GetOutPortCols(block, 1); u = Getint8InPortPtrs(block, 1); y = Getint8OutPortPtrs(block, 1); opar = Getint8OparPtrs(block, 1); k = pow(2, 8) / 2; if (mo*no == 1) { for (i = 0; i < ny * mu; ++i) { D = (double)(opar[0]) * (double)(u[i]); if ((D >= k) | ( D < -k)) { sciprint(_("overflow error")); set_block_error(-4); return; } else { y[i] = (char)D; } } } else { for (l = 0; l < ny; l++) { for (j = 0; j < my; j++) { D = 0; jl = j + l * my; for (i = 0; i < mu; i++) { ji = j + i * my; il = i + l * mu; C = (double)(opar[ji]) * (double)(u[il]); D = D + C; } if ((D >= k) | ( D < -k)) { sciprint(_("overflow error")); set_block_error(-4); return; } else { y[jl] = (char)D; } } } } } }
static void end(scicos_block *block) { MBX *mbx = *(block->work); RT_named_mbx_delete(0, 0, mbx); printf("Scope %s closed\n", Getint8OparPtrs(block,1)); }