Skip to content

Commit

Permalink
修改读取逻辑以适配串口转接。
Browse files Browse the repository at this point in the history
  • Loading branch information
Sucareto committed Jun 20, 2021
1 parent fa485a6 commit 4cac07c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 81 deletions.
31 changes: 19 additions & 12 deletions Arduino-Aime-Reader.ino
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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++;
}
Expand Down
64 changes: 0 additions & 64 deletions ReaderTest.ino

This file was deleted.

12 changes: 7 additions & 5 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down

0 comments on commit 4cac07c

Please sign in to comment.