package com.dy.pipirrComCreator.p206V1; import com.dy.common.mw.protocol.p206V1.CodeV1; import com.dy.pipirrComCreator.ServerProperties; import com.dy.pipirrComCreator.console.Command; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; /** * @Author: liurunyu * @Date: 2025/5/7 11:17 * @Description */ public class P206V1Deal { public static void dealProtocolCom(String command, PrintWriter prtWrt) throws Exception{ String[] coms = command.split(" "); List comList = new ArrayList<>(); for (String com : coms){ if(!com.equals("")){ comList.add(com) ; } } String com = comList.get(0) ; switch (com) { case CodeV1.cd_02: cdWithoutParam(new P206V1Cd02(), comList, prtWrt); break; case CodeV1.cd_10: cdWithParam(new P206V1Cd10(), comList, prtWrt); break; case CodeV1.cd_21: cdWithParam(new P206V1Cd21(), comList, prtWrt); break; case CodeV1.cd_37: cdWithParam(new P206V1Cd37(), comList, prtWrt); break; case CodeV1.cd_3C: cdWithParam(new P206V1Cd3C(), comList, prtWrt); break; case CodeV1.cd_50: cdWithoutParam(new P206V1Cd50(), comList, prtWrt); break; case CodeV1.cd_65: cdWithoutParam(new P206V1Cd65(), comList, prtWrt); break; case CodeV1.cd_66: cdWithoutParam(new P206V1Cd66(), comList, prtWrt); break; case CodeV1.cd_67: cdWithoutParam(new P206V1Cd67(), comList, prtWrt); break; case CodeV1.cd_91: cdWithoutParam(new P206V1Cd91(), comList, prtWrt); break; case CodeV1.cd_92: cdWithoutParam(new P206V1Cd92(), comList, prtWrt); break; case CodeV1.cd_93: cdWithoutParam(new P206V1Cd93(), comList, prtWrt); break; default: Command.outNoIdentify(prtWrt); break; } } private static void cdWithoutParam(P206V1Cd cd, List comList, PrintWriter prtWrt)throws Exception{ if(comList.size() > 1){ String p = comList.get(1); if(p.equals("-h")){ prtWrt.println(cd.helpInfo()); }else{ Command.outNoIdentify(prtWrt) ; } }else{ Command.out(cd.hex(ServerProperties.rtuAddr), prtWrt); } } private static void cdWithParam(P206V1Cd cd, List comList, PrintWriter prtWrt)throws Exception{ if(comList.size() > 1){ String p1 = comList.get(1); if(p1.equals("-h")){ prtWrt.println(cd.helpInfo()); }else{ String[] ps = params2Grp(comList) ; String msg = cd.checkParams(ps) ; if(msg == null){ Command.out(cd.hex(ServerProperties.rtuAddr, ps), prtWrt); }else{ Command.out(msg, prtWrt); } } }else{ Command.outNoParams(prtWrt); ; } } private static String[] params2Grp(List comList){ String[] ps = new String[comList.size()-1] ; for(int i = 1; i < comList.size(); i++){ ps[i-1] = comList.get(i) ; } return ps ; } }