Newer
Older
pgdsc / src / com / szpg / service / command / ExhaustFanCommandService.java
ty-pc\admin on 22 May 2019 4 KB 20190522 环境监测功能梳理
package com.szpg.service.command;

import com.szpg.db.dao.PgHjsbblDao;
import com.szpg.db.dao.impl.PgHjsbblDaoImpl;
import com.szpg.db.data.PgHjsbbl;
import com.szpg.plc.message.command.write.SetFjOffBitCommand;
import com.szpg.plc.message.command.write.SetFjOnBitCommand;
import com.szpg.plc.protocol.fins.FINSConstants;
import com.szpg.plc.util.ByteUtil;

/**
 * 风机控制指令辅助类
 * @author admin
 *
 */
public class ExhaustFanCommandService {

	/**
	 * 根据资产编号构建打开风机控制指令
	 * 
	 * @param sour 源地址
	 * @param dest 目的地址
	 * @param zcbh 资产编号
	 * @return
	 */
	public static SetFjOnBitCommand buildTurnOnCommand(String sour, String dest, String zcbh) {
		PgHjsbblDao blDao = new PgHjsbblDaoImpl();
		
		SetFjOnBitCommand setOnCmd = new SetFjOnBitCommand();
		setOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_ENABLE);
		PgHjsbbl onBlObj = blDao.findBlByBh(zcbh + ".ON");
		if (null != onBlObj) {
			setOnCmd.setMessageProducerId(sour);
			setOnCmd.setDestinationId(dest);
			
			// SID在new对象的时候已经生成
			
			// 内存区域——按位写
			setOnCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT);
			
			int start = onBlObj.getKszdz();
			int end = onBlObj.getJszdz();
			int bit = onBlObj.getSzw();
			
			// 开始字地址
			setOnCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)));
			
			// 位地址
			setOnCmd.setBit(bit);
			
			// 位数
			setOnCmd.setCount(end - start + 1);
			
			// 位内容
			setOnCmd.setValue(new byte[] {(byte) SetFjOnBitCommand.FJ_ON_ENABLE} );
			
			return setOnCmd;
		} else {
			return null;
		}
	}
	
	/**
	 * 根据资产编号构建复位打开风机控制指令
	 * @param sour
	 * @param dest
	 * @param zcbh
	 * @return
	 */
	public static SetFjOnBitCommand buildResetTurnOnCommand(String sour, String dest, String zcbh) {
		PgHjsbblDao blDao = new PgHjsbblDaoImpl();
		
		SetFjOnBitCommand setOnCmd = new SetFjOnBitCommand();
		setOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_DISABLE);
		PgHjsbbl onBlObj = blDao.findBlByBh(zcbh + ".ON");
		if (null != onBlObj) {
			setOnCmd.setMessageProducerId(sour);
			setOnCmd.setDestinationId(dest);
			
			// SID在new对象的时候已经生成
			
			// 内存区域——按位写
			setOnCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT);
			
			int start = onBlObj.getKszdz();
			int end = onBlObj.getJszdz();
			int bit = onBlObj.getSzw();
			
			// 开始字地址
			setOnCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)));
			
			// 位地址
			setOnCmd.setBit(bit);
			
			// 位数
			setOnCmd.setCount(end - start + 1);
			
			// 位内容
			setOnCmd.setValue(new byte[] {(byte) SetFjOnBitCommand.FJ_ON_DISABLE} );
			
			return setOnCmd;
		} else {
			return null;
		}
	}
	
	
	public static SetFjOffBitCommand buildTurnOffCommand(String sour, String dest, String zcbh) {
		PgHjsbblDao blDao = new PgHjsbblDaoImpl();
		
		SetFjOffBitCommand setOffCmd = new SetFjOffBitCommand();
		setOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_ENABLE);
		PgHjsbbl offBlObj = blDao.findBlByBh(zcbh + ".OFF");
		if (null != offBlObj) {
			setOffCmd.setMessageProducerId(sour);
			setOffCmd.setDestinationId(dest);
			
			// SID在new对象的时候已经生成
			
			// 内存区域——按位写
			setOffCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT);
			
			int start = offBlObj.getKszdz();
			int end = offBlObj.getJszdz();
			int bit = offBlObj.getSzw();
			
			// 开始字地址
			setOffCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)));
			
			// 位地址
			setOffCmd.setBit(bit);
			
			// 位数
			setOffCmd.setCount(end - start + 1);
			
			// 位内容
			setOffCmd.setValue(new byte[] {SetFjOffBitCommand.FJ_OFF_ENABLE} );
			
			return setOffCmd;
		} else {
			return null;
		}
	}
	
	/**
	 * 根据资产编号构建复位关闭风机控制指令
	 * @param sour
	 * @param dest
	 * @param zcbh
	 * @return
	 */
	public static SetFjOffBitCommand buildResetTurnOffCommand(String sour, String dest, String zcbh) {
		PgHjsbblDao blDao = new PgHjsbblDaoImpl();
		
		SetFjOffBitCommand setOffCmd = new SetFjOffBitCommand();
		setOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_DISABLE);
		PgHjsbbl offBlObj = blDao.findBlByBh(zcbh + ".OFF");
		if (null != offBlObj) {
			setOffCmd.setMessageProducerId(sour);
			setOffCmd.setDestinationId(dest);
			
			// SID在new对象的时候已经生成
			
			// 内存区域——按位写
			setOffCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT);
			
			int start = offBlObj.getKszdz();
			int end = offBlObj.getJszdz();
			int bit = offBlObj.getSzw();
			
			// 开始字地址
			setOffCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)));
			
			// 位地址
			setOffCmd.setBit(bit);
			
			// 位数
			setOffCmd.setCount(end - start + 1);
			
			// 位内容
			setOffCmd.setValue(new byte[] {SetFjOffBitCommand.FJ_OFF_DISABLE} );
			
			return setOffCmd;
		} else {
			return null;
		}
	}
}