wuzeyu
2024-05-23 781aaa24d1f12659581eb545fc4ee678e4d85b7f
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java
@@ -23,9 +23,10 @@
    public static final int connectTimeout = 3000 ;
    public int sendTimes = 0 ;//发送数据次数
    public int heartbeatTimes = 0 ;//上报心跳次数
    public int sendTimes = 1 ;//发送数据次数
    public int heartbeatTimes = 1 ;//上报心跳次数
    public long overStart = 0L;
    public boolean isOver = false ;
    public MyThreadJob(){
@@ -38,21 +39,35 @@
    @Override
    public void execute() throws Exception {
        log.info("RTU" + rtuAddr + "开始任务");
        if(session != null){
            log.info("RTU" + rtuAddr + "将要执行" + ServerProperties.sendTimes + "轮次任务,当前轮次是" + sendTimes);
            if(sendTimes <= ServerProperties.sendTimes){
                sendDataOfP206V1_0_0() ;
            }else{
                this.jobOver() ;
        if(!this.isOver){
            if(session != null){
                if(sendTimes <= ServerProperties.sendTimes){
                    log.info("RTU" + rtuAddr + "开始任务");
                    log.info("RTU" + rtuAddr + "将要执行" + ServerProperties.sendTimes + "轮次任务,当前轮次是" + sendTimes);
                    sendDataOfP206V1_0_0() ;
                }else{
                    if(ServerProperties.sendOverThenCloseConnect == 1){
                        log.info("RTU" + rtuAddr + "等待一会,以接收通信中间件下行数据");
                        if(overStart == 0){
                            overStart = System.currentTimeMillis() ;
                        }else{
                            long now = System.currentTimeMillis() ;
                            if(now - overStart >= 30 * 1000){
                                this.jobOver() ;
                            }
                        }
                    }else{
                        this.jobOver() ;
                    }
                }
            }
        }
    }
    private void sendDataOfP206V1_0_0(){
        try{
            if(heartbeatTimes >= ServerProperties.heartbeatTimes){
                heartbeatTimes = 0 ;
            if(heartbeatTimes > ServerProperties.heartbeatTimes){
                heartbeatTimes = 1 ;
                this.sendReportData() ;
                TcpClUnit.clientSendData();
                sendTimes++ ;
@@ -86,7 +101,9 @@
    }
    private void jobOver(){
        session.closeOnFlush() ;
        if(ServerProperties.sendOverThenCloseConnect == 1){
            session.closeOnFlush() ;
        }
        this.isOver = true ;
        TcpClUnit.clientOver() ;
    }