Ejemplo n.º 1
0
	void CybPhantom::HLIdleFunc()
	{
		HLerror error;
		while (HL_ERROR(error = hlGetError()))
		{
			fprintf(stderr, "Error: %s\n", error.errorCode);
	
			if (error.errorCode == HL_DEVICE_ERROR)
			{
				hduPrintError(stderr, &error.errorInfo,
						"Error during haptic rendering\n");
			}
		}
	
		if(cybCore->phantomOn && !flagWorkspaceUpdate){
	
			hapticWorkspaceCalibration();
			flagWorkspaceUpdate = true;
		}
		else if(!cybCore->phantomOn)
		{
			flagWorkspaceUpdate = false;
		}		
	
	}
Ejemplo n.º 2
0
bool SQLiteUserDatabase::initialize()
{
	QString filePath = d->_dbFilePath;
	if (filePath.isEmpty()) {
		filePath = QDir::temp().filePath("users.db");
	}

	bool createTables = false;
	const QFileInfo sqliteDbInfo(filePath);
	if (!sqliteDbInfo.exists())
		createTables = true;

	d->_db = QSqlDatabase::addDatabase("QSQLITE", "users_connection");
	d->_db.setHostName("127.0.0.1");
	d->_db.setDatabaseName(filePath);
	d->_db.setUserName(QString());
	d->_db.setPassword(QString());

	bool errorOccured = false;
	if (!d->_db.open()) {
		HL_ERROR(HL, "Can not open database connection. Check your file permissions.");
		errorOccured = true;
	} else if (createTables) {
		QFile f(":/users.sqlite.sql");
		if (!f.open(QIODevice::ReadOnly)) {
			errorOccured = true;
		} else {
			QString sql = f.readAll();
			QStringList statements = sql.split(";", QString::SkipEmptyParts);
			foreach (const QString &stmt, statements) {
				QSqlQuery query(d->_db);
				if (!query.exec(stmt)) {
					HL_ERROR(HL, QString("SQL error (error=%1)").arg(query.lastError().text()).toStdString());
					d->_db.close();
					QFile::remove(sqliteDbInfo.filePath());
					return false;
				}
			}
		}
	}
void ControlToMasterConnectionHandler::Private::onSocketStateChanged(QAbstractSocket::SocketState state)
{
  QTcpSocket *socket = _conn->socket();
  switch (state) {
    case QAbstractSocket::ConnectedState:
      HL_INFO(HL, QString("Connected to master server (address=%1; port=%2)").arg(socket->peerAddress().toString()).arg(socket->peerPort()).toStdString());
      break;
    case QAbstractSocket::UnconnectedState:
      if (!_shutdown) {
        HL_ERROR(HL, QString("Lost connection to master server (error=%1)").arg(socket->errorString()).toStdString());
        _owner->startup(_opts);
      }
      emit _owner->disconnected();
      break;
  }
}
Ejemplo n.º 4
0
/*******************************************************************************
 GLUT callback for idle state.  Use this as an opportunity to request a redraw.
 Checks for HLAPI errors that have occurred since the last idle check.
*******************************************************************************/
void glutIdle()
{
    HLerror error;

    while (HL_ERROR(error = hlGetError()))
    {
        fprintf(stderr, "HL Error: %s\n", error.errorCode);
        
        if (error.errorCode == HL_DEVICE_ERROR)
        {
            hduPrintError(stderr, &error.errorInfo,
                "Error during haptic rendering\n");
        }
    }
    
    glutPostRedisplay();
}
Ejemplo n.º 5
0
/*******************************************************************************
 GLUT callback for idle state.  Use this as an opportunity to request a redraw.
 Checks for HLAPI errors that have occurred since the last idle check.
*******************************************************************************/
void glutIdle()
{
    HLerror error;

    while (HL_ERROR(error = hlGetError()))
    {
        fprintf(stderr, "HL Error: %s\n", error.errorCode);

        if (error.errorCode == HL_DEVICE_ERROR)
        {
            hduPrintError(stderr, &error.errorInfo,
                "Error during haptic rendering\n");
        }
    }

    char title[40];
    sprintf(title, "Haptic Displacement Mapping %4.1f fps", DetermineFPS());

    glutSetWindowTitle(title);
    glutPostRedisplay();
}
Ejemplo n.º 6
0
bool MediaStreamingSocketHandler::Private::processDatagram(QByteArray *data, const QHostAddress &sender, quint16 sender_port)
{
  QDataStream in(*data);
  in.setVersion(UdpProtocol::QDS_VERSION);

  UdpProtocol::UdpDatagramHeader header;
  in >> header;

  switch (header.type) {
    case UdpProtocol::DG_TYPE_TOKEN:
      return processTokenDatagram(in, data, sender, sender_port);
    case UdpProtocol::DG_TYPE_VIDEO_FRAME_V1:
      return processVideoFrameDatagramV1(in, data, sender, sender_port);
    case UdpProtocol::DG_TYPE_VIDEO_FRAME_RECOVERY_V1:
      return processVideoFrameRecoveryDatagramV1(in, data, sender, sender_port);
    case UdpProtocol::DG_TYPE_AUDIO_FRAME_V1:
      return processAudioFrameDatagramV1(in, data, sender, sender_port);
    default:
      HL_ERROR(HL, QString("Invalid datagram (sender=%1; port=%2)").arg(sender.toString()).arg(sender_port).toStdString());
      break;
  }
  return false;
}
Ejemplo n.º 7
0
bool VirtualServer::init()
{
  // Init QCorServer listening for new client connections.
  const quint16 port = _opts.port;
  if (!_corServer.listen(_opts.address, port)) {
    HL_ERROR(HL, QString("Can not bind to TCP port (port=%1)").arg(port).toStdString());
    return false;
  }
  HL_INFO(HL, QString("Listening for client connections (protocol=TCP; address=%1; port=%2)").arg(_opts.address.toString()).arg(port).toStdString());
  // Accepting new connections.
  connect(&_corServer, &QCorServer::newConnection, [this](QCorConnection *connection) {
    auto conn = new ClientConnectionHandler(this, connection, this);
  });

  // Init media socket.
  _mediaSocketHandler = new MediaSocketHandler(port, this);
  if (!_mediaSocketHandler->init()) {
    return false;
  }
  HL_INFO(HL, QString("Listening for media data (protocol=UDP; address=%1; port=%2)").arg(_opts.address.toString()).arg(port).toStdString());
  // Handle media authentications.
  // Note: This lambda slot is not thread-safe. If MediaSocketHandler should run in a separate thread, we need to reimplement this function.
  connect(_mediaSocketHandler, &MediaSocketHandler::tokenAuthentication, [this](const QString &token, const QHostAddress &address, quint16 port) {
    if (!_tokens.contains(token)) {
      HL_WARN(HL, QString("Received invalid media auth token (token=%1; address=%2; port=%3)").arg(token).arg(address.toString()).arg(port).toStdString());
      return;
    }
    // Update client-info with address and port.
    auto clientId = _tokens.take(token);
    auto clientEntity = _clients.value(clientId);
    if (!clientEntity) {
      HL_WARN(HL, QString("No matching client-entity for auth token (token=%1; client-id=%2)").arg(token).arg(clientId).toStdString());
      return;
    }
    clientEntity->mediaAddress = address.toString();
    clientEntity->mediaPort = port;

    // Notify client about the successful media authentication.
    auto conn = _connections.value(clientId);
    if (conn) {
      conn->sendMediaAuthSuccessNotify();
    }
    this->updateMediaRecipients();
  });
  QObject::connect(_mediaSocketHandler, &MediaSocketHandler::networkUsageUpdated, [this](const NetworkUsageEntity &networkUsage) {
    _networkUsageMediaSocket = networkUsage;
  });

  // Init status web-socket.
  WebSocketStatusServer::Options wsopts;
  wsopts.address = _opts.wsStatusAddress;
  wsopts.port = _opts.wsStatusPort;
  _wsStatusServer = new WebSocketStatusServer(wsopts, this);
  if (!_wsStatusServer->init()) {
    HL_ERROR(HL, QString("Can not bind to TCP port (port=%1)").arg(wsopts.port).toStdString());
    return false;
  }
  HL_INFO(HL, QString("Listening for web-socket status connections (protocol=TCP; address=%1; port=%2)").arg(wsopts.address.toString()).arg(wsopts.port).toStdString());

  return true;
}
Ejemplo n.º 8
0
/*******************************************************************************
 Main function.
*******************************************************************************/
int main(int argc, char *argv[])
{


    HHD hHD;
    HHLRC hHLRC;
    HDErrorInfo error;
    HLuint friction, spring;
    HLerror frameError;

    hHD = hdInitDevice(HD_DEFAULT_DEVICE);
    if (HD_DEVICE_ERROR(error = hdGetError())) 
    {
        hduPrintError(stderr, &error, "Failed to initialize haptic device");
        fprintf(stderr, "\nPress any key to quit.\n");
        getch();
        return -1;
    }
    hdMakeCurrentDevice(hHD);    

    hHLRC = hlCreateContext(hHD);
    hlMakeCurrent(hHLRC);
    
    hlDisable(HL_USE_GL_MODELVIEW);

    spring = hlGenEffects(1);

    /* Add a callback to handle button down in the collision thread. */
    hlAddEventCallback(HL_EVENT_1BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, 
                       buttonCB, &spring);
    hlAddEventCallback(HL_EVENT_1BUTTONUP, HL_OBJECT_ANY, HL_CLIENT_THREAD, 
                       buttonCB, &spring);
    hlAddEventCallback(HL_EVENT_2BUTTONDOWN, HL_OBJECT_ANY, HL_CLIENT_THREAD, 
                       buttonCB, 0);

    /* Start an ambient friction effect. */
    friction = hlGenEffects(1);

    hlBeginFrame();
    hlEffectd(HL_EFFECT_PROPERTY_GAIN, 0.2);
    hlEffectd(HL_EFFECT_PROPERTY_MAGNITUDE, 0.5);
    hlStartEffect(HL_EFFECT_FRICTION, friction);
    hlEndFrame();

    printf("Move around to feel the ambient stick-slip friction.\n\n");
    printf("Press and hold the primary stylus button to feel the spring effect.\n\n");
    printf("Press the second stylus button to trigger an impulse.\n\n");

    /* Run the main loop. */
    while (!_kbhit())
    {
        hlBeginFrame();

        /* Poll for events.  Note that client thread event callbacks get
           dispatched from within a frame here, so we can safely start/stop
           effects from the event callback directly */
        hlCheckEvents();

        hlEndFrame();

        /* Check for any errors. */
        while (HL_ERROR(frameError = hlGetError()))
        {
            fprintf(stderr, "HL Error: %s\n", frameError.errorCode);
            
            if (frameError.errorCode == HL_DEVICE_ERROR)
            {
                hduPrintError(stderr, &frameError.errorInfo,
                    "Error during haptic rendering\n");
            }
        }
    }

    /* Stop the friction effect. */
    hlBeginFrame();
    hlStopEffect(friction);
    hlEndFrame();

    hlDeleteEffects(friction, 1);
    hlDeleteEffects(spring, 1);

    hlDeleteContext(hHLRC);
    hdDisableDevice(hHD);

    return 0;
}