whyclj
2021-01-05 64aba412c2b739d67795b14a3cae069d311697f9
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
package com.dev.fbs9100;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
 
public class FBS9100_StatAndParam {
    private final int BYTE_LEN = 6;
    
    public int dev_id = 0;
    public String dev_ipaddr = "127.0.0.1";
    
    public int op_cmd = FBS9100_ComBase.CMD_NULL;
    public int test_type = FBS9100_ComBase.TestType_NULL;
    public String dev_name;
    
    public FBS9100_VCData m_FBS_VCData = new FBS9100_VCData();
    public FBS9100_ParamDischarge m_FBS_DiscParam = new FBS9100_ParamDischarge();
    public FBS9100_ParamDischarge m_FBS_DiscParamFromDev = new FBS9100_ParamDischarge();
    public FBS9100_CMCC_Power m_CMCC_Power = new FBS9100_CMCC_Power();
    
    public int CRC = 0;
    
    public FBS9100_StatAndParam(String ipaddr, int devid)
    {
        dev_ipaddr = ipaddr;
        dev_id = devid;
    }
 
    public boolean putByteBuffer(final ByteBuffer bf)
    {
        if(bf.limit() != BYTE_LEN){
            //System.out.println("limit´íÎó"+bf.limit());
            return false;
        }
        ByteBuffer tmpbuf = bf;
        /*int id = */tmpbuf.getInt();
        int crc0 = tmpbuf.getShort() & 0xFFFF;
        int crc1 = FBS9100_Crc16.CalCRC16(tmpbuf, BYTE_LEN-2);
        if(crc0 != crc1){
            System.out.println("crc´íÎó");
            return false;
        }
        tmpbuf.position(0);
        
        dev_id = tmpbuf.getInt();
        
        
        tmpbuf.compact();
        tmpbuf.flip();
        
        return true;
    }
    
    public ByteBuffer getByteBuffer()
    {
        ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        
        //bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(dev_id));
        bytebuffer.putInt(dev_id);
        CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
        
        bytebuffer.flip();
        
        //System.out.println("bytebuffer limit"+bytebuffer.limit());
        return bytebuffer;
    }
 
    @Override
    public String toString() {
        return "FBS9100_StatAndParam [BYTE_LEN=" + BYTE_LEN + ", dev_id=" + dev_id + ", dev_ipaddr=" + dev_ipaddr
                + ", op_cmd=" + op_cmd + ", test_type=" + test_type + "]";
    }
}