예제 #1
0
/*
*******************************************************************************
**
** This function simply queries a message mailbox without blocking if no
** message is available.
**
*******************************************************************************
*/
RTOS_Message RTOS_MailboxQuery( RTOS_Mailbox mailbox )
{
    OS_MBOX_DATA mboxdata;

    if( ! RTOS_MailboxIsValid( mailbox ) )
        return( (RTOS_Message)0 );
     
    if( OSMboxQuery( (OS_EVENT*)mailbox, &mboxdata ) != OS_NO_ERR )
        return( (RTOS_Message)0 );

    return( (RTOS_Message) mboxdata.OSMsg );
}
예제 #2
0
파일: main.cpp 프로젝트: Quang2695/ECE492
/* Checks for fingerprint */
void task1(void* pdata) {
	INT8U err;
	bool firstBuffer = true;
	while (true) {
		//Init sensor
		ZFMComm fingerprintSensor;
		fingerprintSensor.init(SERIAL_NAME);
		//Continue while we have no error
		while (!fingerprintSensor.hasError()) {
			OSTimeDlyHMSM(0, 0, 1, 0);
			printf("Checking for fingerprint\n");
			LCD::writeToLCD("Checking for", "fingerprint");
			//Check if the web server is pending on a fingerprint
			bool sendToMailbox = OSSemAccept(fingerprintSem) > 0;
			while (!fingerprintSensor.scanFinger()
					|| !fingerprintSensor.storeImage(getBufferNum(firstBuffer))) {
				//Sleep for a second and try again
				OSTimeDlyHMSM(0, 0, 1, 0);
				if (!sendToMailbox) {
					sendToMailbox = OSSemAccept(fingerprintSem) > 0;
				}
			}
			printf("Fingerprint acquired, looking for fingerprint ID\n");
			LCD::writeToLCD("Print found", "Looking for ID");
			int fid = fingerprintSensor.findFingerprint(getBufferNum(firstBuffer));
			printf("Fingerprint id:%d\n", fid);

			stringstream sStream;
			sStream << fid;
			LCD::writeToLCD("Print ID: ", sStream.str());


			if (sendToMailbox) {
				//Swap Fingerprint Buffer used in case we enroll next
				firstBuffer = !firstBuffer;
				if(m_enrollNow){
					Database dbAccess;
					fid = dbAccess.findNextID(USER_PRINTS);
					fingerprintSensor.storeFingerprint(fid);
					m_enrollNow = false;
				}
				//We need to wait for the mailbox to empty before we do anything
				while (true) {
					OS_MBOX_DATA mboxData;
					OSMboxQuery(fingerprintMailbox, &mboxData);
					if (mboxData.OSMsg == NULL) {
						//We can add data to the mailbox now
						break;
					}
					OSTimeDlyHMSM(0, 0, 1, 0);
				}
				err = OSMboxPost(fingerprintMailbox, &fid);
				if (err != OS_NO_ERR) {
					printf("Error sending message to fingerprint mailbox");
				}
				//Restart loop
				continue;
			}

			//Check if fingerprint is allowed access and unlock door
			//After this point, we fall through to the error if (uriString.compare(0, 7,
			{
				Database dbAccess;
				if(dbAccess.checkAccess(fid)){
					//Success, unlock door!
					char * ledBase = (char*) GREEN_LEDS_BASE;
					for (int i = 0; i < GREEN_LEDS_DATA_WIDTH; i++){
						*ledBase = 1 << i;
						OSTimeDlyHMSM(0, 0, 0, 100);
					}
					*ledBase = 0;
					printf("Open up!!!\n\n");
					printf("Unlocking\n");
					LCD::writeToLCD("Unlocking", "");
					Solenoid::unlock();
					continue;
				}
			}

			//Fallthrough error case. Notify owner!
			printf("Failed to verify print!\n\n");
			LCD::writeToLCD("Print not", "verified");
			{
				Audio sound(databaseSemaphore);
				for (int i = 0; i < 3; i++){
					sound.play();
				}
			}
		}
	}
}