zsh_root
2023-06-01 6a11d13546c73912c019002f914c39202b3b49d2
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package baowen;
import java.util.Vector;
import data_model.YuanshiByt;
 
/**´¦ÀíԭʼÊý¾Ý*/
public class Dell_uanshi_byt {
 
    static Vector<YuanshiByt>  yuanshivec=new Vector<>();
 
 
    /**²åÈëԭʼ²â¾àÊý¾Ý£¬Ã¿¸öipÒ»¸ö¼¯ºÏÿ¸öIPÉÏÀ´µÄÊý¾Ý×°Èë¸÷×ÔIPÖ®ÖÐ*/
    public static void intsert(String ip,String hex,String time,int timestamp,int port) {        
        if(get_ys(ip) !=null) {    
            int lenth=hex.length()/2;
            for(int i=0;i<lenth;i++) {
                String hex1=hex.substring(2*i, (i+1)*2);
                get_ys(ip).getData().add(hex1);
                hex1=null;
            }
            get_ys(ip).setTime(time);
            get_ys(ip).setTimestamp(timestamp);
            dell_ysbyt(get_ys(ip),ip,port);
        }else {
            YuanshiByt ysbyt=new YuanshiByt();
            Vector<String> data1=new Vector<>();
            StringBuffer okhex=new StringBuffer();
            ysbyt.setIp(ip);
            ysbyt.setPort(port);
            ysbyt.setData(data1);
            ysbyt.setTimestamp(timestamp);
            ysbyt.setTime(time);
            ysbyt.setUsart_state(0);
            ysbyt.setPack(okhex);
            ysbyt.setDatalen(0);
            ysbyt.setType("");
            int lenth=hex.length()/2;
            for(int i=0;i<lenth;i++) {
                String hex1=hex.substring(2*i, (i+1)*2);
                data1.add(hex1);
                hex1=null;
            }
            yuanshivec.add(ysbyt);
            dell_ysbyt(ysbyt,ip,port);
        }
 
    }
 
    /**ͨ¹ýIPÕÒµ½¸ÃIPµÄÊý¾Ý¼¯ºÏ*/
    public static YuanshiByt  get_ys(String ip) {
        YuanshiByt ysbyt=null;
        int size=yuanshivec.size();
        for(int i=0;i<size;i++) {
            YuanshiByt ysbyt1=yuanshivec.get(i);
            String ip1=ysbyt1.getIp();            
            if(ip1.equals(ip)) {
                ysbyt=ysbyt1;
                break;
            }
        }
        return ysbyt;
    }
 
 
 
    /**´¦Àíԭʼ¼¯ºÏÖеÄÊý¾Ý*/
    public static void  dell_ysbyt(YuanshiByt ysbyt,String ip,int port) {        
        String time=ysbyt.getTime();
        int timestamp=ysbyt.getTimestamp();
        while(ysbyt.getData().size() !=0) {    
            String hex=ysbyt.getData().get(0);
            int usart_state=ysbyt.getUsart_state();
            //½«Ô­Ê¼Êý¾Ý¼¯ºÏÖеĵÚÒ»ÌõÊý¾ÝÈ¡³ö·ÅÈëswichÑ­»·
            switch(usart_state) {
 
            case 0:
                //Èç¹ûÊý¾ÝÊÇ55ÔòÖ´ÐР   
                if(hex.equals("55")) {
                    //½«Êý¾Ý´¦ÀíµÄ״̬ÐÞ¸ÄΪ1
                    ysbyt.setUsart_state(1);
                    //ͬʱ²åÈëÊý¾ÝÔÚ×Ö·û´®ÖÐ
                    ysbyt.getPack().append(hex);
                }
                break;
 
            case 1:
                //Èç¹ûÊý¾ÝÊÇAAÔòÖ´ÐР   
                if(hex.equals("AA")) {//״̬1Çé¿öÏ£¬µÈ´ý½ÓÊÕµ½AA°üÍ·2£¬È»ºó±ä³É״̬2                        
                    ysbyt.setUsart_state(2);
                    ysbyt.getPack().append(hex);
                }
                break;
 
            case 2:
                //Êý¾ÝÀàÐ͸øTYPE
                ysbyt.setType(hex);
                ysbyt.setUsart_state(3);
                ysbyt.getPack().append(hex);
                break;
 
            case 3:
                //±¨ÎÄÊý¾Ý¶ÎÊý¾Ý³¤¶È
                int d=Udp_Receive.decodeHEX(hex);
                ysbyt.getPack().append(hex);
                ysbyt.setUsart_state(4);
                ysbyt.setDatalen(d);
                break;
 
            case 4:
                ysbyt.getPack().append(hex);
                int lenth=ysbyt.getPack().length();
                int a=ysbyt.getDatalen()*2+8;
                if(lenth==a) {                        
                    //Êý¾Ý´¦ÀíµÄ״̬
                    ysbyt.setUsart_state(0);
                    //УÑé
                    String check=Jiaoyan.check2(ysbyt.getPack().toString());                    
                    String panck_cmd=ysbyt.getPack().toString().substring(lenth-2,lenth)
                            +ysbyt.getPack().substring(lenth-4, lenth-2);
 
                    //Èç¹ûУÑé³É¹¦
                    if(check.equals(panck_cmd)) {
                        //Èç¹ûÊDzâ¾àÊý¾Ý
                        String type=ysbyt.getType();
                        switch(type) {
                        case "01"://²â¾àÐÅÏ¢
                            
                            break;
 
                        case "0A"://0A×¢²á°ü
                            break;
 
                        case "02"://ÐÄÌø°ü
                            break;
 
                        case "0C"://²â¾àÊý¾Ý
                            Udp_Receive.dell_55aa0c(ysbyt.getPack().toString(), ip, port);
                            break;
 
                        case "09"://¶ÁÈ¡»ùÕ¾ÅäÖÃÐÅÏ¢³É¹¦
                            break;
 
                        case "03"://ÅäÖÃÐÅÏ¢
                            break;
 
                        case "07":    
                            break;
                        case "10":    
                            break;
                        case "12":
                            break;
                        case "0E":
                            break;
                        }
                    }
 
                    ysbyt.getPack().setLength(0);
                    ysbyt.setDatalen(0);
                    ysbyt.setType("");
                }else if(lenth>a ) {
                    ysbyt.getPack().setLength(0);
                    ysbyt.setDatalen(0);
                    ysbyt.setType("");
                }
 
                break;
 
            }
            //ɾ³ý´¦Àí¹ýµÄÊý¾Ý
            ysbyt.getData().removeElement(hex);
        }
 
    }
    
}