Blame view

C5/xpadprotocal/src/main/java/com/sunvote/cmd/basestation/ConfirmBaseBeaconResponse.java 2.21 KB
fac86401   孙向锦   初始化C5 Vote
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
  package com.sunvote.cmd.basestation;
  
  import com.sunvote.cmd.BaseCmd;
  import com.sunvote.cmd.ICmd;
  
  import java.io.ByteArrayOutputStream;
  import java.util.Arrays;
  
  /**
   * Created by Elvis on 2017/8/30.
   * Email:Eluis@psunsky.com
   * 版权所有:长沙中天电子设计开发有限公司
   * Description:平板模块键盘投票功能模块
   *
   * 基站应答:
   字节	标识符	描述
   1	BASECMD	0xE0 基站类指令应答
   2	BASEID	应答的基站的编号
   3	CMDTYPE	应答类型
   6 确认数据包应答
   4	OK	1 表示收到指令
   5-29		无实际意义
  
   */
  public class ConfirmBaseBeaconResponse extends BaseCmd {
  
  
      private byte basecmd;
      private byte baseid;
      private byte cmdtype;
      private byte OK;
      private byte[] data = new byte[25];
  
  
      @Override
      public byte[] toBytes() {
          try{
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              stream.write(getBasecmd());
              stream.write(getBaseid());
              stream.write(getCmdtype());
              stream.write(getOK());
              stream.write(getData());
              return stream.toByteArray();
          }catch (Exception ex){
              ex.printStackTrace();
          }
          return new byte[0];
      }
  
      @Override
      public ICmd parseCmd(byte[] source, int start) {
          setBasecmd(source[start]);
          setBaseid(source[start+1]);
          setCmdtype(source[start+2]);
          setOK(source[start+4]);
          if(source.length > 5) {
              setData(Arrays.copyOfRange(source, start + 5, source.length));
          }
          return this;
      }
  
      public byte getBasecmd() {
          return basecmd;
      }
  
      public void setBasecmd(byte basecmd) {
          this.basecmd = basecmd;
      }
  
      public byte getBaseid() {
          return baseid;
      }
  
      public void setBaseid(byte baseid) {
          this.baseid = baseid;
      }
  
      public byte getCmdtype() {
          return cmdtype;
      }
  
      public void setCmdtype(byte cmdtype) {
          this.cmdtype = cmdtype;
      }
  
      public byte getOK() {
          return OK;
      }
  
      public void setOK(byte OK) {
          this.OK = OK;
      }
  
      public byte[] getData() {
          return data;
      }
  
      public void setData(byte[] data) {
          this.data = data;
      }
  }