• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ receiveByte函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中receiveByte函数的典型用法代码示例。如果您正苦于以下问题:C++ receiveByte函数的具体用法?C++ receiveByte怎么用?C++ receiveByte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了receiveByte函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: test_that_rxbytecounter_is_reset_when_last_byte_is_received

void test_that_rxbytecounter_is_reset_when_last_byte_is_received(){
  receiveByte(3); // length = 3
  receiveByte(1);
  receiveByte(2);
  
  assertEquals(0, rxbytecounter, "RX byte counter not reset");
}
开发者ID:tysseng,项目名称:Xonik-M8,代码行数:7,代码来源:Spi.test.c


示例2: receiveByte

// Receive a packet, copying it into a memory buffer and returning the buffer
static uint8_t *receivePacket(int fd)
{
	uint8_t packet_header[5];
	uint8_t *packet_buffer;
	uint32_t length;
	uint32_t i;

	for (i = 0; i < 5; i++)
	{
		packet_header[i] = receiveByte(fd);
	}
	length = readU32LittleEndian(&(packet_header[1]));
	if (length > PACKET_LENGTH_LIMIT)
	{
		printf("Got absurdly large packet length of %d\n", length);
		printf("Exiting, since the packet is probably garbled\n");
		exit(1);
	}
	packet_buffer = malloc(length + 5);
	memcpy(packet_buffer, packet_header, 5);
	for (i = 0; i < length; i++)
	{
		packet_buffer[i + 5] = receiveByte(fd);
	}
	return packet_buffer;
}
开发者ID:RagnarDanneskjold,项目名称:hardware-bitcoin-wallet,代码行数:27,代码来源:hwb_tester.c


示例3: start

uint8_t I2C::read(uint8_t address, uint8_t numberBytes, uint8_t *dataBuffer)
{
  bytesAvailable = 0;
  bufferIndex = 0;
  if(numberBytes == 0){numberBytes++;}
  nack = numberBytes - 1;
  returnStatus = 0;
  returnStatus = start();
  if(returnStatus){return(returnStatus);}
  returnStatus = sendAddress(SLA_R(address));
  if(returnStatus){return(returnStatus);}
  for(uint8_t i = 0; i < numberBytes; i++)
  {
    if( i == nack )
    {
      returnStatus = receiveByte(0);
      if(returnStatus != MR_DATA_NACK){return(returnStatus);}
    }
    else
    {
      returnStatus = receiveByte(1);
      if(returnStatus != MR_DATA_ACK){return(returnStatus);}
    }
    dataBuffer[i] = TWDR;
    bytesAvailable = i+1;
    totalBytes = i+1;
  }
  returnStatus = stop();
  return(returnStatus);
}
开发者ID:bubgum,项目名称:crw-cmu,代码行数:30,代码来源:I2C.cpp


示例4: test_that_command_is_not_called_when_not_all_bytes_are_ready

void test_that_command_is_not_called_when_not_all_bytes_are_ready(){
  receiveByte(3); // length = 3
  receiveByte(SPI_CMD_PT_TEST); // type that triggers test function on receive

  SPI_checkForReceivedData();

  assertEquals(0, lastPackage[0], "No command should have been treated");
}
开发者ID:tysseng,项目名称:Xonik-M8,代码行数:8,代码来源:Spi.test.c


示例5: timerHandlerReadByte1

void timerHandlerReadByte1(void *T)
{
	static volatile uint32_t stageOfReading = 0;
	static uint8_t whichByte = 0;
	static uint8_t whichDevice = 0;
	addressAndData *address = (addressAndData*)T;

	if(readingAllowed == TRUE)
	{
		if(0 == whichDevice) //accel
		{
			receiveByte(address->adr.addressDevice[0], (address->adr.subAddress[0] + whichByte), &(address->dane[whichByte]));
			whichByte++;

			if(whichByte == 6)
			{
				//readingAllowed = FALSE;

				whichDevice++;

				whichByte = 0;
				stageOfReading = 0;
			}
		}
		else if(1 == whichDevice) //gyro
		{
			receiveByte(address->adr.addressDevice[0], (address->adr.subAddress[1] + whichByte), &(address->dane[whichByte + 6]));
			whichByte++;

			if(whichByte == 6)
			{
				//readingAllowed = FALSE;

				whichDevice++;

				whichByte = 0;
				stageOfReading++;
			}
		}
		else if(2 == whichDevice)
		{
			receiveByte(address->adr.addressDevice[1], (address->adr.subAddress[2] + whichByte), &(address->dane[whichByte + 12]));
			whichByte++;

			if(whichByte == 6)
			{
				readingAllowed = FALSE;

				whichDevice = 0;

				whichByte = 0;
				stageOfReading++;
			}
		}

	}
}
开发者ID:Mateusz1992,项目名称:BachelorLSM9DS1,代码行数:57,代码来源:Main.c


