| | |
| | | import com.dy.common.mw.protocol.p206V1.CodeV1; |
| | | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; |
| | | import com.dy.pipirrComCreator.ServerProperties; |
| | | import com.dy.pipirrComCreator.p206V1.Cd02; |
| | | import com.dy.pipirrComCreator.p206V1.Cd10; |
| | | import com.dy.pipirrComCreator.p206V1.Cd92; |
| | | import com.dy.pipirrComCreator.p206V1.Cd93; |
| | | import com.dy.pipirrComCreator.p206V1.P206V1Deal; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | |
| | | public class Command { |
| | |
| | | commands = new String[]{ |
| | | "config 查看配置信息", |
| | | "XY ... 协议命令", |
| | | "XY -h 协议命令帮助", |
| | | "exit 退出", |
| | | }; |
| | | } |
| | |
| | | }else if(command.equals("exit")){ |
| | | exit = true ; |
| | | }else if(isProtocolCom(command)){ |
| | | dealProtocolCom(command, prtWrt); |
| | | if(ServerProperties.protocolName.equals(ProtocolConstantV206V1.protocolName)){ |
| | | P206V1Deal.dealProtocolCom(command, prtWrt); |
| | | }else{ |
| | | out("当前不支持协议" + ServerProperties.protocolName, prtWrt) ; |
| | | } |
| | | }else { |
| | | outNoIdentify(prtWrt); |
| | | } |
| | | return exit ; |
| | | } |
| | | private static boolean isProtocolCom(String command){ |
| | | public static boolean isProtocolCom(String command){ |
| | | if(ServerProperties.protocolName.equals(ProtocolConstantV206V1.protocolName)){ |
| | | String[] coms = command.split(" "); |
| | | for (String com : coms){ |
| | |
| | | } |
| | | return false ; |
| | | } |
| | | private static void dealProtocolCom(String command, PrintWriter prtWrt) throws Exception{ |
| | | String[] coms = command.split(" "); |
| | | List<String> comList = new ArrayList<>(); |
| | | for (String com : coms){ |
| | | if(!com.equals("")){ |
| | | comList.add(com) ; |
| | | } |
| | | } |
| | | String com = comList.get(0) ; |
| | | switch (com) { |
| | | case CodeV1.cd_02: cd02(comList, prtWrt); break; |
| | | case CodeV1.cd_10: cd10(comList, prtWrt); break; |
| | | case CodeV1.cd_92: cd92(comList, prtWrt); break; |
| | | case CodeV1.cd_93: cd93(comList, prtWrt); break; |
| | | default: outNoIdentify(prtWrt); break; |
| | | } |
| | | } |
| | | |
| | | private static void cd02(List<String> comList, PrintWriter prtWrt)throws Exception{ |
| | | if(comList.size() > 1){ |
| | | String p = comList.get(1); |
| | | if(p.equals("-h")){ |
| | | prtWrt.println("02[Enter](心跳命令应答(链路维持报应答))"); |
| | | }else{ |
| | | outNoIdentify(prtWrt) ; |
| | | } |
| | | }else{ |
| | | out(new Cd02().hex(ServerProperties.rtuAddr), prtWrt); |
| | | } |
| | | } |
| | | private static void cd10(List<String> comList, PrintWriter prtWrt)throws Exception{ |
| | | if(comList.size() > 1){ |
| | | String p1 = comList.get(1); |
| | | if(p1.equals("-h")){ |
| | | prtWrt.println("10 *...*[Enter](设置控制器地址)"); |
| | | }else{ |
| | | String[] ps = params2Grp(comList) ; |
| | | Cd10 cd = new Cd10() ; |
| | | String msg = cd.checkParams(ps) ; |
| | | if(msg == null){ |
| | | out(new Cd10().hex(ServerProperties.rtuAddr, ps), prtWrt); |
| | | }else{ |
| | | out(msg, prtWrt); |
| | | } |
| | | } |
| | | }else{ |
| | | outNoParams(prtWrt); ; |
| | | } |
| | | } |
| | | private static void cd92(List<String> comList, PrintWriter prtWrt)throws Exception{ |
| | | if(comList.size() > 1){ |
| | | String p = comList.get(1); |
| | | if(p.equals("-h")){ |
| | | prtWrt.println("92[Enter](平台远程开启阀门)"); |
| | | }else{ |
| | | outNoIdentify(prtWrt) ; |
| | | } |
| | | }else{ |
| | | out(new Cd92().hex(ServerProperties.rtuAddr), prtWrt); |
| | | } |
| | | } |
| | | private static void cd93(List<String> comList, PrintWriter prtWrt)throws Exception{ |
| | | if(comList.size() > 1){ |
| | | String p = comList.get(1); |
| | | if(p.equals("-h")){ |
| | | prtWrt.println("93[Enter](平台远程关闭阀门)"); |
| | | }else{ |
| | | outNoIdentify(prtWrt) ; |
| | | } |
| | | }else{ |
| | | out(new Cd93().hex(ServerProperties.rtuAddr), prtWrt); |
| | | } |
| | | } |
| | | |
| | | private static String[] params2Grp(List<String> comList){ |
| | | String[] ps = new String[comList.size()-1] ; |
| | | for(int i = 1; i < comList.size(); i++){ |
| | | ps[i-1] = comList.get(i) ; |
| | | } |
| | | return ps ; |
| | | } |
| | | |
| | | private static void out(String str, PrintWriter prtWrt){ |
| | | public static void out(String str, PrintWriter prtWrt){ |
| | | prtWrt.println(str==null?"":str); |
| | | } |
| | | private static void outHelp(PrintWriter prtWrt){ |
| | |
| | | } |
| | | prtWrt.println(""); |
| | | } |
| | | private static void outConfig(PrintWriter prtWrt){ |
| | | public static void outConfig(PrintWriter prtWrt){ |
| | | prtWrt.println(""); |
| | | prtWrt.println("预先设置"); |
| | | prtWrt.println(" 协议:" + ServerProperties.protocolName); |
| | |
| | | prtWrt.println(" IC卡编号:" + ServerProperties.icCardNo); |
| | | prtWrt.println(""); |
| | | } |
| | | private static void outNoIdentify(PrintWriter prtWrt){ |
| | | public static void outNoIdentify(PrintWriter prtWrt){ |
| | | prtWrt.println(""); |
| | | prtWrt.println("命令不可识别!"); |
| | | prtWrt.println(""); |
| | | } |
| | | private static void outNoParams(PrintWriter prtWrt){ |
| | | public static void outNoParams(PrintWriter prtWrt){ |
| | | prtWrt.println(""); |
| | | prtWrt.println("请输入命令参数!"); |
| | | prtWrt.println(""); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |