WriteFlashStateResponse.java
2.34 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
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
package com.sunvote.cmd.upgrade;
import com.sunvote.cmd.BaseCmd;
import com.sunvote.cmd.ICmd;
/**
 * Created by Elvis on 2017/8/11.
 * Email:Eluis@psunsky.com
 * Description:按页写FLASH
 * 模块返回写情况:
 * 字节	标识符	描述
 * 1	REQUEST_CMD	0xF8 固件升级指令
 * 2	CMD1	4 模块写页执行情况
 * 3	PAGEH	当前数据的页地址高位
 * 4	PAGEL	当前数据的页地址低位
 * 5	STATUS	1 执行写OK
 * 0 失败
 */
public class WriteFlashStateResponse extends UpgradeBaseCmd{
    public static final int CMD_LENGTH = 5 ;
    public WriteFlashStateResponse(){}
    public WriteFlashStateResponse(WriteFlashStateRequest request){
        parseCmd(request.toBytes());
        setCmd(RESPONSE_CMD);
    }
    /**
     * 固件升级指令
     */
    private byte cmd = RESPONSE_CMD;
    /**
     * 4 模块按页写FLASH
     */
    private byte cmd1 ;
    /**
     * 当前数据的页地址高位
     */
    private byte pageh ;
    /**
     * 当前数据的页地址低位
     */
    private byte pagel ;
    /**
     * 1 执行写OK
     * 0 失败
     */
    private byte status;
    public byte getCmd() {
        return cmd;
    }
    public void setCmd(byte cmd) {
        this.cmd = cmd;
    }
    public byte getCmd1() {
        return cmd1;
    }
    public void setCmd1(byte cmd1) {
        this.cmd1 = cmd1;
    }
    public byte getPageh() {
        return pageh;
    }
    public void setPageh(byte pageh) {
        this.pageh = pageh;
    }
    public byte getPagel() {
        return pagel;
    }
    public void setPagel(byte pagel) {
        this.pagel = pagel;
    }
    public byte getStatus() {
        return status;
    }
    public void setStatus(byte status) {
        this.status = status;
    }
    @Override
    public byte[] toBytes() {
        byte[] result = new byte[CMD_LENGTH];
        result[0] = cmd;
        result[1] = cmd1;
        result[2] = pageh ;
        result[3] = pagel ;
        result[4] = status;
        return result;
    }
    @Override
    public ICmd parseCmd(byte[] source, int start) {
        if(source != null && source.length >= start + CMD_LENGTH){
            cmd = source[start] ;
            cmd1 = source[start + 1] ;
            pageh = source[start + 2] ;
            pagel = source[start + 3] ;
            status = source[start + 4];
        }
        return this;
    }
}