示例6: receiveMessage

//--------------------------------------------------------------
// HIGH LEVEL MESSAGE FUNCTIONS
//--------------------------------------------------------------
// This function will receive a full request message from a
// RasPi and return proper confirmation bytes
int * receiveMessage(void){
    // Hold inital byte received
    uint8_t i=0;
    uint8_t j=0;
    uint8_t n=0;

    // Array to hold received data
    static int msgArray[10];
    int dataByteIn[2];

    // Receive initial byte
    for(j=0; j<2; j++){
        dataByteIn[j] = receiveByte();
    }

    // If message is not properly terminated write error code
        // to entire array and call commError()
    if(dataByteIn[1] != END_MSG){
        for (i=0; i<4; i++){
            msgArray[i] = UART_COMM_ERROR;
        }
        commError();
    }

    // RasPi normal request message to AVR
    else if (dataByteIn[0] == RASPI_REQ_AVR){
        // Transmit AVR ready to receive message
        transmitReady();
        
        // Loop through until EOM reached and store in array
        do{
            msgArray[n] = receiveByte();
            n++;
        }while(msgArray[n-1] != END_MSG);
        transmitConfirm();
    }

    // RasPi initialize request to AVR
    else if(dataByteIn[0] == RASPI_INIT_TO_AVR){
	    // Transmit AVR initialized ready byte
        transmitInitialize();

        // Write initialized byte to array
        for(i=0; i<4; i++){
            msgArray[i] = AVR_INIT_TO_RASPI;
        }
    }

    // Improper initial communication byte, call commError()
    else{
        commError();
    }

    return msgArray;
}
开发者ID:jat0021,项目名称:GardenPi,代码行数:60,代码来源:UART.c


示例7: test_that_package_is_received_by_spi

void test_that_package_is_received_by_spi(){
  receiveByte(3); // length = 3
  receiveByte(SPI_CMD_PT_TEST); // type that triggers test function on receive
  receiveByte(2);
  
  SPI_checkForReceivedData();
  
  assertEquals(3, lastPackage[0], "Incorrect package value 0");
  assertEquals(SPI_CMD_PT_TEST, lastPackage[1], "Incorrect package value 0");
  assertEquals(2, lastPackage[2], "Incorrect package value 0");
}
开发者ID:tysseng,项目名称:Xonik-M8,代码行数:11,代码来源:Spi.test.c


示例8: test_that_only_first_command_is_treated_if_second_is_incomplete

void test_that_only_first_command_is_treated_if_second_is_incomplete(){
  receiveByte(3); // length = 3
  receiveByte(SPI_CMD_PT_TEST); // type that triggers test function on receive
  receiveByte(4);

  receiveByte(4); // length = 3
  receiveByte(SPI_CMD_PT_TEST); // type that triggers test function on receive

  SPI_checkForReceivedData();

  assertEquals(3, lastPackage[0], "Wrong last command");
}
开发者ID:tysseng,项目名称:Xonik-M8,代码行数:12,代码来源:Spi.test.c


示例9: transmitMessage

