int main(int argc, char *argv[]) { int c; struct addrinfo *hints; opterr = 0; while ((c = getopt(argc,argv,"t:v")) != -1) { switch(c) { case 't': if (atoi(optarg) > 255) max_ttl=255; else max_ttl=atoi(optarg); #ifdef DEBUG printf("TTL is %d\n", max_ttl); #endif break; case 'v': #ifdef DEBUG printf("Verbose is selected\n"); #endif verbose = 1; break; case '?': err_quit("unrecognized option: %c\n",c); break; } } if (optind != argc-1) err_quit("Usage: traceroute <-t ttl> <-v> hostname\n"); hostname = argv[optind]; #ifdef DEBUG printf("Hostname is %s\n",hostname); #endif catchsignals(); hostname = "www.cern.ch"; bzero(hints,sizeof(struct addrinfo)); hints->ai_flags = AI_CANONNAME; hints->ai_family = 0; hints->ai_socktype = 0; if ( ( c = getaddrinfo(hostname, NULL, hints, &hints)) != 0) err_quit(gai_strerror(c)); printf("traceroute to %s (%s): %d hops max, %d data bytes\n",hints->ai_canonname,hostntop(hints->ai_addr,hints->ai_addrlen),max_ttl,datalen); if(hints->ai_family == AF_INET) pr = &proto_v4; else err_quit("unknown address family %d",hints->ai_family); pr->sasend = hints->ai_addr; /* contains destination address */ pr->sarecv = calloc(1,hints->ai_addrlen); pr->salast = calloc(1, hints->ai_addrlen); pr->sabind = calloc(1,hints->ai_addrlen); pr->salen = hints->ai_addrlen; traceloop(); exit(0); }
// ###################################################################### int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; // suppress debug messages volatile int signum = 0; catchsignals(&signum); ModelManager manager("Test Motion Energy"); nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); manager.addSubComponent(ifs); nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); manager.addSubComponent(ofs); nub::ref<FoeDetector> fd(new FoeDetector(manager)); manager.addSubComponent(fd); if (manager.parseCommandLine((const int)argc, (const char**)argv, "<stimuli> <options>", 0, 9) == false) return(1); fd->reset(NUM_PYR_LEVEL, NUM_DIRS, NUM_SPEEDS); std::string stimuli("Image"); if(manager.numExtraArgs() > 0) stimuli = manager.getExtraArgAs<std::string>(0); LINFO("Stimuli: %s", stimuli.c_str()); manager.start(); Timer timer(1000000); timer.reset(); // reset the timer int frame = 0; PauseWaiter p; uint step; step = 0; // to get to the good part //for(uint i = 0; i < 50; i++) //was 25 // ifs->updateNext(); // get ground truth file std::string gtFilename ("/lab/tmpib/u/siagian/neuroscience/Data/FOE/driving_nat_Browning.txt"); std::vector<Point2D<int> > gt = getGT(gtFilename); int ldpos = gtFilename.find_last_of('.'); std::string prefix = gtFilename.substr(0, ldpos); // for finding ground truth rutz::shared_ptr<XWinManaged> win; float totalErr = 0.0; std::vector<std::string> args; for(uint i = 0; i < manager.numExtraArgs(); i++) args.push_back(manager.getExtraArgAs<std::string>(i)); Image<byte> prevLum; Image<PixRGB<byte> > prevImage; Image<PixRGB<byte> > prevImage2; while (1) { if (signum != 0) { LINFO("quitting because %s was caught", signame(signum)); break; } if (ofs->becameVoid()) { LINFO("quitting because output stream was closed or became void"); break; } if (p.checkPause()) continue; const FrameState is = ifs->updateNext(); if (is == FRAME_COMPLETE) break; // done receiving frames Image< PixRGB<byte> > input = ifs->readRGB(); if(frame == 0) { uint width = input.getWidth(); uint height = input.getHeight(); win.reset(new XWinManaged(Dims(width, height), 0, 0, "GT")); } // empty image signifies end-of-stream if (!input.initialized()) break; Image<byte> lum = luminance(input); Point2D<float> pshift(0.0,0.0); if(step != 0) { // calculate planar shift using SIFT lum = calculateShift(lum,prevLum, ofs); } if( manager.numExtraArgs() > 0) lum = getImage(stimuli, args, fd, step); // for saving videos prevImage2 = prevImage; prevImage = input; if (!lum.initialized()) break; step++; // compute the focus of expansion (FOE) Point2D<int> foe = fd->getFoe(lum, FOE_METHOD_TEMPLATE, false); //Point2D<int> foe = fd->getFoe(lum, FOE_METHOD_AVERAGE); LINFO("[%d]Foe: %d %d", frame, foe.i, foe.j); // illustration of the size of the receptive field if(!stimuli.compare("ShowRF")) { uint rfI = 44; uint rfJ = 152; lum.setVal(rfI, rfJ, 300.0F); drawRect(lum, Rectangle::tlbrI(144,36,159,51), byte(255)); drawRect(lum, Rectangle::tlbrI(148,40,155,47), byte(255)); drawRect(lum, Rectangle::tlbrI(rfJ-8, rfI-8, rfJ+8, rfI+8), byte(255)); drawRect(lum, Rectangle::tlbrI(rfJ-16,rfI-16,rfJ+16,rfI+16), byte(255)); } ofs->writeGrayLayout(fd->getMTfeaturesDisplay(lum), "MT Features", FrameInfo("motion energy output images", SRC_POS)); // write the file if(frame >= 4) { float err = foe.distance(gt[frame-2]); totalErr += err; LINFO("Foe: %d %d: GT: %d %d --> %f --> avg: %f", foe.i, foe.j, gt[frame-2].i, gt[frame-2].j, err, totalErr/(frame-3)); Image<PixRGB<byte> > simg = prevImage2; drawCross(simg, foe , PixRGB<byte>(0,255,0), 10, 2); drawCross(simg, gt[frame-2], PixRGB<byte>(255,0,0), 10, 2); win->drawImage(simg,0,0); //Raster::WriteRGB(simg, sformat("%s_STnPS_%06d.ppm", prefix.c_str(), frame-2)); } //ofs->writeGrayLayout // (lum, "test-FOE Main", FrameInfo("foe output", SRC_POS)); const FrameState os = ofs->updateNext(); //LINFO("frame[%d]: %8.3f %8.3f", frame, pshift.i, pshift.j); Raster::waitForKey(); if (os == FRAME_FINAL) break; prevLum = lum; frame++; } LINFO("%d frames in %gs (%.2ffps)\n", frame, timer.getSecs(), frame / timer.getSecs()); // stop all our ModelComponents manager.stop(); // all done! return 0; }
int main(int argc, char *argv[]) { char **params = NULL; int op = OP_UNKNOWN; int i, j; int indx = 0; bool dispfp = false; bool skshash = false; bool exact = false; bool ishex = false; bool isfp = false; bool mrhkp = false; uint64_t keyid = 0; struct openpgp_fingerprint fingerprint; char *search = NULL; char *end = NULL; struct openpgp_publickey *publickey = NULL; struct openpgp_packet_list *packets = NULL; struct openpgp_packet_list *list_end = NULL; int result; struct skshash hash; struct onak_dbctx *dbctx; params = getcgivars(argc, argv); for (i = 0; params != NULL && params[i] != NULL; i += 2) { if (!strcmp(params[i], "op")) { if (!strcmp(params[i+1], "get")) { op = OP_GET; } else if (!strcmp(params[i+1], "hget")) { op = OP_HGET; } else if (!strcmp(params[i+1], "index")) { op = OP_INDEX; } else if (!strcmp(params[i+1], "vindex")) { op = OP_VINDEX; } else if (!strcmp(params[i+1], "photo")) { op = OP_PHOTO; } } else if (!strcmp(params[i], "search")) { search = params[i+1]; params[i+1] = NULL; if (search != NULL && strlen(search) == 42 && search[0] == '0' && search[1] == 'x') { /* v4 fingerprint */ fingerprint.length = 20; for (j = 0; j < 20; j++) { fingerprint.fp[j] = (hex2bin( search[2 + j * 2]) << 4) + hex2bin(search[3 + j * 2]); } isfp = true; } else if (search != NULL && strlen(search) == 66 && search[0] == '0' && search[1] == 'x') { /* v5 fingerprint */ fingerprint.length = 32; for (j = 0; j < 32; j++) { fingerprint.fp[j] = (hex2bin( search[2 + j * 2]) << 4) + hex2bin(search[3 + j * 2]); } isfp = true; } else if (search != NULL) { keyid = strtoull(search, &end, 16); if (*search != 0 && end != NULL && *end == 0) { ishex = true; } } } else if (!strcmp(params[i], "idx")) { indx = atoi(params[i+1]); } else if (!strcmp(params[i], "fingerprint")) { if (!strcmp(params[i+1], "on")) { dispfp = true; } } else if (!strcmp(params[i], "hash")) { if (!strcmp(params[i+1], "on")) { skshash = true; } } else if (!strcmp(params[i], "exact")) { if (!strcmp(params[i+1], "on")) { exact = true; } } else if (!strcmp(params[i], "options")) { /* * TODO: We should be smarter about this; options may * have several entries. For now mr is the only valid * one though. */ if (!strcmp(params[i+1], "mr")) { mrhkp = true; } } free(params[i]); params[i] = NULL; if (params[i+1] != NULL) { free(params[i+1]); params[i+1] = NULL; } } if (params != NULL) { free(params); params = NULL; } if (mrhkp) { puts("Content-Type: text/plain\n"); } else if (op == OP_PHOTO) { puts("Content-Type: image/jpeg\n"); } else { start_html("Lookup of key"); } if (op == OP_UNKNOWN) { puts("Error: No operation supplied."); } else if (search == NULL) { puts("Error: No key to search for supplied."); } else { readconfig(NULL); initlogthing("lookup", config.logfile); catchsignals(); dbctx = config.dbinit(config.backend, false); switch (op) { case OP_GET: case OP_HGET: if (op == OP_HGET) { parse_skshash(search, &hash); result = dbctx->fetch_key_skshash(dbctx, &hash, &publickey); } else if (ishex) { result = dbctx->fetch_key_id(dbctx, keyid, &publickey, false); } else if (isfp) { result = dbctx->fetch_key_fp(dbctx, &fingerprint, &publickey, false); } else { result = dbctx->fetch_key_text(dbctx, search, &publickey); } if (result) { logthing(LOGTHING_NOTICE, "Found %d key(s) for search %s", result, search); puts("<pre>"); cleankeys(&publickey, config.clean_policies); flatten_publickey(publickey, &packets, &list_end); armor_openpgp_stream(stdout_putchar, NULL, packets); puts("</pre>"); } else { logthing(LOGTHING_NOTICE, "Failed to find key for search %s", search); puts("Key not found"); } break; case OP_INDEX: find_keys(dbctx, search, keyid, &fingerprint, ishex, isfp, dispfp, skshash, exact, false, mrhkp); break; case OP_VINDEX: find_keys(dbctx, search, keyid, &fingerprint, ishex, isfp, dispfp, skshash, exact, true, mrhkp); break; case OP_PHOTO: if (isfp) { dbctx->fetch_key_fp(dbctx, &fingerprint, &publickey, false); } else { dbctx->fetch_key_id(dbctx, keyid, &publickey, false); } if (publickey != NULL) { unsigned char *photo = NULL; size_t length = 0; if (getphoto(publickey, indx, &photo, &length) == ONAK_E_OK) { fwrite(photo, 1, length, stdout); } free_publickey(publickey); publickey = NULL; } break; default: puts("Unknown operation!"); } dbctx->cleanupdb(dbctx); cleanuplogthing(); cleanupconfig(); } if (!mrhkp) { puts("<hr>"); puts("Produced by onak " ONAK_VERSION ); end_html(); } if (search != NULL) { free(search); search = NULL; } return (EXIT_SUCCESS); }
// ###################################################################### int submain(const int argc, const char** argv) { // catch signals and redirect them for a clean exit (in particular, this gives us a chance to do useful things like // flush and close output files that would otherwise be left in a bogus state, like mpeg output files): catchsignals(&signum); LINFO("#############################################STARTING##############################################"); ModelManager mgr("App Scorbot MultiGrab"); scorbot.reset(new ScorbotSimple(mgr)); mgr.addSubComponent(scorbot); setupGrabbers(mgr); ofs.reset(new OutputFrameSeries(mgr)); mgr.addSubComponent(ofs); if(mgr.parseCommandLine(argc, argv, "FilePrefix SceneID", 2, 2) == false) return -1; mgr.start(); if (grabbers.size() < NUMCAMS) LFATAL("Only found %" ZU " cameras instead of %d. Reboot your machine and try again.", grabbers.size(), NUMCAMS); // get our grabbers to start grabbing: for (size_t cameraID = 0; cameraID < grabbers.size(); ++cameraID) grabberThreadServer.enqueueJob(rutz::make_shared(new GrabJob(cameraID))); sceneDir = mgr.getExtraArg(0); sceneID = boost::lexical_cast<int>(mgr.getExtraArg(1)); pthread_t displayThread; pthread_create(&displayThread, NULL, &displayThreadMethod, NULL); // Create the interactive window userInteractiveWindow = new XWinManaged(Dims(640,480), -1, -1, "User Interactive"); userInteractiveWindow->setVisible(false); userInteractiveWindow->setPosition(0, 0); // Main loop: int runnumber = 0; while(true) { if(signum != 0) break; // home the robot once in a while: if ((runnumber % 5) == 0) { int gogo = 0; getInt("Perform robot homing sequence and press ENTER", gogo); } // select the scene: getInt("Enter scene ID (-1 to exit):", sceneID); if (sceneID == -1) break; // abort on scene -1 // STEP 1. Load the scene file SceneSetup setup = loadSceneSetup(sceneID); // STEP 2. Show the interactive window: userInteractiveWindow->setVisible(true); // STEP 3. Display background image and ask the user to place it on the scene Image< PixRGB<byte> > backgroundImage = Raster::ReadRGB(setup.setupPath + "/" + setup.backgroundFileName); backgroundImage = rescale(backgroundImage, Dims(640, 480)); writeText(backgroundImage, Point2D<int>(0, 0), "Please place this background on the scene and press ENTER."); userInteractiveWindow->drawImage(backgroundImage, 0, 0, true); LINFO("Place background map on scene and add houses, trees, and other background objects. See User Interactive window for instructions..."); // eat all previous mouse clicks and key presses, just in case: while (userInteractiveWindow->getLastMouseClick() != Point2D<int>(-1, -1)) { } while (userInteractiveWindow->getLastKeyPress() != -1) { } // wait for ENTER: while(userInteractiveWindow->getLastKeyPress() != 36) usleep(100000); LINFO("Background map done. Make sure you have built a nice scene."); // STEP 4. Display each object and ask user to put on the scene and specify its bounding box for (size_t i = 0; i < setup.objects.size(); ++i) setup.objects[i].outline = promptPlaceObjectOnScene(setup, i); // STEP 5. Hide the interactive window userInteractiveWindow->setVisible(false); // STEP 6. Write out outlines to a file { std::string objectFileName = sformat("%s/RobotScene-s%04d-polygons.txt", dataDir, sceneID); std::ofstream objectFile(objectFileName.c_str()); LINFO("Saving the object bounding boxes into: %s", objectFileName.c_str()); for(size_t i=0; i<setup.objects.size(); ++i) { for(size_t j=0; j<setup.objects[i].outline.size(); ++j) { Point2D<int> &pnt = setup.objects[i].outline[j]; if(j != 0) objectFile << ','; objectFile << pnt.i << ',' << pnt.j; } objectFile << std::endl; } } // STEP 7. Execute the path and record the videos for (pathID = 0; pathID < int(setup.pathIndex.size()); ++pathID) { if(signum != 0) break; // create a directory for this scene / light: const std::string dir = sformat("%s/RobotScene-s%04d-p%02d", dataDir, sceneID, pathID); const std::string cmd = sformat("/bin/mkdir -p %s", dir.c_str()); if (system(cmd.c_str()) == -1) PLFATAL("Could not create directory %s", dir.c_str()); int gogo = pathID; getInt("Set light and press ENTER to start video recording", gogo); // make sure we don't have too many pending disk writes: while(writer.size() > 1000) { LINFO("Waiting for image writer thread, queue size = %" ZU "...", writer.size()); usleep(1000000); } LINFO("Running Scene %04d Path %02d ...", sceneID, setup.pathIndex[pathID]); executePath(setup.pathIndex[pathID]); } if(signum != 0) break; // STEP 8. Instruct users to place the objects back into the bins userInteractiveWindow->setVisible(true); userInteractiveWindow->setPosition(0, 0); for(size_t i=0; i<setup.objects.size(); ++i) promptReturnObjectToTray(setup, i); userInteractiveWindow->setVisible(false); // STEP 9. Ready for next scene ++sceneID; ++runnumber; } // stop grabbing: keepgoing = false; // wait for all pics to be written (note: this just waits until the queue of pending jobs is empty, the writer's // destructor will wait until all jobs are complete): while(writer.size()) { LINFO("Waiting for image writer thread, queue size = %" ZU "...", writer.size()); usleep(500000); } writer.flushQueue(250000, true); // make sure all is done LINFO("Cleaning up... Stand by..."); usleep(2000000); // stop all our ModelComponents mgr.stop(); LINFO("Finished."); return 0; }
// ###################################################################### int Streamer::tryRun(const int argc, const char** argv, const char* extraArgsDescription, const int minExtraArgs, const int maxExtraArgs) { volatile int signum = 0; catchsignals(&signum); if (itsManager->parseCommandLine(argc, argv, extraArgsDescription, minExtraArgs, maxExtraArgs) == false) return(1); this->handleExtraArgs(*itsManager); itsManager->start(); itsIfs->startStream(); int c = 0; PauseWaiter p; while (true) { if (signum != 0) { LINFO("quitting because %s was caught", signame(signum)); return -1; } if (itsOfs->becameVoid()) { LINFO("quitting because output stream was closed or became void"); return 0; } if (p.checkPause()) continue; const FrameState is = itsIfs->updateNext(); if (is == FRAME_COMPLETE) break; GenericFrame input = itsIfs->readFrame(); if (!input.initialized()) break; const FrameState os = itsOfs->updateNext(); this->onFrame(input, *itsOfs, itsIfs->frame()); if (os == FRAME_FINAL) break; LDEBUG("frame %d", c++); if (itsIfs->shouldWait() || itsOfs->shouldWait()) Raster::waitForKey(); } itsManager->stop(); return 0; }