예제 #1
1
void ProcessesList::produzirListaProcessos(){
    this->listaProcessos.clear();

    QDir *directory;
    QFile *arquivo;
    QString *S;

    QStringList files;
    std::string data;

    QDir aDir("/proc");

    aDir.setFilter(QDir::Dirs);
    QStringList entries = aDir.entryList();
    this->numThreads = 0;

    for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry)
    {
        S = new QString("/proc/" + QString(*entry));

        if((S->compare("/proc/.") == 0) || (S->compare("/proc/..") == 0)){
            continue;
        }

        directory = new QDir(*S);

        if(!directory->exists()){
            continue;
        } else if(!((S->toStdString()[6] >= '0') && (S->toStdString()[6] <= '9'))){
            continue;
        }

        directory->setFilter(QDir::Files);

        arquivo = new QFile(*S + "/status");

        if((!arquivo)){
            qDebug() << "ERRO 1! (" << *S << ")";
            continue;
        } else if(!arquivo->open(QIODevice::ReadOnly | QIODevice::Text)){
            qDebug() << arquivo->errorString();
            qDebug() << "ERRO 2! (" << *S << ")";
            continue;
        }

        process P;

        QTextStream buffer(arquivo);
        QStringList fileContent = buffer.readAll().split("\n");
        QString buf;

        P.nome = processName(fileContent.at(0));
        P.status = processStatus(fileContent.at(1));

        P.pid = processPid(fileContent.at(3));
        P.ppid = processPPid(fileContent.at(4));

        P.user = processUser(fileContent.at(6));

        for (int var = 7; var < fileContent.size(); ++var) {
            buf = fileContent.at(var);
            if(buf.startsWith("Threads")){
                break;
            }
        }

        P.threads = processThreadsNumber(buf);
        this->numThreads += P.threads;

        P.trocas_contexto = processTrocasContexto(fileContent.at(fileContent.size()-3),fileContent.at(fileContent.size()-2));

        this->listaProcessos.push_back(P);

        arquivo->close();
    }

    delete arquivo;
    delete directory;
    delete S;
}
예제 #2
0
void SensorHandler::receiveMsg(const ComsPacket & msg)
{
  if ( msg.getModuleId() != MODULE_ID) {
    return;
  }
  if ( msg.getPacketId() != DATA_PACKET_ID ) {
    return;
  }
  uint32_t s = msg.getSeqNumber();
  if ( s == lastSeqNum_ ) {
    return;
  }
  if ( (s+1) != lastSeqNum_ ) {
    ROS_INFO("We appear to have missed USB packets");
    ROS_INFO("S: %d", s);
    ROS_INFO("LastSeqNum_: %d", lastSeqNum_);
  }
  lastSeqNum_ = s;

  const uint8_t *data = msg.getPayload();
  processStatus(data);
  processDepth(data);
  processINS(data);
  processPower(data);
}
예제 #3
0
BtSs82::BtSs82(RDMatrix *matrix,QObject *parent,const char *name)
  : QObject(parent,name)
{
  //
  // Initialize Data Structures
  //
  bt_istate=0;
  for(int i=0;i<BTSS82_GPIO_PINS;i++) {
    bt_gpi_state[i]=false;
    bt_gpi_mask[i]=false;
  }

  //
  // Get Matrix Parameters
  //
  bt_matrix=matrix->matrix();
  bt_inputs=matrix->inputs();
  bt_outputs=matrix->outputs();
  bt_gpis=matrix->gpis();
  bt_gpos=matrix->gpos();

  //
  // Initialize the TTY Port
  //
  RDTty *tty=new RDTty(rdstation->name(),matrix->port(RDMatrix::Primary));
  bt_device=new RDTTYDevice();
  if(tty->active()) {
    bt_device->setName(tty->port());
    bt_device->setSpeed(tty->baudRate());
    bt_device->setWordLength(tty->dataBits());
    bt_device->setParity(tty->parity());
    bt_device->open(IO_Raw|IO_ReadWrite);
  }
  delete tty;

  //
  // Interval OneShots
  //
  bt_gpi_oneshot=new RDOneShot(this);
  connect(bt_gpi_oneshot,SIGNAL(timeout(void *)),
	  this,SLOT(gpiOneshotData(void*)));
  bt_gpo_oneshot=new RDOneShot(this);
  connect(bt_gpo_oneshot,SIGNAL(timeout(void *)),
	  this,SLOT(gpoOneshotData(void*)));

  //
  // The Poll Timer
  //
  QTimer *timer=new QTimer(this,"poll_timer");
  connect(timer,SIGNAL(timeout()),this,SLOT(processStatus()));
  timer->start(BTSS82_POLL_INTERVAL);
}
예제 #4
0
파일: btgpi16.cpp 프로젝트: WMTH/rivendell
BtGpi16::BtGpi16(RDMatrix *matrix,QObject *parent,const char *name)
  : Switcher(matrix,parent,name)
{
  //
  // Initialize Data Structures
  //
  bt_istate=0;
  for(int i=0;i<BTGPI16_GPIO_PINS;i++) {
    bt_gpi_state[i]=false;
    bt_gpi_mask[i]=false;
  }

  //
  // Get Matrix Parameters
  //
  bt_matrix=matrix->matrix();
  bt_gpis=matrix->gpis();

  //
  // Initialize the TTY Port
  //
  RDTty *tty=new RDTty(rdstation->name(),matrix->port(RDMatrix::Primary));
  bt_device=new RDTTYDevice();
  if(tty->active()) {
    bt_device->setName(tty->port());
    bt_device->setSpeed(tty->baudRate());
    bt_device->setWordLength(tty->dataBits());
    bt_device->setParity(tty->parity());
    if(!bt_device->open(IO_Raw|IO_ReadWrite)) {
      LogLine(RDConfig::LogWarning,"unable to open serial device \""+tty->port()+"\".");
    }
  }
  delete tty;

  //
  // The Poll Timer
  //
  QTimer *timer=new QTimer(this,"poll_timer");
  connect(timer,SIGNAL(timeout()),this,SLOT(processStatus()));
  timer->start(BTGPI16_POLL_INTERVAL);
}
예제 #5
0
/*
 * Processes an event from the CanHandler.
 *
 * In case a CAN message was received which pass the masking and id filtering,
 * this method is called. Depending on the ID of the CAN message, the data of
 * the incoming message is processed.
 */
