本文整理汇总了C++中sendCommandCheckAck函数的典型用法代码示例。如果您正苦于以下问题:C++ sendCommandCheckAck函数的具体用法?C++ sendCommandCheckAck怎么用?C++ sendCommandCheckAck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendCommandCheckAck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wirereaddata
uint32_t Adafruit_NFCShield_I2C::targetTxRx(char *DataOut,char *DataIn)
{
///////////////////////////////////// Receiving from Initiator ///////////////////////////
pn532_packetbuffer[0] = PN532_COMMAND_TGGETDATA;
if (! sendCommandCheckAck(pn532_packetbuffer, 1))
return false;
// read data packet
wirereaddata(pn532_packetbuffer, 18+6);
#ifdef PN532DEBUG
Serial.println();
// check the response
Serial.println("TARGET_RX");
for(uint8_t i=0;i<18+6;i++)
{
Serial.print(pn532_packetbuffer[i], HEX); Serial.print(" ");
}
#endif
for(uint8_t iter=8;iter<(8+16);iter++)
{
DataIn[iter-8] = pn532_packetbuffer[iter]; //data received from initiator
}
///////////////////////////////////// Sending to Initiator ///////////////////////////
if(pn532_packetbuffer[7] == 0x00) //If no errors in receiving, send data.
{
pn532_packetbuffer[0] = PN532_COMMAND_TGSETDATA;
for(uint8_t iter=(1+0);iter<(1+16);iter++)
{
pn532_packetbuffer[iter] = DataOut[iter-1]; //pack the data to send to target
}
if (! sendCommandCheckAck(pn532_packetbuffer, 17))
return false;
// read data packet
wirereaddata(pn532_packetbuffer, 2+6);
#ifdef PN532DEBUG
Serial.println();
// check the response
Serial.println("TARGET_TX");
for(uint8_t i=0;i<2+6;i++)
{
Serial.print(pn532_packetbuffer[i], HEX); Serial.print(" ");
}
#endif
return (pn532_packetbuffer[7] == 0x00); //No error
}
}
示例2: Pins
boolean Adafruit_PN532::writeGPIO(uint8_t pinstate) {
uint8_t errorbit;
// Make sure pinstate does not try to toggle P32 or P34
pinstate |= (1 << PN532_GPIO_P32) | (1 << PN532_GPIO_P34);
// Fill command buffer
pn532_packetbuffer[0] = PN532_COMMAND_WRITEGPIO;
pn532_packetbuffer[1] = PN532_GPIO_VALIDATIONBIT | pinstate; // P3 Pins
pn532_packetbuffer[2] = 0x00; // P7 GPIO Pins (not used ... taken by SPI)
#ifdef PN532DEBUG
puts("Writing P3 GPIO: "); puts(pn532_packetbuffer[1]); puts("Append leading 0 for small values riga 275");
#endif
// Send the WRITEGPIO command (0x0E)
if (! sendCommandCheckAck(pn532_packetbuffer, 3))
return 0x0;
// Read response packet (00 FF PLEN PLENCHECKSUM D5 CMD+1(0x0F) DATACHECKSUM 00)
readspidata(pn532_packetbuffer, 8);
#ifdef PN532DEBUG
puts("Received: ");
// PrintHex(pn532_packetbuffer, 8);
puts("PrintHex riga 287");
puts("");
#endif
return (pn532_packetbuffer[5] == 0x0F);
}
示例3: readspidata
uint32_t Adafruit_PN532::getFirmwareVersion(void) {
uint32_t response;
pn532_packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
if (! sendCommandCheckAck(pn532_packetbuffer, 1))
return 0;
// read data packet
readspidata(pn532_packetbuffer, 12);
// check some basic stuff
if (0 != strncmp((char *)pn532_packetbuffer, (char *)pn532response_firmwarevers, 6)) {
return 0;
}
response = pn532_packetbuffer[6];
response <<= 8;
response |= pn532_packetbuffer[7];
response <<= 8;
response |= pn532_packetbuffer[8];
response <<= 8;
response |= pn532_packetbuffer[9];
return response;
}
示例4: wirereaddata
uint32_t Adafruit_NFCShield_I2C::getFirmwareVersion(void) {
uint32_t response;
pn532_packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
if (! sendCommandCheckAck(pn532_packetbuffer, 1))
return 0;
// read data packet
wirereaddata(pn532_packetbuffer, 12);
// check some basic stuff
if (0 != strncmp((char *)pn532_packetbuffer, (char *)pn532response_firmwarevers, 6)) {
#ifdef PN532DEBUG
Serial.println("Firmware doesn't match!");
#endif
return 0;
}
response = pn532_packetbuffer[7];
response <<= 8;
response |= pn532_packetbuffer[8];
response <<= 8;
response |= pn532_packetbuffer[9];
response <<= 8;
response |= pn532_packetbuffer[10];
return response;
}
示例5: Pins
boolean Adafruit_NFCShield_I2C::writeGPIO(uint8_t pinstate) {
uint8_t errorbit;
// Make sure pinstate does not try to toggle P32 or P34
pinstate |= (1 << PN532_GPIO_P32) | (1 << PN532_GPIO_P34);
// Fill command buffer
pn532_packetbuffer[0] = PN532_COMMAND_WRITEGPIO;
pn532_packetbuffer[1] = PN532_GPIO_VALIDATIONBIT | pinstate; // P3 Pins
pn532_packetbuffer[2] = 0x00; // P7 GPIO Pins (not used ... taken by I2C)
#ifdef PN532DEBUG
Serial.print("Writing P3 GPIO: "); Serial.println(pn532_packetbuffer[1], HEX);
#endif
// Send the WRITEGPIO command (0x0E)
if (! sendCommandCheckAck(pn532_packetbuffer, 3))
return 0x0;
// Read response packet (00 00 FF PLEN PLENCHECKSUM D5 CMD+1(0x0F) DATACHECKSUM)
wirereaddata(pn532_packetbuffer, 8);
#ifdef PN532DEBUG
Serial.print("Received: ");
PrintHex(pn532_packetbuffer, 8);
Serial.println("");
#endif
return (pn532_packetbuffer[6] == 0x0F);
}
示例6: Number
uint8_t Adafruit_NFCShield_I2C::mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t * data)
{
#ifdef MIFAREDEBUG
Serial.print("Trying to write 16 bytes to block ");Serial.println(blockNumber);
#endif
/* Prepare the first command */
pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
pn532_packetbuffer[1] = 1; /* Card number */
pn532_packetbuffer[2] = MIFARE_CMD_WRITE; /* Mifare Write command = 0xA0 */
pn532_packetbuffer[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
memcpy (pn532_packetbuffer+4, data, 16); /* Data Payload */
/* Send the command */
if (! sendCommandCheckAck(pn532_packetbuffer, 20))
{
#ifdef MIFAREDEBUG
Serial.println("Failed to receive ACK for write command");
#endif
return 0;
}
delay(10);
/* Read the response packet */
wirereaddata(pn532_packetbuffer, 26);
return 1;
}
示例7: once
boolean Adafruit_PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength) {
pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later)
pn532_packetbuffer[2] = cardbaudrate;
if (! sendCommandCheckAck(pn532_packetbuffer, 3))
return 0x0; // no cards read
// read data packet
readspidata(pn532_packetbuffer, 20);
// check some basic stuff
/* ISO14443A card response should be in the following format:
byte Description
------------- ------------------------------------------
b0..6 Frame header and preamble
b7 Tags Found
b8 Tag Number (only one used in this example)
b9..10 SENS_RES
b11 SEL_RES
b12 NFCID Length
b13..NFCIDLen NFCID */
#ifdef MIFAREDEBUG
puts("Found "); puts(pn532_packetbuffer[7], DEC); puts(" tags");
#endif
if (pn532_packetbuffer[7] != 1)
return 0;
uint16_t sens_res = pn532_packetbuffer[9];
sens_res <<= 8;
sens_res |= pn532_packetbuffer[10];
#ifdef MIFAREDEBUG
puts("ATQA: 0x"); puts("riga 451"); // puts(sens_res, HEX);
puts("SAK: 0x"); puts("riga 452");
#endif
/* Card appears to be Mifare Classic */
*uidLength = pn532_packetbuffer[12];
#ifdef MIFAREDEBUG
puts("UID:");
#endif
for (uint8_t i=0; i < pn532_packetbuffer[12]; i++)
{
uid[i] = pn532_packetbuffer[13+i];
#ifdef MIFAREDEBUG
puts(" 0x");puts("riga 464");
#endif
}
#ifdef MIFAREDEBUG
puts();
#endif
return 1;
}
示例8: digitalWrite
void Adafruit_PN532::begin() {
digitalWrite(_ss, LOW);
delay(1000);
// not exactly sure why but we have to send a dummy command to get synced up
pn532_packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
sendCommandCheckAck(pn532_packetbuffer, 1);
// ignore response!
}
示例9:
boolean Adafruit_NFCShield_I2C::powerDown(uint32_t uiBlock) {
pn532_packetbuffer[0] = PN532_COMMAND_POWERDOWN;
pn532_packetbuffer[1] = (0xFF); // I2C will wake up
if (sendCommandCheckAck(pn532_packetbuffer, 2)){
#ifdef MIFAREDEBUG
Serial.println("powered down");
#endif
return 1;
}
return 0;
}
示例10: delay
uint32_t Adafruit_NFCShield_I2C::configurePeerAsTarget() {
byte pbuffer[38] = { PN532_COMMAND_TGINITASTARGET,
0x00,
0x08, 0x00, //SENS_RES
0x12, 0x34, 0x56, //NFCID1
0x60, //SEL_RES
0x01, 0xFE, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, // NFCID2t
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, //PAD
0xFF, 0xFF, //System Code
0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, //NFCID3t: Change this to desired value
0x00, //Length of general bytes
0x00 //Length of historical bytes
};
for(uint8_t iter=0;iter<38;iter++)
{
pn532_packetbuffer[iter] = pbuffer[iter];
}
if (! sendCommandCheckAck(pn532_packetbuffer, 38)){
#ifdef PN532DEBUG
Serial.println("failed to recieve send ACK");
#endif
return 0;
}
delay(6000);
Serial.print("___");
// read data packet
wirereaddata(pn532_packetbuffer, 18+6);
Serial.print("___");
#ifdef PN532DEBUG
// Serial.println();
// check some basic stuff
// Serial.println("PEER_TARGET");
// for(uint8_t i=0;i<18+6;i++)
// {
// Serial.print(pn532_packetbuffer[i], HEX); Serial.println(" ");
// }
#endif
return (pn532_packetbuffer[23] == 0x00); //No error as it received all response
}
示例11: memcpy
uint8_t Adafruit_NFCShield_I2C::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t * keyData)
{
uint8_t len;
uint8_t i;
// Hang on to the key and uid data
memcpy (_key, keyData, 6);
memcpy (_uid, uid, uidLen);
_uidLen = uidLen;
#ifdef MIFAREDEBUG
Serial.print("Trying to authenticate card ");
Adafruit_NFCShield_I2C::PrintHex(_uid, _uidLen);
Serial.print("Using authentication KEY ");Serial.print(keyNumber ? 'B' : 'A');Serial.print(": ");
Adafruit_NFCShield_I2C::PrintHex(_key, 6);
#endif
// Prepare the authentication command //
pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE; /* Data Exchange Header */
pn532_packetbuffer[1] = 1; /* Max card numbers */
pn532_packetbuffer[2] = (keyNumber) ? MIFARE_CMD_AUTH_B : MIFARE_CMD_AUTH_A;
pn532_packetbuffer[3] = blockNumber; /* Block Number (1K = 0..63, 4K = 0..255 */
memcpy (pn532_packetbuffer+4, _key, 6);
for (i = 0; i < _uidLen; i++)
{
pn532_packetbuffer[10+i] = _uid[i]; /* 4 byte card ID */
}
if (! sendCommandCheckAck(pn532_packetbuffer, 10+_uidLen))
return 0;
// Read the response packet
wirereaddata(pn532_packetbuffer, 12);
// Check if the response is valid and we are authenticated???
// for an auth success it should be bytes 5-7: 0xD5 0x41 0x00
// Mifare auth error is technically byte 7: 0x14 but anything other and 0x00 is not good
if (pn532_packetbuffer[7] != 0x00)
{
#ifdef PN532DEBUG
Serial.print("Authentification failed: ");
Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 12);
#endif
return 0;
}
return 1;
}
示例12: MxRtyATR
boolean Adafruit_NFCShield_I2C::setPassiveActivationRetries(uint8_t maxRetries) {
pn532_packetbuffer[0] = PN532_COMMAND_RFCONFIGURATION;
pn532_packetbuffer[1] = 5; // Config item 5 (MaxRetries)
pn532_packetbuffer[2] = 0xFF; // MxRtyATR (default = 0xFF)
pn532_packetbuffer[3] = 0x01; // MxRtyPSL (default = 0x01)
pn532_packetbuffer[4] = maxRetries;
#ifdef MIFAREDEBUG
Serial.print("Setting MxRtyPassiveActivation to "); Serial.print(maxRetries, DEC); Serial.println(" ");
#endif
if (! sendCommandCheckAck(pn532_packetbuffer, 5))
return 0x0; // no ACK
return 1;
}
示例13: memcpy
uint8_t Adafruit_NFCShield_I2C::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t * keyData)
{
uint8_t len;
uint8_t i;
// Hang on to the key and uid data
memcpy (_key, keyData, 6);
memcpy (_uid, uid, uidLen);
_uidLen = uidLen;
#ifdef MIFAREDEBUG
Serial.print("Trying to authenticate card ");
Adafruit_NFCShield_I2C::PrintHex(_uid, _uidLen);
Serial.print("Using authentication KEY ");Serial.print(keyNumber ? 'B' : 'A');Serial.print(": ");
Adafruit_NFCShield_I2C::PrintHex(_key, 6);
#endif
// Prepare the authentication command //
pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE; /* Data Exchange Header */
pn532_packetbuffer[1] = 1; /* Max card numbers */
pn532_packetbuffer[2] = (keyNumber) ? MIFARE_CMD_AUTH_A : MIFARE_CMD_AUTH_B;
pn532_packetbuffer[3] = blockNumber; /* Block Number (1K = 0..63, 4K = 0..255 */
memcpy (pn532_packetbuffer+4, _key, 6);
for (i = 0; i < _uidLen; i++)
{
pn532_packetbuffer[10+i] = _uid[i]; /* 4 byte card ID */
}
if (! sendCommandCheckAck(pn532_packetbuffer, 10+_uidLen))
return 0;
// Read the response packet
wirereaddata(pn532_packetbuffer, 12);
// ToDo: How to check if the response is valid and we are authenticated???
// #ifdef PN532DEBUG
// Serial.println("Authentification failed%s");
// #endif
// return 0;
return 1;
}
示例14: once
boolean Adafruit_NFCShield_I2C::readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength) {
pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later)
pn532_packetbuffer[2] = cardbaudrate;
if (! sendCommandCheckAck(pn532_packetbuffer, 3))
{
#ifdef PN532DEBUG
Serial.println("No card(s) read");
#endif
return 0x0; // no cards read
}
// Wait for a card to enter the field
uint8_t status = PN532_I2C_BUSY;
#ifdef PN532DEBUG
Serial.println("Waiting for IRQ (indicates card presence)");
#endif
while (wirereadstatus() != PN532_I2C_READY)
{
delay(10);
}
#ifdef PN532DEBUG
Serial.println("Found a card");
#endif
// read data packet
wirereaddata(pn532_packetbuffer, 20);
// check some basic stuff
/* ISO14443A card response should be in the following format:
byte Description
------------- ------------------------------------------
b0..6 Frame header and preamble
b7 Tags Found
b8 Tag Number (only one used in this example)
b9..10 SENS_RES
b11 SEL_RES
b12 NFCID Length
b13..NFCIDLen NFCID */
#ifdef MIFAREDEBUG
Serial.print("Found "); Serial.print(pn532_packetbuffer[7], DEC); Serial.println(" tags");
#endif
if (pn532_packetbuffer[7] != 1)
return 0;
uint16_t sens_res = pn532_packetbuffer[9];
sens_res <<= 8;
sens_res |= pn532_packetbuffer[10];
#ifdef MIFAREDEBUG
Serial.print("ATQA: 0x"); Serial.println(sens_res, HEX);
Serial.print("SAK: 0x"); Serial.println(pn532_packetbuffer[11], HEX);
#endif
/* Card appears to be Mifare Classic */
*uidLength = pn532_packetbuffer[12];
#ifdef MIFAREDEBUG
Serial.print("UID:");
#endif
for (uint8_t i=0; i < pn532_packetbuffer[12]; i++)
{
uid[i] = pn532_packetbuffer[13+i];
#ifdef MIFAREDEBUG
Serial.print(" 0x");Serial.print(uid[i], HEX);
#endif
}
#ifdef MIFAREDEBUG
Serial.println();
#endif
return 1;
}
示例15: wirereaddata
boolean Adafruit_NFCShield_I2C::inListPassiveTarget() {
pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
pn532_packetbuffer[1] = 1;
pn532_packetbuffer[2] = 0;
#ifdef PN532DEBUG
Serial.print("About to inList passive target");
#endif
if (!sendCommandCheckAck(pn532_packetbuffer,3,1000)) {
#ifdef PN532DEBUG
Serial.println("Could not send inlist message");
#endif
return false;
}
if (!waitUntilReady(30000)) {
return false;
}
wirereaddata(pn532_packetbuffer,sizeof(pn532_packetbuffer));
if (pn532_packetbuffer[0] == 0 && pn532_packetbuffer[1] == 0 && pn532_packetbuffer[2] == 0xff) {
uint8_t length = pn532_packetbuffer[3];
if (pn532_packetbuffer[4]!=(uint8_t)(~length+1)) {
#ifdef PN532DEBUG
Serial.println("Length check invalid");
Serial.println(length,HEX);
Serial.println((~length)+1,HEX);
#endif
return false;
}
if (pn532_packetbuffer[5]==PN532_PN532TOHOST && pn532_packetbuffer[6]==PN532_RESPONSE_INLISTPASSIVETARGET) {
if (pn532_packetbuffer[7] != 1) {
#ifdef PN532DEBUG
Serial.println("Unhandled number of targets inlisted");
#endif
Serial.println("Number of tags inlisted:");
Serial.println(pn532_packetbuffer[7]);
return false;
}
inListedTag = pn532_packetbuffer[8];
Serial.print("Tag number: ");
Serial.println(inListedTag);
return true;
} else {
#ifdef PN532DEBUG
Serial.print("Unexpected response to inlist passive host");
#endif
return false;
}
}
else {
#ifdef PN532DEBUG
Serial.println("Preamble missing");
#endif
return false;
}
return true;
}