41 changed files with 1059 additions and 614 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,128 @@ |
|||
#include "app_task_tcp.h" |
|||
#include "../msp/uart0.h" |
|||
#include "../msp/uart2.h" |
|||
#include "../app/task_w600.h" |
|||
#include "../app/app_config.h" |
|||
|
|||
#define MODBUS_SLAVER_DW20_REG_START 0x02 |
|||
#define MODBUS_SLAVER_DW20_REG_NUM 0x02 |
|||
#define MODBUS_SLAVER_RETRY_MAX_TIME 1 |
|||
|
|||
TS_tcp ts_tcp; |
|||
|
|||
void L3_task_tcp_init(void) |
|||
{ |
|||
L1_task_init(&ts_tcp.task); |
|||
L3_task_s_go(ts_tcp,D_task_init); |
|||
ts_tcp.slaverIndex = 0; |
|||
ts_tcp.pkglen = 0; |
|||
ts_tcp.retryTimes = 0; |
|||
ts_tcp.ackFlag = 0; |
|||
} |
|||
|
|||
#define D_task_tcp_constructor_modbus_pkg 0x51 |
|||
#define D_task_tcp_send_modbus_pkg 0x52 |
|||
#define D_task_tcp_wait_modbus_ack 0x53 |
|||
#define D_task_tcp_switch_next_slaver 0x54 |
|||
|
|||
void L3_task_tcp_handle(TS_tcp *s) |
|||
{ |
|||
TTSS_Task_init() |
|||
L2_task_go(D_task_tcp_constructor_modbus_pkg); |
|||
|
|||
TTSS_Task_step(D_task_tcp_constructor_modbus_pkg) //构造包
|
|||
if(G.ccmd_slaver_info[s->slaverIndex].mask > 0) |
|||
{ |
|||
s->pkglen = L3_pack_ccmodbus(&s->loopPkg,G.ccmd_slaver_info + s->slaverIndex); |
|||
s->ackFlag = 0; |
|||
s->retryTimes = 0; |
|||
L2_task_go(D_task_tcp_send_modbus_pkg); |
|||
} |
|||
else |
|||
{ |
|||
L2_task_go(D_task_tcp_switch_next_slaver); |
|||
} |
|||
|
|||
TTSS_Task_step(D_task_tcp_send_modbus_pkg) //发送包
|
|||
L3_gm35_send_data((U8*)&s->loopPkg,s->pkglen); |
|||
s->sendStamp = s_nos_tick.t_1s; |
|||
if(G.ccmd_slaver_info[s->slaverIndex].mask == 1) |
|||
{ |
|||
G.ccmd_slaver_info[s->slaverIndex].mask = 0; |
|||
} |
|||
L2_task_go(D_task_tcp_wait_modbus_ack); |
|||
TTSS_Task_step(D_task_tcp_wait_modbus_ack) //等待ack
|
|||
//L0_uart0_uc(s_uart2_tcp_rec.ok + '0');
|
|||
if(s_uart2_tcp_rec.ok) |
|||
{ |
|||
s_uart2_tcp_rec.ok = 0; |
|||
s_task_gm35_flow.tcp_last_recv_stmp = s_nos_tick.t_1s; |
|||
s->pAckPkg = (TS_PH3_ccmodbus*)(s_uart2_tcp_rec.sp); |
|||
L3_gm35_rcv_data((U8*)s->pAckPkg,s->pAckPkg->num); |
|||
if(s->pAckPkg->slaver == G.ccmd_slaver_info[s->slaverIndex].slaver) |
|||
{ |
|||
s->ackFlag = 1; |
|||
|
|||
switch(s->slaverIndex) |
|||
{ |
|||
case 0://如果oper == 90:成功,91 == 不成功
|
|||
switch(G.ccmd_slaver_info[s->slaverIndex].oper) |
|||
{ |
|||
case 0x90: |
|||
//L0_uart0_sendstr("11111");
|
|||
G.authed = 1; |
|||
break; |
|||
case 0x91: |
|||
G.authed = 0; |
|||
break; |
|||
} |
|||
#if 0 |
|||
if(G.ccmd_slaver_info[s->slaverIndex].oper == 0x90) |
|||
{ |
|||
L0_uart0_sendstr("111"); |
|||
G.authed = 1; |
|||
G.au_succ = 1; |
|||
} |
|||
else |
|||
{ |
|||
L0_uart0_sendstr("222"); |
|||
G.authed = 0; |
|||
G.au_fail = 1; |
|||
} |
|||
#endif |
|||
break; |
|||
case 2: |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
L2_task_go(D_task_tcp_switch_next_slaver); |
|||
} |
|||
else if(s_nos_tick.t_1s - s->sendStamp >= 5) //重发
|
|||
{ |
|||
if(++s->retryTimes < 3) |
|||
{ |
|||
L2_task_go(D_task_tcp_send_modbus_pkg); |
|||
} |
|||
else |
|||
{ |
|||
L2_task_go(D_task_tcp_switch_next_slaver); |
|||
} |
|||
} |
|||
|
|||
//L0_uart0_uc(s->ackFlag);
|
|||
|
|||
TTSS_Task_step(D_task_tcp_switch_next_slaver) //切换下一个
|
|||
if(++ s->slaverIndex >= CCMD_SLAVER_INFO_MAX) |
|||
{ |
|||
s->slaverIndex = 0; |
|||
} |
|||
L2_task_go(D_task_tcp_constructor_modbus_pkg); |
|||
|
|||
TTSS_Task_end(); |
|||
} |
|||
|
|||
|
|||
|
@ -0,0 +1,80 @@ |
|||
#include "app_task_tcp_control.h" |
|||
#include "../msp/uart0.h" |
|||
#include "../app/task_w600.h" |
|||
#include "../app/app_task_tcp.h" |
|||
|
|||
TS_tcp_control ts_tcp_control; |
|||
|
|||
void L3_task_tcp_control_init(void) |
|||
{ |
|||
L1_task_init(&ts_tcp_control.task); |
|||
L3_task_s_go(ts_tcp_control,D_task_init); |
|||
ts_tcp_control.conn_ok_pool = 0; |
|||
ts_tcp_control.tcp_send_stmp = 0; |
|||
} |
|||
|
|||
#define D_task_tcp_control_01 0x51 |
|||
#define D_task_tcp_control_02 0x52 |
|||
#define D_task_tcp_control_03 0x53 |
|||
|
|||
|
|||
void L3_task_tcp_control_handle(TS_tcp_control *s)//判定是否抬笔/缓冲区满,调用读函数读取一段,从G->R, R.extra num 动态修改数量
|
|||
|
|||
{ |
|||
TTSS_Task_init() |
|||
L2_task_go(D_task_tcp_control_01); |
|||
TTSS_Task_step(D_task_tcp_control_01) |
|||
if(s->conn_ok_pool != s_task_gm35_flow.conn_ok) |
|||
{ |
|||
G.authed = 0; |
|||
s->conn_ok_pool =s_task_gm35_flow.conn_ok; |
|||
} |
|||
L2_task_go(D_task_tcp_control_02); |
|||
TTSS_Task_step(D_task_tcp_control_02)//是否发认证包
|
|||
if(s_task_gm35_flow.conn_ok) |
|||
{ |
|||
//3s一次发送数据包
|
|||
if(s_nos_tick.t_1s - ts_tcp_control.tcp_send_stmp >= 3) |
|||
{ |
|||
if(!G.authed) |
|||
{ |
|||
//L0_uart0_sendstr("111");
|
|||
//发送认证包
|
|||
G.ccmd_slaver_info[0].mask = 1; |
|||
L2_task_go(D_task_tcp_control_01); |
|||
} |
|||
else |
|||
{ |
|||
L2_task_go(D_task_tcp_control_03); |
|||
} |
|||
ts_tcp_control.tcp_send_stmp = s_nos_tick.t_1s; |
|||
} |
|||
else if(s_nos_tick.t_1s - ts_tcp_control.tcp_send_stmp >= 60) |
|||
{ |
|||
G.ccmd_slaver_info[1].mask = 1; |
|||
L2_task_go(D_task_tcp_control_01); |
|||
ts_tcp_control.tcp_send_stmp = s_nos_tick.t_1s; |
|||
} |
|||
} |
|||
|
|||
|
|||
TTSS_Task_step(D_task_tcp_control_03) |
|||
if(wr_buf.full == 1) |
|||
{ |
|||
wr_buf.full = 0; |
|||
Lc_read_cyc_buf(&R.points ,&wr_buf ,POINT_LEN); |
|||
G.ccmd_slaver_info[2].mask = 1; |
|||
L2_task_go(D_task_tcp_control_01); |
|||
} |
|||
else if(G.pen_up == 1) |
|||
{ |
|||
Lc_read_cyc_buf(&R.points ,&wr_buf ,sizeof(wr_buf.buf)/2); |
|||
G.ccmd_slaver_info[2].mask = 1; |
|||
L2_task_go(D_task_tcp_control_01); |
|||
} |
|||
TTSS_Task_end(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,22 @@ |
|||
#ifndef APP_TASK_TCP_CONTROL |
|||
#define APP_TASK_TCP_CONTROL |
|||
|
|||
#include "../ctask/task.h" |
|||
#include "../tpc/ccmodbus.h" |
|||
#include "../app/app_config.h" |
|||
|
|||
|
|||
typedef struct |
|||
{ |
|||
TS_task task; |
|||
vU8 conn_ok_pool; |
|||
vU32 tcp_send_stmp; |
|||
}TS_tcp_control; |
|||
|
|||
extern TS_tcp_control ts_tcp_control; |
|||
|
|||
extern void L3_task_tcp_control_init(void); |
|||
extern void L3_task_tcp_control_handle(TS_tcp_control *s); |
|||
|
|||
#endif |
|||
|
@ -0,0 +1 @@ |
|||
|
@ -0,0 +1,126 @@ |
|||
////////////////////////////////////////////////////////////////////////////
|
|||
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|||
///-------------------------------------------------------------------------
|
|||
/// @file bsp_test.c.c
|
|||
/// @brief bsp @ driver config
|
|||
///-------------------------------------------------------------------------
|
|||
/// @version 1.0
|
|||
/// @author CC
|
|||
/// @date 20180331
|
|||
/// @note cc_AS_stc02
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
#include "task_key.h" |
|||
#include "../clib/clib.h" |
|||
|
|||
struct _s_task_key_ s_task_key_handle; |
|||
void L0_key_init(void) |
|||
{ |
|||
//使能 INT1下降沿中断
|
|||
IT0 = 0; |
|||
//外部中断允许
|
|||
EX0 = 1; |
|||
//使能 INT1下降沿中断
|
|||
IT1 = 0; |
|||
//外部中断允许
|
|||
EX1 = 1; |
|||
L1_task_init(&s_task_key_handle.task); |
|||
L3_task_s_go(s_task_key_handle,D_task_init); |
|||
} |
|||
|
|||
void INT0_isrHanddle(void) D_SERVE_INT0 |
|||
{ |
|||
struct _s_task_key_ *p = &s_task_key_handle; |
|||
EX0=0; //关中断
|
|||
//do sth
|
|||
if(key1 == 0) |
|||
{ |
|||
//Lc_delay_ms(10);//按键防抖
|
|||
if(key1 == 0) |
|||
{ |
|||
p->key1_ok = 1; |
|||
while(!key1) |
|||
{ |
|||
p->time1++; |
|||
} |
|||
} |
|||
} |
|||
IE0 = 0; //清除INT0中断程序执行过程中的中断请求
|
|||
EX0 = 1; //开中断
|
|||
} |
|||
void INT1_isrHanddle(void) D_SERVE_INT1 |
|||
{ |
|||
struct _s_task_key_ *p = &s_task_key_handle; |
|||
EX1 = 0; //关中断
|
|||
//do sth
|
|||
if(key2 == 0) |
|||
{ |
|||
//Lc_delay_ms(10);
|
|||
if(key2 == 0) |
|||
{ |
|||
p->key2_ok = 1; |
|||
while(!key2) |
|||
{ |
|||
p->time2++; |
|||
} |
|||
} |
|||
} |
|||
IE1 = 0; //清除INT1中断程序执行过程中的中断请求
|
|||
EX1 = 1; //开中断
|
|||
} |
|||
|
|||
void L3_task_key_handle(struct _s_task_key_ *p) |
|||
{ |
|||
if(p->key1_ok) |
|||
{ |
|||
if(p->time1>=180) |
|||
{ |
|||
LED1 = ~LED1; |
|||
} |
|||
else |
|||
{ |
|||
LED2 = ~LED2; |
|||
} |
|||
p->key1_ok = 0; |
|||
p->time1=0; |
|||
} |
|||
if(p->key2_ok) |
|||
{ |
|||
if(p->time2>=180) |
|||
{ |
|||
LED1 = ~LED1; |
|||
} |
|||
else |
|||
{ |
|||
LED2 = ~LED2; |
|||
} |
|||
p->key2_ok = 0; |
|||
p->time2=0; |
|||
} |
|||
if(key3 == 0) |
|||
{ |
|||
//Lc_delay_ms(10);//按键防抖
|
|||
if(key3 == 0) |
|||
{ |
|||
p->key3_ok = 1; |
|||
while(!key3) |
|||
{ |
|||
p->time3++; |
|||
} |
|||
} |
|||
} |
|||
if(p->key3_ok) |
|||
{ |
|||
if(p->time3>=180) |
|||
{ |
|||
LED1 = ~LED1; |
|||
} |
|||
else |
|||
{ |
|||
LED2 = ~LED2; |
|||
} |
|||
p->key3_ok = 0; |
|||
p->time3=0; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,33 @@ |
|||
////////////////////////////////////////////////////////////////////////////
|
|||
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|||
///-------------------------------------------------------------------------
|
|||
/// @file bsp_test.c.c
|
|||
/// @brief bsp @ driver config
|
|||
///-------------------------------------------------------------------------
|
|||
/// @version 1.0
|
|||
/// @author CC
|
|||
/// @date 20180331
|
|||
/// @note cc_AS_stc02
|
|||
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#ifndef _app_task_key_H |
|||
#define _app_task_key_H |
|||
#include "../bsp/bsp_config.h" |
|||
#include "../ctask/task.h" |
|||
|
|||
|
|||
struct _s_task_key_ |
|||
{ |
|||
TS_task task; |
|||
vU8 key1_ok; |
|||
vU8 key2_ok; |
|||
vU8 key3_ok; |
|||
vU8 time1; |
|||
vU8 time2; |
|||
vU8 time3; |
|||
}; |
|||
extern struct _s_task_key_ s_task_key_handle; |
|||
extern void L0_key_init(void); |
|||
extern void L3_task_key_handle(struct _s_task_key_ *p); |
|||
#endif |
|||
|
@ -0,0 +1,35 @@ |
|||
#include "task_pen_head.h" |
|||
|
|||
struct _s_task_pen_head_ s_task_pen_head; |
|||
|
|||
|
|||
void L3_task_pen_head_init() |
|||
{ |
|||
L1_task_init(&s_task_pen_head.task); |
|||
L3_task_s_go(s_task_pen_head,D_task_init); |
|||
} |
|||
#define TTSS_TASK_HEAD_DATA_WRITE 0x01 |
|||
|
|||
U8 i = 0; |
|||
void L3_task_pen_head_handle(struct _s_task_pen_head_ *s) |
|||
{ |
|||
TTSS_Task_init() |
|||
L2_task_go_Tdelay(TTSS_TASK_HEAD_DATA_WRITE,0); |
|||
TTSS_Task_step(TTSS_TASK_HEAD_DATA_WRITE) |
|||
{ |
|||
s->point.x_axis = i; |
|||
s->point.y_axis = i; |
|||
s->point.time = D_sys_now; |
|||
i++; |
|||
Lc_write_cyc_buf(&s->point,&wr_buf,1); |
|||
Lc_buf_full(&wr_buf); |
|||
} |
|||
L2_task_go_Tdelay(TTSS_TASK_HEAD_DATA_WRITE,D_Tdelay_20ms); |
|||
TTSS_Task_end(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,22 @@ |
|||
#ifndef _app_task_pen_head_H |
|||
#define _app_task_pen_head_H |
|||
|
|||
#include "../bsp/bsp_config.h" |
|||
#include "../bsp/w600.h" |
|||
#include "../ctask/task.h" |
|||
#include "../tpc/at0d0a.h" |
|||
#include "../tpc/ccmodbus.h" |
|||
#include "../app/app_config.h" |
|||
struct _s_task_pen_head_ |
|||
{ |
|||
TS_task task; |
|||
vU32 last_write_time; |
|||
vU32 now_write_time; |
|||
vU32 time_lag; |
|||
PenPoint point; |
|||
}; |
|||
extern struct _s_task_pen_head_ s_task_pen_head; |
|||
extern void L3_task_pen_head_init(); |
|||
extern void L3_task_pen_head_handle(struct _s_task_pen_head_ *s); |
|||
|
|||
#endif |
Loading…
Reference in new issue