package com.dy.aceMw.server.tasks;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import com.dy.common.mw.core.CoreTask;
|
import com.dy.common.mw.protocol.MidResult;
|
import com.dy.common.mw.protocol.Command;
|
import com.dy.common.mw.protocol.Driver;
|
import com.dy.common.mw.protocol.ProtocolCach;
|
import com.dy.aceMw.server.ServerProperties;
|
import com.dy.aceMw.server.forTcp.TcpSessionCach;
|
|
/**
|
* 从web业务系统发向RTU的命令任务
|
* @author Administrator
|
*
|
*/
|
public class RtuDownTask extends CoreTask {
|
|
private static Logger log = LogManager.getLogger(RtuDownTask.class.getName());
|
|
@Override
|
public Integer excute() {
|
Command com = (Command)this.data ;
|
try {
|
log.info("下发远程命令" + com.getCode() + "的核心任务开始执行");
|
this.deal(com);
|
} catch (Exception e) {
|
log.error("处理下行命令出错" + (e.getMessage()==null?"!":("," + e.getMessage())) ,e);
|
}
|
return null ;
|
}
|
|
/**
|
* 处理命令
|
* @param webJgroupName
|
* @param com
|
* @throws Exception
|
*/
|
private void deal(Command com) throws Exception{
|
String rtuAddr = com.getRtuAddr() ;
|
//前面已经判断rtuAddr为空情况,至此其不为空
|
Driver dri = null ;
|
String protocolName = TcpSessionCach.getTcpProtocolName(rtuAddr) ;
|
if(protocolName == null){
|
//RTU未曾上线
|
int count = ProtocolCach.driverCount() ;
|
if(count == 1){
|
//只有一个协议
|
dri = ProtocolCach.getFirstDriver() ;
|
}
|
}else{
|
dri = ProtocolCach.getDriver(protocolName) ;
|
}
|
if(dri == null){
|
log.error("严重错误,未能得到协议" + protocolName + "驱动类实例!");
|
}else{
|
MidResult[] actions = dri.createCommand(ServerProperties.isLowPower, com) ;
|
log.info("下发远程命令" + com.getCode() + "由协议驱动构造完成");
|
if(actions != null){
|
for(MidResult act : actions){
|
act.action();
|
}
|
}
|
}
|
}
|
|
}
|