修改读取逻辑以适配串口转接。
This commit is contained in:
parent
fa485a610c
commit
4cac07cb0e
@ -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<WS2812B, DATA_PIN, GRB>(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++;
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
#include <Wire.h>
|
||||
#include <PN532_I2C.h>
|
||||
#include <PN532.h>
|
||||
|
||||
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");
|
||||
}
|
12
cmd.h
12
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);
|
||||
|
Loading…
Reference in New Issue
Block a user