diff --git a/Arduino-Aime-Reader.ino b/Arduino-Aime-Reader.ino index a765698..5026d3e 100644 --- a/Arduino-Aime-Reader.ino +++ b/Arduino-Aime-Reader.ino @@ -1,5 +1,8 @@ #include "cmd.h" +#define SerialDevice SerialUSB //32u4,samd21 +//#define SerialDevice Serial + void SerialCheck() { switch (packet_read()) { case SG_NFC_CMD_RESET: @@ -55,8 +58,9 @@ void SerialCheck() { } void setup() { - SerialUSB.begin(38400); - SerialUSB.setTimeout(0); + SerialDevice.begin(38400); + // SerialUSB.begin(119200);//high_baudrate=true + SerialDevice.setTimeout(0); FastLED.addLeds(leds, NUM_LEDS); nfc.begin(); if (!nfc.getFirmwareVersion()) { @@ -82,13 +86,16 @@ void loop() { packet_write(); } +static uint8_t len, r, checksum; +static bool escape = false; + static uint8_t packet_read() { - uint8_t len, r, checksum; - bool escape = false; - while (SerialUSB.available()) { - r = SerialUSB.read(); + + while (SerialDevice.available()) { + r = SerialDevice.read(); if (r == 0xE0) { req.frame_len = 0xFF; + len = 0; continue; } if (req.frame_len == 0xFF) { @@ -119,7 +126,7 @@ static void packet_write() { if (res.cmd == 0) { return; } - SerialUSB.write(0xE0); + SerialDevice.write(0xE0); while (len <= res.frame_len) { uint8_t w; if (len == res.frame_len) { @@ -129,14 +136,14 @@ static void packet_write() { checksum += w; } if (w == 0xE0 || w == 0xD0) { - if (SerialUSB.availableForWrite() < 2) + if (SerialDevice.availableForWrite() < 2) return; - SerialUSB.write(0xD0); - SerialUSB.write(--w); + SerialDevice.write(0xD0); + SerialDevice.write(--w); } else { - if (SerialUSB.availableForWrite() < 1) + if (SerialDevice.availableForWrite() < 1) return; - SerialUSB.write(w); + SerialDevice.write(w); } len++; } diff --git a/ReaderTest.ino b/ReaderTest.ino deleted file mode 100644 index 211dee1..0000000 --- a/ReaderTest.ino +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include - -PN532_I2C pn532i2c(Wire); -PN532 nfc(pn532i2c); - -uint16_t systemCode = 0xFFFF; -uint8_t requestCode = 0x01; -uint16_t systemCodeResponse; -typedef union { - uint8_t block[16]; - struct { - uint8_t IDm[8]; - uint8_t PMm[8]; - }; -} Card_Data; - -Card_Data card; -uint8_t AimeKey[6] = {0x57, 0x43, 0x43, 0x46, 0x76, 0x32}; -uint8_t BanaKey[6] = {0x60, 0x90, 0xD0, 0x06, 0x32, 0xF5}; -uint8_t MifareKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -#define M2F_B 1 - -void setup() { - SerialUSB.begin(38400); - SerialUSB.setTimeout(0); - while (!SerialUSB); - nfc.begin(); - while (!nfc.getFirmwareVersion()) { - SerialUSB.println("Didn't find PN53x board"); - delay(2000); - } - nfc.setPassiveActivationRetries(0x10); - nfc.SAMConfig(); -} - -void loop() { - uint8_t uid[4], uL; - delay(1000); - - if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL) && nfc.mifareclassic_AuthenticateBlock(uid, uL, 1, 1, AimeKey)) { - SerialUSB.println("Aime"); - return; - } - if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL) && nfc.mifareclassic_AuthenticateBlock(uid, uL, 1, 0, BanaKey)) { - SerialUSB.println("Bana"); - return; - } - if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL) && nfc.mifareclassic_AuthenticateBlock(uid, uL, M2F_B, 0, MifareKey)) { - SerialUSB.println("Default Key Mifare"); - return; - } - if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL)) { - SerialUSB.println("Mifare:Unknown key"); - return; - } - - if (nfc.felica_Polling(systemCode, requestCode, card.IDm, card.PMm, &systemCodeResponse, 200)) { - SerialUSB.println("Found a Felica card!"); - return; - } - SerialUSB.println("Didn't find card"); -} diff --git a/cmd.h b/cmd.h index f01d551..2c323d7 100644 --- a/cmd.h +++ b/cmd.h @@ -143,13 +143,15 @@ static void sg_nfc_cmd_reset() {//重置读卡器 } static void sg_nfc_cmd_get_fw_version() { - sg_res_init(sizeof(res.version)); - memcpy(res.version, "TN32MSEC003S F/W Ver1.2E", 23); + sg_res_init(23); + // memcpy(res.version, "TN32MSEC003S F/W Ver1.2E", 23); + memcpy(res.version, "Sucareto Aime Reader FW", 23); } static void sg_nfc_cmd_get_hw_version() { - sg_res_init(sizeof(res.version)); - memcpy(res.version, "TN32MSEC003S H/W Ver3.0J", 23); + sg_res_init(23); + // memcpy(res.version, "TN32MSEC003S H/W Ver3.0J", 23); + memcpy(res.version, "Sucareto Aime Reader HW", 23); } static void sg_nfc_cmd_mifare_set_key() { @@ -162,7 +164,7 @@ static void sg_nfc_cmd_mifare_set_key() { } static void sg_led_cmd_reset() { - sg_res_init(sizeof(res.reset_payload)); + sg_res_init(1); res.reset_payload = 0; fill_solid(leds, NUM_LEDS, 0x000000); FastLED[0].show(leds, NUM_LEDS, BRI);