Ejemplo n.º 1
0
bool MainWindow::connectRobot (const QString& address) {
  if (m_connectedRobots.end() != m_connectedRobots.find(address)) {
    /* The requested robot is already connected */
    return true;
  }

  auto newrobot = new mobot_t;
  Mobot_init(newrobot);

  /* extract the 8-bit byte array from QString, from which we can then extract
   * the C-string */
  auto baAddress = address.toLocal8Bit();

  if (-1 == Mobot_connectWithAddress(newrobot, baAddress.data(), 1)) {
    delete newrobot;
    qDebug() << "(barobolab) ERROR: Mobot_connectWithTTY failed\n";
    return false;
  }
  Mobot_enableButtonCallback(newrobot, strdup(baAddress.data()), JsInterface::robotButtonCallback);
  auto l = new RobotListener(newrobot, address);
  QObject::connect(l, SIGNAL(scrollUp(QString)), m_interface, SLOT(scrollUpSlot(QString)));
  QObject::connect(l, SIGNAL(scrollDown(QString)), m_interface, SLOT(scrollDownSlot(QString)));
  QThread *thread = new QThread(this);
  l->moveToThread(thread);
  thread->start();
  QMetaObject::invokeMethod(l, "startWork", Qt::QueuedConnection);
  m_connectedRobots.insert(std::make_pair(address, newrobot));
  m_robotListeners.insert(std::make_pair(address, l));
  return true;
}
Ejemplo n.º 2
0
void MainWindow::baroboInit () {
  Mobot_init(m_dongle.get());
  char tty[64];
  if (-1 == Mobot_dongleGetTTY(tty, sizeof(tty))) {
    qWarning("(barobolab) WARNING: Mobot_dongleGetTTY failed\n");
  }
  if (-1 == Mobot_connectWithTTY(m_dongle.get(), tty)) {
    qWarning("(barobolab) WARNING: Mobot_connectWithTTY failed\n");
  }
  Mobot_setDongleMobot(m_dongle.get());
}
Ejemplo n.º 3
0
int main()
{
  int i = 0;
  mobot_t mobot;
  Mobot_init(&mobot);
  //Mobot_connectWithAddress(&mobot, "LQLX", 1);
  Mobot_connectWithAddress(&mobot, "S3S3", 1);
  Mobot_enableJointEventCallback(&mobot, NULL, jointcb);
  Mobot_enableAccelEventCallback(&mobot, NULL, accelcb);
  printf("Press enter to quit.\n");
  getchar();

  return 0;
}
void* findDongleWorkerThread(void* arg)
{
  /* The argument is a pointer to an int */
  int num = *(int*)arg;
  char buf[80];
  mobot_t* mobot;
  int rc;
#if defined (_WIN32) or defined (_MSYS)
  sprintf(buf, "\\\\.\\COM%d", num);
#else
  sprintf(buf, "/dev/ttyACM%d", num);
#endif
  /* Try to connect to it */
  mobot = (mobot_t*)malloc(sizeof(mobot_t));
  Mobot_init(mobot);
  rc = Mobot_connectWithTTY(mobot, buf);
  if(rc != 0) {
    rc = Mobot_connectWithTTY_500kbaud(mobot, buf);
  }
  if(rc == 0) {
    /* We found the Mobot */
    MUTEX_LOCK(&g_giant_lock);
    /* Only update g_mobot pointer if no one else has updated it already */
    if(g_mobot == NULL) {
      g_mobot = mobot;
      g_dongleSearchStatus = DONGLE_FOUND;
      strcpy(g_comport, buf);
      COND_SIGNAL(&g_giant_cond);
      MUTEX_UNLOCK(&g_giant_lock);
    } else {
      MUTEX_UNLOCK(&g_giant_lock);
      Mobot_disconnect(mobot);
      free(mobot);
    }
    Mobot_getStatus(mobot);
  } else {
    free(mobot);
  }
  MUTEX_LOCK(&g_giant_lock);
  g_numThreads--;
  COND_SIGNAL(&g_giant_cond);
  MUTEX_UNLOCK(&g_giant_lock);
  return NULL;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
  int rc;
  mobot_t mobot;
  if(argc != 3) {
    printf("Expected usage: %s <tty device> <mobot id>\n", argv[0]);
    return 0;
  }
  Mobot_init(&mobot);
  if(rc = Mobot_connectWithTTY(&mobot, argv[1])) {
    fprintf(stderr, "Connection failed with error code %d.\n", rc);
    exit(rc);
  }

  if(rc = Mobot_setID(&mobot, argv[2])) {
    fprintf(stderr, "Error setting the Mobot's ID. %d\n", rc);
    exit(rc);
  }

  return 0;
}