DELL
2024-02-23 e389edf76a0619128ea2919c2d140f7e0e2e8a2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.iedscout;
 
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import com.dec.fbs9100.MysqlConnPool;
import com.iedscout.BTS61850_IEDScout_Task_Thread.IEDScout_Param;
 
public class BTS61850_IEDScout_Task_Thread extends Thread{
    
    private Logger logger = null;
    
    private MysqlConnPool pool;
    
    public BTS61850_IEDScout_Task_Thread(MysqlConnPool pool) {
        this.pool = pool;
        this.logger = LogManager.getFormatterLogger();
    }
    
    @Override
    public void run() {
        logger.info("BTS61850_IEDScout_Task_Thread Start Monitor ... ");
        BTS61850_IEDScout_Task_Thread_SQL.insertConnect_Inf_Table(pool);
        
        
        IEDScout_Param param = new IEDScout_Param();
        BTS61850_IEDScout_Task task = new BTS61850_IEDScout_Task(pool, param);
        while(true) {
            try {
                BTS61850_IEDScout_Task_Thread_SQL.queryConnect_Inf_Table(pool,param);
                if(IEDScout_Param.CONN_STATE_START == param.conn_st) {
                    param.setConn_st(IEDScout_Param.CONN_STATE_CONNECT);
                    param.setFail_reasion(IEDScout_Param.FAILREASION_NULL);    
                    BTS61850_IEDScout_Task_Thread_SQL.updateConnect_Inf_Table(pool, param);     
                    
                    logger.printf(Level.INFO,"BTS61850_IEDScout_Task Start Connect IP:%s,Port:%d",param.target_ip,param.target_port);
                    task.connectIEDDevice();                    
                }            
                Thread.sleep(1000);
            } catch (Exception e) {
                logger.error(e.toString(), e);
            }        
        }          
    }
    
    
  /**
   *     连接参数信息
   * @author DELL
   *
   */
    public class IEDScout_Param{
        public static final int CONN_STATE_NULL       = 0;        //默认
        public static final int CONN_STATE_START       = 1;        //开始连接
        public static final int CONN_STATE_CONNECT  = 2;        //连接中
        public static final int CONN_STATE_SUCCESS  = 3;        //连接成功
        public static final int CONN_STATE_FAIL       = 4;        //连接失败
        
        
        public static final int FAILREASION_NULL            = 0;        //无
        public static final int FAILREASION_FILENOTFOUND    = 1;        //文件不存在
        public static final int FAILREASION_FILEERROR        = 2;        //文件不匹配
        public static final int FAILREASION_PARAMERROR           = 3;        //IP或者端口错误
        public static final int FAILREASION_TIMEOUT            = 4;        //连接超时
        
        public String target_ip;        //'目标IP地址',
        public int target_port;            //'目的端口号',
        public String target_icd;        //'目的设备icd文件路径',
        public int conn_st;                //'连接状态0-默认  1-开始连接[平台设置]  2-连接中   3-连接成功  4-连接失败',
        public int fail_reasion;        //'失败原因:0-无  1-ICD文件不存在  2-ICD文件不匹配',
        public long comm_num;            //通信计数',
        public long error_num;            //'通信错误计数',
        
        public long errcount;            //连续通信错误计数 >10 断开连接
        
        public int GetConnStateNull() {
            return CONN_STATE_NULL;
        }
        public int GetConnStateStart() {
            return CONN_STATE_START;
        }
        public int GetConnStateConnect() {
            return CONN_STATE_CONNECT;
        }
        public int GetConnStateSuccess() {
            return CONN_STATE_SUCCESS;
        }
        public int GetConnStateFail() {
            return CONN_STATE_FAIL;
        }
        public String getTarget_ip() {
            return target_ip;
        }
        public int getTarget_port() {
            return target_port;
        }
        public String getTarget_icd() {
            return target_icd;
        }
        public int getConn_st() {
            return conn_st;
        }
        public int getFail_reasion() {
            return fail_reasion;
        }
        public long getComm_num() {
            return comm_num;
        }
        public long getError_num() {
            return error_num;
        }
        
        public void setTarget_ip(String target_ip) {
            this.target_ip = target_ip;
        }
        public void setTarget_port(int target_port) {
            this.target_port = target_port;
        }
        public void setTarget_icd(String target_icd) {
            this.target_icd = target_icd;
        }
        public void setConn_st(int conn_st) {
            this.conn_st = conn_st;
        }
        public void setFail_reasion(int fail_reasion) {
            this.fail_reasion = fail_reasion;
        }
        public void setComm_num(long comm_num) {
            this.comm_num = comm_num;
        }
        public void setError_num(long error_num) {
            this.error_num = error_num;
        }
        
        /**
         *     累加通信计数
         */
        public void addCommNum() {
            if(this.comm_num < 999999990){
                this.comm_num ++;
                errcount = 0;
            }
        }
        
        /**
         *     累加错误计数
         */
        public void addErrorNum() {
            if(this.error_num < 999999990){
                this.error_num ++;
            }
            this.errcount ++;
        }
        
        
        public long getErrcount() {
            return errcount;
        }
        public void setErrcount(long errcount) {
            this.errcount = errcount;
        }
        
        
        
    }
    
}