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);
|
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;
|
}
|
|
|
|
}
|
|
}
|