liurunyu
2 天以前 f84d149459b73928c864eb5aebf764cf58105c73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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<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: 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<String> 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<String> 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<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 ;
    }
}