本文整理汇总了C++中receiveByte函数的典型用法代码示例。如果您正苦于以下问题:C++ receiveByte函数的具体用法?C++ receiveByte怎么用?C++ receiveByte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了receiveByte函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例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;
}
示例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);
}
示例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");
}
示例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++;
}
}
}
}
示例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;
}
示例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");
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
示例12: while
bool PBBP::receiveBytes(uint8_t *buf, uint8_t len) {
while (len--) {
if (!receiveByte(buf++))
return false;
}
return true;
}
示例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;
}
示例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);
}
示例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);
}
}