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.
67 lines
1.7 KiB
67 lines
1.7 KiB
#include "app_task_tcp.h"
|
|
#include "../msp/uart0.h"
|
|
#include "../msp/uart4.h"
|
|
#include "../app/app_task_gm35.h"
|
|
#include "../app/app_common.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
|
|
{
|
|
P55 = 0;
|
|
L2_task_go(D_task_tcp_switch_next_slaver);
|
|
}
|
|
|
|
TTSS_Task_step(D_task_tcp_send_modbus_pkg) //发送包
|
|
L0_uart4_sendArray((U8*)&s->loopPkg, s->pkglen);
|
|
//L0_uart0_sendArray((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_switch_next_slaver);
|
|
|
|
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();
|
|
}
|
|
|
|
|
|
|