Exemplo n.º 1
0
int main( int argc, char *argv[] )
{
    int currentIdx = 0;

    createSocket();
    myConnect();
    openUART();
    setCenter();

    if( wiringPiSetup() < 0 )
    {
        fprintf( stderr, "Unable to setup wiringPi\n" );
        return 1;
    }
    fprintf( stderr, "Setup wiringPi\n" );

    // create a thread for sensing, capturing
    pthread_create( &tid1, NULL, threadFunc1, 0 );
    // for recv
    pthread_create( &tid2, NULL, threadFunc2, (void *)&sockfd );

    for( ;; )
    {
        waiting = 1;
        biSem_wait( &sem_validIdx[currentIdx] );
        waiting = 0;

        checkStop();

        while( sendFile( imageFile[currentIdx] ) == -1 )
        {
            reconnect();
        }
        currentIdx = 1 - currentIdx;

        waiting_result = 1;
        waiting = 1;
        biSem_wait( &sem_result );
        waiting_result = 0;
        waiting = 0;

        checkStop();

        fprintf( stderr, "Result from the server is %d\n", result );

        // motor
        classify( result );
    }

    myClose( sockfd );
    fprintf( stderr, "Connection lost\n" );
    return 0;
}
Exemplo n.º 2
0
void DebuggerProxy::processInterrupt(CmdInterrupt &cmd) {
  TRACE(2, "DebuggerProxy::processInterrupt\n");
  // Do the server-side work for this cmd, which just notifies the client.
  if (!cmd.onServer(this)) {
    Debugger::RemoveProxy(shared_from_this()); // on socket error
    return;
  }

  // Wait for commands from the debugger client and process them. We'll stay
  // here until we get a command that should cause the thread to continue.
  while (true) {
    DebuggerCommandPtr res;
    while (!DebuggerCommand::Receive(m_thrift, res,
                                     "DebuggerProxy::processInterrupt()")) {
      // we will wait forever until DebuggerClient sends us something
      checkStop();
    }
    checkStop();
    if (res) {
      // Any control flow command gets installed here and we continue execution.
      m_flow = dynamic_pointer_cast<CmdFlowControl>(res);
      if (m_flow) {
        m_flow->onServer(this);
        processFlowControl(cmd);
        if (m_flow && m_threadMode == Normal) {
          switchThreadMode(Sticky);
        }
        return;
      }
      if (res->is(DebuggerCommand::KindOfQuit)) {
        Debugger::RemoveProxy(shared_from_this());
        throw DebuggerClientExitException();
      }
    }
    try {
      // Perform the server-side work for this command.
      if (!res || !res->onServer(this)) {
        Debugger::RemoveProxy(shared_from_this());
        return;
      }
    } catch (const DebuggerException &e) {
      throw;
    } catch (...) {
      Logger::Error("onServer() throws non DebuggerException: %d",
                    res->getType());
      Debugger::RemoveProxy(shared_from_this());
      return;
    }
    if (res->shouldExitInterrupt()) {
      return;
    }
  }
}
Exemplo n.º 3
0
void CPollingThread::stop()
{
    if(!checkStop()) {
        mutex.lock();
        stopFlag = true;
        mutex.unlock();
    }
}
Exemplo n.º 4
0
void CPollingThread::run()
{
    state = CSerialPortPrivate::STATE_REQUESTING; //CSerialPortPrivate::STATE_WRITING;
    forever {
        if (checkStop()) {
            break;
        } else if (!sp->getStatus()){
            msleep(30);
        } else {
            doPoll();
        }
    }
    qDebug() << "stop";
}
Exemplo n.º 5
0
std::string DebuggerProxy::requestAuthToken() {
  Lock lock(m_signalMutex);
  TRACE_RB(2, "DebuggerProxy::requestauthToken: sending auth request\n");

  // Try to use the current sandbox's path, defaulting to the path from
  // DebuggerDefaultSandboxPath if the current sandbox path is empty.
  auto sandboxPath = getSandbox().m_path;
  if (sandboxPath.empty()) {
    sandboxPath = RuntimeOption::DebuggerDefaultSandboxPath;
  }

  CmdAuth cmd;
  cmd.setSandboxPath(sandboxPath);
  if (!cmd.onServer(*this)) {
    TRACE_RB(2, "DebuggerProxy::requestAuthToken: "
             "Failed to send CmdAuth to client\n");
    return "";
  }

  DebuggerCommandPtr res;
  while (!DebuggerCommand::Receive(m_thrift, res,
                                   "DebuggerProxy::requestAuthToken()")) {
    checkStop();
  }
  if (!res) {
    TRACE_RB(2, "DebuggerProxy::requestAuthToken: "
             "Failed to get CmdAuth back from client\n");
    return "";
  }

  auto token = std::dynamic_pointer_cast<CmdAuth>(res);
  if (!token) {
    TRACE_RB(2, "DebuggerProxy::requestAuthToken: "
             "bad response from token request: %d", res->getType());
    return "";
  }

  return token->getToken();
}
Exemplo n.º 6
0
void DebuggerProxy::processInterrupt(CmdInterrupt &cmd) {
  TRACE_RB(2, "DebuggerProxy::processInterrupt\n");
  // Do the server-side work for this interrupt, which just notifies the client.
  if (!cmd.onServer(*this)) {
    TRACE_RB(1, "Failed to send CmdInterrupt to client\n");
    Debugger::UsageLog("server", getSandboxId(), "ProxyError",
                       "Send interrupt");
    stopAndThrow();
  }

  Debugger::UsageLogInterrupt("server", getSandboxId(), cmd);

  // Wait for commands from the debugger client and process them. We'll stay
  // here until we get a command that should cause the thread to continue.
  while (true) {
    DebuggerCommandPtr res;
    while (!DebuggerCommand::Receive(m_thrift, res,
                                     "DebuggerProxy::processInterrupt()")) {
      // we will wait forever until DebuggerClient sends us something
      checkStop();
    }
    checkStop();
    if (res) {
      TRACE_RB(2, "Proxy got cmd type %d\n", res->getType());
      Debugger::UsageLog("server", getSandboxId(),
                         folly::to<std::string>(res->getType()));
      // Any control flow command gets installed here and we continue execution.
      m_flow = std::dynamic_pointer_cast<CmdFlowControl>(res);
      if (m_flow) {
        m_flow->onSetup(*this, cmd);
        if (!m_flow->complete()) {
          TRACE_RB(2, "Incomplete flow command %d remaining on proxy for "
                   "further processing\n", m_flow->getType());
          if (m_threadMode == Normal) {
            // We want the flow command to complete on the thread that
            // starts it.
            switchThreadMode(Sticky);
          }
        } else {
          // The flow cmd has determined that it is done with its work and
          // doesn't need to remain for later processing.
          TRACE_RB(2, "Flow command %d completed\n", m_flow->getType());
          m_flow.reset();
        }
        return;
      }
      if (res->is(DebuggerCommand::KindOfQuit)) {
        TRACE_RB(2, "Received quit command\n");
        res->onServer(*this); // acknowledge receipt so that client can quit.
        stopAndThrow();
      }
    }
    bool cmdFailure = false;
    try {
      // Perform the server-side work for this command.
      if (res) {
        if (!res->onServer(*this)) {
          TRACE_RB(1, "Failed to execute cmd %d from client\n", res->getType());
          Debugger::UsageLog("server", getSandboxId(), "ProxyError",
                             "Command failed");
          cmdFailure = true;
        }
      } else {
        TRACE_RB(1, "Failed to receive cmd from client\n");
        Debugger::UsageLog("server", getSandboxId(), "ProxyError",
                           "Command receive failed");
        cmdFailure = true;
      }
    } catch (const DebuggerException &e) {
      throw;
    } catch (const Object &o) {
      Logger::Warning(DEBUGGER_LOG_TAG
                      "Cmd type %d onServer() threw a php exception %s",
                      res->getType(), o->getVMClass()->name()->data());
      Debugger::UsageLog("server", getSandboxId(), "ProxyError",
                         "Command exception");
      cmdFailure = true;
    } catch (const std::exception& e) {
      Logger::Warning(DEBUGGER_LOG_TAG
       "Cmd type %d onServer() threw exception %s", res->getType(), e.what());
      Debugger::UsageLog("server", getSandboxId(), "ProxyError",
                         "Command exception");
      cmdFailure = true;
    } catch (...) {
      Logger::Warning(DEBUGGER_LOG_TAG
       "Cmd type %d onServer() threw non standard exception", res->getType());
      Debugger::UsageLog("server", getSandboxId(), "ProxyError",
                         "Command exception");
      cmdFailure = true;
    }
    if (cmdFailure) stopAndThrow();
    if (res->shouldExitInterrupt()) return;
  }
}
Exemplo n.º 7
0
followLine()
{
    switch(currState)
       {
           case idle:
               flag = 0;
                //turn off the motors
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 0; 
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 0;
                //wait for button press
                if(SWITCH == 0) //pressed
                {
                    currState = debouncePress;
                }
               break;
        case debouncePress:
            delayMs(10);
            currState = waitForRelease;
            break;
        case waitForRelease:
            if(SWITCH == 1) //released
            {
                currState = debounceRelease;
            }
            break;
        case debounceRelease:
            delayMs(10);
            if(flag == 1) currState = idle;
            else currState = findLine;
            break;
           case findLine:
               checkStop();
               //DONUT
               LEFTMOTORDIRECTION1 = 0; 
               LEFTMOTORDIRECTION2 = 1;         
               RIGHTMOTORDIRECTION1 = 0;
               RIGHTMOTORDIRECTION2 = 1;
               RW = 500;
               LW = 250; 
               break;
           case moveRight:
               checkStop();
               // Turn off right wheel
               // Turn on left wheel at full power
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 100; 
                LW = 700; 
               break;
           case moveLeft:
                checkStop();
                //Turn off left wheel
                //Turn on right wheel at full power
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 700; 
                LW = 100; 
               break;
           case moveFwd: 
                checkStop();
                //Turn on both motors at full power
                LEFTMOTORDIRECTION1 = 0; 
                LEFTMOTORDIRECTION2 = 1;         
                RIGHTMOTORDIRECTION1 = 0;
                RIGHTMOTORDIRECTION2 = 1;
                RW = 700;
                LW = 700; 
               break;      
       }
}