Esempio n. 1
0
void Framebuffer::clearBuffer(const GLenum buffer, const GLint drawBuffer, const glm::vec4 & value)
{
    clearBuffer(buffer, drawBuffer, glm::value_ptr(value));
}
Esempio n. 2
0
// Function: clearMregister
// Description: Returns a copy of the M register
// Params: none
// Returns: none
// Modifies: M
void clearMregister()
{
    clearBuffer((char *) &M, sizeof(M));
    M.stat = SAOK;
    M.icode = NOP;
}
Esempio n. 3
0
 void BConsole::clear(){
     ::clrscr();
     clearBuffer();
 }
Esempio n. 4
0
HttpParserImpl::ParseState HttpParserImpl::parseChunk(const char*& cur_pos, const char* end)
{
    const char* p_line = nullptr;
    const char* p_end = nullptr;
    bool b_line = false;
    while (cur_pos < end)
    {
        switch (chunk_state_)
        {
            case CHUNK_READ_SIZE:
            {
                b_line = getLine(cur_pos, end, p_line, p_end);
                if(!b_line)
                {// need more data, save remain data.
                    if(saveData(cur_pos, end) != KUMA_ERROR_NOERR) {
                        return PARSE_STATE_ERROR;
                    }
                    cur_pos = end;
                    return PARSE_STATE_CONTINUE;
                }
                std::string str;
                if(!str_buf_.empty()) {
                    str.swap(str_buf_);
                    clearBuffer();
                }
                str.append(p_line, p_end);
                // need not parse chunk extension
                chunk_size_ = (uint32_t)strtol(str.c_str(), NULL, 16);
                KUMA_INFOTRACE("HttpParser::parseChunk, chunk_size="<<chunk_size_);
                if(0 == chunk_size_)
                {// chunk completed
                    chunk_state_ = CHUNK_READ_TRAILER;
                } else {
                    chunk_bytes_read_ = 0;
                    chunk_state_ = CHUNK_READ_DATA;
                }
                break;
            }
            case CHUNK_READ_DATA:
            {
                uint32_t cur_len = uint32_t(end - cur_pos);
                if(chunk_size_ - chunk_bytes_read_ <= cur_len) {// data enough
                    const char* notify_data = cur_pos;
                    uint32_t notify_len = chunk_size_ - chunk_bytes_read_;
                    total_bytes_read_ += notify_len;
                    chunk_bytes_read_ = chunk_size_ = 0; // reset
                    chunk_state_ = CHUNK_READ_DATA_CR;
                    cur_pos += notify_len;
                    bool destroyed = false;
                    destroy_flag_ptr_ = &destroyed;
                    if(cb_data_) cb_data_(notify_data, notify_len);
                    if(destroyed) {
                        return PARSE_STATE_DESTROY;
                    }
                    destroy_flag_ptr_ = nullptr;
                } else {// need more data
                    const char* notify_data = cur_pos;
                    total_bytes_read_ += cur_len;
                    chunk_bytes_read_ += cur_len;
                    cur_pos += cur_len;
                    if(cb_data_) cb_data_(notify_data, cur_len);
                    return PARSE_STATE_CONTINUE;
                }
                break;
            }
            case CHUNK_READ_DATA_CR:
            {
                if(*cur_pos != CR) {
                    KUMA_ERRTRACE("HttpParser::parseChunk, can not find data CR");
                    read_state_ = HTTP_READ_ERROR;
                    return PARSE_STATE_ERROR;
                }
                ++cur_pos;
                chunk_state_ = CHUNK_READ_DATA_LF;
                break;
            }
            case CHUNK_READ_DATA_LF:
            {
                if(*cur_pos != LF) {
                    KUMA_ERRTRACE("HttpParser::parseChunk, can not find data LF");
                    read_state_ = HTTP_READ_ERROR;
                    return PARSE_STATE_ERROR;
                }
                ++cur_pos;
                chunk_state_ = CHUNK_READ_SIZE;
                break;
            }
            case CHUNK_READ_TRAILER:
            {
                b_line = getLine(cur_pos, end, p_line, p_end);
                if(b_line) {
                    if(p_line == p_end && bufferEmpty()) {
                        // blank line, http completed
                        read_state_ = HTTP_READ_DONE;
                        onComplete();
                        return PARSE_STATE_DONE;
                    }
                    clearBuffer(); // discard trailer
                } else { // need more data
                    if(saveData(cur_pos, end) != KUMA_ERROR_NOERR) {
                        return PARSE_STATE_ERROR;
                    }
                    cur_pos = end; // all data was consumed
                    return PARSE_STATE_CONTINUE;
                }
                break;
            }
        }
    }
    return HTTP_READ_DONE == read_state_?PARSE_STATE_DONE:PARSE_STATE_CONTINUE;
}
Esempio n. 5
0
void
Normalizer::setIndexOnly(int32_t index) {
    text->setIndex(index);  // pins index
    currentIndex=nextIndex=text->getIndex();
    clearBuffer();
}
Esempio n. 6
0
void testApp::holdBuffer() {
    if(holdingBuffer != 1) {
        clearBuffer();
        holdingBuffer = 1;
    }
}
//========================================================
void ResearchMenu(){

	char w[20];
	int validPath;
	int const maxSizePath = 100;
	char *path[maxSizePath] , *pathOfList[maxSizePath];
	int choice;
	float *percent;
	float *positionFile;
	char openPath[50]="xdg-open"; // Permite to default open file ex: xdg-open img.png
	
	PileVD *valDesc , tmpVD;
	PictureDesc imgDsc;
	SoundDesc sdDsc;
	//TextDesc txtDsc;
	FILE *IMGbase;
	FILE *TXTbase;
	FILE *SOUNDbase;
	FILE *fileOfDesc;
	FILE *GivenPath;
	
	do{
		printf("+=========================+\n");
		printf("|                         |\n");
		printf("|1. Research a word       |\n");
		printf("|2. Research a color      |\n");
		printf("|3. Research similar sound|\n");
		printf("|                         |\n");
		printf("+=================0.RETURN+\n");

		scanf("%d" , &choice);
		if(choice!=1 && choice !=2 && choice!=0 && choice!=3){
			system("clear");
		}
	}while(choice!=1 && choice!=2 && choice!=0 && choice!=3);
	clearBuffer();
	switch(choice){
		case(1):
			/*TXTbase=fopen("TextBaseDesc.db" , 'r');
			researchTXT
			fclose(TXTbase);
			system("clear");
			*/
			break;
		case(2):
			system("clear");
			if(!fileExists("PictureBaseDesc.db"))printf("PictureBaseDesc.db don\'t exists\n");
			else{
				IMGbase=fopen("PictureBaseDesc.db" , 'r');
				researchIMG(IMGbase);
				fclose(IMGbase);
			}
			ResearchMenu();
			break;
		case(3):
			if(!fileExists("PictureBaseDesc.db"))printf("PictureBaseDesc.db don\'t exists\n");
			else{
				SOUNDbase=fopen("SoundBaseDesc.db" , 'r');
				researchSound(SOUNDbase);
				fclose(SOUNDbase);
			}
			system("clear");
			ResearchMenu();
			break;
		case(0): 
			system("clear");
			mainMenu(); 
			break;
		default: // to secure
			exit(0); 
			break;
	}
	mainMenu();
}
Esempio n. 8
0
LRESULT
CArchConsoleWindows::wndProc(HWND hwnd,
				UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_CLOSE:
		ShowWindow(m_frame, FALSE);
		m_show = false;
		return 0;

	case SYNERGY_MSG_CONSOLE_OPEN:
		return 0;

	case SYNERGY_MSG_CONSOLE_CLOSE:
		SendMessage(m_frame, WM_CLOSE, 0, 0);
		m_show = false;
		return 0;

	case SYNERGY_MSG_CONSOLE_SHOW:
		m_show = true;
		if (wParam != 0 || !m_buffer.empty()) {
			ShowWindow(m_frame, TRUE);
		}
		return 0;

	case SYNERGY_MSG_CONSOLE_WRITE:
		appendBuffer(reinterpret_cast<const char*>(wParam));
		return 0;

	case SYNERGY_MSG_CONSOLE_CLEAR:
		clearBuffer();
		return 0;

	case WM_SIZE:
		if (hwnd == m_frame) {
			MoveWindow(m_hwnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
		}
		break;

	case WM_SIZING:
		if (hwnd == m_frame) {
			// get window vs client area info
			int wBase = 40 * m_wChar;
			int hBase = 40 * m_hChar;
			DWORD style   = GetWindowLong(m_frame, GWL_STYLE);
			DWORD exStyle = GetWindowLong(m_frame, GWL_EXSTYLE);
			RECT rect;
			rect.left   = 100;
			rect.top    = 100;
			rect.right  = rect.left + wBase;
			rect.bottom = rect.top + hBase;
			AdjustWindowRectEx(&rect, style, FALSE, exStyle);
			wBase = rect.right - rect.left - wBase;
			hBase = rect.bottom - rect.top - hBase;

			// get closest size that's a multiple of the character size
			RECT* newRect = (RECT*)lParam;
			int width  = (newRect->right - newRect->left - wBase) / m_wChar;
			int height = (newRect->bottom - newRect->top - hBase) / m_hChar;
			width  = width  * m_wChar + wBase;
			height = height * m_hChar + hBase;

			// adjust sizing rect
			switch (wParam) {
			case WMSZ_LEFT:
			case WMSZ_TOPLEFT:
			case WMSZ_BOTTOMLEFT:
				newRect->left = newRect->right - width;
				break;

			case WMSZ_RIGHT:
			case WMSZ_TOPRIGHT:
			case WMSZ_BOTTOMRIGHT:
				newRect->right = newRect->left + width;
				break;
			}
			switch (wParam) {
			case WMSZ_TOP:
			case WMSZ_TOPLEFT:
			case WMSZ_TOPRIGHT:
				newRect->top = newRect->bottom - height;
				break;

			case WMSZ_BOTTOM:
			case WMSZ_BOTTOMLEFT:
			case WMSZ_BOTTOMRIGHT:
				newRect->bottom = newRect->top + height;
				break;
			}
			return TRUE;
		}
		break;

	default:
		break;
	}

	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Esempio n. 9
0
/* Function Name: clearWregister
 * Purpose:       Clears the W register
 * 
 * Parameters:    -
 * Returns:       -
 * Modifies:      W
 */
void clearWregister(){
    clearBuffer((char *) &W, sizeof(W));
    W.stat = SAOK;
    W.icode = INOP;
}
Esempio n. 10
0
byte Dynamixel::rxPacket(byte bRxLength){
	unsigned long ulCounter, ulTimeLimit;
	byte bCount, bLength, bChecksum;
	byte bTimeout;

	bTimeout = 0;
	if(bRxLength == 255)
		ulTimeLimit = RX_TIMEOUT_COUNT1;
	else
		ulTimeLimit = RX_TIMEOUT_COUNT2;
	for(bCount = 0; bCount < bRxLength; bCount++)
	{
		ulCounter = 0;
		while(mDxlDevice->read_pointer == mDxlDevice->write_pointer)
		{
			nDelay(NANO_TIME_DELAY); //[ROBOTIS] porting ydh
			if(ulCounter++ > ulTimeLimit)
			{
				bTimeout = 1;
				//TxDStringC("Timeout\r\n");
				break;
			}
			uDelay(0); //[ROBOTIS] porting ydh added
		}
		if(bTimeout) break;
		mRxBuffer[bCount] = mDxlDevice->data_buffer[mDxlDevice->read_pointer++]; // get packet data from USART device
		//TxDStringC("mRxBuffer = ");TxDHex8C(mRxBuffer[bCount]);TxDStringC("\r\n");
	}

	bLength = bCount;
	bChecksum = 0;


	if( mTxBuffer[2] != BROADCAST_ID )
	{
		if(bTimeout && bRxLength != 255)
		{
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
			TxDStringC("Rx Timeout");
			TxDByteC(bLength);
#endif
			mDXLtxrxStatus |= (1<<COMM_RXTIMEOUT);
			clearBuffer();
			//TxDStringC("Rx Timeout");
			return 0;
		}
		if(bLength > 3) //checking available length.
		{
			if(mRxBuffer[0] != 0xff || mRxBuffer[1] != 0xff )
			{
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
				TxDStringC("Wrong Header");//[Wrong Header]
#endif
				mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXHEADER);
				clearBuffer();
				return 0;
			}
			if(mRxBuffer[2] != mTxBuffer[2] )
			{
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
				TxDStringC("[Error:TxID != RxID]");
#endif
				mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXID);
				clearBuffer();
				return 0;
			}
			if(mRxBuffer[3] != bLength-4)
			{
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
				TxDStringC("RxLength Error");
#endif
				mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXLENGTH);
				clearBuffer();
				return 0;
			}
			for(bCount = 2; bCount < bLength; bCount++){
				bChecksum += mRxBuffer[bCount]; //Calculate checksum of received data for compare
			}
			if(bChecksum != 0xff)
			{
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
				TxDStringC("[RxChksum Error]");
#endif
				mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXCHECKSUM);
				clearBuffer();
				return 0;
			}
		}
	}

	return bLength;
}
Esempio n. 11
0
byte Dynamixel::rxPacket(int bRxLength) {
    unsigned long ulCounter, ulTimeLimit;
    word bCount, bLength, bChecksum;
    byte bTimeout;


    bTimeout = 0;
    if(bRxLength == 255 || bRxLength == 0xffff) //2014-04-03
        ulTimeLimit = RX_TIMEOUT_COUNT1;
    else
        ulTimeLimit = RX_TIMEOUT_COUNT2;
    for(bCount = 0; bCount < bRxLength; bCount++)
    {
        ulCounter = 0;
        while(mDxlDevice->read_pointer == mDxlDevice->write_pointer)
        {
            nDelay(NANO_TIME_DELAY); //[ROBOTIS] porting ydh
            if(ulCounter++ > ulTimeLimit)
            {
                bTimeout = 1;
                //TxDStringC("Timeout\r\n");
                break;
            }
            uDelay(0); //[ROBOTIS] porting ydh added  //if exist DXL 1.0 -> ok DXL 2.0 -> ok, if not exist 1.0 not ok, 2.0 ok
        }
        if(bTimeout) break;
        mRxBuffer[bCount] = mDxlDevice->data_buffer[mDxlDevice->read_pointer++ & DXL_RX_BUF_SIZE]; // get packet data from USART device
        //TxDStringC("mRxBuffer = ");TxDHex8C(mRxBuffer[bCount]);TxDStringC("\r\n");
    }

    bLength = bCount;
    bChecksum = 0;
    if( mTxBuffer[mPktIdIndex] != BROADCAST_ID )
    {
        if(bTimeout && bRxLength != 255)
        {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
            TxDStringC("Rx Timeout");
            TxDByteC(bLength);
#endif
            mDXLtxrxStatus |= (1<<COMM_RXTIMEOUT);
            clearBuffer();
            //TxDStringC("Rx Timeout");
            return 0;
        }
        if(bLength > 3) //checking available length.
        {
            /*if(mPacketType == 1){
            	if(mRxBuffer[0] != 0xff || mRxBuffer[1] != 0xff ) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXHEADER);
            	else if(mRxBuffer[mPktIdIndex] != mTxBuffer[mPktIdIndex] ) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXID);
            	else if(mRxBuffer[mPktLengthIndex] != bLength-mPktInstIndex) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXLENGTH);
            	else{
            		for(bCount = 2; bCount < bLength; bCount++){
            			bChecksum += mRxBuffer[bCount]; //Calculate checksum of received data for compare
            		}
            		if(bChecksum != 0xff) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXCHECKSUM);
            		return 0;
            	}
            }else{
            	if(mRxBuffer[0] != 0xff || mRxBuffer[1] != 0xff || mRxBuffer[2] != 0xfd)  mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXHEADER);
            	else if(mRxBuffer[mPktIdIndex] != mTxBuffer[mPktIdIndex] ) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXID);
            	else if(mRxBuffer[mPktLengthIndex] != bLength-mPktInstIndex) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXLENGTH);
            	else{
            		bChecksum = DXL_MAKEWORD(mRxBuffer[bRxLength-2], mRxBuffer[bRxLength-1]);
            		if(update_crc(0, mRxBuffer, bRxLength-2) != bChecksum) mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXCHECKSUM);
            		return 0;
            	}
            }
            */
            if(mPacketType == 1) { //Dxl 1.0 header check
                if(mRxBuffer[0] != 0xff || mRxBuffer[1] != 0xff ) {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                    TxDStringC("Wrong Header");//[Wrong Header]
#endif
                    mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXHEADER);
                    clearBuffer();
                    return 0;
                }
            } else { // Dxl 2.0 header check
                if(mRxBuffer[0] != 0xff || mRxBuffer[1] != 0xff || mRxBuffer[2] != 0xfd)
                {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                    TxDStringC("Wrong Header");//[Wrong Header]
#endif
                    mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXHEADER);
                    clearBuffer();
                    return 0;
                }
            }

            if(mRxBuffer[mPktIdIndex] != mTxBuffer[mPktIdIndex] )  //id check
            {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                TxDStringC("[Error:TxID != RxID]");
#endif
                mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXID);
                clearBuffer();
                return 0;
            }

            if(mRxBuffer[mPktLengthIndex] != bLength-mPktInstIndex) // status packet length check
            {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                TxDStringC("RxLength Error");
#endif
                mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXLENGTH);
                clearBuffer();
                return 0;
            }

            if(mPacketType == 1 && mRxBuffer[mPktErrorIndex] != 0) {										//140512 shin
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                for(bTryCount = 0; bTryCount<= 6; bTryCount++) {
                    if((mRxBuffer[mPktErrorIndex] & (1<<bTryCount)) == TRUE) {
                        switch(bTryCount) {
                        case 0:
                            TxDStringC("InputVoltage Error");
                            break;
                        case 1:
                            TxDStringC("Angle Limit Error");
                            break;
                        case 2:
                            TxDStringC("Overheating Error");
                            break;
                        case 3:
                            TxDStringC("Range Error");
                            break;
                        case 4:
                            TxDStringC("Checksum Error");
                            break;
                        case 5:
                            TxDStringC("Overload Error");
                            break;
                        case 6:
                            TxDStringC("Instruction Error");
                            break;
                        }
                    }
                }
#endif
            } else {																					//140512 shin
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                for(bTryCount = 1; bTryCount<= 7; bTryCount++) {
                    if((mRxBuffer[mPktErrorIndex]) == bTryCount) {
                        switch(bTryCount) {
                        case 1:
                            TxDStringC("Result Fail");
                            break;
                        case 2:
                            TxDStringC("Instruction Error");
                            break;
                        case 3:
                            TxDStringC("CRC Error");
                            break;
                        case 4:
                            TxDStringC("DataRange Error");
                            break;
                        case 5:
                            TxDStringC("DataLength Error");
                            break;
                        case 6:
                            TxDStringC("DataLimit Error");
                            break;
                        case 7:
                            TxDStringC("Accrss Error");
                            break;
                        }
                    }
                }
#endif
            }

            if(mPacketType == 1) { // Dxl 1.0 checksum
                for(bCount = 2; bCount < bLength; bCount++) {
                    bChecksum += mRxBuffer[bCount]; //Calculate checksum of received data for compare
                }
                if(bChecksum != 0xff)
                {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                    TxDStringC("[RxChksum Error]");
#endif
                    mDXLtxrxStatus |= (1<<COMM_RXCORRUPT);//RXCHECKSUM);
                    clearBuffer();
                    return 0;
                }
            } else { // Dxl 2.0 checksum
                bChecksum = DXL_MAKEWORD(mRxBuffer[bRxLength-2], mRxBuffer[bRxLength-1]);
                if(update_crc(0, mRxBuffer, bRxLength-2) == bChecksum) { // -2 : except CRC16
                    return bLength;
                }
                else {
#ifdef PRINT_OUT_COMMUNICATION_ERROR_TO_USART2
                    TxDStringC("CRC-16 Error\r\n");
#endif
                    return 0;
                }
            }//end of checksum
        }//(bLength > 3)
    }//end of Rx status packet check

    return bLength;
}
int receiverZigbeeTest(void) {
	/*
	char *macAdresse = "1";
	char *panId = "1620";
	char *channel = "100000";
	char *function = "0";
	char *adresse = "0";
	char *data;
	char receiveChar;
	char valide;
	int toto;
	*/
	
	TRISB = 0;
	TRISB = 0;

	// Configure serialBuffer
	Buffer zigbeeBuffer;
	initBuffer(&zigbeeBuffer, SERIAL_PORT_ZIGBEE);
	setAndOpenSerialBuffer(&zigbeeBuffer);

	Buffer debugBuffer;
	initBuffer(&debugBuffer, SERIAL_PORT_DEBUG);
	setAndOpenSerialBuffer(&debugBuffer);

	setSerialBuffer(&debugBuffer);
	putString("Beacon Receiver start rs232\n");

	initPwmForServo(1500);	

	// Initialization of laserDetector
	// Laser 1
	initLaserDetectorStruct(
			LASER_INDEX_1,
			LASER_SERVO_INDEX_1,
			&getLaserPin1,
			SERVO_LASER_1_MAX_LEFT_POSITION_DEFAULT_VALUE, 
			SERVO_LASER_1_MAX_RIGHT_POSITION_DEFAULT_VALUE,
			SHORT_TRACKING_INTERVAL,
			BEACON_SERVO_1_FACTOR,
			BEACON_SERVO_1_INIT_COMPUTE_VALUE,
			BEACON_SERVO_1_ANGLE_DEGREE
	);
	// Laser 2
	initLaserDetectorStruct(
			LASER_INDEX_2,
			LASER_SERVO_INDEX_2,
			&getLaserPin2,
			SERVO_LASER_2_MAX_LEFT_POSITION_DEFAULT_VALUE,
			SERVO_LASER_2_MAX_RIGHT_POSITION_DEFAULT_VALUE,
			SHORT_TRACKING_INTERVAL,
			BEACON_SERVO_2_FACTOR,
			BEACON_SERVO_2_INIT_COMPUTE_VALUE,
			BEACON_SERVO_2_ANGLE_DEGREE
	);

	while (1) {
		int laserIndex;
		for (laserIndex = 0; laserIndex < LASER_COUNT; laserIndex++) {
			detectsLaser(laserIndex);
		}
		delay100us(5);

		char c = handleChar(&debugBuffer, FALSE);
		if (c != 0) {
			putString("---------\n");
			Laser* laser1 = getLaser(LASER_INDEX_1);
			Laser* laser2 = getLaser(LASER_INDEX_2);
	
			printLaserStruct(&debugBuffer, laser1);
			println();
			printLaserStruct(&debugBuffer, laser2);
			clearBuffer(&debugBuffer);

			Point p = getPosition(DISTANCE_BETWEEN_BEACON);
			if (p.x != 0 && p.y != 0) {
				sendDec(p.x);
				putString(", ");
				sendDec(p.y);
				println();
			}	
		}
	}

	/*
	valide = 0;
	while (1) {
		if (U2STAbits.URXDA == 1){
				valide = getc();
				putc1 (valide);
		}
		if (U1STAbits.URXDA == 1){
				valide = getc1();
				putc (valide);
		}
	}
	*/
}
/////////////////
// Constructor //
/////////////////
MG2639_Cell::MG2639_Cell():uart0(CELL_SW_TX, CELL_SW_RX)
{
	memset(rxBuffer, '\0', RX_BUFFER_LENGTH); // Clear rxBuffer
	clearBuffer(); // Clear UART receive buffer
}
Esempio n. 14
0
void Framebuffer::clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, float value)
{
    clearBuffer(buffer, drawBuffer, &value);
}
Esempio n. 15
0
void clearEregister()
{
  clearBuffer((char *) &E, (sizeof(E)));
  E.stat = SAOK;
  E.icode = INOP;
}
Esempio n. 16
0
static void resetBuffer(bufferPo b, strgPo old, integer pos) {
  clearBuffer(b);
  stringIntoBuffer(b, old);
  seekBuffer(b, pos);
}
Esempio n. 17
0
// C++ level interrupt handler for this instance
void RH_RF24::handleInterrupt()
{
    uint8_t status[8];
    command(RH_RF24_CMD_GET_INT_STATUS, NULL, 0, status, sizeof(status));

    // Decode and handle the interrupt bits we are interested in
//    if (status[0] & RH_RF24_INT_STATUS_CHIP_INT_STATUS)
    if (status[0] & RH_RF24_INT_STATUS_MODEM_INT_STATUS)
    {
//	if (status[4] & RH_RF24_INT_STATUS_INVALID_PREAMBLE)
	if (status[4] & RH_RF24_INT_STATUS_INVALID_SYNC)
	{
	    // After INVALID_SYNC, sometimes the radio gets into a silly state and subsequently reports it for every packet
	    // Need to reset the radio and clear the RX FIFO, cause sometimes theres junk there too
	    _mode = RHModeIdle;
	    clearRxFifo();
	    clearBuffer();
	}
    }
    if (status[0] & RH_RF24_INT_STATUS_PH_INT_STATUS)
    {
	if (status[2] & RH_RF24_INT_STATUS_CRC_ERROR)
	{
	    // CRC Error
	    // Radio automatically went to _idleMode
	    _mode = RHModeIdle;
	    _rxBad++;

	    clearRxFifo();
	    clearBuffer();
	}
	if (status[2] & RH_RF24_INT_STATUS_PACKET_SENT)
	{
	    _txGood++; 
	    // Transmission does not automatically clear the tx buffer.
	    // Could retransmit if we wanted
	    // RH_RF24 configured to transition automatically to Idle after packet sent
	    _mode = RHModeIdle;
	    clearBuffer();
	}
	if (status[2] & RH_RF24_INT_STATUS_PACKET_RX)
	{
	    // A complete message has been received with good CRC
	    // Get the RSSI, configured to latch at sync detect in radio_config
	    uint8_t modem_status[6];
	    command(RH_RF24_CMD_GET_MODEM_STATUS, NULL, 0, modem_status, sizeof(modem_status));
	    _lastRssi = modem_status[3];
	    _lastPreambleTime = millis();
	    
	    // Save it in our buffer
	    readNextFragment();
	    // And see if we have a valid message
	    validateRxBuf();
	    // Radio will have transitioned automatically to the _idleMode
	    _mode = RHModeIdle;
	}
	if (status[2] & RH_RF24_INT_STATUS_TX_FIFO_ALMOST_EMPTY)
	{
	    // TX FIFO almost empty, maybe send another chunk, if there is one
	    sendNextFragment();
	}
	if (status[2] & RH_RF24_INT_STATUS_RX_FIFO_ALMOST_FULL)
	{
	    // Some more data to read, get it
	    readNextFragment();
	}
    }
}
Esempio n. 18
0
DrawBuffer::~DrawBuffer() 
{
    clearBuffer();
}
Esempio n. 19
0
void testApp::releaseBuffer() {
    if(holdingBuffer == 1) {
        clearBuffer();
        holdingBuffer = 0;
    }
}
Esempio n. 20
0
void LineBuffer::createBuffer(unsigned numVertices)
{
    clearBuffer();
    m_vertices = new Vector3F[numVertices];
	m_numVertices = numVertices;
}
//========================================================
void IndexationMenu(){
	int choice , validPath;
	int const maxSizePath = 100;
	char *path[maxSizePath];
	FileType filetype;
	FILE *fileTOindex;
	BaseDesc basedesc;
	initList(&basedesc);
	void *desc = NULL;
	
	do{
		printf("+=========================+\n");
		printf("|                         |\n");
		printf("|1. Index a SOUND         |\n");
		printf("|2. Index an IMAGE        |\n");
		printf("|3. Index a TEXT          |\n");
		printf("|                         |\n");
		printf("+=================0.RETURN+\n");

		scanf("%d" , &choice);
		if(choice!=1 && choice!=0 && choice!=2 && choice!=3){
			system("clear");
		}
	}while(choice!=1 && choice!=2 && choice!=0);
	clearBuffer();
	
	do{
			
					printf("Sgronieunieux\n");
					fflush(stdout);	
		if(choice==0){ system("clear");mainMenu(); }
		printf("Add an empty path with \"Enter\" to start Indexation.\n");
		printf("Enter your(s) path(s) : \n");
		validPath = getKeyboard_String(path,0, maxSizePath);
		if(fileExists(path)){
			fileTOindex=fopen(path,"r");
			if(fileTOindex==NULL){ printf("FAIL !\n"); fflush(stdout) ; exit(0);}
			switch(choice){
				case(1):			 
					addDesc(&basedesc,createSoundDesc(fileTOindex),SOUND);
				break;
				case(2):	
					addDesc(&basedesc,createPictureDesc(fileTOindex),PICTURE);
				break;
				case(3):			
					/*desc=createTextDesc(fileTOindex); 
					basedesc=;
					addDesc(&basedesc,desc,TEXT);*/
				break;
				default: 
					exit(0); 
				break;
			}
			fclose(fileTOindex);
			strcpy(path,""); // Permite to  secure the next path to enter by the user
			printf("Succesfull indexation.\n");
		}
		else{
			system("clear");
			printf("Error, file don\'t exists\n");
			mainMenu();
		}				
	} while ( validPath > 0 ); //while !0=NULL or !-1=so littre or !=-2=ERROR
	mainMenu();
}
Esempio n. 22
0
LineBuffer::~LineBuffer() 
{
    clearBuffer();
}
Esempio n. 23
0
void Normalizer::reset() {
    currentIndex=nextIndex=text->setToStart();
    clearBuffer();
}
Esempio n. 24
0
/*----------------------------------------------------------------------------*
* NAME
*     UartDrv_Reset
* 
* DESCRIPTION
*
*   This function is called to reset the UART driver.  The transmit and
*   receive buffers are flushed.
*
*   NOTE: the UART configuration does NOT change.
*
* RETURNS
*   None
*
*/
void UartDrv_Reset(void)
{
	/*	clear any data in the in/out buffers	*/
	clearBuffer();
}
Esempio n. 25
0
/**
 * Return the last character in the normalized text.  This resets
 * the <tt>Normalizer's</tt> position to be just before the
 * the input text corresponding to that normalized character.
 */
