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
81
82
83
84
85
86
87
88
89
90
91
package com.whyc.res;
 
import com.whyc.util.ComBase;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
 
 
/**
 *     内阻数据头
 * @author LiJun
 *
 */
public class RESDataHead {
    public static final int BYTE_LEN = 4;
    
    private int[] SYNCode = new int[2];            //固定值0xAA 0xAA
    private int record_times;                    //记录次数,记录有多少笔RES_DATA数据
    
    public boolean setHeadData(byte[] databuf) {
        if(databuf.length < BYTE_LEN) {
            return false;
        }
        ByteBuffer bf = ByteBuffer.allocate(databuf.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(databuf);
        bf.position(0);
        for(int i=0;i<SYNCode.length;i++) {
            SYNCode[i] = ComBase.changeByteToInt(bf.get());
        }
        record_times = ComBase.changeShortToInt(bf.getShort());
        //System.out.println("次数:"+record_times);
        return true;
    }
    
    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((0xAA != (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 int[] getSYNCode() {
        return SYNCode;
    }
    public int getRecord_times() {
        return record_times;
    }
    public void setSYNCode(int[] sYNCode) {
        this.SYNCode = sYNCode;
    }
    public void setRecord_times(int record_times) {
        this.record_times = record_times;
    }
    
    
    
}