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.
151 lines
4.2 KiB
151 lines
4.2 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_rs485.h"
|
|
#include "../app/app_config.h"
|
|
#include "../bsp/bsp_config.h"
|
|
#include "../msp/uart0.h"
|
|
#include "../msp/uart4.h"
|
|
|
|
S_TASK_RS485 _s_task_rs485;
|
|
TPC_RS485 tpc_rs485;
|
|
TPC_RS485_ACK tpc_rs485_ack;
|
|
static U8 acklen = 0;
|
|
static U8 i = 0;
|
|
U16 setLedStatus = 0;
|
|
|
|
U8 constructor_rs485_ack();
|
|
|
|
//=============================================
|
|
void L3_task_rs485_init(void)
|
|
{
|
|
L1_task_init(&_s_task_rs485.task);
|
|
L3_task_s_go(_s_task_rs485,D_task_init);
|
|
}
|
|
|
|
#define D_task_RS485_READ 0x50
|
|
#define D_task_RS485_PRINT 0x51
|
|
#define D_task_RS485_ACK 0x52
|
|
#define D_task_RS485_MODE 0x53
|
|
|
|
void L3_task_rs485_handler(S_TASK_RS485 *s)
|
|
{
|
|
TTSS_Task_init()
|
|
L2_task_go(D_task_RS485_READ);
|
|
|
|
TTSS_Task_step(D_task_RS485_READ)
|
|
if(ts_uart4_recv_buf.ok == 1)
|
|
{
|
|
//L0_uart0_uc('%');
|
|
// LED0 ^= 1;
|
|
ts_uart4_recv_buf.ok = 0;
|
|
Lc_buf_copy_uc((U8*)&tpc_rs485, ts_uart4_recv_buf.buf, ts_uart4_recv_buf.num);
|
|
tpc_rs485.ocr = tpc_rs485.buf[tpc_rs485.num[0] << 8 | tpc_rs485.num[1]];
|
|
//L2_task_go_Tdelay(D_task_RS485_PRINT,0);
|
|
L2_task_go_Tdelay(D_task_RS485_ACK,0);
|
|
}
|
|
|
|
TTSS_Task_step(D_task_RS485_ACK)
|
|
if(tpc_rs485.slaveId == R.slave_id)
|
|
{
|
|
//读取
|
|
if(tpc_rs485.cmd == 0x10)
|
|
{
|
|
//1.buf[0]高4位是否需要授权标志
|
|
R.auth_flag &= 0x0F;
|
|
R.auth_flag |= tpc_rs485.buf[0] & 0xF0;
|
|
|
|
//2.buf[0]低四位是否进入低功耗模式
|
|
// R.low_power_mode = tpc_rs485.buf[0] & 0x0F;
|
|
L3_set_power_mode(tpc_rs485.buf[0] & 0x0F);
|
|
|
|
//3.buf[1-2], rfid映射
|
|
//TODO 上位机发过来的rfid编号如何处理
|
|
setLedStatus = (U16)tpc_rs485.buf[1] << 8 | tpc_rs485.buf[2];
|
|
if(setLedStatus != 0x00)
|
|
{
|
|
//0位是功能按键,常亮,不提供设置功能
|
|
for(i=1;i<LED_BTN_NUM;i++)
|
|
{
|
|
//不处理0,只处理1的情况(代表其他端产生了sop中的节点,比如平板上触发谈话等)
|
|
if((setLedStatus >> i) & 0x0001)
|
|
{
|
|
R.led_status[i] = LED0_ON;
|
|
}
|
|
}
|
|
}
|
|
|
|
//构造响应包,并且返回
|
|
acklen = constructor_rs485_ack();
|
|
//写出
|
|
L0_uart4_sendArray((U8*)&tpc_rs485_ack, acklen);
|
|
}
|
|
}
|
|
L2_task_go_Tdelay(D_task_RS485_READ,0);
|
|
|
|
TTSS_Task_step(D_task_RS485_PRINT)
|
|
L0_uart0_sendstr("\r\n--------- Recv RS485 --------\r\n");
|
|
L0_uart0_sendstr("slaveId : ");
|
|
L0_uart0_uchex(tpc_rs485.slaveId);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("cmd: ");
|
|
L0_uart0_uchex(tpc_rs485.cmd);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("num: ");
|
|
L0_uart0_uchex(tpc_rs485.num[0]);
|
|
L0_uart0_uchex(tpc_rs485.num[1]);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("dat : ");
|
|
L0_uart0_sendArrayHex(tpc_rs485.buf, tpc_rs485.num[0] << 8 | tpc_rs485.num[1]);
|
|
L0_uart0_0d0a();
|
|
L0_uart0_sendstr("ocr: ");
|
|
L0_uart0_uchex(tpc_rs485.ocr);
|
|
L0_uart0_0d0a();
|
|
L2_task_go_Tdelay(D_task_RS485_READ,0);
|
|
|
|
TTSS_Task_end();
|
|
}
|
|
|
|
U8 constructor_rs485_ack()
|
|
{
|
|
U8 num = (1 + sizeof(R.nfc) + sizeof(R.rfids));
|
|
tpc_rs485_ack.head[0] = 0xAA;
|
|
// tpc_rs485_ack.head[1] = 0x55;
|
|
tpc_rs485_ack.slaveId = R.slave_id;
|
|
tpc_rs485_ack.cmd = 0x10;
|
|
tpc_rs485_ack.num[0] = (num >> 8) & 0xFF;
|
|
tpc_rs485_ack.num[1] = num & 0xFF;
|
|
tpc_rs485_ack.buf[0] = R.func_btn;
|
|
Lc_buf_copy_uc((U8*)&tpc_rs485_ack.buf[1], (U8*)&R.nfc, sizeof(R.nfc));
|
|
Lc_buf_copy_uc((U8*)&tpc_rs485_ack.buf[1+sizeof(R.nfc)], (U8*)R.rfids, sizeof(R.rfids));
|
|
tpc_rs485_ack.ocr = 0;
|
|
tpc_rs485_ack.ocr += tpc_rs485_ack.slaveId;
|
|
tpc_rs485_ack.ocr += tpc_rs485_ack.cmd;
|
|
tpc_rs485_ack.ocr += tpc_rs485_ack.num[0];
|
|
tpc_rs485_ack.ocr += tpc_rs485_ack.num[1];
|
|
for(i=0;i<num;i++)
|
|
{
|
|
tpc_rs485_ack.ocr += tpc_rs485_ack.buf[i];
|
|
}
|
|
tpc_rs485_ack.buf[num] = tpc_rs485_ack.ocr;
|
|
|
|
//清0资源
|
|
R.func_btn = 0;
|
|
L3_nfc_clear();
|
|
L3_rfid_clear();
|
|
|
|
return 5 + num + 1;
|
|
}
|
|
|
|
|
|
|
|
|
|
|