UChar32 Normalizer::last() {
    currentIndex=nextIndex=text->setToEnd();
    clearBuffer();
    return previous();
}
// This checks the Serial stream for characters, and assembles them into a buffer.  
// When the terminator character (default '\r') is seen, it starts parsing the 
// buffer for a prefix command, and calls handlers setup by addCommand() member
void SerialCommand::readSerial() 
{
	// If we're using the Hardware port, check it.   Otherwise check the user-created SoftwareSerial Port
	#ifdef SERIALCOMMAND_HARDWAREONLY
	while (Serial.available() > 0) 
	#else
	while ((usingSoftwareSerial==0 && Serial.available() > 0) || (usingSoftwareSerial==1 && SoftSerial->available() > 0) )
	#endif
	{
		int i; 
		boolean matched; 
		if (usingSoftwareSerial==0) {
			// Hardware serial port
			inChar=Serial.read();   // Read single available character, there may be more waiting
		} else {
			#ifndef SERIALCOMMAND_HARDWAREONLY
			// SoftwareSerial port
			inChar = SoftSerial->read();   // Read single available character, there may be more waiting
			#endif
		}
		#ifdef SERIALCOMMANDDEBUG
		Serial.print(inChar);   // Echo back to serial stream
		#endif
		if (inChar==term) {     // Check for the terminator (default '\r') meaning end of command
			#ifdef SERIALCOMMANDDEBUG
			Serial.print("Received: "); 
			Serial.println(buffer);
		    #endif
			bufPos=0;           // Reset to start of buffer
			token = strtok_r(buffer,delim,&last);   // Search for command at start of buffer
			if (token == NULL) return; 
			matched=false; 
			for (i=0; i<numCommand; i++) {
				#ifdef SERIALCOMMANDDEBUG
				Serial.print("Comparing ["); 
				Serial.print(token); 
				Serial.print("] to [");
				Serial.print(CommandList[i].command);
				Serial.println("]");
				#endif
				// Compare the found command against the list of known commands for a match
				String tmp = token;
				if(tmp.equalsIgnoreCase(CommandList[i].command))
				{
					#ifdef SERIALCOMMANDDEBUG
					Serial.print("Matched Command: "); 
					Serial.println(token);
					#endif
					// Execute the stored handler function for the command
					(*CommandList[i].function)(); 
					clearBuffer(); 
					matched=true; 
					break; 
				}
			}
			if (matched==false) {
				(*defaultHandler)(token); 
				clearBuffer(); 
			}

		}
		if (isprint(inChar))   // Only printable characters into the buffer
		{
			buffer[bufPos++]=inChar;   // Put character into buffer
			buffer[bufPos]='\0';  // Null terminate
			if (bufPos > SERIALCOMMANDBUFFER-1) bufPos=0; // wrap buffer around if full  
		}
	}
}
Esempio n. 27
0
 ~SAOutputCallbacks() {
    clearBuffer();
 }
