Message80Cmd.java
1.72 KB
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
package com.bsth.socket.protocol;
import com.bsth.constant.Constant;
import com.bsth.util.ConvertUtil;
import org.joda.time.DateTime;
import java.nio.ByteBuffer;
import java.util.Arrays;
/**
* @author Hill
* 参数查询
*/
public class Message80Cmd implements IMessageBody {
/**
* byte[6]
* 数据采集时间
*/
private long timestamp;
/**
* 参数总数
* n
*/
private byte paramNum;
/**
* 参数命令ID
* n*1
*/
private byte[] paramIds;
@Override
public void read(byte[] bytes) {
// TODO Auto-generated method stub
int idx = 0;
timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6;
paramNum = bytes[idx]; idx++;
int len = paramNum & Constant.BYTE_INT;
Arrays.copyOfRange(bytes, idx, idx + len); idx += len;
}
@Override
public byte[] write() {
// TODO Auto-generated method stub
ByteBuffer buf = ByteBuffer.allocate(7 + paramIds.length);
buf.put(ConvertUtil.timestamp2bytes(timestamp));
buf.put(paramNum);
buf.put(paramIds);
return buf.array();
}
public long getTimestamp() {
return timestamp;
}
@Override
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public byte getParamNum() {
return paramNum;
}
public void setParamNum(byte paramNum) {
this.paramNum = paramNum;
}
public byte[] getParamIds() {
return paramIds;
}
public void setParamIds(byte[] paramIds) {
this.paramIds = paramIds;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss"))
.append(" 参数数量:").append(paramNum)
.append(" 参数命令IDS:").append(ConvertUtil.toHexString(paramIds));
return sb.toString();
}
}