本文整理汇总了C++中EthernetClient::readBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetClient::readBytes方法的具体用法?C++ EthernetClient::readBytes怎么用?C++ EthernetClient::readBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EthernetClient
的用法示例。
在下文中一共展示了EthernetClient::readBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCommand
//---------------------------------------------------------------------
uint8_t getCommand()
{
if ( !client_.available() )
return (uint8_t)(-1);
uint8_t in_buf = '\0';
size_t bytes_read = client_.readBytes( (char*)&in_buf, 1 );
if ( bytes_read < 1 )
return (uint8_t)(-1);
return in_buf;
}
示例2: emulateNfcTag
//---------------------------------------------------------------------
void emulateNfcTag()
{
client_.println(CMD_NFC_EMULATION_STARTED);
uint8_t tag_writeable = 0;
char uid_str[6];
uint8_t uid[] = {0, 0, 0};
int16_t bytes_read = 0;
bool err = false;
bytes_read = client_.read( &tag_writeable, 1 );
if ( bytes_read != 1 )
{
#ifdef DEBUG_SERIAL
Serial.print( "ERROR: emulateNfcTag: received " );
Serial.print( bytes_read );
Serial.println( " bytes");
#endif
return;
}
bytes_read = client_.readBytes( uid_str, 6 );
err = hexStringToByteArray( uid_str, 6, uid );
if ( bytes_read != 6 )
{
#ifdef DEBUG_SERIAL
Serial.print( "ERROR: emulateNfcTag: received " );
Serial.print( bytes_read );
Serial.println( " bytes");
#endif
return;
}
if ( err )
return;
#ifdef DEBUG_SERIAL
Serial.print( "DEBUG: tag writeable = ");
Serial.println( tag_writeable - '0' );
Serial.print( "DEBUG: uid = " );
Serial.print( uid[0], HEX );
Serial.print( " " );
Serial.print( uid[1], HEX );
Serial.print( " " );
Serial.println( uid[2], HEX );
#endif
// read hexstring from input and set it as NDEF message
uint8_t *ndef_fd = nfc_.getNdefFilePtr();
uint8_t max_ndef_len = nfc_.getNdefMaxLength();
#ifdef DEBUG_SERIAL
Serial.print( "DEBUG: max ndef len = " );
Serial.println( max_ndef_len );
#endif
char ndef_msg_str[max_ndef_len];
bytes_read = client_.readBytes( ndef_msg_str, max_ndef_len );
bytes_read = ( bytes_read > max_ndef_len ) ? max_ndef_len : bytes_read;
err = hexStringToByteArray( ndef_msg_str, bytes_read - 1, ndef_fd );
if ( err )
return;
nfc_.setTagWriteable( tag_writeable == CMD_NFC_TAG_WRITEABLE );
nfc_.setUid( uid );
changeSPI( PIN_PN532_CS );
if ( !nfc_.emulate(NFC_EMULATION_TIMEOUT_MS) )
{
delay(1000);
changeSPI( PIN_ETHERNET_CS );
client_.println( CMD_NFC_EMULATION_TIMEOUT );
#ifdef DEBUG_SERIAL
Serial.print( "ERROR: ");
Serial.println( CMD_NFC_EMULATION_TIMEOUT );
#endif
}
else
{
delay(1000);
changeSPI( PIN_ETHERNET_CS );
if ( nfc_.writeOccured() )
{
uint8_t *tagbuf;
uint16_t length;
nfc_.getContent( &tagbuf, &length );
client_.println( NDEF_MODIFIED );
#ifdef DEBUG_SERIAL
Serial.print( "ERROR: ");
Serial.println( NDEF_MODIFIED );
#endif
for ( uint8_t i = 0; i < length; i++ )
{
if ( tagbuf[i] < 0x10 )
client_.print( "0" );
client_.print( tagbuf[i], HEX );
}
//.........这里部分代码省略.........