package com.szpg;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.szpg.db.dao.impl.PgAcuDaoImpl;
import com.szpg.db.data.PgAcu;
import com.szpg.plc.server.ACUClient;
import com.szpg.plc.server.ACUClientUtil;
import com.szpg.task.ACUSocketCheckTask;
import com.szpg.task.ReadCH4StatusTask;
import com.szpg.task.ReadCH4ValueTask;
import com.szpg.task.ReadCOStatusTask;
import com.szpg.task.ReadCOValueTask;
import com.szpg.task.ReadDSStatusTask;
import com.szpg.task.ReadFjRtTask;
import com.szpg.task.ReadFjStatTask;
import com.szpg.task.ReadHSStatusTask;
import com.szpg.task.ReadHSValueTask;
import com.szpg.task.ReadJgStatusTask;
import com.szpg.task.ReadO2StatusTask;
import com.szpg.task.ReadO2ValueTask;
import com.szpg.task.ReadSbRtTask;
import com.szpg.task.ReadSbStatTask;
import com.szpg.task.ReadWSStatusTask;
import com.szpg.task.ReadWSValueTask;
import com.szpg.task.ReadYWStatusTask;
import com.szpg.task.ReadZmRtTask;
import com.szpg.task.ReadZmStatTask;

public class DSCTest {
	
	private static DSCTest dsc = new DSCTest();
	
	public static void main(String[] args) {
		// PLC设备地址和端口
		ACUClient client = new ACUClient("192.168.0.244", 6800);
		
		PgAcu acu = new PgAcuDaoImpl().findACUById(1);
		client.setAcucode(acu.getAcu_code());
		client.setNet(acu.getAcu_net()); //网络号
		client.setNode(acu.getAcu_node()); //节点号
		client.setUnit(acu.getAcu_unit()); //单元号
		
		// 3将ACU的信息加入到map中
		ACUClientUtil.getInstance().addClient(client);
		
		// 4新建线程启动client
		new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(new ACUSocketCheckTask(client), 0, 30, TimeUnit.SECONDS);
		
		// 甲烷
//		dsc.testSendCH4Command();
//		dsc.testSendCH4StatusCommand();
		
		// 温湿度
//		dsc.testSendWSCommand();
//		dsc.testSendWSStatusCommand();
		
		// 一氧化碳
//		dsc.testSendCOCommand();
//		dsc.testSendCOStatusCommand();
		
		// 氧气
//		dsc.testSendO2Command();
//		dsc.testSendO2StatusCommand();
		
		// 硫化氢
//		dsc.testSendHSCommand();
//		dsc.testSendHSStatusCommand();
		
		// 爆管液位
//		dsc.testSendYWStatusCommand();
		
		// 对射报警
//		dsc.testSendDSStatusCommand();
		
		// 井盖
		dsc.testSendJgStatusCommand();
		
		// 风机
//		dsc.testSendFjStatCommand();
//		dsc.testSendFjRtCommand();
		
		// 水泵
//		dsc.testSendSbRtCommand();
//		dsc.testSendSbStatCommand();
		
		// 照明
//		dsc.testSendZmRtCommand();
//		dsc.testSendZmStatCommand();
		
	}

	/**
	 * 发送查询甲烷监测值命令
	 * 
	 * @param client
	 */
	private void testSendCH4Command() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadCH4ValueTask(), 10, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询甲烷报警状态命令
	 * @param client
	 */
	private void testSendCH4StatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadCH4StatusTask(), 15, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询温湿度监测值命令
	 * 
	 * @param client
	 */
	private void testSendWSCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadWSValueTask(), 20, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询温湿度报警状态命令
	 * @param client
	 */
	private void testSendWSStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadWSStatusTask(), 25, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询一氧化碳监测值命令
	 * 
	 * @param client
	 */
	private void testSendCOCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadCOValueTask(), 30, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询一氧化碳报警状态命令
	 * @param client
	 */
	private void testSendCOStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadCOStatusTask(), 35, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询氧气监测值命令
	 * 
	 * @param client
	 */
	private void testSendO2Command() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadO2ValueTask(), 40, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询一氧化碳报警状态命令
	 * @param client
	 */
	private void testSendO2StatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadO2StatusTask(), 45, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询硫化氢监测值命令
	 * 
	 * @param client
	 */
	private void testSendHSCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadHSValueTask(), 50, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询硫化氢报警状态命令
	 * @param client
	 */
	private void testSendHSStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadHSStatusTask(), 55, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询爆管液位报警状态命令
	 * @param client
	 */
	private void testSendYWStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadYWStatusTask(), 10, 300, TimeUnit.SECONDS);
	}
	
	
	/**
	 * 发送查询对射报警状态命令
	 * @param client
	 */
	private void testSendDSStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadDSStatusTask(), 20, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询井盖状态命令
	 * @param client
	 */
	private void testSendJgStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadJgStatusTask(), 30, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询风机运行状态命令
	 * @param client
	 */
	private void testSendFjStatCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadFjStatTask(), 15, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询风机运行时长命令
	 * @param client
	 */
	private void testSendFjRtCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadFjRtTask(), 20, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询水泵运行状态命令
	 * @param client
	 */
	private void testSendSbStatCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadSbStatTask(), 25, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询水泵运行时长命令
	 * @param client
	 */
	private void testSendSbRtCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadSbRtTask(), 30, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询照明运行状态命令
	 * @param client
	 */
	private void testSendZmStatCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadZmStatTask(), 35, 300, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询照明运行时长命令
	 * @param client
	 */
	private void testSendZmRtCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadZmRtTask(), 40, 300, TimeUnit.SECONDS);
	}
}
