Admin
2021-02-24 e96bf56b0e732059459a955b3eec9b0d221af752
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
package safeluck.drive.evaluation.platformMessage;
 
 
 
import com.safeluck.aykj.annotation.AnnotationRegister;
import com.safeluck.aykj.annotation.Int16;
import com.safeluck.aykj.annotation.Int8;
import com.safeluck.aykj.annotation.Length;
import com.safeluck.aykj.annotation.Order;
import com.safeluck.aykj.decoder.BitStateCoder;
import com.safeluck.aykj.decoder.Int16Coder;
import com.safeluck.aykj.message.BinMessageBase;
import com.safeluck.aykj.utils.BitState;
import com.safeluck.aykj.utils.BytesUtils;
 
import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.platformMessage.decoder.JWD;
import safeluck.drive.evaluation.platformMessage.decoder.JWDCoder;
import safeluck.drive.evaluation.platformMessage.decoder.Phone;
import safeluck.drive.evaluation.platformMessage.decoder.PhoneCoder;
import safeluck.drive.evaluation.platformMessage.decoder.SPEED;
import safeluck.drive.evaluation.platformMessage.decoder.SpeedCoder;
 
public class JK2019MessageBase extends BinMessageBase {
    static {
        AnnotationRegister.register(JWD.class, new JWDCoder());
        AnnotationRegister.register(Phone.class, new PhoneCoder());
        //增加speed 编码器
        AnnotationRegister.register(SPEED.class, new SpeedCoder());
 
    }
    static Int16Coder coder = new Int16Coder();
    public JK2019MessageBase()
    {
        this.messageNo = getMessageNo();
        String message_name = this.getClass().getSimpleName();
        if(message_name.startsWith("JKMessage"))
        {
            String message_id = message_name.substring(9,13);
            if(message_id.equals("Unkn") ){
                return;
            }
            this.messageId= coder.decode(message_id);
        }
        this.setMultiPacket(false);
    }
 
 
    @Override
    public void parse(String hex){
 
        BitStateCoder coder = new BitStateCoder();
        this.props = coder.decode(hex.substring(8,12));
        if(this.isMultiPacket())
        {
            this.removeDisableField("totalPacket");
            this.removeDisableField("packetNo");
        }
        super.parse(hex);
    }
 
    @Override
    public String toString()
    {
        if(!this.isMultiPacket())
        {
            this.registerDisableField("totalPacket");
            this.registerDisableField("packetNo");
        }
        //计算消息体长度
        String hex = super.toString();
//        Log.i(PlatFormConstant.TAG, "toString: 消息体长度:"+hex);
        int message_head_len = 19;
        if(this.isMultiPacket())
        {
            message_head_len+=4;
        }
        int len2 = hex.length()/2-message_head_len;
        this.setMessageLen(len2);
        //计算校验
        hex = super.toString();
        byte[] bytes = BytesUtils.hexStringToBytes(hex);
        bytes[bytes.length - 2] = BytesUtils.xor(bytes,1,bytes.length -2);
 
        return BytesUtils.bytesToHexString(bytes);
    }
    @Order(1)
    @Int8
    public int head=0x7E;
    @Order(2)
    @Int8
    public int protocalVer=0xEB;
    @Order(3)
    @Int16
    public int messageId;
    @Order(4)
    @Length(2)
    @com.safeluck.aykj.annotation.BitState
    public BitState props = new BitState((short) 0);
    @Order(5)
    @Phone
    public String phone= ExamPlatformData.getInstance().getPhone();
    @Order(6)
    @Int16
    public int messageNo;
    @Order(7)
    @Int8
    public int reserved = 0;
//    @Order(8)
//    @Int16
//    public int totalPacket;
//    @Order(9)
//    @Int16
//    public int packetNo;
 
 
    @Order(Integer.MAX_VALUE-10001)
    @Int8
    public int checksum;
    @Order(Integer.MAX_VALUE-10000)
    @Int8
    public int end=0x7E;
 
    /**
     * 是否消息经过分包处理
     * @param b
     */
    public void setMultiPacket(boolean b)
    {
        this.props.set(13,b);
    }
    public boolean isMultiPacket()
    {
        return this.props.get(13);
    }
 
    /**
     * 获取属性中的消息体长度
     * @return
     */
    public int getMessageLen()
    {
        BitState state = new BitState((short)this.props.value);
        for (int i = 0; i < 10; i++)
        {
            state.set(10 + i, false);
        }
        return (int) state.value;
    }
 
    /**
     * 设置属性中的消息体长度
     * @param len
     */
    public void setMessageLen(int len)
    {
        BitState state = new BitState((short)len);
 
        for (int i = 0; i < 10; i++)
        {
            this.props.set(i, state.get(i));
        }
    }
 
 
 
}