/*!
 This function sets up a UDP socket and sends a message to the drone that we are ready to
 receive data.
 */
void NavDataHandler::initialize()
{
	qDebug() << "[NavDataHandler] Initialize";

	QMutexLocker locker(&mMutex);

	mDroneResponded = false;
	mDroneBooting = true;

	// UDP socket for receiving data from the drone.
	mUdpSocketNavData = new QUdpSocket(this);
	bool res = mUdpSocketNavData->bind(NAVDATA_PORT, QUdpSocket::ShareAddress);
	if (!res)
	{
		qDebug() << "[NavDataHandler] Error connecting to Navdata " << " result:" << res;
	}
	else
	{
		connect(mUdpSocketNavData, SIGNAL(readyRead()), this, SLOT(newNavDataReady()));
	}

	// Send message to drone every 200ms to signal that we are ready to receive data.
	mInitTimer = new QTimer(this);
	connect(mInitTimer, SIGNAL(timeout()), this, SLOT(sendReadySignal()));
	mInitTimer->start(200);
}
Esempio n. 2
0
int main() {
    int isNormal;
    setVariables();
    while (1) {
        calibrateInit();
        displayCalibrate();
        if(isCalibrated(&gAccRead)) {
            standbyInit();
            countDown();
            while(1) {
                if (resetFlag) break;
                sendReadySignal();
                runTemp(&isNormal);
                if (isSafe && isNormal && hasEstablished) {
                    initActive();
                    while(1) {
                        int freq = calculateFreq();
                        runActive(freq);
                        runTemp(&isNormal);
                        if (resetFlag)
                            break;

                        if(isMayDay) {
                            switchDisplayToMayDay();
                            break;
                        }

                        if(!isNormal || !isSafe || standbyFlag) {
                            standbyFlag = 0;
                            switchDisplayToStandby();
                            countDown();
                            break;
                        }
                    }
                    if(resetFlag) {
                        switchDisplayToCalibrate();
                        break;
                    }

                    if(isMayDay) {
                        initMayDay();
                        runMayDay();
                        initLight();
                        switchDisplayToStandby();
                        countDown();
                    }
                }
            }
        }
    }
}