void testBasics() { report(0,"testing the basics of RF..."); ResourceFinder rf; const char *fname0 = "_yarp_regression_test.ini"; const char *fname1 = "_yarp_regression_test_rf1.txt"; const char *fname2 = "_yarp_regression_test_rf2.txt"; // create some test files { FILE *fout = fopen(fname0,"w"); yAssert(fout!=NULL); fprintf(fout,"style capability\n"); fprintf(fout,"capability_directory \".\"\n"); fprintf(fout,"default_capability \".\"\n"); fclose(fout); fout = NULL; fout = fopen(fname1,"w"); yAssert(fout!=NULL); fprintf(fout,"alt %s\n", fname2); fclose(fout); fout = NULL; fout = fopen(fname2,"w"); fprintf(fout,"x 14\n"); fclose(fout); fout = NULL; const char *argv[] = { "ignore", "--_yarp_regression_test", ".", "--from", fname1, "--verbose", "0", NULL }; int argc = 7; rf.configure(argc,(char **)argv); ConstString alt = rf.findFile("alt"); checkTrue(alt!="","found ini file"); rf.setDefault("alt2",fname2); alt = rf.findFile("alt2"); checkTrue(alt!="","default setting worked"); rf.setDefault("alt3","_yarp_nonexistent.txt"); alt = rf.findFile("alt3"); checkTrue(alt=="","cannot find nonexistent files"); rf.setDefault("alt","_yarp_nonexistent.txt"); alt = rf.findFile("alt"); checkTrue(alt!="","default setting is safe"); checkTrue(rf.findPath()!="","existing path found"); alt=rf.findFileByName(fname1); checkTrue(alt!="","found file by name"); } }
int main(int argc, char * argv[]) { Network yarp; ResourceFinder rf; rf.setVerbose(true); rf.setDefaultConfigFile("trajectVisualize.ini"); //overridden by --from parameter rf.setDefaultContext("morphoGenApp/conf"); //overridden by --context parameter rf.configure("ICUB_ROOT", argc, argv); yarp::os::ConstString path = rf.findPath("trajPoints.txt"); printf("File found! path %s \n", path.c_str()); yarp::os::BufferedPort<yarp::os::Bottle> output; output.open("/trajectVisualize/cmd:o"); Network::connect("/trajectVisualize/cmd:o","/iCubGui/objects"); string line; char *ptrLine; string word; ifstream trajFile (path.c_str()); if (trajFile.is_open()) { while ( trajFile.good() ) { getline (trajFile,line); cout << "line: "<<line << endl; if(line.empty()) { printf("empty line \n"); break; } char text[line.length()]; char * pch; double value[3]; int i = 0; pch = strtok ((char*)line.c_str()," "); printf("%s \n", pch); value[i] = atof(pch); i++; while (pch != NULL) { pch = strtok (NULL, " "); //value[i] = stod(pch); if(pch !=NULL) { printf("%s \n", pch); value[i] = atof(pch); } i++; } printf("Preparing the port \n"); yarp::os::Bottle& b = output.prepare(); b.clear(); //trajPoint.addString("addpoint"); //trajPoint.addString("trajA"); //trajPoint.addDouble(x); //trajPoint.addDouble(y); //trajPoint.addDouble(z); b.addString("addpoint"); b.addString("trajA"); b.addDouble(value[0] * 1000); b.addDouble(value[1] * 1000); b.addDouble((value[2] + 0.35) * 1000 ); //trajPoint = b.addList(); output.write(); Time::delay(0.1); } trajFile.close(); } else cout << "Unable to open file"; //module.runModule(rf); return 0; }