Exemple #1
0
void ShowDataReceivedOverUART( void )
{
	char receiveBuffer[RECEIVE_BUFFER_SIZE];
	uint8_t nrOfCharsReceived = getBufferLength();
	
	// check if no data was received
	if (nrOfCharsReceived == 0) return;

	int index = 0;
	while(getBufferLength() > 0) {
		receiveBuffer[index] = readChar();
		index++;

		//- reserve the last character of the buffer for '\0' character
		//- check not to write outside array boundaries.	
		if (index > (RECEIVE_BUFFER_SIZE -2)) 
		{
			break;
		}
	}

	receiveBuffer[index] = '\0';

	writeString_P("Echo: ");
	writeString(receiveBuffer);
}
Exemple #2
0
byte Message_Receive(void)
{
	if (getBufferLength() < MS_DataBegin)
	{
		return 0;
	}

	if (readChar() != MS_CharA)
	{
		return 0;
	}

	if (readChar() != MS_CharB)
	{
		return 0;
	}

	Message_BeginWrite();

	VarAction = readChar();
	VarDataLength = readChar();

	if (VarDataLength > MS_MaxDataLen)
	{
		VarDataLength = MS_MaxDataLen;
	}

	VarCorrChk = readChar();

	if (getBufferLength() < VarDataLength)
	{
		//sleep 25 ms (well or less..)
		//delay(25);
		mSleep(25);
		if (getBufferLength() < VarDataLength)
		{
			VarIsCorrupt = true;
			return MS_DataBegin;//discart message because we are not receiving anything further
		}
	}

	for (int i = 0; i < VarDataLength; ++i)
	{
		VarBuffer[MS_DataBegin + i] = readChar();
	}

	CurrCorrChk = CalculateCorruptionCheck();
	VarIsCorrupt = VarCorrChk != CurrCorrChk;
	return MS_DataBegin + VarDataLength;
}
 void getResult( double *left, double *right, uint64_t length ){
     uint64_t size = getBufferLength();
     for( uint64_t i = 0; i < size; i++ ){
         left[i] = bufferLeft[i];
         right[i] = bufferRight[i];
     }
 }
