| package com.dy.pipirrComCreator.console; | 
|   | 
| 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.P206V1Deal; | 
|   | 
| import java.io.PrintWriter; | 
|   | 
|   | 
| public class Command { | 
|      | 
|     private static String[] commands ; | 
|     static{ | 
|         commands = new String[]{ | 
|                 "config 查看配置信息",     | 
|                 "XY ... 协议命令(3C、10、21、37、50、65、66、67、91、92、93、97、98、99、A0、A1、A2)", | 
|                 "XY -h 协议命令帮助", | 
|                 "exit 退出", | 
|         }; | 
|     } | 
|      | 
|      | 
|     public static boolean dealCommand(String command, PrintWriter prtWrt) throws Exception{ | 
|         boolean exit = false ; | 
|         command = command.trim() ; | 
|         if (command.equals("help")) { | 
|             outHelp(prtWrt); | 
|         }else if (command.equals("config")) { | 
|             outConfig(prtWrt); | 
|         }else if(command.equals("exit")){ | 
|             exit = true ; | 
|         }else if(isProtocolCom(command)){ | 
|             if(ServerProperties.protocolName.equals(ProtocolConstantV206V1.protocolName)){ | 
|                 P206V1Deal.dealProtocolCom(command, prtWrt); | 
|             }else{ | 
|                 out("当前不支持协议" + ServerProperties.protocolName, prtWrt)  ; | 
|             } | 
|         }else { | 
|             outNoIdentify(prtWrt); | 
|         } | 
|         return exit ; | 
|     } | 
|     public static boolean isProtocolCom(String command){ | 
|         if(ServerProperties.protocolName.equals(ProtocolConstantV206V1.protocolName)){ | 
|             String[] coms = command.split(" "); | 
|             for (String com : coms){ | 
|                 if(!com.equals("")){ | 
|                     if(CodeV1.isValid(com)){ | 
|                         return true ; | 
|                     }else{ | 
|                         return false ; | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|         return false ; | 
|     } | 
|   | 
|     public static void out(String str, PrintWriter prtWrt){ | 
|         prtWrt.println(str==null?"":str); | 
|     } | 
|     private static void outHelp(PrintWriter prtWrt){ | 
|         prtWrt.println(""); | 
|         prtWrt.println("命令"); | 
|         for(String s : commands){ | 
|             prtWrt.println("  " + s); | 
|         } | 
|         prtWrt.println(""); | 
|     } | 
|     public static void outConfig(PrintWriter prtWrt){ | 
|         prtWrt.println(""); | 
|         prtWrt.println("预先设置"); | 
|         prtWrt.println("  协议:" + ServerProperties.protocolName); | 
|         prtWrt.println("  协议版本号:" + ServerProperties.protocolVersion); | 
|         prtWrt.println("  Rtu地址:" + ServerProperties.rtuAddr); | 
|         prtWrt.println("  IC卡地址:" + ServerProperties.icCardAddr); | 
|         prtWrt.println("  IC卡编号:" + ServerProperties.icCardNo); | 
|         prtWrt.println(""); | 
|     } | 
|     public static void outNoIdentify(PrintWriter prtWrt){ | 
|         prtWrt.println(""); | 
|         prtWrt.println("命令不可识别!"); | 
|         prtWrt.println(""); | 
|     } | 
|     public static void outNoParams(PrintWriter prtWrt){ | 
|         prtWrt.println(""); | 
|         prtWrt.println("请输入命令参数!"); | 
|         prtWrt.println(""); | 
|     } | 
|   | 
|   | 
|     public static void main(String[] args) { | 
|         String com = "   02 123       345          789"; | 
|         com = com.trim() ; | 
|         String[] coms = com.split(" "); | 
|         for(String s : coms){ | 
|             System.out.println(s); | 
|         } | 
|     } | 
|   | 
| } |