void Test1Byte( void ) /*FOLD00*/ { uint32_t responce; uint32_t reslen = 4096; int n; uint32_t sec = time(NULL); while( (sec+5) > time(NULL) ) //for( n = 0; n < 10000; n++ ) { SetTick( l.start ); if( !TransactServerMessage( l.MsgBaseClient + MSG_Test1 , l.data, 1 , &responce, l.data_in, &reslen ) ) { printf( WIDE("Transact message generally failed - suppose that's a timeout.\n") ); } else { if( responce & 0x80000000 ) lprintf( WIDE("Responce was faillure from the server...") ); else { uint64_t del; SetTick( l.end ); l.accum += (del = l.end - l.start); l.passes++; l.bytes += reslen; if( (!l.min) || (del < l.min) ) l.min = del; if( del > l.max ) l.max = del; l.waiting = 0; } } } DumpStats(); }
void TCPTest1000Byte( void ) { int n; uint32_t sec = time(NULL); while( (sec+5) > time(NULL) ) //for( n = 0; n < 10000; n++ ) { l.waiting = 1; SetTick( l.start ); SendTCP( l.pClient, l.data, 1000 ); // have to wait here until the responce is received. while( l.waiting ) Relinquish(); } DumpStats(); }
void CPROC ClientReadComplete( PCLIENT pc, POINTER buffer, int len ) { if( !buffer ) { buffer = Allocate( 4096 ); } else { uint64_t del; SetTick( l.end ); l.accum += (del = l.end - l.start); l.passes++; l.bytes += len; if( (!l.min) || ( del < l.min ) ) l.min = del; if( del > l.max ) l.max = del; l.waiting = 0; } ReadTCP( pc, buffer, 4096 ); }
void CPlotDlg::OnMenu(UINT nID) { static char fullfname[MAX_PATH]; static CAxis *axSpec(NULL); CAxis *localax(gcf->ax[0]); // Following the convention CRect rt; CSize sz; CFont editFont; CPosition pos; double range, miin(1.e15), maax(-1.e15); double width, newmin, newmax; int i, len, id1, id2, iSel(-1); char errstr[256]; CSignals signal; bool multi; static void *playPoint; switch (nID) { case IDM_FULLVIEW: localax->setRange('x',localax->m_ln[0]->xdata[0], localax->m_ln[0]->xdata[localax->m_ln[0]->len-1]); localax->setTick('x', 0, localax->m_ln[0]->xdata[localax->m_ln[0]->len-1]/10, 1, 0, "%6.3f"); // 2/3/2011, commented out by jhpark, because y axis is not affected by zooming. //localax->setRange('y', -1, 1); OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_ZOOM_IN: width = localax->xlim[1] - localax->xlim[0]; if (width<0.005) return; localax->setRange('x', localax->xlim[0] + width/4., localax->xlim[1] - width/4.); width = localax->xtick.a2 - localax->xtick.a1; localax->xtick.a2 -= width/4.; localax->xtick.a1 += width/4.; OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_ZOOM_OUT: if (localax->xlim[1]==localax->xlimFull[1] && localax->xlim[0]==localax->xlimFull[0]) return; for (i=0; i<localax->nLines; i++) miin = min(miin, getMin(localax->m_ln[i]->len, localax->m_ln[i]->xdata)); for (i=0; i<localax->nLines; i++) maax = max(maax, getMax(localax->m_ln[i]->len, localax->m_ln[i]->xdata)); width = localax->xlim[1] - localax->xlim[0]; localax->setRange('x', max(miin,localax->xlim[0] - width/2.), min(maax,localax->xlim[1] + width/2.)); width = localax->xtick.a2 - localax->xtick.a1; //Oh, I just realized that a1 and a2 do not need to be within the range==> no need to check, it will still draw the ticks only within the range. localax->xtick.a2 += width/2.; localax->xtick.a1 -= width/2.; if (localax->xtick.a1<0) localax->xtick.a1=0; OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_SCROLL_LEFT: for (i=0; i<localax->nLines; i++) miin = min(miin, getMin(localax->m_ln[i]->len, localax->m_ln[i]->xdata)); range = localax->xlim[1] - localax->xlim[0]; newmin = max(miin, localax->xlim[0]-range); localax->setRange('x', newmin, newmin+range); rt = localax->axRect; rt.InflateRect(5,0,5,30); InvalidateRect(&rt); OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_SCROLL_RIGHT: for (i=0; i<localax->nLines; i++) maax = max(maax, getMax(localax->m_ln[i]->len, localax->m_ln[i]->xdata)); range = localax->xlim[1] - localax->xlim[0]; newmax = min(maax, localax->xlim[1]+range); localax->setRange('x', newmax-range, newmax); rt = localax->axRect; rt.InflateRect(5,0,5,30); InvalidateRect(&rt); OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_LEFT_STEP: for (i=0; i<localax->nLines; i++) miin = min(miin, getMin(localax->m_ln[i]->len, localax->m_ln[i]->xdata)); range = localax->xlim[1] - localax->xlim[0]; newmin = max(miin, localax->xlim[0]-range/4.); localax->setRange('x', newmin, newmin+range); rt = localax->axRect; rt.InflateRect(5,0,5,30); InvalidateRect(&rt); OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_RIGHT_STEP: for (i=0; i<localax->nLines; i++) maax = max(maax, getMax(localax->m_ln[i]->len, localax->m_ln[i]->xdata)); range = localax->xlim[1] - localax->xlim[0]; newmax = min(maax, localax->xlim[1]+range/4.); localax->setRange('x', newmax-range, newmax); rt = localax->axRect; rt.InflateRect(5,0,5,30); InvalidateRect(&rt); OnMenu(IDM_SPECTRUM_INTERNAL); return; case IDM_PLAY: errstr[0]=0; if (!playing) if(!GetSignalInRange(signal,1)) MessageBox (errStr); else { playPoint = signal.PlayArray(devID, WM__SOUND_EVENT, hDlg, &block, errstr); playing = true; } else { PauseResumePlay(playPoint, paused); playing = paused; if (paused) paused = false; } return; case IDM_PAUSE: errstr[0]=0; if (playing) { PauseResumePlay(playPoint, false); paused = true; } return; case IDM_SPECTRUM: // To draw a spectrum, first re-adjust the aspect ratio of the client window // so that the width is at least 1.5 times the height. if (!specView) { GetWindowRect(&rt); sz = rt.Size(); if (sz.cx<3*sz.cy/2) { rt.InflateRect(0, 0, 3*sz.cy/2, 0); MoveWindow(&rt, 0); } //Again, //Assuming that the first axis is the waveform viewer, the second one is for spectrum viewing lastPos = gcf->ax[0]->pos; gcf->ax[0]->setPos(.08, .1, .62, .8); axSpec = gcf->axes(.75, .3, .22, .4); axSpec->colorBack = RGB(230, 230, 190); OnMenu(IDM_SPECTRUM_INTERNAL); } else { deleteObj(axSpec); axSpec=NULL; gcf->ax[0]->setPos(lastPos); } specView = !specView; break; case IDM_SPECTRUM_INTERNAL: rfftw_plan plan; double *freq, *fft, *mag, *fft2, *mag2, fs, maxx, maxmag, ylim; multi = localax->nLines>1 ? true : false; if (gcf->nAxes==1) break; fs = (double)sig.GetFs(); for (; gcf->ax[1]->nLines>0;) deleteObj(gcf->ax[1]->m_ln[0]); GetIndicesInRange(localax, id1, id2); len = id2-id1+1; freq = new double[len]; fft = new double[len]; mag = new double[len/2]; for (i=0; i<len; i++) freq[i]=(double)i/(double)len*fs; plan = rfftw_create_plan(len, FFTW_FORWARD, FFTW_ESTIMATE|FFTW_OUT_OF_PLACE); rfftw_one(plan, &localax->m_ln[0]->ydata[id1], fft); if (multi) { fft2 = new double[len]; mag2 = new double[len/2]; rfftw_one(plan, &localax->m_ln[1]->ydata[id1], fft2); } rfftw_destroy_plan(plan); for (i=0; i<len/2; i++) mag[i] = 20.*log10(fabs(fft[len-i])); if (multi) for (i=0; i<len/2; i++) mag2[i] = 20.*log10(fabs(fft2[len-i])); maxmag = getMax(len/2,mag); maxx = 5.*(maxmag/5.+1); for (int j=0; j<len/2; j++) mag[j] -= maxx; if (multi) { maxmag = getMax(len/2,mag2); maxx = 5.*(maxmag/5.+1); for (int j=0; j<len/2; j++) mag2[j] -= maxx; } ylim = 10.*(maxmag/10.+1)-maxx; PlotDouble(gcf->ax[1], len/2, freq, mag); SetRange(gcf->ax[1], 'x', 0, fs/2); SetTick(gcf->ax[1], 'x', 0, 1000, 0, 0, "%2.0lfk", 0.001); SetRange(gcf->ax[1], 'y', getMean(len/2,mag)-40, ylim); SetTick(gcf->ax[1], 'y', 0, 10); gcf->ax[1]->m_ln[0]->color = gcf->ax[0]->m_ln[0]->color; if (multi) { PlotDouble(gcf->ax[1], len/2, freq, mag2); gcf->ax[1]->m_ln[1]->color = gcf->ax[0]->m_ln[1]->color; delete[] fft2; delete[] mag2; } delete[] freq; delete[] fft; delete[] mag; break; case IDM_WAVWRITE: char fname[MAX_PATH]; CFileDlg fileDlg; fileDlg.InitFileDlg(hDlg, hInst, ""); errstr[0]=0; if(!GetSignalInRange(signal,1)) { MessageBox (errStr); return; } if (fileDlg.FileSaveDlg(fullfname, fname, "Wav file (*.WAV)\0*.wav\0", "wav")) if (!signal.Wavwrite(fullfname, errstr)) {MessageBox (errstr);} else { CStdString str; if (GetLastError()!=0) { GetLastErrorStr(str); MessageBox (str.c_str(), "Filesave error");} } return; } InvalidateRect(NULL); }