void BrusaMotorController::handleCanFrame( CAN_FRAME *frame) {
	switch (frame->id) {
	case CAN_ID_STATUS:
		processStatus(frame->data.bytes);
		break;
	case CAN_ID_ACTUAL_VALUES:
		processActualValues(frame->data.bytes);
		break;
	case CAN_ID_ERRORS:
		processErrors(frame->data.bytes);
		break;
	case CAN_ID_TORQUE_LIMIT:
		processTorqueLimit(frame->data.bytes);
		break;
	case CAN_ID_TEMP:
		processTemperature(frame->data.bytes);
		break;
	default:
		Logger::warn(BRUSA_DMC5, "received unknown frame id %X", frame->id);
	}
}
예제 #6
0
processMultireads::processMultireads(QWidget *parent) :
    QWidget(parent),
    progressView(new analysisProgressView(this)),
    multireadsView(new processMultireadsView(this))
{
    // set a window title
    setWindowTitle(tr("Rcount-multireads"));

    // initialize all the other widgets
    // get and set the minimal sizes
    int minWidth = multireadsView->sizeHint().width();
    int minHeight = multireadsView->sizeHint().height()+progressView->sizeHint().height()*1.5;
    this->setMinimumHeight(minHeight);
    this->setMinimumWidth(minWidth);

    // layout
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(multireadsView);
    layout->addWidget(progressView);
    setLayout(layout);

    // hide the progressView
    //! progressView->hide();

    // connections
    connect(&processor, SIGNAL(processStatus(QString)), progressView, SLOT(updateStatus(QString)));
    connect(&processor, SIGNAL(processProgress(int)), progressView, SLOT(updateProgress(int)));
    connect(&processor, SIGNAL(errorMessage(QString)), progressView, SLOT(updateStatus(QString)));
    //! connect(&processor, SIGNAL(idleAgain()), this, SLOT(hideProgress()));
    connect(&processor, SIGNAL(workFinished(QString)), multireadsView, SLOT(removeFromQueue(QString)));
    connect(progressView, SIGNAL(analysisCanceled()), &processor, SLOT(cancelProcessing()));
    connect(multireadsView, SIGNAL(closeAll()), &processor, SLOT(cancelProcessing()));
    connect(multireadsView, SIGNAL(closeAll()), this, SLOT(close()));
    connect(multireadsView, SIGNAL(processReads(QString)), this, SLOT(runProcessor(QString)));

}
예제 #7
0
void YahooClient::process_packet()
{
    Params params;
    Params::iterator it;
    for (;;) {
        string key;
        string value;
        if (!m_socket->readBuffer.scan("\xC0\x80", key) || !m_socket->readBuffer.scan("\xC0\x80", value))
            break;
        unsigned key_id = atol(key.c_str());
        params.push_back(PARAM(key_id, value));
        log(L_DEBUG, "Param: %u %s", key_id, value.c_str());
    }
    switch (m_service) {
    case YAHOO_SERVICE_VERIFY:
        if (m_pkt_status != 1) {
            m_reconnect = NO_RECONNECT;
            m_socket->error_state(I18N_NOOP("Yahoo! login lock"));
            return;
        }
        addParam(1, getLogin().utf8());
        sendPacket(YAHOO_SERVICE_AUTH);
        break;
    case YAHOO_SERVICE_AUTH:
        process_auth(params[13], params[94], params[1]);
        break;
    case YAHOO_SERVICE_AUTHRESP:
        m_pkt_status = 0;
        if (params[66])
            m_pkt_status = atol(params[66]);
        switch (m_pkt_status) {
        case YAHOO_LOGIN_OK:
            authOk();
            return;
        case YAHOO_LOGIN_PASSWD:
            m_reconnect = NO_RECONNECT;
            m_socket->error_state(I18N_NOOP("Login failed"), AuthError);
            return;
        case YAHOO_LOGIN_LOCK:
            m_reconnect = NO_RECONNECT;
            m_socket->error_state(I18N_NOOP("Your account has been locked"), AuthError);
            return;
        case YAHOO_LOGIN_DUPL:
            m_reconnect = NO_RECONNECT;
            m_socket->error_state(I18N_NOOP("Your account is being used from another location"));
            return;
        default:
            m_socket->error_state(I18N_NOOP("Login failed"));
        }
        break;
    case YAHOO_SERVICE_LIST:
        authOk();
        loadList(params[87]);
        for (it = params.begin(); it != params.end(); ++it) {
            if ((*it).first == 59) {
                string s = (*it).second;
                string n = getToken(s, ' ');
                const char *p = s.c_str();
                for (; *p; ++p)
                    if (*p != ' ')
                        break;
                string cookie = p;
                s = getToken(cookie, ';');
                if (n == "Y")
                    setCookieY(s.c_str());
                if (n == "T")
                    setCookieT(s.c_str());
            }
        }
        break;
    case YAHOO_SERVICE_LOGOFF:
        if (m_pkt_status == (unsigned long)(-1)) {
            m_reconnect = NO_RECONNECT;
            m_socket->error_state(I18N_NOOP("Your account is being used from another location"));
            return;
        }
    case YAHOO_SERVICE_LOGON:
        if (params[1])
            authOk();
    case YAHOO_SERVICE_USERSTAT:
    case YAHOO_SERVICE_ISAWAY:
    case YAHOO_SERVICE_ISBACK:
    case YAHOO_SERVICE_GAMELOGON:
    case YAHOO_SERVICE_GAMELOGOFF:
    case YAHOO_SERVICE_IDACT:
    case YAHOO_SERVICE_IDDEACT:
        if (params[7] && params[13])
            processStatus(m_service, params[7], params[10], params[19], params[47], params[137]);
        break;
    case YAHOO_SERVICE_IDLE:
    case YAHOO_SERVICE_MAILSTAT:
    case YAHOO_SERVICE_CHATINVITE:
    case YAHOO_SERVICE_CALENDAR:
    case YAHOO_SERVICE_NEWPERSONALMAIL:
    case YAHOO_SERVICE_ADDIDENT:
    case YAHOO_SERVICE_ADDIGNORE:
    case YAHOO_SERVICE_PING:
    case YAHOO_SERVICE_GOTGROUPRENAME:
    case YAHOO_SERVICE_GROUPRENAME:
    case YAHOO_SERVICE_PASSTHROUGH2:
    case YAHOO_SERVICE_CHATLOGON:
    case YAHOO_SERVICE_CHATLOGOFF:
    case YAHOO_SERVICE_CHATMSG:
    case YAHOO_SERVICE_REJECTCONTACT:
    case YAHOO_SERVICE_PEERTOPEER:
        break;
    case YAHOO_SERVICE_MESSAGE:
        if (params[4] && params[14])
            process_message(params[4], params[14], params[97]);
        break;
    case YAHOO_SERVICE_NOTIFY:
        if (params[4] && params[49])
            notify(params[4], params[49], params[13]);
        break;
    case YAHOO_SERVICE_NEWCONTACT:
        if (params[1]) {
            contact_added(params[3], params[14]);
            return;
        }
        if (params[7]) {
            processStatus(m_service, params[7], params[10], params[14], params[47], params[137]);
            return;
        }
        if (m_pkt_status == 7)
            contact_rejected(params[3], params[14]);
        break;
    case YAHOO_SERVICE_P2PFILEXFER:
        if ((params[49] == NULL) || strcmp(params[49], "FILEXFER")) {
            log(L_WARN, "Unhandled p2p type %s", params[49]);
            break;
        }
    case YAHOO_SERVICE_FILETRANSFER:
        if (params[4] && params[27] && params[28] && params[14] && params[20])
            process_file(params[4], params[27], params[28], params[14], params[20]);
        break;
    default:
        log(L_WARN, "Unknown service %X", m_service);
    }
}
예제 #8
0
void AMCSubNode::update() {
  double current, velocity, position;
  
  processStatus();
  
  if (getState() != AMCSubNode::OperationEnabled) {
    setPosition(tpdo_ptr_->actual_position);
  }
  
  if (getState() == AMCSubNode::Fault) {
		// go to ReadyToSwitchOn state
		RTT::log(RTT::Warning) << "Fault" << RTT::endlog();
		target_state_ = ResetFault;
	} else if (getState() == AMCSubNode::QuickStopActive) {
		// go to ReadyToSwitchOn state
		RTT::log(RTT::Warning) << "QuickStop" << RTT::endlog();
		target_state_ = DisableVoltage;
	} else if (getState() == AMCSubNode::NotReadyToSwitchOn) {
		// go to ReadyToSwitchOn state
		//RTT::log(RTT::Warning) << "NotReadyToSwitchOn" << RTT::endlog();
		target_state_ = ShutDown;
	} else if (getState() == AMCSubNode::SwitchOnDisabled) {
		// go to ReadyToSwitchOn state
		//RTT::log(RTT::Warning) << "ReadyToSwitchOn" << RTT::endlog();
		target_state_ = ShutDown;
	} else if (getState() == AMCSubNode::ReadyToSwitchOn) {
		// go to OperationDisabled state
		//RTT::log(RTT::Warning) << "OperationDisabled" << RTT::endlog();
		setPosition(tpdo_ptr_->actual_position);
		target_state_ = SwitchOn;
	} else if (getState() == AMCSubNode::SwitchedOn) {
	  //RTT::log(RTT::Warning) << "SwitchedOn" << RTT::endlog();
	  
	  setPosition(tpdo_ptr_->actual_position);
	  
	  if (position_valid_) {
	    RTT::log(RTT::Warning) << "enable" << RTT::endlog();
	    setControlMode(mode_);
	    target_state_ = EnableOperation;
	  } else {
	    RTT::log(RTT::Warning) << "homing" << RTT::endlog();
	    setControlMode(Homing);
	    target_state_ = BeginHoming;
	    homing_ = true;
	  }
	} else if (getState() == AMCSubNode::OperationEnabled) {
	  //RTT::log(RTT::Warning) << "OperationEnabled" << RTT::endlog();
	  if (position_valid_) {
	    if (port_motor_position_command_.read(position) == RTT::NewData) {
        setPosition(position);
      }

      if (port_motor_velocity_command_.read(velocity) == RTT::NewData) {
        setVelocity(velocity);
      }
    
      if (port_motor_current_command_.read(current) == RTT::NewData) {
        setCurrent(current);
      }
      
      // dio
      
      bool dio;
      
      if (port_do1_command_.read(dio) == RTT::NewData) {
        if (dio) {
          setDO(0);
        } else {
          resetDO(0);
        }
      }
      
      if (port_do2_command_.read(dio) == RTT::NewData) {
        if (dio) {
          setDO(1);
        } else {
          resetDO(1);
        }
      }
      
      if (port_do3_command_.read(dio) == RTT::NewData) {
        if (dio) {
          setDO(2);
        } else {
          resetDO(2);
        }
      }
      
      if (port_do4_command_.read(dio) == RTT::NewData) {
        if (dio) {
          setDO(3);
        } else {
          resetDO(3);
        }
      }
      
	  } else {
	    if ((actualMode_ == Homing)) {
	      if (isHomingCompleted()) {
	        position_valid_ = true;
	        setPosition(tpdo_ptr_->actual_position);
	        setControlMode(mode_);
	        target_state_ = EnableOperation;
	      } else {
	        target_state_ = BeginHoming;
        }
	    } else {
	      setControlMode(Homing);
	      target_state_ = BeginHoming;
      }
	  }
  }
  
  enterStateNoCheck(target_state_);
  
  if (position_valid_) {
    port_motor_position_.write(getActualPosition());
    port_motor_velocity_.write(getActualVelocity());
    port_motor_current_.write(getActualCurrent());
  }
}