diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetSdThresholdTask.java b/src/com/szpg/task/SetSdThresholdTask.java new file mode 100644 index 0000000..e0c8ac1 --- /dev/null +++ b/src/com/szpg/task/SetSdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetSdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetSdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetSdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetSdThresholdWordCommand setWetThreCmd = new SetSdThresholdWordCommand(); + setWetThreCmd.setThreshold(threshold); + PgHjsbbl wetBlObj = blDao.findBlByBh(deviceCode + ".WetSet"); + if (null != wetBlObj) { + setWetThreCmd.setMessageProducerId(sour); + setWetThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setWetThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = wetBlObj.getKszdz(); + int end = wetBlObj.getJszdz(); + + // 开始字地址 + setWetThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setWetThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setWetThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setWetThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setWetThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setWetThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetSdThresholdTask.java b/src/com/szpg/task/SetSdThresholdTask.java new file mode 100644 index 0000000..e0c8ac1 --- /dev/null +++ b/src/com/szpg/task/SetSdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetSdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetSdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetSdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetSdThresholdWordCommand setWetThreCmd = new SetSdThresholdWordCommand(); + setWetThreCmd.setThreshold(threshold); + PgHjsbbl wetBlObj = blDao.findBlByBh(deviceCode + ".WetSet"); + if (null != wetBlObj) { + setWetThreCmd.setMessageProducerId(sour); + setWetThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setWetThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = wetBlObj.getKszdz(); + int end = wetBlObj.getJszdz(); + + // 开始字地址 + setWetThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setWetThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setWetThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setWetThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setWetThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setWetThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetWdThresholdTask.java b/src/com/szpg/task/SetWdThresholdTask.java new file mode 100644 index 0000000..ef2630c --- /dev/null +++ b/src/com/szpg/task/SetWdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetWdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetWdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetWdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetWdThresholdWordCommand setTemThreCmd = new SetWdThresholdWordCommand(); + setTemThreCmd.setThreshold(threshold); + PgHjsbbl temBlObj = blDao.findBlByBh(deviceCode + ".TemSet"); + if (null != temBlObj) { + setTemThreCmd.setMessageProducerId(sour); + setTemThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setTemThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = temBlObj.getKszdz(); + int end = temBlObj.getJszdz(); + + // 开始字地址 + setTemThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setTemThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setTemThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setTemThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setTemThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setTemThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetSdThresholdTask.java b/src/com/szpg/task/SetSdThresholdTask.java new file mode 100644 index 0000000..e0c8ac1 --- /dev/null +++ b/src/com/szpg/task/SetSdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetSdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetSdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetSdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetSdThresholdWordCommand setWetThreCmd = new SetSdThresholdWordCommand(); + setWetThreCmd.setThreshold(threshold); + PgHjsbbl wetBlObj = blDao.findBlByBh(deviceCode + ".WetSet"); + if (null != wetBlObj) { + setWetThreCmd.setMessageProducerId(sour); + setWetThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setWetThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = wetBlObj.getKszdz(); + int end = wetBlObj.getJszdz(); + + // 开始字地址 + setWetThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setWetThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setWetThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setWetThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setWetThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setWetThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetWdThresholdTask.java b/src/com/szpg/task/SetWdThresholdTask.java new file mode 100644 index 0000000..ef2630c --- /dev/null +++ b/src/com/szpg/task/SetWdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetWdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetWdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetWdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetWdThresholdWordCommand setTemThreCmd = new SetWdThresholdWordCommand(); + setTemThreCmd.setThreshold(threshold); + PgHjsbbl temBlObj = blDao.findBlByBh(deviceCode + ".TemSet"); + if (null != temBlObj) { + setTemThreCmd.setMessageProducerId(sour); + setTemThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setTemThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = temBlObj.getKszdz(); + int end = temBlObj.getJszdz(); + + // 开始字地址 + setTemThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setTemThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setTemThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setTemThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setTemThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setTemThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/TurnOffFjTask.java b/src/com/szpg/task/TurnOffFjTask.java index 6280063..2b45870 100644 --- a/src/com/szpg/task/TurnOffFjTask.java +++ b/src/com/szpg/task/TurnOffFjTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetFjOffBitCommand; +import com.szpg.plc.message.command.write.SetFjOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJON); + SetFjOnBitCommand clearOnCmd = new SetFjOnBitCommand(); + clearOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getFjon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJOFF); + SetFjOffBitCommand setOffCmd = new SetFjOffBitCommand(); + setOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getFjoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetSdThresholdTask.java b/src/com/szpg/task/SetSdThresholdTask.java new file mode 100644 index 0000000..e0c8ac1 --- /dev/null +++ b/src/com/szpg/task/SetSdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetSdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetSdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetSdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetSdThresholdWordCommand setWetThreCmd = new SetSdThresholdWordCommand(); + setWetThreCmd.setThreshold(threshold); + PgHjsbbl wetBlObj = blDao.findBlByBh(deviceCode + ".WetSet"); + if (null != wetBlObj) { + setWetThreCmd.setMessageProducerId(sour); + setWetThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setWetThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = wetBlObj.getKszdz(); + int end = wetBlObj.getJszdz(); + + // 开始字地址 + setWetThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setWetThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setWetThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setWetThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setWetThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setWetThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetWdThresholdTask.java b/src/com/szpg/task/SetWdThresholdTask.java new file mode 100644 index 0000000..ef2630c --- /dev/null +++ b/src/com/szpg/task/SetWdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetWdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetWdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetWdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetWdThresholdWordCommand setTemThreCmd = new SetWdThresholdWordCommand(); + setTemThreCmd.setThreshold(threshold); + PgHjsbbl temBlObj = blDao.findBlByBh(deviceCode + ".TemSet"); + if (null != temBlObj) { + setTemThreCmd.setMessageProducerId(sour); + setTemThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setTemThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = temBlObj.getKszdz(); + int end = temBlObj.getJszdz(); + + // 开始字地址 + setTemThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setTemThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setTemThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setTemThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setTemThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setTemThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/TurnOffFjTask.java b/src/com/szpg/task/TurnOffFjTask.java index 6280063..2b45870 100644 --- a/src/com/szpg/task/TurnOffFjTask.java +++ b/src/com/szpg/task/TurnOffFjTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetFjOffBitCommand; +import com.szpg.plc.message.command.write.SetFjOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJON); + SetFjOnBitCommand clearOnCmd = new SetFjOnBitCommand(); + clearOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getFjon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJOFF); + SetFjOffBitCommand setOffCmd = new SetFjOffBitCommand(); + setOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getFjoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/task/TurnOffZmTask.java b/src/com/szpg/task/TurnOffZmTask.java index d3a1ff3..c46119b 100644 --- a/src/com/szpg/task/TurnOffZmTask.java +++ b/src/com/szpg/task/TurnOffZmTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetZmOffBitCommand; +import com.szpg.plc.message.command.write.SetZmOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMON); + SetZmOnBitCommand clearOnCmd = new SetZmOnBitCommand(); + clearOnCmd.setZmon(SetZmOnBitCommand.ZM_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getZmon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMOFF); + SetZmOffBitCommand setOffCmd = new SetZmOffBitCommand(); + setOffCmd.setZmoff(SetZmOffBitCommand.ZM_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getZmoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetSdThresholdTask.java b/src/com/szpg/task/SetSdThresholdTask.java new file mode 100644 index 0000000..e0c8ac1 --- /dev/null +++ b/src/com/szpg/task/SetSdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetSdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetSdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetSdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetSdThresholdWordCommand setWetThreCmd = new SetSdThresholdWordCommand(); + setWetThreCmd.setThreshold(threshold); + PgHjsbbl wetBlObj = blDao.findBlByBh(deviceCode + ".WetSet"); + if (null != wetBlObj) { + setWetThreCmd.setMessageProducerId(sour); + setWetThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setWetThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = wetBlObj.getKszdz(); + int end = wetBlObj.getJszdz(); + + // 开始字地址 + setWetThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setWetThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setWetThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setWetThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setWetThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setWetThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetWdThresholdTask.java b/src/com/szpg/task/SetWdThresholdTask.java new file mode 100644 index 0000000..ef2630c --- /dev/null +++ b/src/com/szpg/task/SetWdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetWdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetWdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetWdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetWdThresholdWordCommand setTemThreCmd = new SetWdThresholdWordCommand(); + setTemThreCmd.setThreshold(threshold); + PgHjsbbl temBlObj = blDao.findBlByBh(deviceCode + ".TemSet"); + if (null != temBlObj) { + setTemThreCmd.setMessageProducerId(sour); + setTemThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setTemThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = temBlObj.getKszdz(); + int end = temBlObj.getJszdz(); + + // 开始字地址 + setTemThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setTemThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setTemThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setTemThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setTemThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setTemThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/TurnOffFjTask.java b/src/com/szpg/task/TurnOffFjTask.java index 6280063..2b45870 100644 --- a/src/com/szpg/task/TurnOffFjTask.java +++ b/src/com/szpg/task/TurnOffFjTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetFjOffBitCommand; +import com.szpg.plc.message.command.write.SetFjOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJON); + SetFjOnBitCommand clearOnCmd = new SetFjOnBitCommand(); + clearOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getFjon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJOFF); + SetFjOffBitCommand setOffCmd = new SetFjOffBitCommand(); + setOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getFjoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/task/TurnOffZmTask.java b/src/com/szpg/task/TurnOffZmTask.java index d3a1ff3..c46119b 100644 --- a/src/com/szpg/task/TurnOffZmTask.java +++ b/src/com/szpg/task/TurnOffZmTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetZmOffBitCommand; +import com.szpg.plc.message.command.write.SetZmOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMON); + SetZmOnBitCommand clearOnCmd = new SetZmOnBitCommand(); + clearOnCmd.setZmon(SetZmOnBitCommand.ZM_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getZmon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMOFF); + SetZmOffBitCommand setOffCmd = new SetZmOffBitCommand(); + setOffCmd.setZmoff(SetZmOffBitCommand.ZM_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getZmoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/task/TurnOnFjTask.java b/src/com/szpg/task/TurnOnFjTask.java index 5be904a..d61cded 100644 --- a/src/com/szpg/task/TurnOnFjTask.java +++ b/src/com/szpg/task/TurnOnFjTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetFjOffBitCommand; +import com.szpg.plc.message.command.write.SetFjOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将停止位置0 - WriteMemoryCommand clearOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJOFF); + SetFjOffBitCommand clearOffCmd = new SetFjOffBitCommand(); + clearOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_DISABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { clearOffCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOffCmd.setCount(end - start + 1); // 位内容 - clearOffCmd.setValue(new byte[] {0x00} ); + clearOffCmd.setValue(new byte[] {(byte) clearOffCmd.getFjoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOffCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJON); + SetFjOnBitCommand setOnCmd = new SetFjOnBitCommand(); + setOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_ENABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { setOnCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOnCmd.setCount(end - start + 1); // 位内容 - setOnCmd.setValue(new byte[] {0x01} ); + setOnCmd.setValue(new byte[] {(byte) setOnCmd.getFjon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOnCmd); diff --git a/src/com/szpg/DSCTest.java b/src/com/szpg/DSCTest.java index edef399..3e9ac7f 100644 --- a/src/com/szpg/DSCTest.java +++ b/src/com/szpg/DSCTest.java @@ -28,6 +28,14 @@ import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; +import com.szpg.task.ResetDsTask; +import com.szpg.task.SetCH4ThresholdTask; +import com.szpg.task.SetCOThresholdTask; +import com.szpg.task.SetHSThresholdTask; +import com.szpg.task.SetJgUnlockTask; +import com.szpg.task.SetO2ThresholdTask; +import com.szpg.task.SetSdThresholdTask; +import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; @@ -99,8 +107,29 @@ // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 - dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); - dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); +// dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); + + // 井盖解锁 +// dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); + + // 对射报警清除 +// dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); + + // 甲烷报警阈值设定 +// dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); + + // 硫化氢报警阈值设定 +// dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); + + // 温湿度报警阈值设定 +// dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); + + // 氧气报警阈值设定 + dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); + + // 一氧化碳阈值设定 + dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** @@ -318,4 +347,72 @@ sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } + + + /** + * 发送解锁井盖 + */ + private void testSendUnlockJgCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 清除对射报警 + */ + private void testSendResetDsCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置甲烷报警阈值 + */ + private void testSendCH4ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendHSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置硫化氢报警阈值 + */ + private void testSendWSThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + + ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); + sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); + sche2.shutdown(); + } + + /** + * 设置氧气报警阈值 + */ + private void testSendO2ThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); + sche.shutdown(); + } + + /** + * 设置一氧化碳报警阈值 + */ + private void testSendCOThresholdCommand(String deviceCode) { + ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); + sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); + sche.shutdown(); + } } diff --git a/src/com/szpg/plc/message/AppMessageConstants.java b/src/com/szpg/plc/message/AppMessageConstants.java index 5bbda5f..01cbef7 100644 --- a/src/com/szpg/plc/message/AppMessageConstants.java +++ b/src/com/szpg/plc/message/AppMessageConstants.java @@ -29,4 +29,13 @@ public final static String CMD_TYPE_SETZMOFF = "51"; // 设置照明停止位命令 public final static String CMD_TYPE_SETFJON = "52"; // 设置风机启动位命令 public final static String CMD_TYPE_SETFJOFF = "53"; // 设置风机停止位命令 + public final static String CMD_TYPE_SETJGUNLOCK = "54"; // 设置井盖锁定位 + public final static String CMD_TYPE_SETDSRESET = "55"; // 清除对射报警 + + public final static String CMD_TYPE_SETCH4THRESHOLD = "60"; // 设置甲烷浓度报警阈值 + public final static String CMD_TYPE_SETHSTHRESHOLD = "61"; // 设置硫化氢浓度报警阈值 + public final static String CMD_TYPE_SETWDTHRESHOLD = "62"; // 设置温度报警阈值 + public final static String CMD_TYPE_SETSDTHRESHOLD = "63"; // 设置湿度报警阈值 + public final static String CMD_TYPE_SETO2THRESHOLD = "64"; // 设置氧气浓度报警阈值 + public final static String CMD_TYPE_SETCOTHRESHOLD = "65"; // 设置一氧化碳浓度报警阈值 } diff --git a/src/com/szpg/plc/message/command/WriteMemoryCommand.java b/src/com/szpg/plc/message/command/WriteMemoryCommand.java index 5df5f9c..a2d717e 100644 --- a/src/com/szpg/plc/message/command/WriteMemoryCommand.java +++ b/src/com/szpg/plc/message/command/WriteMemoryCommand.java @@ -1,11 +1,6 @@ package com.szpg.plc.message.command; import com.szpg.plc.message.AppCommand; -import com.szpg.plc.message.AppMessageConstants; -import com.szpg.plc.message.command.write.SetFjOffBitCommand; -import com.szpg.plc.message.command.write.SetFjOnBitCommand; -import com.szpg.plc.message.command.write.SetZmOffBitCommand; -import com.szpg.plc.message.command.write.SetZmOnBitCommand; public abstract class WriteMemoryCommand extends AppCommand { @@ -59,23 +54,6 @@ public void setValue(byte[] value) { this.value = value; } - - public static WriteMemoryCommand getInstance(String type) { - switch (type) { - case AppMessageConstants.CMD_TYPE_SETZMON: - return new SetZmOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETZMOFF: - return new SetZmOffBitCommand(); - - case AppMessageConstants.CMD_TYPE_SETFJON: - return new SetFjOnBitCommand(); - case AppMessageConstants.CMD_TYPE_SETFJOFF: - return new SetFjOffBitCommand(); - - default: - return null; - } - } public abstract String getCommandType(); } diff --git a/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java new file mode 100644 index 0000000..204173f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCH4ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCH4ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 6243092925002262130L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCH4THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置甲烷浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java new file mode 100644 index 0000000..b196d18 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetCOThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetCOThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 1822531865868879343L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETCOTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置一氧化碳浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java new file mode 100644 index 0000000..f8d2e54 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetDsRstBitCommand.java @@ -0,0 +1,40 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetDsRstBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -1383089865755117482L; + + public final static int DS_RST = 1; //对射报警清除 + + private int rst; + + public int getRst() { + return rst; + } + + public void setRst(int rst) { + this.rst = rst; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETDSRESET; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置对射报警清除位命令[" + rst + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java index 2e116ab..eaf4b05 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetFjOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -1263699293153077982L; + private static final long serialVersionUID = 2115681907959419460L; + + public final static int FJ_OFF_ENABLE = 1; //风机停止 + public final static int FJ_OFF_DISABLE = 0; + + private int fjoff; + + public int getFjoff() { + return fjoff; + } + + public void setFjoff(int fjoff) { + this.fjoff = fjoff; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机停止位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机停止位命令[" + fjoff + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java index b2a4532..3af2b73 100644 --- a/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetFjOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = -4282052929122659440L; + private static final long serialVersionUID = -3412842531558580772L; + + public final static int FJ_ON_ENABLE = 1; //风机启动 + public final static int FJ_ON_DISABLE = 0; + + private int fjon; + + public int getFjon() { + return fjon; + } + + public void setFjon(int fjon) { + this.fjon = fjon; + } @Override public String getCommandType() { @@ -23,6 +36,6 @@ @Override public String toString() { - return "向终端[" + getDestinationId() + "]发送设置风机启动位命令"; + return "向终端[" + getDestinationId() + "]发送设置风机启动位命令[" + fjon + "]"; } } diff --git a/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java new file mode 100644 index 0000000..11ee515 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetHSThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetHSThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -5097003070743720696L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETHSTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置硫化氢浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java new file mode 100644 index 0000000..e3898b4 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetJgUnlockBitCommand.java @@ -0,0 +1,41 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetJgUnlockBitCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 935723353287421429L; + + public final static int JG_LOCK = 0; //井盖锁定 + public final static int JG_UNLOCK = 1; //井盖解锁 + + private int unlock; + + public int getUnlock() { + return unlock; + } + + public void setUnlock(int unlock) { + this.unlock = unlock; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETJGUNLOCK; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置井盖解锁位命令[" + unlock + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java new file mode 100644 index 0000000..69081a0 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetO2ThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetO2ThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -4164791631385024850L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETO2THRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置氧气浓度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java new file mode 100644 index 0000000..2be42a6 --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetSdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetSdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = -2589117442780524296L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETSDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置湿度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java new file mode 100644 index 0000000..e0c017f --- /dev/null +++ b/src/com/szpg/plc/message/command/write/SetWdThresholdWordCommand.java @@ -0,0 +1,38 @@ +package com.szpg.plc.message.command.write; + +import com.szpg.plc.message.AppMessageConstants; +import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.response.WriteMemoryCommandResponse; + +public class SetWdThresholdWordCommand extends WriteMemoryCommand { + + /** + * + */ + private static final long serialVersionUID = 3035676529310605546L; + + private float threshold; + + public float getThreshold() { + return threshold; + } + + public void setThreshold(float threshold) { + this.threshold = threshold; + } + + @Override + public String getCommandType() { + return AppMessageConstants.CMD_TYPE_SETWDTHRESHOLD; + } + + @Override + public Class getResponseClass() { + return WriteMemoryCommandResponse.class; + } + + @Override + public String toString() { + return "向终端[" + getDestinationId() + "]发送设置温度报警阈值命令[" + threshold + "]"; + } +} diff --git a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java index b96f742..41ee68e 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOffBitCommand.java @@ -5,11 +5,24 @@ import com.szpg.plc.message.response.WriteMemoryCommandResponse; public class SetZmOffBitCommand extends WriteMemoryCommand { - + /** * */ - private static final long serialVersionUID = -4397813530861878200L; + private static final long serialVersionUID = 699292946605155345L; + + public final static int ZM_OFF_ENABLE = 1; + public final static int ZM_OFF_DISABLE = 0; + + private int zmoff; + + public int getZmoff() { + return zmoff; + } + + public void setZmoff(int zmoff) { + this.zmoff = zmoff; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java index 5a60c8f..2fd2dfd 100644 --- a/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java +++ b/src/com/szpg/plc/message/command/write/SetZmOnBitCommand.java @@ -9,7 +9,20 @@ /** * */ - private static final long serialVersionUID = 7634275732105602031L; + private static final long serialVersionUID = 2855891145220342447L; + + public final static int ZM_ON_ENABLE = 1; + public final static int ZM_ON_DISABLE = 0; + + private int zmon; + + public int getZmon() { + return zmon; + } + + public void setZmon(int zmon) { + this.zmon = zmon; + } @Override public String getCommandType() { diff --git a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java index 9d0837a..7ec43a6 100644 --- a/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java +++ b/src/com/szpg/plc/protocol/fins/FINSDTProtocolImp.java @@ -212,34 +212,36 @@ } } else if (commandCode.equalsIgnoreCase("0102")) { - WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); - - // 设置ACU代码 - wmcr.setAcucode(cmd.getDest_acu_code()); - - // 写内存命令响应 - byte[] body = finsFrame.TEXT_DATA_BODY; - wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); - - if (body.length == 4) { - if (body[2] == 0x00 && body[3] == 0x00) { - // 写入成功 - wmcr.setSuccess(true); + if (null != cmd) { + WriteMemoryCommandResponse wmcr = new WriteMemoryCommandResponse(); + + // 设置ACU代码 + wmcr.setAcucode(cmd.getDest_acu_code()); + + // 写内存命令响应 + byte[] body = finsFrame.TEXT_DATA_BODY; + wmcr.setMessageProducerId(FINSByteFrameTool.getControlDest(finsFrame)); + + if (body.length == 4) { + if (body[2] == 0x00 && body[3] == 0x00) { + // 写入成功 + wmcr.setSuccess(true); + } else { + wmcr.setSuccess(false); + } + wmcr.setValid(true); } else { - wmcr.setSuccess(false); + wmcr.setValid(false); } - wmcr.setValid(true); - } else { - wmcr.setValid(false); + + wmcr.setCmdId(cmd.getId()); + wmcr.setCommandType(commandType); + + // 4将已响应的命令删除 + cmdDao.deleteCmdRecord(cmd.getId()); + + received = wmcr; } - - wmcr.setCmdId(cmd.getId()); - wmcr.setCommandType(commandType); - - // 4将已响应的命令删除 - cmdDao.deleteCmdRecord(cmd.getId()); - - received = wmcr; } } else { received = new UnKnownMessage(byteMessage); diff --git a/src/com/szpg/task/ResetDsTask.java b/src/com/szpg/task/ResetDsTask.java new file mode 100644 index 0000000..a9a5a1e --- /dev/null +++ b/src/com/szpg/task/ResetDsTask.java @@ -0,0 +1,142 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetDsRstBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 清除对射报警 + * 0=正常/1=清除 + * + * @author admin + * + */ +public class ResetDsTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public ResetDsTask(String deviceCode) { + this.deviceCode = deviceCode; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetDsRstBitCommand setRstCmd = new SetDsRstBitCommand(); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".RST"); + if (null != onBlObj) { + setRstCmd.setMessageProducerId(sour); + setRstCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setRstCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setRstCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setRstCmd.setBit(bit); + + // 位数 + setRstCmd.setCount(end - start + 1); + + // 位内容 + setRstCmd.setValue(new byte[] {(byte) SetDsRstBitCommand.DS_RST} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setRstCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setRstCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setRstCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCH4ThresholdTask.java b/src/com/szpg/task/SetCH4ThresholdTask.java new file mode 100644 index 0000000..5944f82 --- /dev/null +++ b/src/com/szpg/task/SetCH4ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCH4ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置甲烷报警阈值 + * + * @author admin + * + */ +public class SetCH4ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCH4ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCH4ThresholdWordCommand setThreCmd = new SetCH4ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetCOThresholdTask.java b/src/com/szpg/task/SetCOThresholdTask.java new file mode 100644 index 0000000..0bc4ed9 --- /dev/null +++ b/src/com/szpg/task/SetCOThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetCOThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetCOThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetCOThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetCOThresholdWordCommand setThreCmd = new SetCOThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetHSThresholdTask.java b/src/com/szpg/task/SetHSThresholdTask.java new file mode 100644 index 0000000..38b6861 --- /dev/null +++ b/src/com/szpg/task/SetHSThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetHSThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置硫化氢报警阈值 + * + * @author admin + * + */ +public class SetHSThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetHSThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetHSThresholdWordCommand setThreCmd = new SetHSThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetJgUnlockTask.java b/src/com/szpg/task/SetJgUnlockTask.java new file mode 100644 index 0000000..f97a579 --- /dev/null +++ b/src/com/szpg/task/SetJgUnlockTask.java @@ -0,0 +1,145 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetJgUnlockBitCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.util.Configure; + +/** + * 设置井盖解锁 + * 0=锁定/1=解锁 + * + * @author admin + * + */ +public class SetJgUnlockTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private int unlock; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetJgUnlockTask(String deviceCode, int unlock) { + this.deviceCode = deviceCode; + this.unlock = unlock; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置解锁位的命令 + SetJgUnlockBitCommand setUnlockCmd = new SetJgUnlockBitCommand(); + setUnlockCmd.setUnlock(unlock); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Lock"); + if (null != onBlObj) { + setUnlockCmd.setMessageProducerId(sour); + setUnlockCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按位写 + setUnlockCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_BIT); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + int bit = onBlObj.getSzw(); + + // 开始字地址 + setUnlockCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2))); + + // 位地址 + setUnlockCmd.setBit(bit); + + // 位数 + setUnlockCmd.setCount(end - start + 1); + + // 位内容 + setUnlockCmd.setValue(new byte[] {(byte) unlock} ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setUnlockCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setUnlockCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setUnlockCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetO2ThresholdTask.java b/src/com/szpg/task/SetO2ThresholdTask.java new file mode 100644 index 0000000..9bbfb20 --- /dev/null +++ b/src/com/szpg/task/SetO2ThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetO2ThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置氧气报警阈值 + * + * @author admin + * + */ +public class SetO2ThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetO2ThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetO2ThresholdWordCommand setThreCmd = new SetO2ThresholdWordCommand(); + setThreCmd.setThreshold(threshold); + PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".Set"); + if (null != onBlObj) { + setThreCmd.setMessageProducerId(sour); + setThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = onBlObj.getKszdz(); + int end = onBlObj.getJszdz(); + + // 开始字地址 + setThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetSdThresholdTask.java b/src/com/szpg/task/SetSdThresholdTask.java new file mode 100644 index 0000000..e0c8ac1 --- /dev/null +++ b/src/com/szpg/task/SetSdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetSdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetSdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetSdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetSdThresholdWordCommand setWetThreCmd = new SetSdThresholdWordCommand(); + setWetThreCmd.setThreshold(threshold); + PgHjsbbl wetBlObj = blDao.findBlByBh(deviceCode + ".WetSet"); + if (null != wetBlObj) { + setWetThreCmd.setMessageProducerId(sour); + setWetThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setWetThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = wetBlObj.getKszdz(); + int end = wetBlObj.getJszdz(); + + // 开始字地址 + setWetThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setWetThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setWetThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setWetThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setWetThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setWetThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/SetWdThresholdTask.java b/src/com/szpg/task/SetWdThresholdTask.java new file mode 100644 index 0000000..ef2630c --- /dev/null +++ b/src/com/szpg/task/SetWdThresholdTask.java @@ -0,0 +1,147 @@ +package com.szpg.task; + +import org.apache.log4j.Logger; + +import com.szpg.db.dao.PgAcuCmdDao; +import com.szpg.db.dao.PgAcuDao; +import com.szpg.db.dao.PgDeviceDao; +import com.szpg.db.dao.PgHjsbblDao; +import com.szpg.db.dao.impl.PgAcuCmdDaoImpl; +import com.szpg.db.dao.impl.PgAcuDaoImpl; +import com.szpg.db.dao.impl.PgDeviceDaoImpl; +import com.szpg.db.dao.impl.PgHjsbblDaoImpl; +import com.szpg.db.data.PgAcu; +import com.szpg.db.data.PgAcuCmd; +import com.szpg.db.data.PgHjsbbl; +import com.szpg.plc.message.CommandResponse; +import com.szpg.plc.message.command.write.SetWdThresholdWordCommand; +import com.szpg.plc.protocol.DTProtocolInterface; +import com.szpg.plc.protocol.ProtocolFactory; +import com.szpg.plc.protocol.fins.FINSConstants; +import com.szpg.plc.server.ACUClient; +import com.szpg.plc.server.ACUClientUtil; +import com.szpg.plc.util.ByteUtil; +import com.szpg.plc.util.Bytes; +import com.szpg.util.Configure; + +/** + * 设置温湿度报警阈值 + * + * @author admin + * + */ +public class SetWdThresholdTask implements Runnable { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + + private String deviceCode; + private float threshold; + private PgHjsbblDao blDao = new PgHjsbblDaoImpl(); + + public SetWdThresholdTask(String deviceCode, float threshold) { + this.deviceCode = deviceCode; + this.threshold = threshold; + } + + @Override + public void run() { + // 查找ACU的信息 + PgAcuDao acuDao = new PgAcuDaoImpl(); + PgDeviceDao deviceDao = new PgDeviceDaoImpl(); + String acucode = deviceDao.findAcuCodeByCode(deviceCode); + PgAcu acu = acuDao.findACUByCode(acucode); + ACUClient client = ACUClientUtil.getInstance().getClients().get(acu.getAcu_host() + ":" + acu.getAcu_port()); + if (null != client) { + // 源地址 + String sour = Configure.getProperty("sys", "LOCALHOST.NET") + + Configure.getProperty("sys", "LOCALHOST.NODE") + + Configure.getProperty("sys", "LOCALHOST.UNIT"); + + // 目标地址 + String dest = client.getNet() + client.getNode() + client.getUnit(); + + DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); + + // 发送设置报警阈值的命令 + SetWdThresholdWordCommand setTemThreCmd = new SetWdThresholdWordCommand(); + setTemThreCmd.setThreshold(threshold); + PgHjsbbl temBlObj = blDao.findBlByBh(deviceCode + ".TemSet"); + if (null != temBlObj) { + setTemThreCmd.setMessageProducerId(sour); + setTemThreCmd.setDestinationId(dest); + + // SID在new对象的时候已经生成 + + // 内存区域——按字写 + setTemThreCmd.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD); + + int start = temBlObj.getKszdz(); + int end = temBlObj.getJszdz(); + + // 开始字地址 + setTemThreCmd.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(start, 2)) + "00"); + + // 字数 + int n = end - start + 1; + setTemThreCmd.setCount(n); + + // 字内容 + byte[] temps = ByteUtil.intToBins(Float.floatToIntBits(threshold)); + Bytes dataByte = new Bytes(); + for (int j = n; j > 0; j--) { + dataByte.append(new byte[] {temps[2 * (j-1)], temps[2 * (j-1) + 1]}); + } + setTemThreCmd.setValue( dataByte.toBytes() ); + + // 解析命令对象为字节数组 + byte[] content = finspi.messageToBytes(setTemThreCmd); + + // 通过socket接口发送出去 + ACUClientUtil.getInstance().sendACUCommand(client, content); + } + + // 3将命令存入数据库 + PgAcuCmdDao cmdDao = new PgAcuCmdDaoImpl(); + PgAcuCmd cmd = new PgAcuCmd(); + cmd.setCmd_type(setTemThreCmd.getCommandType()); + cmd.setDest_acu_code(acucode); + cmd.setTm(setTemThreCmd.getTime().getTime()); + cmdDao.addCmdRecord(cmd); + + // 4阻塞,循环查找响应消息池,找到对应的响应消息 + boolean flag = false; + int times = 0; + CommandResponse response = null; + while (flag == false && times < 240) { + response = ACUClientUtil.getInstance().responsePool.getResponse(cmd.getId()); + + if (null != response && response.equals("") == false) { + flag = true; + } + + times++; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO 阻塞线程被打断,需要处理异常 + // 目前的处理流程为1)记录日志;2)将命令置为超时 + logger.error("在响应池中查找命令的响应消息阻塞线程被异常打断", e); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + + return; + } + } + + // 5若未超时,将值存入数据库 + if (null != response) { + // 6根据命令类型的不同将监测值存入对应的数据库 + response.afterAction(); + } else { + // 9超时,将命令的超时标志位置1 + logger.warn("命令超时" + cmd.getId()); + cmdDao.updateCmdRecordTimeout(cmd.getId()); + } + } + } + +} diff --git a/src/com/szpg/task/TurnOffFjTask.java b/src/com/szpg/task/TurnOffFjTask.java index 6280063..2b45870 100644 --- a/src/com/szpg/task/TurnOffFjTask.java +++ b/src/com/szpg/task/TurnOffFjTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetFjOffBitCommand; +import com.szpg.plc.message.command.write.SetFjOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJON); + SetFjOnBitCommand clearOnCmd = new SetFjOnBitCommand(); + clearOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getFjon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJOFF); + SetFjOffBitCommand setOffCmd = new SetFjOffBitCommand(); + setOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getFjoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/task/TurnOffZmTask.java b/src/com/szpg/task/TurnOffZmTask.java index d3a1ff3..c46119b 100644 --- a/src/com/szpg/task/TurnOffZmTask.java +++ b/src/com/szpg/task/TurnOffZmTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetZmOffBitCommand; +import com.szpg.plc.message.command.write.SetZmOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将启动位置0 - WriteMemoryCommand clearOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMON); + SetZmOnBitCommand clearOnCmd = new SetZmOnBitCommand(); + clearOnCmd.setZmon(SetZmOnBitCommand.ZM_ON_DISABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { clearOnCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOnCmd.setCount(end - start + 1); // 位内容 - clearOnCmd.setValue(new byte[] {0x00} ); + clearOnCmd.setValue(new byte[] {(byte) clearOnCmd.getZmon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOnCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMOFF); + SetZmOffBitCommand setOffCmd = new SetZmOffBitCommand(); + setOffCmd.setZmoff(SetZmOffBitCommand.ZM_OFF_ENABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { setOffCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOffCmd.setCount(end - start + 1); // 位内容 - setOffCmd.setValue(new byte[] {0x01} ); + setOffCmd.setValue(new byte[] {(byte) setOffCmd.getZmoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOffCmd); diff --git a/src/com/szpg/task/TurnOnFjTask.java b/src/com/szpg/task/TurnOnFjTask.java index 5be904a..d61cded 100644 --- a/src/com/szpg/task/TurnOnFjTask.java +++ b/src/com/szpg/task/TurnOnFjTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetFjOffBitCommand; +import com.szpg.plc.message.command.write.SetFjOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将停止位置0 - WriteMemoryCommand clearOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJOFF); + SetFjOffBitCommand clearOffCmd = new SetFjOffBitCommand(); + clearOffCmd.setFjoff(SetFjOffBitCommand.FJ_OFF_DISABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { clearOffCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOffCmd.setCount(end - start + 1); // 位内容 - clearOffCmd.setValue(new byte[] {0x00} ); + clearOffCmd.setValue(new byte[] {(byte) clearOffCmd.getFjoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOffCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETFJON); + SetFjOnBitCommand setOnCmd = new SetFjOnBitCommand(); + setOnCmd.setFjon(SetFjOnBitCommand.FJ_ON_ENABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { setOnCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOnCmd.setCount(end - start + 1); // 位内容 - setOnCmd.setValue(new byte[] {0x01} ); + setOnCmd.setValue(new byte[] {(byte) setOnCmd.getFjon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOnCmd); diff --git a/src/com/szpg/task/TurnOnZmTask.java b/src/com/szpg/task/TurnOnZmTask.java index ab94097..20e8e56 100644 --- a/src/com/szpg/task/TurnOnZmTask.java +++ b/src/com/szpg/task/TurnOnZmTask.java @@ -13,9 +13,9 @@ import com.szpg.db.data.PgAcu; import com.szpg.db.data.PgAcuCmd; import com.szpg.db.data.PgHjsbbl; -import com.szpg.plc.message.AppMessageConstants; import com.szpg.plc.message.CommandResponse; -import com.szpg.plc.message.command.WriteMemoryCommand; +import com.szpg.plc.message.command.write.SetZmOffBitCommand; +import com.szpg.plc.message.command.write.SetZmOnBitCommand; import com.szpg.plc.protocol.DTProtocolInterface; import com.szpg.plc.protocol.ProtocolFactory; import com.szpg.plc.protocol.fins.FINSConstants; @@ -55,7 +55,8 @@ DTProtocolInterface finspi = ProtocolFactory.getDefaultDTProtocol(); // 1首先将停止位置0 - WriteMemoryCommand clearOffCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMOFF); + SetZmOffBitCommand clearOffCmd = new SetZmOffBitCommand(); + clearOffCmd.setZmoff(SetZmOffBitCommand.ZM_OFF_DISABLE); PgHjsbbl offBlObj = blDao.findBlByBh(deviceCode + ".OFF"); if (null != offBlObj) { clearOffCmd.setMessageProducerId(sour); @@ -80,7 +81,7 @@ clearOffCmd.setCount(end - start + 1); // 位内容 - clearOffCmd.setValue(new byte[] {0x00} ); + clearOffCmd.setValue(new byte[] {(byte) clearOffCmd.getZmoff()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(clearOffCmd); @@ -98,7 +99,8 @@ } // 2 发送设置启动位的命令 - WriteMemoryCommand setOnCmd = WriteMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_SETZMON); + SetZmOnBitCommand setOnCmd = new SetZmOnBitCommand(); + setOnCmd.setZmon(SetZmOnBitCommand.ZM_ON_ENABLE); PgHjsbbl onBlObj = blDao.findBlByBh(deviceCode + ".ON"); if (null != onBlObj) { setOnCmd.setMessageProducerId(sour); @@ -123,7 +125,7 @@ setOnCmd.setCount(end - start + 1); // 位内容 - setOnCmd.setValue(new byte[] {0x01} ); + setOnCmd.setValue(new byte[] {(byte) setOnCmd.getZmon()} ); // 解析命令对象为字节数组 byte[] content = finspi.messageToBytes(setOnCmd);