gpt4 book ai didi

c++ - 向MFRC522库添加功能SetKeys

转载 作者:行者123 更新时间:2023-12-02 10:38:51 29 4
gpt4 key购买 nike

我尝试将功能SetKeys添加到我的MFRC522库。
我无法理解MIFARE_Read函数不起作用...
我的标签是Mifare Classic 1k

bool MFRC522::MIFARE_SetKeys(byte *oldKeyA, byte *oldKeyB, byte *newKeyA, byte *newKeyB, byte sector){

byte block_bufferRead[18];
byte block_bufferWrite[16];
byte sizeRead = sizeof(block_bufferRead);
byte sizeWrite = sizeof(block_bufferWrite);
byte block = (sector * 4) + 3;

MFRC522::StatusCode status;
MFRC522::MIFARE_Key key;

for(int i=0; i<6; i++) key.keyByte[i] = oldKeyA[i];

if(!MFRC522::PCD_Authenticate(PICC_CMD_MF_AUTH_KEY_A, block, &key, &uid)){
Serial.println("PCD_Authenticate() failed - Block " + String(block));
return false;
}
else{
status = MIFARE_Read(block, block_bufferRead, &sizeRead);
if(status != MFRC522::STATUS_OK){
Serial.println("MIFARE_Read() failed. Block " + String(block));
Serial.println(GetStatusCodeName(status));
return false;
}
else{
for(int i=0; i<6; i++) key.keyByte[i] = oldKeyB[i];
if(!MFRC522::PCD_Authenticate(PICC_CMD_MF_AUTH_KEY_B, block, &key, &uid)){
Serial.println("PCD_Authenticate() failed - Block " + String(block));
return false;
}
else{
for(byte i=0; i<16; i++) block_bufferWrite[i] = block_bufferRead[i];
for(byte i=0; i<6; i++){
block_bufferWrite[i] = newKeyA[i];
block_bufferWrite[i+10] = newKeyB[i];
}
for(int i=0; i<6; i++) key.keyByte[i] = oldKeyB[i];
status = MIFARE_Write(block, block_bufferWrite, &sizeWrite);
if(status != MFRC522::STATUS_OK){
Serial.println("MIFARE_Write() failed.");
Serial.println(GetStatusCodeName(status));
return false;
}
else return true;
}

}
}
}

最佳答案

好像您缺少该库的include标记。你需要类似的东西#include "MFRC522.h"

关于c++ - 向MFRC522库添加功能SetKeys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55477360/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com