virtual void testAcquire() { report(0, "checking acquire/release..."); BufferedPort<Bottle> in; BufferedPort<Bottle> out; in.setStrict(); out.setStrict(); in.open("/in"); out.open("/out"); Network::connect("/out","/in"); out.prepare().fromString("1"); out.write(true); Bottle *bot = in.read(); checkTrue(bot!=NULL,"Inserted message received"); if (bot!=NULL) { checkEqual(bot->size(),1,"right length"); } out.prepare().fromString("1 2"); out.write(true); void *key = in.acquire(); Bottle *bot2 = in.read(); checkTrue(bot2!=NULL,"Inserted message received"); if (bot2!=NULL) { checkEqual(bot2->size(),2,"right length"); } out.prepare().fromString("1 2 3"); out.write(true); void *key2 = in.acquire(); Bottle *bot3 = in.read(); checkTrue(bot3!=NULL,"Inserted message received"); if (bot3!=NULL) { checkEqual(bot3->size(),3,"right length"); } if (bot2!=NULL) { checkEqual(bot2->size(),2,"original (2) still ok"); } if (bot!=NULL) { checkEqual(bot->size(),1,"original (1) still ok"); } in.release(key); in.release(key2); }
bool open(Searchable& p) { bool dev = true; if (p.check("nodevice")) { dev = false; } if (dev) { poly.open(p); if (!poly.isValid()) { printf("cannot open driver\n"); return false; } if (!p.check("mute")) { // Make sure we can write sound poly.view(put); if (put==NULL) { printf("cannot open interface\n"); return false; } } } port.setStrict(true); if (!port.open(p.check("name",Value("/yarphear")).asString())) { printf("Communication problem\n"); return false; } if (p.check("remote")) { Network::connect(p.check("remote",Value("/remote")).asString(), port.getName()); } return true; }
virtual void testRecentReader() { report(0,"check recent reader..."); BufferedPort<Bottle> in; BufferedPort<Bottle> out; in.setStrict(false); in.open("/in"); out.open("/out"); Network::connect("/out","/in"); Bottle& outBot1 = out.prepare(); outBot1.fromString("hello world"); printf("Writing bottle 1: %s\n", outBot1.toString().c_str()); out.write(true); Bottle& outBot2 = out.prepare(); outBot2.fromString("2 3 5 7 11"); printf("Writing bottle 2: %s\n", outBot2.toString().c_str()); out.write(true); Time::delay(0.25); Bottle *inBot2 = in.read(); checkTrue(inBot2!=NULL,"got 2 of 2 items"); if (inBot2!=NULL) { printf("Bottle 2 is: %s\n", inBot2->toString().c_str()); checkEqual(inBot2->size(),5,"match for item 1"); } }
void testPublisherToBufferedPort() { report(0,"Publisher to BufferedPort test"); Node n("/node"); Publisher<Bottle> p("/very_interesting_topic"); { Node n2("/node2"); BufferedPort<Bottle> pin; pin.setReadOnly(); pin.setStrict(); pin.open("very_interesting_topic"); waitForOutput(p,10); Bottle& b = p.prepare(); b.clear(); b.addInt(42); p.write(); p.waitForWrite(); Bottle *bin = pin.read(); checkTrue(bin!=NULL,"message arrived"); if (!bin) return; checkEqual(bin->get(0).asInt(),42,"message is correct"); } }
Echo() : mutex(1) { put = NULL; port.useCallback(*this); port.setStrict(); muted = false; saving = false; samples = 0; channels = 0; put = NULL; }
int main() { // Initialize YARP - some OSes need network and time service initialization Network yarp; // Work locally - don't rely on name server (just for this example). // If you have a YARP name server running, you can remove this line. Network::setLocalMode(true); // Create two ports that we'll be using to transmit "Bottle" objects. // The ports are buffered, so that sending and receiving can happen // in the background. BufferedPort<Bottle> in; BufferedPort<Bottle> out; // we will want to read every message, with no skipping of "old" messages // when new ones come in in.setStrict(); // Name the ports in.open("/in"); out.open("/out"); // Connect the ports so that anything written from /out arrives to /in Network::connect("/out","/in"); // Send one "Bottle" object. The port is responsible for creating // and reusing/destroying that object, since it needs to be sure // it exists until communication to all recipients (just one in // this case) is complete. Bottle& outBot1 = out.prepare(); // Get the object outBot1.fromString("hello world"); // Set it up the way we want printf("Writing bottle 1 (%s)\n", outBot1.toString().c_str()); out.write(); // Now send it on its way // Send another "Bottle" object Bottle& outBot2 = out.prepare(); outBot2.fromString("2 3 5 7 11"); printf("Writing bottle 2 (%s)\n", outBot2.toString().c_str()); out.writeStrict(); // writeStrict() will wait for any // previous communication to finish; // write() would skip sending if // there was something being sent // Read the first object Bottle *inBot1 = in.read(); printf("Bottle 1 is: %s\n", inBot1->toString().c_str()); // Read the second object Bottle *inBot2 = in.read(); printf("Bottle 2 is: %s\n", inBot2->toString().c_str()); return 0; }
void SamInit(void) { iVoltage=0; task=""; bCharging=true; RecognisePort("PIn"); RecognisePort("PhoneOut"); StartModule("/Phidget"); bRead.open("/Phidget_PIn"); bPhone.open("/Phidget_PhoneOut"); bRead.setStrict(true); bPhone.setStrict(true); bRead.setReporter(myPortStatus); bPhone.setReporter(myPortStatus); //relay switch: on mobile base and start modules CPhidgetInterfaceKit_setOutputState (ifKit, 6, 1); yarp::os::Time::delay(2); system("start.bat"); }
void SamInit(void) { RecognisePort("StarIn"); RecognisePort("GoalIn"); //RecognisePort("PwrOut"); //RecognisePort("LaserIn"); StartModule("/GotoNav"); StarIn.open("/GotoNav_StarIn"); GoalIn.open("/GotoNav_GoalIn"); //PwrOut.open("/GotoNav_PwrOut"); //LaserIn.open("/GotoNav_LaserIn"); StarIn.setStrict(true); GoalIn.setStrict(true); //PwrOut.setStrict(true); //LaserIn.setStrict(true); StarIn.setReporter(myPortStatus); GoalIn.setReporter(myPortStatus); //PwrOut.setReporter(myPortStatus); //LaserIn.setReporter(myPortStatus); //myfile.open ("motion.txt"); //if (myfile.is_open()) //{ // myfile << 0 << "|" << 0 << "\n"; // myfile.close(); //} //system("move.exe"); yarp::os::Time::delay(0.5); puts("started nav go to"); }
virtual void testReaderHandler2() { report(0,"check reader handler, bufferedport style..."); BufferedPort<Bottle> in; Port out; DelegatedCallback callback; in.setStrict(); out.open("/out"); in.open("/in"); Network::connect("/out","/in"); in.useCallback(callback); Bottle src("10 10 20"); out.write(src); callback.produce.wait(); checkEqual(callback.saved.size(),3,"object came through"); in.disableCallback(); }