void moTuioModule::notifyData(moDataStream *input) { WOscBundle *bundle = NULL; moDataGenericList::iterator it; moDataGenericList *list; assert( input != NULL ); assert( input == this->input ); // out input have been updated ! LOGM(MO_TRACE, "Updating Tuio stream"); this->input->lock(); list = static_cast<moDataGenericList *>(this->input->getData()); // we must have data to probe the first time which data we got // and extract if it will be fiducial or simple blob if ( this->type == TUIO_UNKNOWN ) { it = list->begin(); if ( it == list->end() ) { this->input->unlock(); return; } std::string implements = (*it)->properties["implements"]->asString(); if ( moUtils::inList("fiducial", implements) ) this->type = TUIO_2DOBJ; else this->type = TUIO_2DCUR; } std::string osc_path; if ( this->type == TUIO_2DOBJ ) osc_path = "/tuio/2Dobj"; else osc_path = "/tuio/2Dcur"; // // Alive message // bundle = new WOscBundle(); WOscMessage *msg = new WOscMessage(osc_path.c_str()); msg->Add("alive"); for ( it = list->begin(); it != list->end(); it++ ) { assert(moUtils::inList("tracked", (*it)->properties["implements"]->asString())); assert(moUtils::inList("pos", (*it)->properties["implements"]->asString())); msg->Add((*it)->properties["blob_id"]->asInteger()); LOGM(MO_INFO, "tracked :"); LOGM(MO_INFO, (*it)->properties["implements"]->asString()); } bundle->Add(msg); // // Set message // for ( it = list->begin(); it != list->end(); it++ ) { msg = new WOscMessage(osc_path.c_str()); msg->Add("set"); if ( this->type == TUIO_2DOBJ ) { // /tuio/2Dobj set s i x y a X Y A m r msg->Add((*it)->properties["blob_id"]->asInteger()); // class id msg->Add((*it)->properties["fiducial_id"]->asInteger()); // class id msg->Add((float)(*it)->properties["x"]->asDouble()); // x msg->Add((float)(*it)->properties["y"]->asDouble()); // y msg->Add((float)(*it)->properties["angle"]->asDouble()); // a msg->Add((float)0.); // X msg->Add((float)0.); // Y msg->Add((float)0.); // A msg->Add((float)0.); // m msg->Add((float)0.); // r } else if ( this->type == TUIO_2DCUR ) { // /tuio/2Dcur set s x y X Y m msg->Add((*it)->properties["blob_id"]->asInteger()); // class id msg->Add((float)(*it)->properties["x"]->asDouble()); // x msg->Add((float)(*it)->properties["y"]->asDouble()); // y msg->Add((float)0.); // X msg->Add((float)0.); // Y msg->Add((float)0.); // m if ( this->property("sendsize").asBool() && moUtils::inList("size", (*it)->properties["implements"]->asString()) ) { msg->Add((float)(*it)->properties["width"]->asDouble()); // w msg->Add((float)(*it)->properties["height"]->asDouble()); // h } } bundle->Add(msg); } // // Frame sequence message // msg = new WOscMessage(osc_path.c_str()); msg->Add("fseq"); msg->Add(this->fseq++); bundle->Add(msg); //LOGM(MO_TRACE, "Sending OSC bundle"); LOGM(MO_INFO, "Sending OSC bundle"); this->osc->send(bundle); delete bundle; this->input->unlock(); LOGM(MO_TRACE, "TUIO done"); }
void TuioServer::sendMessage(TrackedFiducial fiducials[]) { WOscBundle bundle; // Alive message WOscMessage *aliveMsg = new WOscMessage(OSC_PATH); aliveMsg->Add("alive"); for (int i = 0; i < MAX_FIDUCIALS; i++) { TrackedFiducial &fid = fiducials[i]; if (fid.isTracked) { aliveMsg->Add(i); } } bundle.Add(aliveMsg); // Set message for (int i = 0; i < MAX_FIDUCIALS; i++) { TrackedFiducial &fid = fiducials[i]; if (fid.isTracked) { WOscMessage *setMsg = new WOscMessage(OSC_PATH); setMsg->Add("set"); setMsg->Add(i); // session id setMsg->Add(i); // fiducial id setMsg->Add(fid.x); // horizontal position setMsg->Add(fid.y); // vertical position setMsg->Add(fid.a); // angle setMsg->Add(fid.xspeed); // horizontal motion speed setMsg->Add(fid.yspeed); // vertical motion speed setMsg->Add(fid.aspeed); // rotation speed setMsg->Add(fid.xyacc); // motion acceleration setMsg->Add(fid.aacc); // rotation acceleration bundle.Add(setMsg); } } // Frame sequence message WOscMessage *seqMsg = new WOscMessage(OSC_PATH); seqMsg->Add("fseq"); seqMsg->Add(this->fseq++); bundle.Add(seqMsg); // Send the bundle via UDP struct sockaddr_in servaddr; servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = inet_addr(this->ipaddr.c_str()); servaddr.sin_port = htons(this->port); sendto(this->sock, bundle.GetBuffer(), bundle.GetBufferLen(), 0, (struct sockaddr *) &servaddr, sizeof(servaddr)); }