size_t FileStream::readWin32(char * buffer, size_t size) { testOpen(); DWORD dwRead = 0; BOOL bSuccess = ReadFile(handle, buffer, size, &dwRead, NULL); _eof = (!bSuccess || dwRead == 0); return (_eof ? 0 : dwRead); }
/** * Unit test framework entry point for this set of unit tests. * */ void testSimpleNetwork_runTests() { unsigned char ipBytes[MAX_ADDR_LENGTH]; //can be set to INET6_ADDRSTRLEN; void *handle; int numBytes; char *data; char *hostname = "host.domain"; char* request = "GET /midlets/midlet.jad HTTP/1.0\n\n"; testGetHostByName(hostname, ipBytes); handle = testOpen(ipBytes, 80); printf("open handle = %d\n", (int)handle); testWrite(handle, request); numBytes = testAvailable(handle); printf("numBytes = %d\n", numBytes); if (numBytes > 0) { data = (char *) malloc((numBytes + 1)*sizeof(char)); testRead(handle, data, numBytes); printf("\n Data from server :\n"); printf("%s\n", data); } testClose(handle); }
size_t FileStream::write(const char * buffer, size_t len) { if (win32HandleMode()) { return writeWin32(buffer, len); } testOpen(); return fwrite(buffer, 1, len, fp); }
void FileStream::write(int ch) { if (win32HandleMode()) { writeWin32(ch); } testOpen(); fputc(ch, fp); }
string FileStream::readline() { testOpen(); string ret; int ch; while (ch = read(), (ch >= 0 && ch != '\n')) { ret.append(1, (char)ch); } return ret; }
size_t FileStream::read(char * buffer, size_t len) { if (win32HandleMode()) { return readWin32(buffer, len); } testOpen(); return fread(buffer, 1, len, fp); }
bool FileStream::eof() { if (win32HandleMode()) { return eofWin32(); } testOpen(); return feof(fp) ? true : false; }
void FileStream::seekOffset(long offset) { if (win32HandleMode()) { seekOffsetWin32(offset); } testOpen(); fseek(fp, offset, SEEK_CUR); }
void FileStream::seekEnd(size_t pos) { if (win32HandleMode()) { seekEndWin32(pos); } testOpen(); fseek(fp, pos, SEEK_END); }
int FileStream::read() { if (win32HandleMode()) { return readWin32(); } testOpen(); int ch = fgetc(fp); if (ch == EOF) { ch = -1; } return ch; }
size_t FileStream::position() { if (win32HandleMode()) { positionWin32(); } testOpen(); long pos = ftell(fp); if (pos < 0) { throw IOException("ftell() error", -1, 0); } return (size_t)pos; }
static void do_test_api1(const char *zPattern, int *pRc){ if( testCaseBegin(pRc, zPattern, "api1.lsm") ){ const DatasourceDefn defn = { TEST_DATASOURCE_RANDOM, 10, 15, 200, 250 }; Datasource *pData; TestDb *pDb; int rc = 0; pDb = testOpen("lsm_lomem", 1, &rc); pData = testDatasourceNew(&defn); testWriteDatasourceRange(pDb, pData, 0, 1000, pRc); do_test_api1_lsm(tdb_lsm(pDb), pRc); testDatasourceFree(pData); testClose(&pDb); testCaseFinish(*pRc); } }
int main(int argc, char **argv) { ros::Time::init(); cbSdkResult res = testOpen(); if (res < 0) ROS_INFO("testOpen failed (%d)!\n", res); else ROS_INFO("testOpen succeeded\n"); UINT16 uBegChan = 0; UINT32 uBegMask = 0; UINT32 uBegVal = 0; UINT16 uEndChan = 0; UINT32 uEndMask = 0; UINT32 uEndVal = 0; bool bDouble = false; bool bAbsolute = false; UINT32 uWaveforms = 0; UINT32 uConts = cbSdk_CONTINUOUS_DATA_SAMPLES; UINT32 uEvents = cbSdk_EVENT_DATA_SAMPLES; UINT32 uComments = 0; UINT32 uTrackings = 0; UINT32 bWithinTrial = false; // test cbSdkGet/Set Trial Config UINT32 bActive = 1; res = cbSdkSetTrialConfig(INST, bActive, uBegChan, uBegMask, uBegVal, uEndChan, uEndMask, uEndVal, bDouble, uWaveforms, uConts, uEvents, uComments, uTrackings, bAbsolute); ros::Duration(.1).sleep(); UINT32 bValid = 1; cbSdkTrialCont trialcont = cbSdkTrialCont(); cbPKT_CHANINFO chan_info = cbPKT_CHANINFO(); res = cbSdkInitTrialData(INST, NULL, &trialcont, NULL, NULL); int num_channels = trialcont.count; blackrock_interface::blackrock_data br_data_msg; br_data_msg.num_samples.resize(trialcont.count); br_data_msg.data.resize(trialcont.count); br_data_msg.channel_labels.resize(trialcont.count); for (int ii=0; ii<num_channels; ii++) { cbSdkGetChannelConfig(INST, trialcont.chan[ii], &chan_info); // Get a full channel configuration packet br_data_msg.channel_labels[ii].assign(chan_info.label); } ros::init(argc, argv, "br_data_stream"); ros::NodeHandle n; ros::Publisher chatter_pub = n.advertise<blackrock_interface::blackrock_data>("blackrock_data", 1); ros::Rate loop_rate(STREAM_FREQ); while (ros::ok()) { // 1 - Get how many samples are waiting bool bTrialDouble = false; res = cbSdkGetTrialConfig(INST, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &bTrialDouble, NULL, &uConts, &uEvents); res = cbSdkInitTrialData(INST, NULL, &trialcont, NULL, NULL); // 2 - Allocate buffer for (UINT32 channel = 0; channel < trialcont.count; channel++) { trialcont.samples[channel] = NULL; UINT32 num_samples = trialcont.num_samples[channel]; if (bTrialDouble) trialcont.samples[channel] = calloc(num_samples,sizeof(double)); else trialcont.samples[channel] = calloc(num_samples,sizeof(UINT16)); } // 3 - get the data int bFlushBuffer = 1; INT16 **data = (INT16 **)trialcont.samples; res = cbSdkGetTrialData(INST, bFlushBuffer, NULL, &trialcont, NULL, NULL); data = (INT16 **)trialcont.samples; // 4 - forward the data for (UINT32 channel = 0; channel < trialcont.count; channel++) { blackrock_interface::blackrock_channel_data br_channel_data; // holds single chan data br_channel_data.channel_data.insert( br_channel_data.channel_data.begin(), data[channel], data[channel]+trialcont.num_samples[channel]); br_data_msg.data[channel] = br_channel_data; br_data_msg.num_samples[channel] = trialcont.num_samples[channel]; } chatter_pub.publish(br_data_msg); loop_rate.sleep(); } return 0; }
size_t FileStream::positionWin32() { testOpen(); return (size_t)SetFilePointer(handle, 0, NULL, FILE_CURRENT); }
void FileStream::seekOffsetWin32(long offset) { testOpen(); SetFilePointer(handle, offset, NULL, FILE_CURRENT); }
void FileStream::seekEndWin32(size_t pos) { testOpen(); SetFilePointer(handle, (long)pos, NULL, FILE_END); }
size_t FileStream::writeWin32(const char * buffer, size_t len) { testOpen(); DWORD dwWritten = 0; BOOL bSuccess = WriteFile(handle, buffer, len, &dwWritten, NULL); return (size_t)dwWritten; }
void FileStream::writeWin32(int ch) { testOpen(); writeWin32((const char*)&ch, 1); }
static void doDataTest4( const char *zSystem, /* Database system to test */ Datatest4 *p, /* Structure containing test parameters */ int *pRc /* OUT: Error code */ ){ lsm_db *db = 0; TestDb *pDb; TestDb *pControl; Datasource *pData; int i; int rc = 0; int iDot = 0; int bMultiThreaded = 0; /* True for MT LSM database */ int nRecOn3 = (p->nRec / 3); int iData = 0; /* Start the test case, open a database and allocate the datasource. */ rc = testControlDb(&pControl); pDb = testOpen(zSystem, 1, &rc); pData = testDatasourceNew(&p->defn); if( rc==0 ){ db = tdb_lsm(pDb); bMultiThreaded = tdb_lsm_multithread(pDb); } testWriteDatasourceRange(pControl, pData, iData, nRecOn3*3, &rc); testWriteDatasourceRange(pDb, pData, iData, nRecOn3*3, &rc); for(i=0; rc==0 && i<p->nRepeat; i++){ testDeleteDatasourceRange(pControl, pData, iData, nRecOn3*2, &rc); testDeleteDatasourceRange(pDb, pData, iData, nRecOn3*2, &rc); if( db ){ int nDone; #if 0 fprintf(stderr, "lsm_work() start...\n"); fflush(stderr); #endif do { nDone = 0; rc = lsm_work(db, 1, (1<<30), &nDone); }while( rc==0 && nDone>0 ); if( bMultiThreaded && rc==LSM_BUSY ) rc = LSM_OK; #if 0 fprintf(stderr, "lsm_work() done...\n"); fflush(stderr); #endif } if( i+1<p->nRepeat ){ iData += (nRecOn3*2); testWriteDatasourceRange(pControl, pData, iData+nRecOn3, nRecOn3*2, &rc); testWriteDatasourceRange(pDb, pData, iData+nRecOn3, nRecOn3*2, &rc); testCompareDb(pData, nRecOn3*3, iData, pControl, pDb, &rc); /* If Datatest4.bReopen is true, close and reopen the database */ if( p->bReopen ){ testReopen(&pDb, &rc); if( rc==0 ) db = tdb_lsm(pDb); } } /* Update the progress dots... */ testCaseProgress(i, p->nRepeat, testCaseNDot(), &iDot); } testClose(&pDb); testClose(&pControl); testDatasourceFree(pData); testCaseFinish(rc); *pRc = rc; }
void FileStream::writeline(const string & line) { testOpen(); string nlstr = line + "\n"; write(nlstr.c_str(), nlstr.length()); }
int ScanEnumTree( t_usbInterface* usbInt, LPCTSTR lpEnumPath, TCHAR** openPorts ) { static const TCHAR lpstrPortsClass[] = TEXT("PORTS"); static const TCHAR lpstrPortsClassGUID[] = TEXT("{4D36E978-E325-11CE-BFC1-08002BE10318}"); DWORD dwError=0; HKEY hkEnum=NULL; DWORD dwIndex1; HKEY hkLevel1=NULL; DWORD dwIndex2; HKEY hkLevel2=NULL; HKEY hkDeviceParameters=NULL; TCHAR lpClass[sizeof(lpstrPortsClass)/sizeof(lpstrPortsClass[0])]; DWORD cbClass; TCHAR lpClassGUID[sizeof(lpstrPortsClassGUID)/sizeof(lpstrPortsClassGUID[0])]; DWORD cbClassGUID; LPTSTR lpPortName=NULL; LPTSTR lpFriendlyName=NULL; int result; int openCount = 0; typedef struct { LPCTSTR lpPortName; /* "COM1", etc. */ LPCTSTR lpFriendlyName; /* Suitable to describe the port, as for */ /* instance "Infrared serial port (COM4)" */ }LISTPORTS_PORTINFO; if(dwError=RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpEnumPath,0,KEY_ENUMERATE_SUB_KEYS,&hkEnum)){ goto end; } for(dwIndex1=0;;++dwIndex1) { //post("finding loop; dwIndex1 = %d\n", dwIndex1); if(hkLevel1!=NULL){ RegCloseKey(hkLevel1); hkLevel1=NULL; } if(dwError=OpenSubKeyByIndex(hkEnum,dwIndex1,KEY_ENUMERATE_SUB_KEYS,&hkLevel1)){ if(dwError==ERROR_NO_MORE_ITEMS){ dwError=0; break; } else goto end; } for(dwIndex2=0;;++dwIndex2){ BOOL bFriendlyNameNotFound=FALSE; LISTPORTS_PORTINFO portinfo; if(hkLevel2!=NULL){ RegCloseKey(hkLevel2); hkLevel2=NULL; } if(dwError=OpenSubKeyByIndex(hkLevel1,dwIndex2,KEY_READ,&hkLevel2)){ if(dwError==ERROR_NO_MORE_ITEMS){ dwError=0; break; } else goto end; } /* Look if the driver class is the one we're looking for. * We accept either "CLASS" or "CLASSGUID" as identifiers. * No need to dynamically arrange for space to retrieve the values, * they must have the same length as the strings they're compared to * if the comparison is to be succesful. */ cbClass=sizeof(lpClass); if(RegQueryValueEx(hkLevel2,TEXT("CLASS"),NULL,NULL, (LPBYTE)lpClass,&cbClass)==ERROR_SUCCESS&& _tcsicmp(lpClass,lpstrPortsClass)==0){ /* ok */ } else{ cbClassGUID=sizeof(lpClassGUID); if(RegQueryValueEx(hkLevel2,TEXT("CLASSGUID"),NULL,NULL, (LPBYTE)lpClassGUID,&cbClassGUID)==ERROR_SUCCESS&& _tcsicmp(lpClassGUID,lpstrPortsClassGUID)==0){ /* ok */ } else continue; } /* get "PORTNAME" */ dwError=QueryStringValue(hkLevel2,TEXT("PORTNAME"),&lpPortName); if(dwError==ERROR_FILE_NOT_FOUND){ /* In Win200, "PORTNAME" is located under the subkey "DEVICE PARAMETERS". * Try and look there. */ if(hkDeviceParameters!=NULL){ RegCloseKey(hkDeviceParameters); hkDeviceParameters=NULL; } if(RegOpenKeyEx(hkLevel2,TEXT("DEVICE PARAMETERS"),0,KEY_READ, &hkDeviceParameters)==ERROR_SUCCESS){ dwError=QueryStringValue(hkDeviceParameters,TEXT("PORTNAME"),&lpPortName); } } if(dwError){ if(dwError==ERROR_FILE_NOT_FOUND){ /* boy that was strange, we better skip this device */ dwError=0; continue; } else goto end; } //post("found port, name %ls\n", lpPortName); /* check if it is a serial port (instead of, say, a parallel port) */ if(_tcsncmp(lpPortName,TEXT("COM"),3)!=0)continue; /* now go for "FRIENDLYNAME" */ if(dwError=QueryStringValue(hkLevel2,TEXT("FRIENDLYNAME"),&lpFriendlyName)){ if(dwError==ERROR_FILE_NOT_FOUND){ bFriendlyNameNotFound=TRUE; dwError=0; } else goto end; } /* Assemble the information and pass it on to the callback. * In the unlikely case there's no friendly name available, * use port name instead. */ portinfo.lpPortName=lpPortName; portinfo.lpFriendlyName=bFriendlyNameNotFound?lpPortName:lpFriendlyName; { //post( "Friendly name: %s\n", portinfo.lpFriendlyName ); if (!_tcsncmp(TEXT("Make Controller Kit"), portinfo.lpFriendlyName, 19)) { TCHAR* pname; pname = _tcsdup(portinfo.lpPortName); // We've found a matching entry in the registry... // Now see if it's actually there by trying to open it result = testOpen( usbInt, pname ); // if it is, store it if( result == 0 ) openPorts[ openCount++ ] = pname; } } } } goto end; end: free(lpFriendlyName); free(lpPortName); if(hkDeviceParameters!=NULL)RegCloseKey(hkDeviceParameters); if(hkLevel2!=NULL) RegCloseKey(hkLevel2); if(hkLevel1!=NULL) RegCloseKey(hkLevel1); if(hkEnum!=NULL) RegCloseKey(hkEnum); if(dwError!=0) { SetLastError(dwError); return 0; } else return openCount; }
void FileStream::rewind() { testOpen(); ::rewind(fp); }