DELL
2024-12-23 fed0a447df51e633ab6453261dc6e3d8a906d4a2
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
package com.whyc.mcp;
 
import com.whyc.util.StaticInf;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
 
public class MonitorDataInfo {
    public static final int BYTE_LEN = BattParam.BYTE_LEN + SYSMonitorParam.BYTE_LEN + SYSMonitorState.BYTE_LEN;
 
    public BattParam battparam;                                //电池参数
    public SYSMonitorParam monitorparam;                    //未使用
    public SYSMonitorState monitorstate;
 
 
    public MonitorDataInfo() {
        battparam = new BattParam();
        monitorparam = new SYSMonitorParam();
        monitorstate = new SYSMonitorState();
    }
 
    public boolean checkDataHead(FileInputStream fis)
    {
        boolean check_ok = false;
        boolean file_end = false;
        byte[] tag = new byte[1];
        try {
            while(true)
            {
                int n = 0;
                for(n=0; n<4; n++)
                {
                    if(1 != fis.read(tag, 0, 1))
                    {
                        file_end = true;
                        break;
                    }
                    if((0xFA != (tag[0]&0xFF)) && (0xFB != (tag[0]&0xFF)))
                    {
                        break;
                    }
                }
 
                if(n >= 4)
                {
                    check_ok = true;
                    break;
                }
                if(true == file_end)
                {
                    break;
                }
            }
        } catch (IOException e) {
            //e.printStackTrace();
        }
        return check_ok;
    }
 
    public boolean setHeadData(byte[] buf) {
        boolean flag = false;
        if(buf.length < BYTE_LEN) {
            return flag;
        }
        ByteBuffer bf = ByteBuffer.allocate(buf.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.position(0);
        bf.put(buf);
        bf.flip();
        flag = battparam.putByteBuffer(bf);
        bf.position(0);
        flag &= monitorparam.putByteBuffer(bf);
        bf.position(0);
        flag &= monitorstate.putByteBuffer(bf);
 
        return flag;
    }
}