15 changed files with 1543 additions and 523 deletions
@ -0,0 +1,13 @@ |
|||
{ |
|||
"files.associations": { |
|||
"app_config.h": "c", |
|||
"UARTN.C": "cpp", |
|||
"msp_uart1.h": "c", |
|||
"task_screen.h": "c", |
|||
"msp_uartn.h": "c", |
|||
"bsp_config.h": "c", |
|||
"ttss_task.h": "c", |
|||
"ttss_tick.h": "c", |
|||
"main.h": "c" |
|||
} |
|||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,244 @@ |
|||
#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; |
|||
} |
@ -0,0 +1,110 @@ |
|||
#ifndef _APP_TASK_SCREEN_H |
|||
#define _APP_TASK_SCREEN_H |
|||
|
|||
#include "TTSS_task.h" |
|||
#include "c_lib.h" |
|||
|
|||
typedef struct _s_task_screen |
|||
{ |
|||
TS_task task; |
|||
U8 power_mode; |
|||
} S_TASK_SCREEN; |
|||
|
|||
// typedef struct
|
|||
// {
|
|||
// U8 head[2];
|
|||
// U8 num;
|
|||
// U8 cmd;
|
|||
// U8 start_addr[2];
|
|||
// U8 buf[D_send3_max];
|
|||
// U8 crc[2];
|
|||
// } SCRSetValPkg;
|
|||
|
|||
typedef struct |
|||
{ |
|||
U8 head[2]; |
|||
U8 num; |
|||
U8 cmd; |
|||
U8 start_addr[2]; |
|||
struct |
|||
{ |
|||
//重量
|
|||
U8 weight_kgx100[2]; |
|||
//网络状态
|
|||
U8 net_status[2]; |
|||
//网络状态
|
|||
U8 dl[2]; |
|||
//单位
|
|||
U8 danwei[2]; |
|||
//语言
|
|||
U8 language[2]; |
|||
//蜂鸣器状态
|
|||
U8 beep[2]; |
|||
//界面
|
|||
U8 ui[2]; |
|||
//离床报警标志
|
|||
U8 LeaveForbid_flag[2]; |
|||
//重量保持标志
|
|||
U8 WeightKeep_flag[2]; |
|||
} buf; |
|||
U8 crc[2]; |
|||
} SCRSetValPkg; |
|||
|
|||
typedef struct |
|||
{ |
|||
U8 head[2]; |
|||
U8 num; |
|||
U8 cmd; |
|||
U8 buf[2]; |
|||
U8 crc[2]; |
|||
} SCRControlPkg; |
|||
|
|||
typedef struct _tpc_screen_ |
|||
{ |
|||
U8 head[2]; |
|||
U8 num; |
|||
U8 cmd; |
|||
U8 start_addr[2]; |
|||
U8 buf[5]; |
|||
U8 ocr[2]; |
|||
}TPC_SCREEN; |
|||
|
|||
extern S_TASK_SCREEN _s_task_screen; |
|||
|
|||
extern void L3_task_screen_init(void); |
|||
extern void L3_task_screen_handler(S_TASK_SCREEN *s); |
|||
extern void constructor_scr_pkg(); |
|||
extern void parse_screen_pkg(); |
|||
|
|||
static U8 auchCRCHi[] = { |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, |
|||
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, |
|||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, |
|||
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, |
|||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40}; |
|||
static U8 auchCRCLo[] = { |
|||
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, |
|||
0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, |
|||
0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, |
|||
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, |
|||
0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, |
|||
0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, |
|||
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, |
|||
0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, |
|||
0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, |
|||
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, |
|||
0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, |
|||
0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, |
|||
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40}; |
|||
|
|||
U16 CRC_16(U8 *pMsg, U16 Len); |
|||
|
|||
#endif |
Loading…
Reference in new issue