Esempio n. 28
0
int main(int argc, char * argv[])
{
	int ch, opt;
	int errflag;
	char *optargTrainingSet=NULL, optargSep=',';
	std::vector<char> trainingSet;
	
	while ((opt = getopt(argc, argv, ":hc:s:")) != -1)
	{
		switch (opt)
		{
			case 'h':
				errflag++;
				break;
			case 'c':
				optargTrainingSet = optarg;
				break;
			case 's':
				sscanf(optarg, "%c", &optargSep);
				break;
			case ':':
				std::cerr << "option -" << optopt << "requires an operand" << std::endl;
				errflag++;
				break;
			case '?':
				std::cerr << "unrecognized option:-" << optopt << std::endl;
				errflag++;
				break;
		}
	}
	
	if (errflag || (optargTrainingSet == NULL))
	{
		printCLHelp(argv[0]);
		return EXIT_FAILURE;
	}
	
	if (splitStringToChar(optargTrainingSet, trainingSet, optargSep) != 0)
	{
		return EXIT_FAILURE;
	}
	
	// Initialize app
	initTT();
	
	//char a[] = {'a', 's', 'd', 'f', ' '};
	charsRefer = generateString(trainingSet.data(), (int)trainingSet.size(), buffersize);
	charsTyped.resize(buffersize);
	charsTyped.clear();
	
	setupScreen();
	updateReferLine(charsRefer);
	updateActionLine(charsTyped, charsRefer);
	updateInfoLine();
	updateCursorPosition(charsTyped);
	
	ch = getch();
	while (ch != ASCII_CTRL_C)
	{
		if (!isPrintableKey(ch) && !isSpecialKey(ch))
		{
			ch = getch();
			continue;
		}
		switch (ch)
		{
			case ASCII_BACKSPACE:
			case ASCII_DELETE:
				std::cout << (char) ASCII_CTRL_G; // sound the bell
				refresh();
				break;
			case ASCII_CTRL_R:
				resetStatistics();
			case ASCII_NEWLINE:
			case ASCII_CRETURN:
				if (isEOL(charsTyped) || (ch == ASCII_CTRL_R))
				{
					charsRefer = generateString(trainingSet.data(), (int)trainingSet.size(), buffersize);
					updateReferLine(charsRefer);
					clearActionLine();
					clearBuffer(charsTyped);
				}
				break;
			default:
				if (addChar(charsTyped, ch))
				{
					updateActionLine(charsTyped, charsRefer);
				}
				updateInfoLine();
				updateCursorPosition(charsTyped);
		}
		ch = getch();
	}
	
	refresh();
	endwin();
	
	/*
	std::cout << "buffersize= " << buffersize << std::endl;
	std::cout << "reference = " << charsRefer.size() << std::endl;
	std::cout << "capacity  = " << charsTyped.capacity() << std::endl;
	std::cout << "typed_in  = " << charsTyped.size() << std::endl;
	 */
	printf("Goodbye!\n");
	return 0;
}
Esempio n. 29
0
 void BConsole::clear() {
     ::erase();
     clearBuffer();
 }
