示例#1
0
/*------------------------------------------------------------------------------
-- FUNCTION:    PortIOThreadProc
--
-- DATE:        Oct 13, 2010
--
-- REVISIONS:   Nov 05, 2010
--              Modified the function to also listen for a "disconnect" event,
--              and to break in that case. ProcessRead() is now called once a 
--				complete packet is confirmed (as opposed to sending the 
--				contents of the buffer to ProcessRead() as soon as they arrive).
--
--				Nov 29, 2010
--				Renamed function from ReadThreadProc(). The event handling is
--				from the original function, but the response to each event has
--				changed.
--
-- DESIGNER:    Dean Morin
--
-- PROGRAMMER:  Dean Morin, Daniel Wright
--
-- INTERFACE:   DWORD WINAPI PortIOThreadProc(HWND hWnd)
--                      hWnd - the handle to the window
--
-- RETURNS:     0 because threads are required to return a DWORD.
--
-- NOTES:
--              While connected, this thread will loop and wait for characters
--              to arrive at the port, or for a timeout to occur, then call the
--				appropriate function. This function uses overlapped I/O.
------------------------------------------------------------------------------*/
DWORD WINAPI PortIOThreadProc(HWND hWnd) {
    OVERLAPPED  ol		= {0};
    DWORD       dwEvent = 0;
    DWORD       dwError = 0;
    COMSTAT     cs      = {0};
    HANDLE*     hEvents = NULL;
    PSTATEINFO  psi     = NULL;
    PWNDDATA	pwd		= (PWNDDATA) GetWindowLongPtr(hWnd, 0);
    

    if ((ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) == NULL) {
        DISPLAY_ERROR("Error creating event in read thread");
    }
    hEvents     = (HANDLE*) malloc(sizeof(HANDLE) * PORT_IO_EVENTS);
    hEvents[0]  = CreateEvent(NULL, FALSE, FALSE, TEXT("disconnected"));
    hEvents[1]  = ol.hEvent;
    
    psi = (PSTATEINFO) malloc(sizeof(STATEINFO));
    InitStateInfo(psi);
    DL_STATE = psi->iState;


    while (pwd->bConnected) {
        
        SetCommMask(pwd->hPort, EV_RXCHAR);      
        if (!WaitCommEvent(pwd->hPort, &dwEvent, &ol)) {
            ProcessCommError(pwd->hPort);
        }
        dwEvent = WaitForMultipleObjects(PORT_IO_EVENTS, hEvents, FALSE, 
                                         psi->dwTimeout);
        ClearCommError(pwd->hPort, &dwError, &cs);
 
        if (dwEvent == WAIT_OBJECT_0) {
            // the connection was severed
            break;
        }
        else if (dwEvent == WAIT_OBJECT_0 + 1  &&  cs.cbInQue) {
            // data arrived at the port
            ReadFromPort(hWnd, psi, ol, cs.cbInQue);
        }
        else if (dwEvent == WAIT_TIMEOUT) {
            // a timeout occured
            ProcessTimeout(hWnd, psi);
        }
        else if (dwEvent == WAIT_FAILED) {
            DISPLAY_ERROR("Invalid event occured in the Port I/O thread");
        }
        ResetEvent(ol.hEvent);
    }

    if (!PurgeComm(pwd->hPort, PURGE_RXCLEAR)) {
        DISPLAY_ERROR("Error purging read buffer");
    }
    CloseHandle(ol.hEvent);
    CloseHandle(hEvents[0]);
    free(hEvents);
    return 0;
}
NS_IMETHODIMP
nsIncrementalDownload::Observe(nsISupports *subject, const char *topic,
                               const char16_t *data)
{
  if (strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
    Cancel(NS_ERROR_ABORT);

    // Since the app is shutting down, we need to go ahead and notify our
    // observer here.  Otherwise, we would notify them after XPCOM has been
    // shutdown or not at all.
    CallOnStopRequest();
  }
  else if (strcmp(topic, NS_TIMER_CALLBACK_TOPIC) == 0) {
    mTimer = nullptr;
    nsresult rv = ProcessTimeout();
    if (NS_FAILED(rv))
      Cancel(rv);
  }
  return NS_OK;
}
示例#3
0
DWORD IOCPTimerQueue::ScheduleList( TIMEOUTLIST &timeoutList )
{
	// fire once ,so event can get change 
	if(timeoutList.empty())return INFINITE;

	for(TIMEOUTIT it = timeoutList.begin();
	it != timeoutList.end();){
		DWORD now = GetTickCount();
		if((*it)->expire > now){
			return (*it)->expire;
		}
		else {
			IOCPContext *context = (*it);
			ProcessTimeout(context);
			contextHash_.erase(context);
			it = timeoutList.erase(it);
		}
	}

	return INFINITE;
}
NS_IMETHODIMP
nsBrowserStatusFilter::OnStateChange(nsIWebProgress *aWebProgress,
                                     nsIRequest *aRequest,
                                     PRUint32 aStateFlags,
                                     nsresult aStatus)
{
    if (!mListener)
        return NS_OK;

    if (aStateFlags & STATE_START) {
        if (aStateFlags & STATE_IS_NETWORK) {
            ResetMembers();
        }
        if (aStateFlags & STATE_IS_REQUEST) {
            ++mTotalRequests;

            // if the total requests exceeds 1, then we'll base our progress
            // notifications on the percentage of completed requests.
            // otherwise, progress for the single request will be reported.
            mUseRealProgressFlag = (mTotalRequests == 1);
        }
    }
    else if (aStateFlags & STATE_STOP) {
        if (aStateFlags & STATE_IS_REQUEST) {
            ++mFinishedRequests;
            // Note: Do not return from here. This is necessary so that the
            // STATE_STOP can still be relayed to the listener if needed
            // (bug 209330)
            if (!mUseRealProgressFlag && mTotalRequests)
                OnProgressChange(nsnull, nsnull, 0, 0,
                                 mFinishedRequests, mTotalRequests);
        }
    }
    else if (aStateFlags & STATE_TRANSFERRING) {
        if (aStateFlags & STATE_IS_REQUEST) {
            if (!mUseRealProgressFlag && mTotalRequests)
                return OnProgressChange(nsnull, nsnull, 0, 0,
                                        mFinishedRequests, mTotalRequests);
        }

        // no need to forward this state change
        return NS_OK;
    } else {
        // no need to forward this state change
        return NS_OK;
    }

    // If we're here, we have either STATE_START or STATE_STOP.  The
    // listener only cares about these in certain conditions.
    PRBool isLoadingDocument = PR_FALSE;
    if ((aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK ||
         (aStateFlags & nsIWebProgressListener::STATE_IS_REQUEST &&
          mFinishedRequests == mTotalRequests &&
          (aWebProgress->GetIsLoadingDocument(&isLoadingDocument),
           !isLoadingDocument)))) {
        if (mTimer && (aStateFlags & nsIWebProgressListener::STATE_STOP)) {
            mTimer->Cancel();
            ProcessTimeout();
        }

        return mListener->OnStateChange(aWebProgress, aRequest, aStateFlags,
                                        aStatus);
    }

    return NS_OK;
}
示例#5
0
/**
 * @brief MainWindow::MainWindow
 * @param parent
 */
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    fConnected(false),
    bytesRequired(0),
    boardStatus(0)
{
    ui->setupUi(this);
    cbDevList = new QComboBox(ui->mainToolBar);
    cbDevList->setMinimumWidth(250);
    cbDevList->setEnabled(false);
    ui->mainToolBar->insertWidget(ui->actionHandleConnection, cbDevList);
    ui->mainToolBar->insertSeparator(ui->actionHandleConnection);
    lbI2CErrors = new QLabel(ui->statusBar);
    lbI2CErrors->setText("I2C Errors: 0");
    ui->statusBar->insertPermanentWidget(0, lbI2CErrors);

    serial = new QSerialPort(this);

    connect(ui->actionHandleConnection, SIGNAL(triggered()), this,
            SLOT(HandleSerialConnection()));
    connect(ui->actionRead, SIGNAL(triggered()), this, SLOT(HandleReadSettings()));
    connect(ui->actionSet, SIGNAL(triggered()), this, SLOT(HandleApplySettings()));
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(HandleSaveSettings()));
    connect(&timer, SIGNAL(timeout()), this, SLOT(ProcessTimeout()));
    connect(serial, SIGNAL(readyRead()), this, SLOT(ReadSerialData()));
    connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this,
            SLOT(HandleSerialError(QSerialPort::SerialPortError)));
    connect(ui->pushSensor1AccCalibrate, SIGNAL(clicked()), this, SLOT(HandleAccCalibrate()));
    connect(ui->pushSensor1GyroCalibrate, SIGNAL(clicked()), this, SLOT(HandleGyroCalibrate()));

    FillPortsInfo();

    for(int i = 0; i < 4; i++) {
        ui->comboPitchCommand->addItem(OutputCommands[i].item_name, OutputCommands[i].item_id);
        ui->comboRollCommand->addItem(OutputCommands[i].item_name, OutputCommands[i].item_id);
        ui->comboYawCommand->addItem(OutputCommands[i].item_name, OutputCommands[i].item_id);
    }
    ui->comboPitchCommand->setCurrentIndex(3);
    ui->comboRollCommand->setCurrentIndex(3);
    ui->comboYawCommand->setCurrentIndex(3);

    for(int i = 0; i < 5; i++) {
        ui->comboPitchDeadTime->addItem(OutputDeadTime[i].item_name, OutputDeadTime[i].item_id);
        ui->comboRollDeadTime->addItem(OutputDeadTime[i].item_name, OutputDeadTime[i].item_id);
        ui->comboYawDeadTime->addItem(OutputDeadTime[i].item_name, OutputDeadTime[i].item_id);
    }
    ui->comboPitchDeadTime->setCurrentIndex(4);
    ui->comboRollDeadTime->setCurrentIndex(4);
    ui->comboYawDeadTime->setCurrentIndex(4);

    for(int i = 0; i < 6; i++) {
        ui->comboInputChannelPitch->addItem(InputChannel[i].item_name, InputChannel[i].item_id);
        ui->comboInputChannelRoll->addItem(InputChannel[i].item_name, InputChannel[i].item_id);
        ui->comboInputChannelYaw->addItem(InputChannel[i].item_name, InputChannel[i].item_id);
    }
    ui->comboInputChannelPitch->setCurrentIndex(5);
    ui->comboInputChannelRoll->setCurrentIndex(5);
    ui->comboInputChannelYaw->setCurrentIndex(5);

    for(int i = 0; i < 3; i++) {
        ui->comboInputModePitch->addItem(InputMode[i].item_name, InputMode[i].item_id);
        ui->comboInputModeRoll->addItem(InputMode[i].item_name, InputMode[i].item_id);
        ui->comboInputModeYaw->addItem(InputMode[i].item_name, InputMode[i].item_id);
    }
    ui->comboInputModePitch->setCurrentIndex(0);
    ui->comboInputModeRoll->setCurrentIndex(0);
    ui->comboInputModeYaw->setCurrentIndex(0);

    for(int i = 0; i < 6; i++) {
        ui->comboSensor1AxisTOP->addItem(SensorAxis[i].item_name, SensorAxis[i].item_id);
        ui->comboSensor1AxisRIGHT->addItem(SensorAxis[i].item_name, SensorAxis[i].item_id);
    }
    ui->comboSensor1AxisTOP->setCurrentIndex(2);
    ui->comboSensor1AxisRIGHT->setCurrentIndex(3);

    ui->comboData->addItem(PlotData[0].item_name, PlotData[0].item_id);
    ui->comboData->setCurrentIndex(0);

    ui->plotData->addGraph();
     /* line color red for first graph. */
    ui->plotData->graph(0)->setPen(QPen(Qt::red));
    ui->plotData->addGraph();
    /* line color green for second graph. */
    ui->plotData->graph(1)->setPen(QPen(Qt::green));
    ui->plotData->addGraph();
    /* line color blue for third graph. */
    ui->plotData->graph(2)->setPen(QPen(Qt::blue));

    ui->plotData->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->plotData->xAxis->setDateTimeFormat("hh:mm:ss");
    ui->plotData->xAxis->setAutoTickStep(false);
    ui->plotData->xAxis->setTickStep(2);
    ui->plotData->axisRect()->setupFullAxesBox();

    ui->plotData->yAxis->setLabel("Attitude, deg");

    /* make left and bottom axes transfer their ranges to right and top axes: */
    connect(ui->plotData->xAxis, SIGNAL(rangeChanged(QCPRange)),
            ui->plotData->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->plotData->yAxis, SIGNAL(rangeChanged(QCPRange)),
            ui->plotData->yAxis2, SLOT(setRange(QCPRange)));

    connect(ui->checkDataX, SIGNAL(clicked()), this, SLOT(HandleDataXClicked()));
    connect(ui->checkDataY, SIGNAL(clicked()), this, SLOT(HandleDataYClicked()));
    connect(ui->checkDataZ, SIGNAL(clicked()), this, SLOT(HandleDataZClicked()));
}