DELL
2025-04-28 e6eb7fb0af366e370f125668d62e89eb0004f517
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
package com.dev.bts.data;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
 
 
public class FBS9100_DFU implements Cloneable
{
    public static final int DFU_BUF_LEN = 256;
    private final int BYTE_LEN_WriteAck = 6;
    private final int BYTE_LEN = DFU_BUF_LEN + BYTE_LEN_WriteAck;
    
    public int op_cmd = 0;
    public int test_cmd = 0;
    
    public int DataBlockIndex = 0;
    public int DataLen = 0;
    public byte[] DataDfu = new byte[DFU_BUF_LEN];
    public int CRC = 0;
    
    public FBS9100_DFU clone()
    {
        FBS9100_DFU obj = null;  
        try
        {
            obj = (FBS9100_DFU)super.clone();
        }
        catch(CloneNotSupportedException e)
        {
            e.printStackTrace();
        }
        return obj;
    }
    
    public void clear()
    {
        CRC = 0;
    }
    
    public boolean putWriteAckByteBuffer(final ByteBuffer bf)
    {
        if(bf.limit() < BYTE_LEN_WriteAck)
            return false;
        
        ByteBuffer tmpbuf = bf;
        int crc0 = tmpbuf.getShort(BYTE_LEN_WriteAck-2) & 0xFFFF;
        int crc1 = FBS9100_Crc16.CalCRC16(tmpbuf, BYTE_LEN_WriteAck-2);
        if(crc0 != crc1) {
            return false;
        }
        
        tmpbuf.position(0);
        DataBlockIndex = (tmpbuf.getShort()&0xFFFF);
        DataLen = (tmpbuf.getShort()&0xFFFF);
        
        tmpbuf.compact();
        tmpbuf.flip();
        
        return true;
    }
    
    public boolean putReadAckByteBuffer(final ByteBuffer bf)
    {
        if(bf.limit() < BYTE_LEN)
            return false;
        
        ByteBuffer tmpbuf = bf;
        int crc0 = tmpbuf.getShort(BYTE_LEN-2) & 0xFFFF;
        int crc1 = FBS9100_Crc16.CalCRC16(tmpbuf, BYTE_LEN-2);
        if(crc0 != crc1) {
            return false;
        }
        
        tmpbuf.position(0);
        DataBlockIndex = (tmpbuf.getShort()&0xFFFF);
        DataLen = (tmpbuf.getShort()&0xFFFF);
        
        tmpbuf.compact();
        tmpbuf.flip();
        
        return true;
    }
    
    public boolean checkDfuWriteAckBuf(ByteBuffer ack_bf) {
        boolean res = false;
        
        FBS9100_Cmd m_cmd = new FBS9100_Cmd();
        if(true == m_cmd.putByteBuffer(ack_bf)) {
            if(true == putWriteAckByteBuffer(ack_bf)) {
                res = true;
            }
        }
        
        return res;
    }
    
    public boolean checkDfuReadAckBuf(ByteBuffer ack_bf) {
        boolean res = false;
        
        FBS9100_Cmd m_cmd = new FBS9100_Cmd();
        if(true == m_cmd.putByteBuffer(ack_bf)) {
            if(true == putReadAckByteBuffer(ack_bf)) {
                res = true;
            }
        }
        
        return res;
    }
    
    public ByteBuffer getWriteByteBuffer(int num, byte[] dat, int len)
    {
        ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(num));
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(len));
        bytebuffer.put(dat);
        CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
        
        bytebuffer.flip();
        
        return bytebuffer;
    }
    
    public ByteBuffer getReadByteBuffer(int num, int data_len)
    {
        ByteBuffer bytebuffer = ByteBuffer.allocate(128);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        
        //DataBlockIndex = num;
        //DataLen = data_len;
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(num));
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(data_len));
        CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
        
        bytebuffer.flip();
        
        return bytebuffer;
    }
}
/***************************************************************************************
****************************** end of file (FBS_TestParam) *****************************
***************************************************************************************/