// This function will transmit a full message to RasPi
uint8_t transmitMessage(volatile int sendData[4]){
    // Initialize loop counter
    uint8_t i;
    uint8_t badSendFlag = 0;

    // Clear global interrupt to stop receive interrupt
    cli();

    // Send AVR request RasPi byte
    transmitRequest();

    // Wait for response from RasPi
    // **** This has possibility of hanging program -- needs improvement!
    if (receiveByte() == RASPI_READY){
        // Remove EOM from buffer
        receiveByte();

        // Loop to send all of data array
        for(i=0; i<4; i++){
            transmitByte(sendData[i]);
        }

        // Transmit end of message byte
        transmitByte(END_MSG);

        // Check for good confirm byte
        if (receiveByte() == RASPI_REC_MSG_CONFIRM){
            // Remove EOM from buffer
            receiveByte();
        }
        else{
            // Set bad send flag
            badSendFlag = 2;
        }
    }

    // If improper response is received, call commError()
    else{
        // Set bad send flag
            badSendFlag = 1;
    }

    // If badSendFlag is set - call commError()
    if(badSendFlag != 0){
        commError();
    }

    // reenable global interrupts
    sei();

    // Return value of badSendFlag
    return badSendFlag;
}
开发者ID:jat0021,项目名称:GardenPi,代码行数:54,代码来源:UART.c


示例10: main

int main(void)
{
	DDRD = (1<<1);		// habilita output no pino PD1 (TXD)
	DDRB = (1<<PB0);	// LED na porta PB0
	DDRB = (1<<PB5);	// habilita LED usado no bootloader 
						// (para piscar em status)
	
	char serialCharacter;
	
	LED_DDR=0xff;
	
	initUSART();
	PORTB |= (1<<PB0);
	PORTB &= ~(1<<PB5);
	printString("Ola Mundo\r\n");
	
	
    while(1)
    {
		serialCharacter = receiveByte();
		PORTB ^= _BV(PB0);
		transmitByte(serialCharacter);
		
		//LED_PORT=serialCharacter;
		PORTB ^= _BV(PB5);
		
	}
	
	return(0);
}
开发者ID:roneymonte,项目名称:atmel_studio,代码行数:30,代码来源:03_UART.c


示例11: main

int main(void)
{
  // Single character for serial TX/RX
  char a;

  // Enable output on all 8 bits in DDRB (but only PB0 and PB1 are used)
  DDRB = 0xff;

  // Enable pin change interrupt for the B pins, but only check PB0 and PB1.
  sei();
  PCICR |= (1 << PCIE0);
  PCMSK0 |= ((1 << PB0) | (1 << PB1));

  init_timer1();
  initUSART();

  pb[0] = PB0;
  pb[1] = PB1;
  while (1)
  {

    // for (uint8_t i=0; i<255; i++)
    //   cmd[i] = 0;

    // char cmd[255];
    // readString(cmd, 255);

    // if (strcmp(cmd, "V0_ON") == 0)
    // {
    //   printString("\r\nYou wrote: ");
    //   printString(cmd);
    //   printString("\r\n");
    //   PORTB |= (1 << PB0);
    // }

    // if (strcmp(cmd, "V1_ON"))
    //   PORTB |= (1 << PB1);
    // if (strcmp(cmd, "V0_OFF"))
    //   PORTB &= ~(1 << PB0);
    // if (strcmp(cmd, "V1_OFF"))
    //   PORTB &= ~(1 << PB1);

    // if (cmd == "V0_ON") set_bit(PORTB, PB0);
    // PORTB |= (1 << PB0);
    a = receiveByte();
    transmitByte(a);

    if (a == '0')
      PORTB &= ~(1 << PB0);
    if (a == '1')
      PORTB |= (1 << PB0);
    if (a == '2')
      PORTB &= ~(1 << PB1);
    if (a == '3')
      PORTB |= (1 << PB1);

    // PORTB = a;
  }
  return 0;
}
开发者ID:andrewadare,项目名称:avr-breadboarding,代码行数:60,代码来源:dual_vacuum_switcher.c


示例12: while

bool PBBP::receiveBytes(uint8_t *buf, uint8_t len) {
  while (len--) {
    if (!receiveByte(buf++))
      return false;
  }
  return true;
}
开发者ID:AdamMagaluk,项目名称:library-pinoccio,代码行数:7,代码来源:PBBP.cpp


示例13: readString

