Administrator
2021-08-09 92aad2bdb3fc2552dfc199801c32b8bd9bb61472
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
package com.dev.btse.data;
 
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 op_cmd_ack = FBS9100_ComBase.CMD_NULL;
    public int test_type = FBS9100_ComBase.TestType_NULL;
    public String dev_reg_code;
    public long dev_station_id = 0;
    
    public FBS9100_SysState m_SysState = new FBS9100_SysState();
    //public int[] Mcu_Id = new int[4];
    public String m_DevVersion = "";
    public String m_GPRS_inf = "";
    
    public long dev_comm_data_flowsum = 0;
    
    public int CRC = 0;
    
    public FBS9100_StatAndParam(String ipaddr, int devid)
    {
        dev_ipaddr = ipaddr;
        dev_id = devid;
    }
    
    public void makeDevCommDataFlowSum (int dat_len) {
        int datlen = dat_len;
        if(datlen < 64) {
            datlen = 64;
        }
        dev_comm_data_flowsum += datlen;
    }
 
    public boolean putByteBuffer(final ByteBuffer bf)
    {
        if(bf.limit() != BYTE_LEN){
            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_ack + ", test_type=" + test_type + "]";
    }
}