DELL
2025-03-03 2cdf5ae1cc004e7c36375874d28eacdc191f2de6
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
package FBS9100;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
 
 
public class FBS9100_DFU implements Cloneable
{
    private final int BYTE_LEN = 518;
    private final int BYTE_LEN_READ = 6;
    
    public int op_cmd = 0;
    public int test_cmd = 0;
    
    public int DataBlockIndex = 0;
    public int DataLen = 0;
    public byte[] DataDfu = new byte[512];
    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 putByteBuffer(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.compact();
        tmpbuf.flip();
        
        return true;
    }
    
    public ByteBuffer getByteBuffer(int num, int data_len)
    {
        ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        
        DataBlockIndex = num;
        DataLen = data_len;
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataBlockIndex));
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataLen));
        for(int n=0; n<DataDfu.length; n++) {
            DataDfu[n] = (byte) n;
        }
        bytebuffer.put(DataDfu);
        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(BYTE_LEN_READ);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        
        DataBlockIndex = num;
        DataLen = data_len;
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataBlockIndex));
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(DataLen));
        CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
        
        bytebuffer.flip();
        
        return bytebuffer;
    }
}
/***************************************************************************************
****************************** end of file (FBS_TestParam) *****************************
***************************************************************************************/