void FILE_READEROBJ::work(void) { int x,d; float f; char tmp[2],tmp1[256]; DWORD dwRead; int s_int; unsigned int u_int; if ((outports==0)||(state==0)||(file==INVALID_HANDLE_VALUE)) return; if (format<5) { for (x=0;x<outports;x++) { tmp1[0]=0;tmp[1]=0; do { tmp[0]=0; ReadFile(file,tmp,1,&dwRead,NULL); if (((tmp[0]>='0')&&(tmp[0]<='9'))||(tmp[0]=='.')||(tmp[0]=='-')) strcat(tmp1,tmp); } while ((tmp[0]!=0) && (tmp[0]!=13)&&(tmp[0]!=9)&&(tmp[0]!=',')); tmp1[strlen(tmp1)]=0; if ((format==2)||(format==3)||(format==4)) { // SetDlgItemText(ghWndStatusbox,IDC_STATUS,tmp1); sscanf(tmp1,"%f",&f); if (format==4) pass_values(x,f*1000000); else pass_values(x,f); } else { sscanf(tmp1,"%d",&d); pass_values(x,(float)d); } } } else { ReadFile(file,tmp1,2,&dwRead,NULL); if (format==5) { s_int= (tmp1[1]<<8) + tmp1[0]; f=(float)(s_int); } else { u_int= (tmp1[1]<<8) + tmp1[0]; f=(float)(u_int); } pass_values(0,f); } }
void TRANSLATEOBJ::work(void) { int index; if (input==INVALID_VALUE) {pass_values(0,INVALID_VALUE); return; } if (in_ports[0].in_max!=in_ports[0].in_min) index=(int)((input-in_ports[0].in_min)/(in_ports[0].in_max-in_ports[0].in_min)*1023.0f); if (index<0) index=0; if(index>1023) index=1023; pass_values(0,map[index]*(out_ports[0].out_max-out_ports[0].out_min)+out_ports[0].out_min); }
void BUTTONOBJ::work(void) { switch (buttonfunction) { case BUTTONFUNCTION_VAL1VAL2: if (state==STATE_PRESSED) { pass_values(0,value1); state=STATE_IDLE; } else pass_values(0,value2); break; case BUTTONFUNCTION_VAL1INV: if (state==STATE_PRESSED) { pass_values(0,value1); state=STATE_IDLE; } else pass_values(0,INVALID_VALUE); break; case BUTTONFUNCTION_TOGGLEVAL: if (togglecount) pass_values(0,value1); else pass_values(0,value2); break; case BUTTONFUNCTION_TOGGLE1SEC: if ((togglecount) && (togglecount<PACKETSPERSECOND)) { pass_values(0,value1); togglecount++; if (togglecount>=PACKETSPERSECOND) togglecount=0; } else { pass_values(0,value2); } break; } }
void BALLGAMEOBJ::work(void) { if (GLOBAL.fly) return; if (state==0) { rpos=input+adjust_r; xpos+=xspeed*speed/50.0f; if ((xpos>100)||(xpos<0)) {xspeed=-xspeed; xpos+=xspeed*speed/50.0f; pass_values(0,30);} ypos+=yspeed*speed/50.0f;if (ypos<0) {yspeed=-yspeed; ypos+=yspeed*speed/50.0f; pass_values(0,30);} if (ypos>93) { if ((xpos>(rpos-5))&&(xpos<rpos+racket)) { yspeed=-yspeed; // xspeed=((rand()%50)-25)/100.0f; xspeed=(xpos-(rpos+racket/2))/50.0f; if (xspeed>0.3f) xspeed=0.3f;if (xspeed<-0.3f) xspeed=-0.3f; xspeed+=((rand()%50)-25)/500.0f; ypos+=yspeed*speed/50.0f; points++; if (points>best) { best=points; pass_values(0,100); } else pass_values(0,70); } else { state=1;points=0; pass_values(0,20); } } } if (state>0) { state++; if (state==512) { state=0; xpos=50; ypos=50; xspeed=0; yspeed=0.2f; if (reset_middle) adjust_r= -input+50-racket/2; } } if ((displayWnd)&&(!TIMING.draw_update)) { InvalidateRect(displayWnd,NULL,FALSE); } }
void FILTEROBJ::work(void) { float x; x=(float)(funcp(fbuf,(double)input)); // if ((filtertype==2)||(filtertype==3)||(filtertype==6)||(filtertype==7)) x+=512.0f; pass_values(0,x); }
void COUNTEROBJ::work(void) { switch (mode) { case 0: if ((oldinput==INVALID_VALUE) && (input!=INVALID_VALUE)) countervalue++; break; case 1: if ((oldinput!=INVALID_VALUE) && (input==INVALID_VALUE)) countervalue++; break; case 2: countervalue=input; break; case 3: if ((oldinput==INVALID_VALUE) && (input!=INVALID_VALUE)) { period=TIMING.acttime-prev_time; prev_time=TIMING.acttime; countervalue=(float)TIMING.pcfreq/(float)period; } if (period*2<TIMING.acttime-prev_time) countervalue=0; break; } pass_values(0,countervalue); if ((displayWnd)&&(!TIMING.draw_update)) { InvalidateRect(displayWnd,NULL,FALSE); } }
// Common interface of pascal and worker // ----------------------------------------------------- // Arguments: // id -- identifier of the process // (0 for pascal, 1..n for worker) // left[0] -- read end of the pipe leading from the previous process // left[1] -- write end of the pipe leading to the previous process // right[0], right[1] -- as above, but the next process // if there is no previous/next process, left/right is NULL // // Postcondition: // function closes left[0..1], right[0..1] void worker(int id, int left[2], int right[2]) { uint64_t value = 1, recv; for(int iter = 1; true; ++iter) { switch(read(left[0], &recv, sizeof(recv))) { case -1: syserr("Worker %d: Unable to read", id); case 0: // EOF: pass values, close pipes and return if(right != NULL && -1 == close(right[1])) syserr("Worker %d: Unable to close", id); if(-1 == write(left[1], &value, sizeof(value))) syserr("Worker %d: Unable to write", id); if(right != NULL) { pass_values(id, right[0], left[1]); if(-1 == close(right[0])) syserr("Worker %d: Unable to close", id); } if(-1 == close(left[0]) || -1 == close(left[1])) syserr("Worker %d: Unable to close", id); return; default: value += recv; if(id + iter != n && right != NULL && -1 == write(right[1], &value, sizeof(value))) syserr("Worker %d: Unable to write", id); } } }
void KEYCAPTUREOBJ::work(void) { if (mode==0) pass_values(0, GLOBAL.pressed_key); else if (mode==1) { if (GLOBAL.pressed_key == findcode) pass_values(0, replacecode); else pass_values(0, 0); } if ((!TIMING.dialog_update) && (hDlg==ghWndToolbox)) { SetDlgItemInt(hDlg, IDC_ACTKEY, GLOBAL.pressed_key, 0); } }
void SAMPLE_HOLDOBJ::work(void) { if ((mode==1) && (trigger!=INVALID_VALUE) && (old_value==INVALID_VALUE)) hold=act; if ((mode==2) && (trigger==INVALID_VALUE)&& (old_value!=INVALID_VALUE)) hold=act; pass_values(0, hold); }
void EDF_READEROBJ::work(void) { int x; // short actval; double actval; char szdata[100]; double fact; DWORD dwRead; if ((outports==0)||(state!=2)||(edffile==INVALID_HANDLE_VALUE)) return; if ((TIMING.packetcounter<offset)||(TIMING.packetcounter>sessionlength)) return; if (sampos<header.samplespersegment-1) { for (x=0; x<outports; x++) { actval=channel[x].buffer[sampos]; if (channel[x].samples==1) actval=channel[x].buffer[0]; fact=(channel[x].physmax-channel[x].physmin)/(double)(channel[x].digmax-channel[x].digmin); actval-=channel[x].digmin; // actval=(int)(actval*fact); actval=actval*fact; pass_values(x,(float)actval+channel[x].physmin); } sampos++; packetcount++; if (((int)(packetcount/1000))*1000==packetcount) { sprintf(szdata,"%d Packets read\n",packetcount); if (hDlg==ghWndToolbox) add_to_listbox(hDlg,IDC_LIST, szdata); } } else { sampos=0; for (x=0; x<outports; x++) { ReadFile(edffile,channel[x].buffer,(DWORD)(2*channel[x].samples),&dwRead,NULL); if (dwRead<(DWORD)2*channel[x].samples) { // session_pos(0); packetcount=0; sampos=header.samplespersegment; x=outports; } } } }
void NEUROBITOBJ::work(void) { DWORD dwWritten,dwRead; if ((filehandle!=INVALID_HANDLE_VALUE) && (filemode == FILE_READING)) ReadFile(filehandle,current_chn,sizeof(float)*4, &dwRead, NULL); pass_values(0, current_chn[0]); pass_values(1, current_chn[1]); pass_values(2, current_chn[2]); pass_values(3, current_chn[3]); if ((filehandle!=INVALID_HANDLE_VALUE) && (filemode == FILE_WRITING)) WriteFile(filehandle,current_chn,sizeof(float)*4, &dwWritten, NULL); if ((!TIMING.dialog_update) && (hDlg==ghWndToolbox)) { InvalidateRect(hDlg,NULL,FALSE); } }
void MAGNITUDEOBJ::work(void) { float sig1,sig2; sig1=(float)sin(TIMING.packetcounter*2*DDC_PI/PACKETSPERSECOND*center)*(input); sig2=(float)cos(TIMING.packetcounter*2*DDC_PI/PACKETSPERSECOND*center)*(input); sig1= (float)(lp1funcp(lp1fbuf,sig1)); sig2= (float)(lp2funcp(lp2fbuf,sig2)); pass_values(0,(float)(2*sqrt(sig1*sig1+sig2*sig2)*gain/100.0f)); }
void SIGNALOBJ::work(void) { float x,s,g; angle+=frequency/PACKETSPERSECOND*2*(float)DDC_PI; if (angle>(float)(DDC_PI*2.0f)) angle-=(float)(DDC_PI*2.0f); // s=(float)sin((float)(TIMING.packetcounter+phase*PACKETSPERSECOND/720)/PACKETSPERSECOND*2*DDC_PI*frequency); //s=(float)sin((angle+phase/360)*2*DDC_PI); s=(float)sin(angle+(phase/360)*2*DDC_PI); g=gain/1000.0f*out_ports[0].out_max; switch (sigtype) { case SIG_SINUS: x=s*g; break; case SIG_SAWTOOTH: x=(float)asin(s)*g*0.625f; break; case SIG_RECTANGLE: if (s>0) x=g; else x=-g; break; case SIG_RAMP: x=(float)((angle-DDC_PI)/DDC_PI*g); { char tmp[20]; sprintf(tmp,"%.2f",angle); SetDlgItemText(ghWndStatusbox,IDC_STATUS,tmp); } break; } if (noise) x+=(float)(rand()%noise-noise/2); if ((!TIMING.dialog_update) && (hDlg==ghWndToolbox) && (enable_in)) { char sztemp[25]; sprintf(sztemp,"%.2f",frequency); SetDlgItemText(hDlg, IDC_FREQUENCY,sztemp); SetScrollPos(GetDlgItem(hDlg, IDC_FREQUENCYBAR), SB_CTL, (int)(frequency*100.0f), 1); sprintf(sztemp,"%.2f",phase); SetDlgItemText(hDlg, IDC_PHASE,sztemp); SetScrollPos(GetDlgItem(hDlg, IDC_PHASEBAR), SB_CTL, (int)(phase), 1); } pass_values(0,x+center); }
void NOTOBJ::work(void) { float value; if (!binary) { if (input == INVALID_VALUE) value = TRUE_VALUE; else value = INVALID_VALUE; } else { value=(float) ( ((int)input) ^ bits ); } pass_values(0, value); }
void EVALOBJ::work(void) { static char *names[] = {"A", "B", "C", "D", "E", "F"}; static double values[NUMINPUTS]; double result=INVALID_VALUE; if ((evaluator != NULL)&&(!setexp)) { values[0] = inputA; values[1] = inputB; values[2] = inputC; values[3] = inputD; values[4] = inputE; values[5] = inputF; result = evaluator_evaluate(evaluator, NUMINPUTS, names, values); } pass_values(0, (float)result); }
void MIXER4OBJ::work(void) { int valid =0; float result=0; if (input1 != INVALID_VALUE) { valid++; result+=input1*chn1vol/100.0f; } if (input2 != INVALID_VALUE) { valid++; result+=input2*chn2vol/100.0f; } if (input3 != INVALID_VALUE) { valid++; result+=input3*chn3vol/100.0f; } if (input4 != INVALID_VALUE) { valid++; result+=input4*chn4vol/100.0f; } if (invmode==1) if ( ((chn1vol!=0) && (input1==INVALID_VALUE)) && ((chn2vol!=0) && (input2==INVALID_VALUE)) && ((chn3vol!=0) && (input3==INVALID_VALUE)) && ((chn4vol!=0) && (input4==INVALID_VALUE)) ) result=INVALID_VALUE; if (invmode==2) if ( ((chn1vol!=0) && (input1==INVALID_VALUE)) || ((chn2vol!=0) && (input2==INVALID_VALUE)) || ((chn3vol!=0) && (input3==INVALID_VALUE)) || ((chn4vol!=0) && (input4==INVALID_VALUE)) ) result=INVALID_VALUE; // if (valid) result/=valid; pass_values(0, result); }
void TCP_RECEIVEOBJ::work(void) { int x; if ((outports==0)||(watching==FALSE)) return; if (watch_tcp(watchbuf,sizeof(watchbuf))==TCP_ERROR) { if (hDlg==ghWndToolbox) add_to_listbox(hDlg,IDC_LIST, "--WATCH-ERROR---"); } if (bufend!=bufstart) { for (x=0;x<outports;x++) pass_values(x,(float)channel[x].buffer[bufstart]); if (++bufstart>=samplebuflen) bufstart=0; //bufstart=bufend; } if ((!TIMING.dialog_update) && (hDlg==ghWndToolbox)) { SetDlgItemInt(hDlg, IDC_STATUS, syncloss, 0); } }
void CAMOBJ::work(void) { char sztemp[255]; if ((hDlg==ghWndToolbox) && (!TIMING.dialog_update)) { sprintf(sztemp,"Distance=%.2f, Angle=%.2f, Time=%d",dist_error,angle_error,time_to_restore); SetDlgItemText(hDlg,IDC_CAMSTATUS,sztemp); SetDlgItemInt(hDlg,IDC_CUR_RATE,cur_rate,0); } if (trackface) { if ((!need_to_init)&&(init_flag>0)) { pass_values(0, x_move); pass_values(1, y_move); pass_values(2, x_click); pass_values(3, y_click); } else { // pass_values(0, 0); // pass_values(1, 0); // pass_values(2, 0); // pass_values(3, 0); } } else { pass_values(0, x_move); pass_values(1, y_move); } }
void DEVIATIONOBJ::work(void) { pass_values(0, deviation); pass_values(1, mean); }
void CONSTANTOBJ::work(void) { pass_values(0, value); }
void INTEGRATEOBJ::work(void) { if (max!=min) { if (i_value>max) i_value=max; if (i_value<min) i_value=min; } pass_values(0, i_value); }
void DIFFERENTIATEOBJ::work(void) { pass_values(0, difference); }
void THRESHOLDOBJ::work(void) { float l,x,sum; int t,i; x=(float)((input)*signal_gain/100.0); l=accu[accupos]; avgsum+=x; // (float)input; if ((accupos>=999)||(accupos<0)) accupos=0; else accupos++; accu[accupos]=x; sum=0; for (t=0;t<interval_len;t++) { i=accupos-t; if (i<0) i+=1000; sum+=accu[i]; } gained_value=sum/interval_len; long interval=adapt_interval; if ((baseline) && (!usemedian)) { interval*=PACKETSPERSECOND; } if (adapt_num >= interval) { if (usemedian) { int numtrue, i, sum; if (bigadapt != 0) { numtrue = (int)(adapt_num * bigadapt / 100.0f); for (i = 1024, sum = 0; (i >= 0) && (sum < numtrue); i--) { sum += buckets[i]; } from_input = size_value(0.0f,1024.0f,(float)i,in_ports[0].in_min,in_ports[0].in_max,0); redraw=1; } if (smalladapt != 0) { numtrue = (int)(adapt_num * smalladapt / 100.0f); for (i = 0, sum = 0; (i <= 1024) && (sum < numtrue); i++) { sum += buckets[i]; } to_input = size_value(0.0f,1024.0f,(float)i,in_ports[0].in_min,in_ports[0].in_max,0); redraw=1; } empty_buckets(); } else { if ((!baseline) || (firstadapt)) { if (bigadapt != 0) { from_input = avgsum/interval*bigadapt/100.0f; redraw=1; } if (smalladapt != 0) { to_input = avgsum/interval*smalladapt/100.0f; redraw=1; } firstadapt=0; } } adapt_num=0; avgsum=0; } x=gained_value; if (rising&&(l>=accu[accupos])) x=INVALID_VALUE; if (falling&&(l<=accu[accupos])) x=INVALID_VALUE; if (op&&((gained_value<from_input)||(gained_value>to_input))) x=INVALID_VALUE; if ((!op)&&((gained_value<from_input)&&(gained_value>to_input))) x=INVALID_VALUE; if (baseline && firstadapt) x=INVALID_VALUE; pass_values(0,x); if ((hDlg==ghWndToolbox)&&(!TIMING.dialog_update)) { char temp[100]; sprintf(temp,"%.2f",from_input); SetDlgItemText(hDlg, IDC_AVGFROM, temp); sprintf(temp,"%.2f",to_input); SetDlgItemText(hDlg, IDC_AVGTO, temp); if (smalladapt) SetScrollPos(GetDlgItem(hDlg,IDC_AVGTOBAR), SB_CTL,(int) size_value(in_ports[0].in_min,in_ports[0].in_max, to_input,0.0f,1000.0f,0),TRUE); if (bigadapt) SetScrollPos(GetDlgItem(hDlg,IDC_AVGFROMBAR), SB_CTL,(int) size_value(in_ports[0].in_min,in_ports[0].in_max, from_input ,0.0f,1000.0f,0),TRUE); } if ((displayWnd)&&(!TIMING.draw_update)&&(!GLOBAL.fly)) InvalidateRect(displayWnd,NULL,FALSE); }
void ROUNDOBJ::work(void) { pass_values(0, round); }