From ebb2565ce4c43e8de275790f52bebee381d0bca7 Mon Sep 17 00:00:00 2001 From: QHPaeek Date: Sat, 14 Sep 2024 11:57:48 +0800 Subject: [PATCH] fix felica read and write --- Aime_Reader.h | 18 ++++++++++-------- Arduino-Aime-Reader.ino | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Aime_Reader.h b/Aime_Reader.h index c3a427e..59ade96 100644 --- a/Aime_Reader.h +++ b/Aime_Reader.h @@ -7,7 +7,7 @@ #elif defined(ESP8266) #pragma message "当前的开发板是 ESP8266" #define SerialDevice Serial -#define PN532_SPI_SS D4 +//#define PN532_SPI_SS D4 #define LED_PIN D5 #elif defined(ESP32) @@ -196,7 +196,7 @@ typedef union { struct { uint8_t RW_status[2]; uint8_t numBlock; - uint8_t blockData[1][1][16]; + uint8_t blockData[4][16]; }; uint8_t felica_payload[1]; }; @@ -385,13 +385,12 @@ void nfc_felica_through() { break; case FelicaReadWithoutEncryptData: { - uint16_t serviceCodeList[1] = { (uint16_t)(req.serviceCodeList[1] << 8 | req.serviceCodeList[0]) }; + uint16_t serviceCodeList = req.serviceCodeList[1] << 8 | req.serviceCodeList[0]; + uint16_t blockList[4]; for (uint8_t i = 0; i < req.numBlock; i++) { - uint16_t blockList[1] = { (uint16_t)(req.blockList[i][0] << 8 | req.blockList[i][1]) }; - if (nfc.felica_ReadWithoutEncryption(1, serviceCodeList, 1, blockList, res.blockData[i]) != 1) { - memset(res.blockData[i], 0, 16); // dummy data - } + blockList[i] = (uint16_t)(req.blockList[i][0] << 8 | req.blockList[i][1]); } + nfc.felica_ReadWithoutEncryption(1, &serviceCodeList, req.numBlock, blockList, res.blockData); res.RW_status[0] = 0; res.RW_status[1] = 0; res.numBlock = req.numBlock; @@ -400,7 +399,10 @@ void nfc_felica_through() { break; case FelicaWriteWithoutEncryptData: { - res_init(0x0C); // WriteWithoutEncryption,ignore + uint16_t serviceCodeList = req.serviceCodeList[1] << 8 | req.serviceCodeList[0]; + uint16_t blockList = (uint16_t)(req.blockList_write[0][0] << 8 | req.blockList_write[0][1]); + nfc.felica_WriteWithoutEncryption(1, &serviceCodeList, 1, &blockList, &req.blockData); + res_init(0x0C); res.RW_status[0] = 0; res.RW_status[1] = 0; } diff --git a/Arduino-Aime-Reader.ino b/Arduino-Aime-Reader.ino index 2da040d..6f469c0 100644 --- a/Arduino-Aime-Reader.ino +++ b/Arduino-Aime-Reader.ino @@ -95,8 +95,12 @@ void loop() { case CMD_CARD_HALT: case CMD_EXT_TO_NORMAL_MODE: case CMD_TO_UPDATER_MODE: + res_init(); + break; + case CMD_SEND_HEX_DATA: res_init(); + res.status = STATUS_COMP_DUMMY_3RD; break; case STATUS_SUM_ERROR: