byte PN532::getCommandResponse(byte * resp, const long & wmillis) { if (!IRQ_wait(wmillis)) { #ifdef PN532DEBUG Serial.println("IRQ wail expired."); Serial.print("Couldn't wait "); Serial.println(wmillis); #endif return 0; } comm_status = REQUEST_RECEIVE; byte count = receivepacket(); #ifdef PN532COMM Serial.print("CommandResp. >> "); printBytes(packet, count); Serial.println('\n'); #endif //#undef PN532DEBUG if (!(packet[0] == 0xd5 && packet[1] == (last_command + 1))) { #ifdef PN532DEBUG Serial.println("Missmatch with the last command."); #endif comm_status = RESP_COMMAND_MISSMATCH; return 0; } comm_status = RESP_RECEIVED; count -= 2; memmove(resp, packet + 2, count); return count; }
boolean PN532::checkACKframe(long timeout) { // Wait for chip to say its ready! if (!IRQ_wait(timeout)) return false; // read acknowledgement byte frame_head[] = { PREAMBLE, STARTCODE_1, STARTCODE_2 }; receivepacket(6); //printHexString(packet, 6); if ((0 == memcmp(packet, frame_head, 3)) && (packet[5] == 0)) { if (packet[3] == 0x00 && packet[4] == 0xff) { comm_status = ACK_FRAME_RECEIVED; return true; // ack'd command } else if (packet[3] == 0xff && packet[4] == 0x00) { comm_status = NACK_FRAME_RECEIVED; return true; // ack'd command } } comm_status = WRONG_ACK; return false; }