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
package com.dy.simRtu.tcpClient.downData;
 
import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1;
import com.dy.common.util.ByteUtil;
import com.dy.common.util.CreateRandom;
import com.dy.simRtu.ServerProperties;
import com.dy.simRtu.tcpClient.upData.*;
 
/**
 * @Author: liurunyu
 * @Date: 2024/11/18 10:57
 * @Description 中间件的下行数据
 */
public class DownData {
 
    private static int count9602 = 0;
 
    public void parseData(byte[] bs){
        if(bs != null && bs.length > 0){
            if(bs.length >= (ProtocolConstantV206V1.ctrlIndex)
                    && bs[0] == ProtocolConstantV206V1.P_Head_Byte
                    && bs[2] == ProtocolConstantV206V1.P_Head_Byte){
                this.dealP206V1(bs);
            }else if(bs.length >= (ProtocolConstantV206V1.UG_codeIndex)
                    && bs[0] == ProtocolConstantV206V1.UG_P_Head_Byte
                    && bs[3] == ProtocolConstantV206V1.UG_P_Head_Byte){
                this.dealUpgrade(bs);
            }
 
        }
    }
    private void dealP206V1(byte[] bs){
        //应该是链路检测数据
    }
    private void dealUpgrade(byte[] bs){
        String cdPre = ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.UG_codeIndex, 1);
        if(cdPre.equals("16")){
            //升级功能码
            UpHeartBeat.upHeartBeat = false ;//禁止上行心跳
            if(bs.length >= ProtocolConstantV206V1.UG_lenHead2Cmd + 1){
                String cdSuf = ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.UG_codeIndex + 1, 1);
                String cd = cdPre + cdSuf;
                if(cd.equals("1601")){
                    //升级配置
                    UpCd9601.upData() ;
 
                }else if(cd.equals("1602")){
                    //升级数据
                    count9602 ++ ;
                    if(ServerProperties.argOneDie){
                        UpHeartBeat.upHeartBeat = true ;//使能上行心跳
                    }else{
                        if(ServerProperties.argMultiDie){
                            if(count9602 > 10){
                                int random =  CreateRandom.create_between(10, 100) ;
                                if(random > 90){
                                    UpHeartBeat.upHeartBeat = true ;//使能上行心跳
                                }else{
                                    UpCd9602.upData() ;
                                }
                            }else{
                                UpCd9602.upData() ;
                            }
                        }else{
                            UpCd9602.upData() ;
                        }
                    }
                }else if(cd.equals("1603")){
                    //升级校验
                    UpCd9603.upData() ;
                }else if(cd.equals("1600")){
                    //升级复位
                    UpCd9600.upData() ;
                    UpHeartBeat.upHeartBeat = true ;//不上行心跳
                }
            }
        }
    }
}