You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.7 KiB
125 lines
3.7 KiB
////////////////////////////////////////////////////////////////////////////
|
|
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|
///-------------------------------------------------------------------------
|
|
/// @file bsp_drv.c
|
|
/// @brief bsp @ driver config
|
|
///-------------------------------------------------------------------------
|
|
/// @version 1.0
|
|
/// @author CC
|
|
/// @date 20180331
|
|
/// @note cc_AS_stc02
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "task_rfid.h"
|
|
#include "../app/app_config.h"
|
|
#include "../bsp/bsp_config.h"
|
|
#include "../msp/uart0.h"
|
|
#include "../msp/uart3.h"
|
|
|
|
S_TASK_RFID _s_task_rfid;
|
|
TPC_RFID tpc_rfid;
|
|
|
|
//4通道,读取次数 3 3 3 3
|
|
U8 rfidSetChannelCmd[] = {0xBB,0x00,0x1B,0x00,0x05,0x02,0x03,0x03,0x03,0x03,0x2E,0x7E};
|
|
//设置功率 26dBm
|
|
U8 rfidSetWCmd[] = {0xBB,0x00,0xB6,0x00,0x02,0x0A,0x28,0xEA,0x7E};
|
|
//选择卡片
|
|
U8 rfidSelCmd[] = {0x00};
|
|
//轮询读取(FFFF代表永久轮询)
|
|
U8 rfidLoopRead[] = {0xBB,0x00,0x27,0x00,0x03,0x22,0xFF,0xFF,0x4A,0x7E};
|
|
|
|
//=============================================
|
|
void L3_task_rfid_init(void)
|
|
{
|
|
L1_task_init(&_s_task_rfid.task);
|
|
L3_task_s_go(_s_task_rfid,D_task_init);
|
|
}
|
|
|
|
#define D_task_RFID_READ 0x50
|
|
#define D_task_RFID_PRINT 0x51
|
|
#define D_task_RFID_SET 0x52
|
|
|
|
void L3_task_rfid_handler(S_TASK_RFID *s)
|
|
{
|
|
TTSS_Task_init()
|
|
L0_uart0_uchex(sizeof(rfidSetChannelCmd) / sizeof(U8));
|
|
L0_uart0_uchex(sizeof(rfidSetWCmd) / sizeof(U8));
|
|
L0_uart0_uchex(sizeof(rfidSelCmd) / sizeof(U8));
|
|
L0_uart0_uchex(sizeof(rfidLoopRead) / sizeof(U8));
|
|
|
|
//1.设置天线
|
|
L0_uart3_sendArray(rfidSetChannelCmd, sizeof(rfidSetChannelCmd) / sizeof(U8));
|
|
NOP10();
|
|
//2.设置功率
|
|
L0_uart3_sendArray(rfidSetWCmd, sizeof(rfidSetWCmd) / sizeof(U8));
|
|
NOP10();
|
|
//3.选择掩码
|
|
L0_uart3_sendArray(rfidSelCmd, sizeof(rfidSelCmd) / sizeof(U8));
|
|
NOP10();
|
|
//4.启动轮询
|
|
L0_uart3_sendArray(rfidLoopRead, sizeof(rfidLoopRead) / sizeof(U8));
|
|
NOP10();
|
|
|
|
L2_task_go(D_task_RFID_READ);
|
|
|
|
TTSS_Task_step(D_task_RFID_READ)
|
|
if(ts_uart3_recv_buf.ok == 1)
|
|
{
|
|
ts_uart3_recv_buf.ok = 0;
|
|
Lc_buf_copy_uc((U8*)&tpc_rfid, ts_uart3_recv_buf.buf, ts_uart3_recv_buf.num);
|
|
tpc_rfid.ocr = tpc_rfid.buf[tpc_rfid.num[0] << 8 | tpc_rfid.num[1]];
|
|
if(tpc_rfid.type == 0x02 && tpc_rfid.cmd == 0x22){
|
|
// L2_task_go_Tdelay(D_task_RFID_PRINT,0);
|
|
L2_task_go_Tdelay(D_task_RFID_SET,0);
|
|
}
|
|
}
|
|
|
|
TTSS_Task_step(D_task_RFID_SET)
|
|
U8 index = 0;
|
|
U8 num = (U16)tpc_rfid.num[0] << 8 | tpc_rfid.num[1];
|
|
U16 rfidno = (U16)tpc_rfid.buf[num-5] << 8 | tpc_rfid.buf[num-4];
|
|
U8 rssi = tpc_rfid.buf[0];
|
|
U8 ant = tpc_rfid.buf[num-1];
|
|
|
|
L0_uart0_uc('R');
|
|
L0_uart0_uchex(tpc_rfid.buf[num-5]);
|
|
L0_uart0_uchex(tpc_rfid.buf[num-4]);
|
|
|
|
//1.判定RFID卡号是否符合规则
|
|
//2.保存RFID卡号到寄存器
|
|
L3_new_rfid(rfidno, rssi, ant);
|
|
//3.查找编号是否在rfidtable中
|
|
index = L3_find_rfid_table(rfidno);
|
|
//4.亮灯
|
|
//TODO 如果缓冲区满了,没放进去,是否亮灯
|
|
if(index < LED_BTN_NUM){
|
|
R.led_status[index] = BLED0_ON;
|
|
}
|
|
L2_task_go_Tdelay(D_task_RFID_READ,0);
|
|
|
|
TTSS_Task_step(D_task_RFID_PRINT)
|
|
L0_uart0_sendstr("\r\n--------- Recv RFID --------\r\n");
|
|
L0_uart0_sendstr("type : ");
|
|
L0_uart0_uchex(tpc_rfid.type);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("cmd: ");
|
|
L0_uart0_uchex(tpc_rfid.cmd);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("num: ");
|
|
L0_uart0_uchex(tpc_rfid.num[0]);
|
|
L0_uart0_uchex(tpc_rfid.num[1]);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("dat : ");
|
|
L0_uart0_sendArrayHex(tpc_rfid.buf, tpc_rfid.num[0] << 8 | tpc_rfid.num[1]);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("ocr: ");
|
|
L0_uart0_uchex(tpc_rfid.ocr);
|
|
L0_uart0_0d0a();
|
|
L2_task_go_Tdelay(D_task_RFID_READ,0);
|
|
|
|
TTSS_Task_end();
|
|
}
|
|
|
|
|
|
|
|
|
|
|