Esempio n. 30
0
void SoundPlayer::play(ArchiveFile& file) {
	// If we're not initialised yet, do it now
	if (!_initialised) {
		initialise();
    }

	// Stop any previous playback operations, that might be still active
	clearBuffer();

	// Retrieve the extension
	std::string ext = os::getExtension(file.getName());

	if (boost::algorithm::to_lower_copy(ext) == "ogg") {
		// Convert the file into a buffer, self-destructs at end of scope
		ScopedArchiveBuffer buffer(file);

		// This is an OGG Vorbis file, decode it
		vorbis_info* vorbisInfo;
  		OggVorbis_File oggFile;

  		// Initialise the wrapper class
  		OggFileStream stream(buffer);

  		// Setup the callbacks and point them to the helper class
  		ov_callbacks callbacks;
  		callbacks.read_func = OggFileStream::oggReadFunc;
  		callbacks.seek_func = OggFileStream::oggSeekFunc;
  		callbacks.close_func = OggFileStream::oggCloseFunc;
  		callbacks.tell_func = OggFileStream::oggTellFunc;

  		// Open the OGG data stream using the custom callbacks
  		int res = ov_open_callbacks(static_cast<void*>(&stream), &oggFile,
									NULL, 0, callbacks);

  		if (res == 0) {
  			// Open successful

  			// Get some information about the OGG file
			vorbisInfo = ov_info(&oggFile, -1);

			// Check the number of channels
			ALenum format = (vorbisInfo->channels == 1) ? AL_FORMAT_MONO16
														: AL_FORMAT_STEREO16;

			// Get the sample Rate
			ALsizei freq = (vorbisInfo->rate);
			//std::cout << "Sample rate is " << freq << "\n";

			long bytes;
			char smallBuffer[4096];
			DecodeBufferPtr largeBuffer(new DecodeBuffer());
			do {
				int bitStream;
				// Read a chunk of decoded data from the vorbis file
				bytes = ov_read(&oggFile, smallBuffer, sizeof(smallBuffer),
								0, 2, 1, &bitStream);

				if (bytes == OV_HOLE) {
					rError() << "SoundPlayer: Error decoding OGG: OV_HOLE.\n";
				}
				else if (bytes == OV_EBADLINK) {
					rError() << "SoundPlayer: Error decoding OGG: OV_EBADLINK.\n";
				}
				else {
					// Stuff this into the variable-sized buffer
					largeBuffer->insert(largeBuffer->end(), smallBuffer, smallBuffer + bytes);
				}
			} while (bytes > 0);

			// Allocate a new buffer
			alGenBuffers(1, &_buffer);

			DecodeBuffer& bufferRef = *largeBuffer;

			// Upload sound data to buffer
			alBufferData(_buffer,
						 format,
						 &bufferRef[0],
						 static_cast<ALsizei>(bufferRef.size()),
						 freq);

			// Clean up the OGG routines
  			ov_clear(&oggFile);
  		}
  		else {
  			rError() << "SoundPlayer: Error opening OGG file.\n";
  		}
	}
	else {
		// Must be a wave file
		try {
			// Create an AL sound buffer directly from the buffer in memory
			_buffer = WavFileLoader::LoadFromStream(file.getInputStream());
		}
		catch (std::runtime_error& e) {
			rError() << "SoundPlayer: Error opening WAV file: " << e.what() << std::endl;
			_buffer = 0;
		}
	}

	if (_buffer != 0) {
		alGenSources(1, &_source);
		// Assign the buffer to the source and play it
		alSourcei(_source, AL_BUFFER, _buffer);

		// greebo: Wait 10 msec. to fix a problem with buffers not being played
		// maybe the AL needs time to push the data?
		usleep(10000);

		alSourcePlay(_source);

		// Enable the periodic buffer check, this destructs the buffer
		// as soon as the playback has finished
		_timer.enable();
	}
}