void readString( char myString[], uint8_t maxLength ) 
{
  	char response;
  	uint8_t i;
  	i = 0;
  	while ( i < ( maxLength - 1 ) ) 
  	{
  		/* prevent over-runs */
    	response = receiveByte();
    	/* echo */
    	transmitByte(response);
    	if ( response == '\r' ) 
		{
			/* enter marks the end */
      		break;
    	}
    	else
    	{
    		/* add in a letter */
      		myString[ i ] = response;
      		i++;
    	}
  	}
  	/* terminal NULL character */
  	myString[ i ] = 0;
}
开发者ID:nrahmani110,项目名称:Senior-Design-A-team,代码行数:26,代码来源:USART.c


示例14: main

int main(void) 
{
    //-----------INITS------------//

    DDRB |= 0x01;
    PORTB = 0x00;
    initUSART();

    PORTB = 0x01;
    _delay_ms(100);
    PORTB = 0x00;
    _delay_ms(100);
    PORTB = 0x01;
    _delay_ms(1000);
    PORTB = 0x00;

    //-------EVENT LOOP-----------//
    while(1) 
    {  
        
        char in = receiveByte();
        /*
        if (in == 'h')
            PORTB = 0x01;
        else if (in == 'l')
            PORTB = 0x00;
        */
        PORTB = 0x01;
        for (int i=0; i<in; i++)
            _delay_ms(1);
        PORTB = 0x00;
    }
    return(0);

}
开发者ID:Jamal-Ra-Davis,项目名称:AVR-Programs,代码行数:35,代码来源:serial_test.c


示例15: main

int main(void)
{
	char serialCharacter;
	
	lcd_init(LCD_DISP_ON);
	lcd_gotoxy(2,0); lcd_puts("Serial");
	lcd_gotoxy(3,1); lcd_puts("LCD");
	
	DDRD |= (1<<PD1);	// habilita o pino PD1 como TXD (output)
	DDRB |= (1<<PB0);	// habilita o LED no pino PB0
	
	PORTB|=(1<<PB0);
	
	initUSART();
	printString("Serial ok:");
	
	PORTB&=~(1<<PB0);
	
    while(1)
    {	PORTB|=(1<<PB0);
        serialCharacter = receiveByte();
		PORTB&=~(1<<PB0);
		lcd_putc(serialCharacter);
    }
}
开发者ID:roneymonte,项目名称:atmel_studio,代码行数:25,代码来源:main.c


示例16: receive_and_decode_Z85

/* Reads a z85 encoded string from serial interface and decodes the string into byte array of size size */ 
uint8_t receive_and_decode_Z85(uint8_t *data, size_t size)
{
    //  Accepts only strings bounded to 5 bytes
    /* if (strlen (string) % 5) */
    /*     return NULL; */
    
    /* size_t decoded_size = strlen (string) * 4 / 5; */
    /* byte *decoded = malloc (decoded_size); */
    if (size % 4) // only multiples of 4 bytes are possible
        return 1;
    size_t size_encoded = size*5/4;
    
    size_t byte_nbr = 0;
    size_t char_nbr = 0;
    uint32_t value = 0;
    while (char_nbr < size_encoded) {
        //  Accumulate value in base 85
        /* value = value * 85 + decoder [(byte) string [char_nbr++] - 32]; */
        value = value * 85 + decoder [receiveByte() - 32];
        char_nbr++;
        if (char_nbr % 5 == 0) {
            //  Output value in base 256
            uint32_t divisor = 16777216; // = 256 * 256 * 256;
            while (divisor) {
                data [byte_nbr++] = value / divisor % 256;
                divisor /= 256;
            }
            value = 0;
        }
    }

    if (byte_nbr != size) return 1;

    return 0;
}
开发者ID:prfraanje,项目名称:python-avr-cfw,代码行数:36,代码来源:z85.c


示例17: if

