/*! Initializes the client and connects to \a remoteService. */ void BluetoothClient::startClient(const QBluetoothServiceInfo &remoteService) { if (mSocket || mRetries) { qDebug() << "BluetoothClient::startClient(): Already running!"; return; } mService = remoteService; mRetries = NumberOfRetries; mLastErrorString = ""; Common::resetBuffer(); QBluetoothAddress address = mService.device().address(); qDebug() << "BluetoothClient::startClient(): Bluetooth address: " << address.toString(); mSocket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); connect(mSocket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); connect(mSocket, SIGNAL(connected()), this, SLOT(onConnected())); connect(mSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(mSocket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(onSocketError(QBluetoothSocket::SocketError))); // mSocket->connectToService() call may block the UI thread. Thus, use the // the timer to delay the call in case we want to show some note for the // user. QTimer::singleShot(RetryInterval, this, SLOT(connectToService())); }
void QBluetoothSocket::serviceDiscovered(const QBluetoothServiceInfo &service) { Q_D(QBluetoothSocket); qCDebug(QT_BT) << "FOUND SERVICE!" << service; if (service.protocolServiceMultiplexer() > 0 || service.serverChannel() > 0) { connectToService(service, d->openMode); d->discoveryAgent->deleteLater(); d->discoveryAgent = 0; } else { qCDebug(QT_BT) << "Could not find port/psm for potential remote service"; } }
/** * @brief get here on timed events. */ void OpenNIC::timerEvent(QTimerEvent* e) { if ( e->timerId() == mRefreshTimer ) { connectToService(); mTrayIcon->show(); pollPeriodicKeys(); } else { inherited::timerEvent(e); } }
/*! Error handler for socket errors. */ void BluetoothClient::onSocketError(QBluetoothSocket::SocketError error) { qDebug() << "BluetoothClient::onSocketError():" << error; if (mRetries > 0) { mRetries--; qDebug() << "BluetoothClient::onSocketError(): Will try" << mRetries << "more time(s)."; QTimer::singleShot(RetryInterval, this, SLOT(connectToService())); } else { mLastErrorString = mSocket->errorString(); emit socketError((int) error); } }
///@brief Movement of the robot. double AvatarControllerByOculusCV1::onAction(ActionEvent &evt) { bool oculusCV1Available = checkService(this->oculusCV1DeviceManager.serviceName); if (oculusCV1Available && this->oculusCV1DeviceManager.service == NULL) { this->oculusCV1DeviceManager.service = connectToService(this->oculusCV1DeviceManager.serviceName); } else if (!oculusCV1Available && this->oculusCV1DeviceManager.service != NULL) { this->oculusCV1DeviceManager.service = NULL; } return 1.0; }
///@brief Movement of the robot. double WheelControllerByMyo::onAction(ActionEvent &evt) { bool myoAvailable = checkService(this->myoDeviceManager.serviceName); if (myoAvailable && this->myoDeviceManager.service == NULL) { this->myoDeviceManager.service = connectToService(this->myoDeviceManager.serviceName); } else if (!myoAvailable && this->myoDeviceManager.service != NULL) { this->myoDeviceManager.service = NULL; } return 1.0; }
///@brief Movement of the robot. double AvatarControllerByKinectV2::onAction(ActionEvent &evt) { bool kinectV2Available = checkService(this->kinectV2DeviceManager.serviceName); if (kinectV2Available && this->kinectV2DeviceManager.service == NULL) { this->kinectV2DeviceManager.service = connectToService(this->kinectV2DeviceManager.serviceName); } else if (!kinectV2Available && this->kinectV2DeviceManager.service != NULL) { this->kinectV2DeviceManager.service = NULL; } return 1.0; }
double AvatarControllerByPerceptionNeuron::onAction(ActionEvent &evt) { bool perceptionNeuronAvailable = checkService(this->perceptionNeuronDeviceManager.serviceName); if (perceptionNeuronAvailable && this->perceptionNeuronDeviceManager.service == NULL) { this->perceptionNeuronDeviceManager.service = connectToService(this->perceptionNeuronDeviceManager.serviceName); } else if (!perceptionNeuronAvailable && this->perceptionNeuronDeviceManager.service != NULL) { this->perceptionNeuronDeviceManager.service = NULL; } return 1.0; }
void iControlPadClient::serviceDiscovered(const QBluetoothServiceInfo &serviceInfo) { qDebug() << "Discovered service on" << serviceInfo.device().name() << serviceInfo.device().address().toString(); qDebug() << "\tService name:" << serviceInfo.serviceName(); qDebug() << "\tDescription:" << serviceInfo.attribute(QBluetoothServiceInfo::ServiceDescription).toString(); qDebug() << "\tProvider:" << serviceInfo.attribute(QBluetoothServiceInfo::ServiceProvider).toString(); qDebug() << "\tL2CAP protocol service multiplexer:" << serviceInfo.protocolServiceMultiplexer(); qDebug() << "\tRFCOMM server channel:" << serviceInfo.serverChannel(); if( QString::compare ( serviceInfo.serviceName(), KiCPServiceName, Qt::CaseInsensitive ) == 0 ) connectToService( serviceInfo ); }
void QgsArcGisServiceSourceSelect::connectToServer() { bool haveLayers = false; btnConnect->setEnabled( false ); mModel->setRowCount( 0 ); mAvailableCRS.clear(); QgsOwsConnection connection( mServiceName, cmbConnections->currentText() ); setCursor( Qt::WaitCursor ); bool success = connectToService( connection ); unsetCursor(); if ( success ) { haveLayers = mModel->rowCount() > 0; if ( haveLayers ) { for ( int i = 0; i < treeView->header()->count(); ++i ) { treeView->resizeColumnToContents( i ); if ( i < 2 && treeView->columnWidth( i ) > 300 ) { treeView->setColumnWidth( i, 300 ); } } treeView->selectionModel()->select( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows ); treeView->setFocus(); } else { QMessageBox::information( nullptr, tr( "No Layers" ), tr( "The query returned no layers." ) ); } } btnConnect->setEnabled( true ); emit enableButtons( haveLayers ); if ( mServiceType == FeatureService ) { mBuildQueryButton->setEnabled( haveLayers ); } btnChangeSpatialRefSys->setEnabled( haveLayers ); }
double MyController::onAction(ActionEvent &evt) { // サービスが使用可能か定期的にチェックする bool available = checkService("CleanUpReferee"); if(!available && m_ref != NULL) m_ref = NULL; // 使用可能 else if(available && m_ref == NULL){ // サービスに接続 m_ref = connectToService("CleanUpReferee"); } // 自分の位置取得 Vector3d myPos; m_my->getPosition(myPos); // 衝突中の場合,衝突が継続しているかチェック if(colState){ CParts *parts = m_my->getMainParts(); bool state = parts->getCollisionState(); // 衝突していない状態に戻す if(!state) colState = false; } int entSize = m_entities.size(); for(int i = 0; i < entSize; i++){ // ロボットまたはゴミ箱の場合は除く if(m_entities[i] == "robot_000" || m_entities[i] == "trashbox_0" || m_entities[i] == "trashbox_1" || m_entities[i] == "trashbox_2"){ continue; } // エンティティ取得 SimObj *ent = getObj(m_entities[i].c_str()); // 位置取得 Vector3d tpos; ent->getPosition(tpos); // ゴミ箱からゴミを結ぶベクトル Vector3d vec(tpos.x()-myPos.x(), tpos.y()-myPos.y(), tpos.z()-myPos.z()); // ゴミがゴミ箱の中に入ったかどうか判定 if(abs(vec.x()) < tboxSize_x/2.0 && abs(vec.z()) < tboxSize_z/2.0 && tpos.y() < tboxMax_y && tpos.y() > tboxMin_y ){ // ゴミがリリースされているか確認 if(!ent->getIsGrasped()){ std::string msg; bool success = false; // 台の上に置く(成功) if(strcmp(ent->name(), "mayonaise_0") == 0 && tpos.y() != 57.85) {tpos.y(57.85); success = true;} else if(strcmp(ent->name(), "chigarette") == 0 && tpos.y() != 54.04){ tpos.y(54.04); success = true;} else if(strcmp(ent->name(), "chocolate") == 0 && tpos.y() != 51.15){ tpos.y(51.15); success = true;} else if(strcmp(ent->name(), "mugcup") == 0 && tpos.y() != 54.79){ tpos.y(54.79); success = true;} else if(strcmp(ent->name(), "petbottle_0") == 0 && tpos.y() != 67.45){ tpos.y(67.45); success = true;} else if(strcmp(ent->name(), "petbottle_3") == 0 && tpos.y() != 61.95){ tpos.y(61.95); success = true;} else if(strcmp(ent->name(), "clock") == 0 && tpos.y() != 56.150){ tpos.y(56.150); success = true;} else if(strcmp(ent->name(), "kettle") == 0 && tpos.y() != 60.650){ tpos.y(60.650); success = true;} // 台の上に置く(失敗) else if(strcmp(ent->name(), "petbottle_1") == 0 && tpos.y() != 67.45){ tpos.y(67.45);} else if(strcmp(ent->name(), "petbottle_2") == 0 && tpos.y() != 67.45){ tpos.y(67.45);} else if(strcmp(ent->name(), "petbottle_4") == 0 && tpos.y() != 61.95){ tpos.y(61.95);} else if(strcmp(ent->name(), "mayonaise_1") == 0 && tpos.y() != 57.85){ tpos.y(57.85);} else if(strcmp(ent->name(), "can_0") == 0 && tpos.y() != 55.335){ tpos.y(55.335);} else if(strcmp(ent->name(), "can_1") == 0 && tpos.y() != 55.335){ tpos.y(55.335);} else if(strcmp(ent->name(), "can_2") == 0 && tpos.y() != 57.050){ tpos.y(57.050);} else if(strcmp(ent->name(), "can_3") == 0 && tpos.y() != 57.050){ tpos.y(57.050);} else if(strcmp(ent->name(), "banana") == 0 && tpos.y() != 51.69){ tpos.y(51.69);} else if(strcmp(ent->name(), "apple") == 0 && tpos.y() != 54.675){ tpos.y(54.675);} else{continue;} ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); usleep(100000); if(success){ msg = "CleanUpReferee/"; msg += ent->name(); msg += " succeeded/1000"; } else{ msg = "CleanUpReferee/"; msg += ent->name(); msg += " failed/-600"; } if(m_ref != NULL) { m_ref->sendMsgToSrv(msg.c_str()); } else{ LOG_MSG((msg.c_str())); } } } } return retValue; }
void MyController::onRecvMsg(RecvMsgEvent &evt) { std::string sender = evt.getSender(); char *all_msg = (char*)evt.getMsg(); std::string ss = all_msg; int strPos1 = 0; int strPos2,strPos3; std::string headss,cmd; std::string tmpss; std::cout<<"the massage is :"<< ss <<std::endl; std::cout<<"the sender is :"<< sender <<std::endl; strPos2 = ss.find(" ", strPos1); headss.assign(ss, strPos1, strPos2-strPos1); int jj = ss.size(); cmd.assign(ss, strPos2+1,jj); strPos3 = cmd.find("|", strPos1); id.assign(cmd, strPos1, strPos3-strPos1+1); //std::cout<<"The ID is : "<< id <<std::endl; bool aff = true; if (headss == "MultiUsersMenu") { bool available = checkService(ss); if (!available && m_ref != NULL) m_ref = NULL; else if (available && m_ref == NULL){ m_ref = connectToService(ss); } int nn = 0; for (int j = 0; j< list.size();j++) { if (id != list[j].ID) { nn++; } else { sendMsg(list[j].name,list[j].ID); m_state = 0; ind = j; current_avatar = list[j].name; } } if (nn == list.size()) { for (int i = 0; i< list.size();i++) { if (list[i].ID == "" && aff == true ) { list[i].ID = id; sendMsg(list[i].name,list[i].ID); m_state = 0; ind = i; current_avatar = list[i].name; aff = false; } } } } if (ss == "Info") { std::cout<<"Sending info to:"<< sender <<std::endl; std::string mess = ""; mess += "AvatarInformation/" ; mess += avatars_number; mess += "/" ; for (int j = 0; j< list.size();j++) { mess += list[j].name ; mess += "/" ; } std::cout<<"The message is :"<< mess <<std::endl; sendMsg(sender,mess); } }
double MyController::onAction(ActionEvent &evt) { // サービスが使用可能か定期的にチェックする bool available = checkService("RobocupReferee"); if(!available && m_ref != NULL) m_ref = NULL; // 使用可能 else if(available && m_ref == NULL){ // サービスに接続 m_ref = connectToService("RobocupReferee"); } // 自分の位置取得 Vector3d myPos; m_my->getPosition(myPos); // 衝突中の場合,衝突が継続しているかチェック if(colState){ CParts *parts = m_my->getMainParts(); bool state = parts->getCollisionState(); // 衝突していない状態に戻す if(!state) colState = false; } int entSize = m_entities.size(); for(int i = 0; i < entSize; i++){ // ロボットまたはゴミ箱の場合は除く if(m_entities[i] == "robot_000" || m_entities[i] == "recycle" || m_entities[i] == "burnable" || m_entities[i] == "room" || m_entities[i] == "moderator_0" || m_entities[i] == "Kinect_000" || m_entities[i] == "unburnable"){ continue; } // エンティティ取得 SimObj *ent = getObj(m_entities[i].c_str()); // 位置取得 Vector3d tpos; ent->getPosition(tpos); // ゴミ箱からゴミを結ぶベクトル Vector3d vec(tpos.x()-myPos.x(), tpos.y()-myPos.y(), tpos.z()-myPos.z()); // ゴミがゴミ箱の中に入ったかどうか判定 if(abs(vec.x()) < tboxSize_x/2.0 && abs(vec.z()) < tboxSize_z/2.0 && tpos.y() < tboxMax_y && tpos.y() > tboxMin_y ){ // ゴミがリリースされているか確認 if(!ent->getIsGrasped()){ // ゴミを捨てる tpos.y(-100); tpos.x(myPos.x()); tpos.z(myPos.z()); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setAxisAndAngle(1.0, 0.0, 0.0, 0.0); ent->setPosition(tpos); ent->setPosition(tpos); ent->setPosition(tpos); usleep(500000); tpos.y(-50.0); ent->setPosition(tpos); ent->setPosition(tpos); ent->setPosition(tpos); std::string msg; // ゴミが所定のゴミ箱に捨てられているかチェック // リサイクル /* if(strcmp(myname(), "recycle") == 0){ // 空のペットボトルのみ点が入る if(strcmp(ent->name(), "petbottle") == 0 || strcmp(ent->name(), "petbottle_2") == 0 || strcmp(ent->name(), "petbottle_4") == 0 || strcmp(ent->name(), "mayonaise_1") == 0 ) { msg = "RobocupReferee/Clean up succeeded" "/1000"; } else{ msg = "RobocupReferee/Clean up failed" "/-600"; } } */ // 燃えるゴミ /* else if(strcmp(myname(), "burnable") == 0){ // 燃えるゴミに入れるべきものは無い msg = "RobocupReferee/Clean up failed" "/-600"; } // 缶瓶 else if(strcmp(myname(), "unburnable") == 0){ if(strcmp(ent->name(), "can_0") == 0 || strcmp(ent->name(), "can_1") == 0 || strcmp(ent->name(), "can") == 0 || strcmp(ent->name(), "can_3") == 0) { msg = "RobocupReferee/Clean up succeeded" "/1000"; } else { msg = "RobocupReferee/Clean up succeeded" "/-600"; } } */ if(m_ref != NULL) { // m_ref->sendMsgToSrv(msg.c_str()); } //LOG_MSG((msg.c_str())); } } } return retValue; }