void Cask::CdapOdbc::ColumnsDataReader::getColumnValue(const ColumnBinding& binding) {
  auto& record = this->queryResult.getRows().at(this->currentRowIndex);
  std::wstring name;
  std::wstring typeName;
  SQLSMALLINT radix = 0;

  switch (binding.getColumnNumber()) {
    case 1: // TABLE_CAT 
    case 2: // TABLE_SCHEM 
    case 9: // DECIMAL_DIGITS 
    case 12: // REMARKS 
    case 13: // COLUMN_DEF 
    case 15: // SQL_DATETIME_SUB 
    case 16: // CHAR_OCTET_LENGTH 
      this->fetchNull(binding);
      break;
    case 3: // TABLE_NAME 
      this->fetchVarchar(this->tableName.c_str(), binding);
      break;
    case 4: // COLUMN_NAME 
      name = record.at(L"name").as_string();
      this->fetchVarchar(name.c_str(), binding);
      break;
    case 5: // DATA_TYPE
    case 14: // SQL_DATA_TYPE 
      this->fetchSmallint(getDataType(record.at(L"type")), binding);
      break;
    case 6: // TYPE_NAME 
      typeName = getTypeName(record.at(L"type"));
      this->fetchVarchar(typeName.c_str(), binding);
      break;
    case 7: // COLUMN_SIZE 
      this->fetchInt(getColumnSize(record.at(L"type")), binding);
      break;
    case 8: // BUFFER_LENGTH 
      this->fetchInt(getBufferLength(record.at(L"type")), binding);
      break;
    case 10: // NUM_PREC_RADIX 
      radix = getRadix(record.at(L"type"));
      if (radix > 0) {
        this->fetchSmallint(radix, binding);
      } else {
        this->fetchNull(binding);
      }

      break;
    case 11: // NULLABLE
      this->fetchSmallint(getIsNull(record.at(L"type")), binding);
      break;
    case 17: // ORDINAL_POSITION 
      this->fetchInt(this->currentRowIndex + 1, binding);
      break;
    case 18: // IS_NULLABLE 
      this->fetchVarchar((getIsNull(record.at(L"type")) == SQL_NO_NULLS) ? L"NO" : L"YES", binding);
      break;
  }
}
Exemple #5
0
void DsdSampleReader::clearBuffer() 
{
	if (!isBufferAllocated) {
		allocateBuffer();
		return;
	}
	
	dsf2flac_uint8 c = getIdleSample();
	for (dsf2flac_uint32 i = 0; i<getNumChannels(); i++)
		for (dsf2flac_uint32 j=0; j<getBufferLength(); j++)
			circularBuffers[i].push_front(c);
}
Exemple #6
0
void DsdSampleReader::allocateBuffer()
{
	if (isBufferAllocated)
		return;
		
	circularBuffers = new boost::circular_buffer<dsf2flac_uint8> [getNumChannels()];
	for (dsf2flac_uint32 i = 0; i<getNumChannels(); i++) {
		boost::circular_buffer<dsf2flac_uint8> cb(getBufferLength());
		circularBuffers[i] = cb;
	}
	isBufferAllocated = true;
	clearBuffer();
	return;
}
Exemple #7
0
bool DsdSampleReader::setBufferLength(dsf2flac_uint32 b)
{
	if (b<1) {
		errorMsg = "dsdSampleReader::setBufferLength:buffer length must be >0";
		return false;
	}
	bufferLength=b;
	if (!isBufferAllocated)
		allocateBuffer();
	for (dsf2flac_uint32 i = 0; i<getNumChannels(); i++)
		circularBuffers[i].set_capacity(getBufferLength());
	clearBuffer(); // should be called by rewind... but just incase.
	rewind();
	return true;
}
void askAQuestion(void)
{
	uint8_t bytesToReceive = 1;
	
	clearReceptionBuffer();
	switch(question)
	{
		case 0:
			writeString_P("What's your name? (Enter 8 characters please)\n"); 
			bytesToReceive = 8; 
		break;
		case 1:
			writeString_P("How old are you? (Enter 2 characters please)\n"); 
			bytesToReceive = 2;
		break;
		case 2: 
			writeString_P("Do you want to see some Text output? (\"y\" or \"n\")\n"); 
		break;
		case 3: 
			writeString_P("Do you want to see blinking LEDs and hear the beeper sound? (\"y\" or \"n\")\n"); 
		break;
		case 4: 
			writeString_P("Do you want to do all this again? (\"y\" or \"n\")\n"); 
		break;
	}

	for(size_t i=0; i<100 && getBufferLength() < bytesToReceive; ++i)
		;	
	char receiveBuffer[bytesToReceive];
	readChars(receiveBuffer, bytesToReceive);	

	switch(question)
	{
		case 0: 
			writeString_P("Hello \"");
			writeStringLength(&receiveBuffer[0],bytesToReceive,0);
			writeString_P("\" !\n");
		break;
		case 1: 
			writeString_P("So your age is: \""); 
			writeStringLength(&receiveBuffer[0],bytesToReceive,0);
			writeString_P("\" ! Guess what? Nobody cares... ;-)\n");
		break;
		case 2:
			if(receiveBuffer[0] == 'y') 
			{
				writeString_P("Here we go!\n");
				outputTextStuff();
				writeString_P("\n\nThat's it!\n\n"); 
			}
			else
				writeString_P("OK then... let's move on!\n"); 
		break;
		case 3:
			if(receiveBuffer[0] == 'y')
			{
				writeString_P("Now you get a led and beeper show!\n");
				uint8_t i = 0;
				for(;i < 10; i++)
					Leds_Beeper();
				writeString_P("Oh ... it's over!\n");
			}
			else
				writeString_P("Well, if you don't want that... :*( \n"); 
		break;
		case 4:
			if(receiveBuffer[0] == 'y')
			{
				writeString_P("Great! Here we go again...\n"); 
				question = -1;
			}
			else
			{
				writeString_P("OK good bye! I will wait \n");
				writeString_P("until someone resets me!\n"); 
				question = -2;
			}
		break;
	}
	
	question++;
}
Exemple #9
0
int main(void) {
	//Variable Declarations
	initSolenoid();										/* initialize solenoid valve */
	TIM_TIMERCFG_Type timerCfg;
	initTimeStruct();
	RTC_TIME_Type* watertime = malloc(sizeof(RTC_TIME_Type));
	uint8 fed = 0;
	uint8 watered = 0;
	watertime->HOUR = 5;
	watertime->MIN = 0;

	//Initialize timer0 for delays
	TIM_ConfigStructInit(TIM_TIMER_MODE, &timerCfg);	/* initialize timer config struct */
	TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &timerCfg);		/* initialize timer0 */

	//Initialize Real Time Clock
	RTC_Init(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_ResetClockTickCounter(LPC_RTC);

	// Initialize Peripherals
	INIT_SDRAM();										/* initialize SDRAM */
	servoInit();										/* initialize FSR servo motor for panning camera */
	initStepper();										/* initialize stepper motor for dispensing food */
	initFSR();											/* initialize force sensitive resistor circuit for food and water full signals */
	initWiFi(AUTO_CONNECT);								/* initialize WiFi module -- must be attached*/

	audio_initialize();
	audio_reset();
	//audio_test();
	audio_setupMP3();

	int i = 0, retval;
	uint32 length;										/* length variable for photo */
	printf("Entering while loop\n\r");
	//audio_storeVoice();
	// Enter an infinite loop
    while(1) {

    	if(STATE == DISPENSING_FOOD){
    	    printf("Entering food dispense state\n\r");
    	    /* Execute commands to dispense food */
    	    //spinUntilFull();
    	    spinStepper(300);
    	    reverseSpin(250);
    	    STATE = CONNECTED;
    	}

    	if(STATE == DISPENSING_WATER){
    		printf("Entering water dispense state\n\r");
    		/* Execute commands to dispense water */
    		fillWater();
    		STATE = CONNECTED;
    	   	}

    	if(STATE == CAPTURING){
   	 		printf("Entering camera taking state\n\r");
   	 		/* Initialize camera and set it up to take a picture */
   	 		if(cameraInit())
   	 			printf("Camera not initialized!\n\r");
   	 		retval = stopFrame();
   	 		length = getBufferLength();
   	 		printf("length: %i\n\r", length);

   	 		/* Send length to Android application */
   	 		int temp_len = length;
   	 		while(temp_len){
   	 			uart1PutChar(temp_len % 10);
   	 			temp_len = temp_len / 10;
   	 		}

   	 		/* Send photo and finish set up */
   	 		getAndSendPhoto(length);
   	 		resumeFrame();
   	 		STATE = CONNECTED;
  	   	}

   	    if(STATE == TALKING1){
   	    	audio_playVoice(1);
   	    	STATE = CONNECTED;
	    }

   	    if(STATE == TALKING2){
   	    	audio_playVoice(2);
   	    	STATE = CONNECTED;
	    }

   	    if(STATE == TALKING3){
   	    	audio_playVoice(3);
   	    	STATE = CONNECTED;
	    }

   	    if(STATE == PAN_LEFT){
   	    	/* Execute commands to pan servo left */
   	    	panServo(LEFT);
       		STATE = CONNECTED;
   	    }

   	    if(STATE == PAN_RIGHT){
   	    	/* Execute commands to pan servo right */
   	    	panServo(RIGHT);
       		STATE = CONNECTED;
   	    }

   	    if(STATE == SCHEDULING){
       		/* Execute commands to schedule a feeding time */
       		STATE = CONNECTED;
   	    }

   	    /* Scheduling */
   	    RTC_GetFullTime(LPC_RTC, time);
   	    //Fill water bowl at predetermined time
   	    if (time->HOUR == watertime->HOUR + 1 && watered == 1)
   	    	watered = 0;
   	    if (watertime->HOUR == time->HOUR && watertime->MIN < time->MIN && watered == 0)
   	    {
   	    	fillWater();
   	    	watered = 1;
   	    }
   	    //Feed dog on schedule if any cannot feed dog two consecutive hours
   	    for(i = 0; i < scheduled_feeds; i++)
   	    {
			if (time->HOUR == feedtime[i]->HOUR + 1 && fed == 1)
				fed = 0;
			if (feedtime[i]->HOUR == time->HOUR && feedtime[i]->MIN < time->MIN && fed == 0)
			{
				spinUntilFull();
				fed = 1;
			}
   	    }
    }
    return 0;
}
Exemple #10
0
void DoDataProcess( void )
{
	uint8_t nrOfCharsReceived = getBufferLength();	
	// check if no data was received
	if (nrOfCharsReceived == 0) return;
	
	static char receiveBuffer[RECEIVE_BUFFER_SIZE];
	static int index = -1;
	
	static bool wrapped = false;

	while(getBufferLength() > 0)
	{
		char newchar = readChar();
		
		if(!wrapped)
		{
			if(newchar == '{')
			{
				wrapped = true;
			}
			continue;
		}
		
		if(newchar == '}')
		{					
			if(index > -1)
			{				
				//parse request
				REQUEST_STRUCT request = {0, 0};
				parseRequest(&request, receiveBuffer, (index+1));
				
				writeString_P("{cmd=0x");
				writeInteger(request.cmd, HEX);
				writeString_P(";val=0x");
				writeInteger(request.val, HEX);
				writeString_P("}\n");
				
				switch(request.cmd)
				{
					case CMD_MOVE_FORWARD:
					{		
						if(move_horizontal<=0)
						{
							move_horizontal = request.val;
							if (request.val > topSpeed)
							{
								topSpeed = request.val;
							}
						}
						else
						{
							move_horizontal = 0;
						}
						move_turning = 0;
						break;
					}
					case CMD_MOVE_BACKWARD:
					{		
						if(move_horizontal>=0)
						{
							move_horizontal = request.val;
						}
						else
						{
							move_horizontal = 0;
						}	
						move_turning = 0;
						break;
					}
					case CMD_MOVE_LEFT:
					{		
						if(move_turning<=0)
						{
							move_turning = 1;
						}
						else
						{
							move_turning = 0;
						}		
						move_horizontal = 0;
						break;
					}
					case CMD_MOVE_RIGHT:
					{		
						if(move_turning >= 0)
						{
							move_turning = -1;
						}
						else
						{
							move_turning = 0;
						}
						move_horizontal = 0;
						break;
					}
					case CMD_STOP_MOVING:
					{
						move_horizontal = 0;
						move_turning = 0;
						break;
					}
					case CMD_GET_FUELLVL:
					{
						writeString_P("{cmd=0x");
						writeInteger(request.cmd, HEX);
						writeString_P(";val=0x");
						writeInteger(get_BatteryLevelAsPercentage(), HEX);
						writeString_P("}\n");
						break;
					}
					
					case CMD_GET_SPEED:
					{
						writeString_P("{cmd=0x");
						writeInteger(request.cmd, HEX);
						writeString_P(";val=0x");
						writeInteger(topSpeed, HEX);
						writeString_P("}\n");
						break;
					}
					
					default: //stop
					{
						
					}
				}
				
				//
			}
			wrapped = false;
			index = -1;
			continue;
		}
		
		receiveBuffer[++index] = newchar;

		//- reserve the last character of the buffer for '\0' character
		//- check not to write outside array boundaries.	
		if (index > (RECEIVE_BUFFER_SIZE-2)) //loop from 0 to (RECEIVE_BUFFER_SIZE-)
		{
			index = -1;
			wrapped = false;
			//THROW 'exception'/Error
			continue;
		}
	}
}