bool PBBP::receiveAck() {
  bool first, second;
  if (!receiveBit(&first) || !receiveBit(&second))
    return false;

  // Acks are sent as 01, nacks as 10. Since the 0 is dominant during
  // a bus conflict, a receiveing of 00 means both an ack and a nack was
  // sent.
  if (!first && !second ) {
    this->last_error = ACK_AND_NACK;
    return false;
  } else if (!second ) {
    // Read error code from the slave
    if (receiveByte(&this->last_slave_error)) {
      this->last_error = NACK;
    } else {
      this->last_error = NACK_NO_SLAVE_CODE;
    }
    return false;
  } else if (first) {
    this->last_error = NO_ACK_OR_NACK;
    return false;
  } else {
    return true;
  }
}
开发者ID:AdamMagaluk,项目名称:library-pinoccio,代码行数:26,代码来源:PBBP.cpp


示例18: sizeof

void CDirectSerial::RXBufferEmpty () {
	ULONG dwRead;
	Bit8u chRead;
	USHORT errors = 0;
	ULONG ulParmLen = sizeof(errors);

	if (lastChance > 0) {
		receiveByte (ChanceChar);
		lastChance = 0;
	} else {
		// update RX
		if (DosRead (hCom, &chRead, 1, &dwRead) != NO_ERROR) {
			if (dwRead != 0) {
				//LOG_MSG("UART 0x%x: RX 0x%x", base,chRead);
				receiveByte (chRead);
			}
		}
	}
	// check for errors
	Bit8u errreg = 0;
	APIRET rc = DosDevIOCtl(hCom, IOCTL_ASYNC, ASYNC_GETCOMMERROR, 0, 0, 0, &errors, ulParmLen, &ulParmLen);
	if (rc != NO_ERROR && errors)
                                     {
		if (errors & 8) {
			LOG_MSG ("Serial port at 0x%x: line error: framing error.", base);
			errreg |= LSR_FRAMING_ERROR_MASK;
		}
		if (errors & 4) {
			LOG_MSG ("Serial port at 0x%x: line error: parity error.", base);
			errreg |= LSR_PARITY_ERROR_MASK;
		}
	}
	errors = 0;
	rc = DosDevIOCtl(hCom, IOCTL_ASYNC, ASYNC_GETCOMMEVENT, 0, 0, 0, &errors, ulParmLen, &ulParmLen);
	if (rc != NO_ERROR && errors)
	{
		if (errors & 6) {
			LOG_MSG ("Serial port at 0x%x: line error: break received.", base);
			errreg |= LSR_RX_BREAK_MASK;
		}
	}
	if (errreg != 0)
	{
		receiveError (errreg);
	}

}
开发者ID:BackupTheBerlios,项目名称:smarterdata-svn,代码行数:47,代码来源:directserial_os2.cpp


示例19: if

// recv and decode byte
ERecvState CChannelHandler::recv(unsigned char *byte)
{
    static bool decryptNext;
    unsigned char rawByte;
    
    if(!decryptNext)
    {
        if(receiveByte(&rawByte))
        {
            if(rawByte == '}')
            {
                return eRecvEnd;
            }
            else if(rawByte == '{')
            {
                return eRecvBegin;
            }
            else if(rawByte == '|')
            {
                decryptNext = true;
            }
            else
            {
                *byte = rawByte;
                return eRecvData;
            }
        }
    }
    
    if(decryptNext)
    {
        if(receiveByte(&rawByte))
        {
            decryptNext = false;
            *byte = rawByte ^ 0x20;
            return eRecvData;
        }
    }
    
    return eRecvNothing;
}
开发者ID:Draradech,项目名称:wl_can,代码行数:42,代码来源:ChannelHandler.cpp


示例20: reset

uint16_t SHT1x::readCommand(uint8_t command) {
	reset();

	// Send command
	startCommand();
	bool ok = sendByte(command);
	if(!ok)
		console.print(Error, "Error writing byte to sensor !!!");

	// Wait for competition
	delayTimer.mDelay(320);

	// Receive result
	union {
		uint16_t value;
		uint8_t bytes[2];
	} result;
	result.bytes[1] = receiveByte();
	result.bytes[0] = receiveByte();
	receiveByte();

	return result.value;
}
开发者ID:vladamatena,项目名称:CDEECO,代码行数:23,代码来源:SHT1x.cpp



注:本文中的receiveByte函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ receiveMessage函数代码示例发布时间:2022-05-30
下一篇:
C++ recalculate_sizes函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap