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.
244 lines
6.1 KiB
244 lines
6.1 KiB
10 months ago
|
#include "../app/task_screen.h"
|
||
|
#include "../app/app_config.h"
|
||
|
// #include "../bsp/bsp_config.h"
|
||
|
// #include "../bsp/bsp_ds1302.h"
|
||
|
#include "../msp/uart/msp_uart1.h"
|
||
|
#include "msp_uart1.h"
|
||
|
#include "debug_drv.h"
|
||
|
|
||
|
|
||
|
S_TASK_SCREEN _s_task_screen;
|
||
|
|
||
|
SCRSetValPkg scrSetValPkg = {
|
||
|
0xA5, 0x5A,
|
||
|
0x1C, //长度
|
||
|
0x82, //指令
|
||
|
0x01, 0x1E, //起始地址
|
||
|
0x00, 0x00, //体重
|
||
|
0x00, 0x00, //电量
|
||
|
0x00, 0x00, //网络状态
|
||
|
0x00, 0x00, //单位
|
||
|
0x00, 0x00, //语言
|
||
|
// 0x00, 0x00, //充电状态
|
||
|
0x00, 0x00, //蜂鸣器状态
|
||
|
0x00, 0x00, //界面
|
||
|
0x1C, 0x78, // CRC
|
||
|
};
|
||
|
|
||
|
//息屏指令
|
||
|
SCRControlPkg scrPingOffPkg = {
|
||
|
0xA5, 0x5A,
|
||
|
0x05, //长度
|
||
|
0x80, //指令
|
||
|
0x01, 0x00, //数据
|
||
|
0x71, 0xB8, // CRC
|
||
|
};
|
||
|
|
||
|
//亮屏指令
|
||
|
SCRControlPkg scrPingOnPkg = {
|
||
|
0xA5, 0x5A,
|
||
|
0x05, //长度
|
||
|
0x80, //指令
|
||
|
0x01, 0x30, //数据
|
||
|
0x71, 0xAC, // CRC
|
||
|
};
|
||
|
|
||
|
//=============================================
|
||
|
void L3_task_screen_init(void)
|
||
|
{
|
||
|
L1_task_init(&_s_task_screen.task);
|
||
|
_s_task_screen.power_mode = R.power_mode;
|
||
|
L3_task_s_go(_s_task_screen, D_task_init);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
// #define D_TASK_SCREEN_SEND_CONTROL 0x50
|
||
|
// #define D_TASK_SCREEN_SEND_VAL 0x51
|
||
|
//#define D_task_RFID_SET 0x52
|
||
|
|
||
|
#define D_task_RS485_SEND_BEFORE 0x50
|
||
|
#define D_task_RS485_SEND 0x51
|
||
|
#define D_task_RS485_SEND_AFTER 0x52
|
||
|
#define D_task_RS485_RECV 0x53
|
||
|
|
||
|
void L3_task_screen_handler(S_TASK_SCREEN *s)
|
||
|
{
|
||
|
// L0_uart1_str("_s_task_screen.task.sh: ");
|
||
|
// L0_uart1_uchex(_s_task_screen.task.sh);
|
||
|
// L0_uart1_0d0a();
|
||
|
TTSS_Task_init():
|
||
|
L2_task_go(D_task_RS485_SEND);
|
||
|
//发送前
|
||
|
TTSS_Task_step(D_task_RS485_SEND_BEFORE):
|
||
|
// L1_uartD_uc('A');
|
||
|
// L1_uartD_0d0a();
|
||
|
// L1_uartD_uc('A');
|
||
|
// L1_uartD_0d0a();
|
||
|
|
||
|
// 检测功耗模式是否转变
|
||
|
if(s->power_mode != R.power_mode)
|
||
|
{
|
||
|
s->power_mode = R.power_mode;
|
||
|
if (s->power_mode == POWER_LOW)
|
||
|
{
|
||
|
//发送息屏指令
|
||
|
L1_uart1_Array((U8 *)&scrPingOffPkg, sizeof(scrPingOffPkg));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//发送亮屏指令
|
||
|
L1_uart1_Array((U8 *)&scrPingOnPkg, sizeof(scrPingOnPkg));
|
||
|
}
|
||
|
L2_task_go_Tdelay(D_task_RS485_SEND, D_Tdelay_400ms);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_task_go_Tdelay(D_task_RS485_SEND, 0);
|
||
|
}
|
||
|
//发送
|
||
|
TTSS_Task_step(D_task_RS485_SEND):
|
||
|
if (1)//if (R.power_mode == POWER_NORMAL)
|
||
|
{
|
||
|
// L1_uartD_uc('P');
|
||
|
// L1_uartD_0d0a();
|
||
|
// L1_uartD_uc('P');
|
||
|
// L1_uartD_0d0a();
|
||
|
//构造pkg
|
||
|
constructor_scr_pkg();
|
||
|
//发送pkg
|
||
|
L1_uart1_Array((U8 *)&scrSetValPkg, sizeof(SCRSetValPkg));
|
||
|
// L0_uart0_sendArray((U8 *)&scrSetValPkg, sizeof(SCRSetValPkg));
|
||
|
//延时send next
|
||
|
}
|
||
|
L2_task_go_Tdelay(D_task_RS485_SEND_AFTER, D_Tdelay_400ms);
|
||
|
//发送后
|
||
|
TTSS_Task_step(D_task_RS485_SEND_AFTER):
|
||
|
// rs485_pkg_send_after(index);
|
||
|
L2_task_go_Tdelay(D_task_RS485_RECV, 0);
|
||
|
//接收
|
||
|
TTSS_Task_step(D_task_RS485_RECV):
|
||
|
// if(ts_uart[0].r.ok == 1)
|
||
|
// {
|
||
|
// ts_uart[0].r.ok = 0;
|
||
|
// parse_screen_pkg();
|
||
|
// }
|
||
|
L2_task_go_Tdelay(D_task_RS485_SEND, D_Tdelay_100ms);
|
||
|
|
||
|
TTSS_Task_end();
|
||
|
}
|
||
|
|
||
|
void constructor_scr_pkg()
|
||
|
{
|
||
|
U16 CRC = 0;
|
||
|
|
||
|
scrSetValPkg.buf.weight_kgx100[0] = (R.weight.kgx10_out * 10) >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.weight_kgx100[1] = (R.weight.kgx10_out * 10) >> 0 & 0xFF;
|
||
|
|
||
|
scrSetValPkg.buf.dl[0] = R.dl >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.dl[1] = R.dl >> 0 & 0xFF;
|
||
|
scrSetValPkg.buf.net_status[0] = R.net_status >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.net_status[1] = R.net_status >> 0 & 0xFF;
|
||
|
|
||
|
|
||
|
scrSetValPkg.buf.danwei[0] = R.danwei >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.danwei[1] = R.danwei >> 0 & 0xFF;
|
||
|
scrSetValPkg.buf.beep[0] = R.beep >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.beep[1] = R.beep >> 0 & 0xFF;
|
||
|
|
||
|
// L0_uart0_sendstr("scrSetValPkg.buf.medicine[0]: ");
|
||
|
// L0_uart0_uchex(scrSetValPkg.buf.medicine[0]);
|
||
|
// L0_uart0_0d0a();
|
||
|
// L0_uart0_sendstr("scrSetValPkg.buf.medicine[1]: ");
|
||
|
// L0_uart0_uchex(scrSetValPkg.buf.medicine[1]);
|
||
|
// L0_uart0_0d0a();
|
||
|
|
||
|
scrSetValPkg.buf.LeaveForbid_flag[0] = R.LeaveForbid_flag >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.LeaveForbid_flag[1] = R.LeaveForbid_flag >> 0 & 0xFF;
|
||
|
|
||
|
scrSetValPkg.buf.WeightKeep_flag[0] = R.WeightKeep_flag >> 8 & 0xFF;
|
||
|
scrSetValPkg.buf.WeightKeep_flag[1] = R.WeightKeep_flag >> 0 & 0xFF;
|
||
|
|
||
|
CRC = CRC_16(((U8 *)&scrSetValPkg) + 3, 26);
|
||
|
scrSetValPkg.crc[1] = CRC;
|
||
|
scrSetValPkg.crc[0] = CRC >> 8;
|
||
|
}
|
||
|
|
||
|
//void parse_screen_pkg()
|
||
|
//{
|
||
|
// TPC_SCREEN *p = (TPC_SCREEN *) ts_uart[0].r.buf;
|
||
|
// p->ocr = p->buf[p->num[0] << 8 | p->num[1]];
|
||
|
// if(p->head[0] == 0xAA && 1 /*count_ocr() */)
|
||
|
// {
|
||
|
// if(p->slaveId == R.slave_id && p->cmd == 0x10)
|
||
|
// {
|
||
|
// //1.buf[0]高4位是否需要授权标志
|
||
|
// R.auth_flag &= 0x0F;
|
||
|
// R.auth_flag |= p->buf[0] & 0xF0;
|
||
|
|
||
|
// //2.buf[0]低四位是否进入低功耗模式
|
||
|
// // R.low_power_mode = p->buf[0] & 0x0F;
|
||
|
// L3_set_power_mode(p->buf[0] & 0x0F);
|
||
|
//
|
||
|
// //3.buf[1-2], rfid映射
|
||
|
// //TODO 上位机发过来的rfid编号如何处理
|
||
|
// setLedStatus = (U16)p->buf[1] << 8 | p->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] = 1;
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// //构造响应包,并且返回
|
||
|
// acklen = constructor_rs485_ack();
|
||
|
// //写出
|
||
|
// L0_uart2_sendArray((U8*)&tpc_rs485_ack, acklen);
|
||
|
// //日志
|
||
|
// print_rs485_pkg(p);
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
//void print_rs485_pkg(TPC_RS485 *p)
|
||
|
//{
|
||
|
// L0_uart0_sendstr("\r\n--------- Recv RS485 --------\r\n");
|
||
|
// L0_uart0_sendstr("slaveId : ");
|
||
|
// L0_uart0_uchex(p->slaveId);
|
||
|
// L0_uart0_0d0a();
|
||
|
// L0_uart0_sendstr("cmd: ");
|
||
|
// L0_uart0_uchex(p->cmd);
|
||
|
// L0_uart0_0d0a();
|
||
|
// L0_uart0_sendstr("num: ");
|
||
|
// L0_uart0_uchex(p->num[0]);
|
||
|
// L0_uart0_uchex(p->num[1]);
|
||
|
// L0_uart0_0d0a();
|
||
|
// L0_uart0_sendstr("dat : ");
|
||
|
// L0_uart0_sendArrayHex(p->buf, p->num[0] << 8 | p->num[1]);
|
||
|
// L0_uart0_0d0a();
|
||
|
// L0_uart0_sendstr("ocr: ");
|
||
|
// L0_uart0_uchex(p->ocr);
|
||
|
// L0_uart0_0d0a();
|
||
|
//}
|
||
|
|
||
|
//查表法
|
||
|
U16 CRC_16(U8 *pMsg, U16 Len)
|
||
|
{
|
||
|
U8 i;
|
||
|
U16 j;
|
||
|
U8 uchCRCHi = 0xFF;
|
||
|
U8 uchCRCLo = 0xFF;
|
||
|
while (Len--)
|
||
|
{
|
||
|
i = uchCRCHi ^ (*pMsg++);
|
||
|
uchCRCHi = uchCRCLo ^ auchCRCHi[i];
|
||
|
uchCRCLo = auchCRCLo[i];
|
||
|
}
|
||
|
j = (U16)uchCRCHi << 8 | uchCRCLo;
|
||
|
return j;
|
||
|
}
|