//////////////////////////////////////////////////////////////////////////// ///@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; 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) { 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) { //buf[0] 低功耗模式 R.low_power_mode = tpc_rs485.buf[0]; //buf[1-2], rfid映射 //TODO //构造响应包,并且返回 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