Administrator
2023-05-16 7a49155f41a11c93b692b120705432e04323cd1d
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.fgkj.fbs5100;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
 
public class FBS5100_Alarm {
    public static final int ALMITEM_CAP1             = 0;      //组1容量告警
    public static final int ALMITEM_CAP2             = 1;    //组2容量告警
    public static final int ALMITEM_CAP3             = 2;    //组3容量告警
    public static final int ALMITEM_CAP4             = 3;    //组4容量告警
    public static final int ALMITEM_INPUTVOL         = 4;      //输入电压告警
    public static final int ALMITEM_AC_DOWM         = 5;       //交流失电
    public static final int ALMITEM_GROUPVOL1         = 6;      //组1电压告警
    public static final int ALMITEM_GROUPVOL2         = 7;    //组2电压告警
    public static final int ALMITEM_GROUPVOL3         = 8;    //组3电压告警
    public static final int ALMITEM_GROUPVOL4         = 9;    //组4电压告警
    public static final int ALMITEM_BOOST_FAULT     = 10;      //升压模块故障
    public static final int ALMITEM_BUCK_FAULT         = 11;      //降压模块故障
    public static final int ALMITEM_NBCOMM_FAULT     = 12;     //逆变通信故障
    public static final int ALMITEM_ACDC_FAULT         = 13;      //电源故障
    public static final int ALMITEM_COOLER_TEMP     = 14;      //散热器温度
    public static final int ALMITEM_INNER_TEMP         = 15;   //内部温度
 
    public static final int BYTE_LEN = 16;
    
    public int    SYNCode[] = new int[2]; //AA AA
    
    public int   AlarmItem;                    //告警类型
    public int    AlarmType;                     //1-超出上限 或 产生告警   2-超出下限
    public float  AlarmValue;                //告警值
    public FBS5100_DateTime    StartTime;        //告警开始时间
    public FBS5100_DateTime    EndTime;          //暂未启用,不要显示
    
    
    public FBS5100_Alarm() {
        StartTime  = new FBS5100_DateTime();
        EndTime  = new FBS5100_DateTime();
    }
    
    public boolean putByteBuffer(final byte[] buf)
    {
        
        ByteBuffer bf = ByteBuffer.allocate(buf.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(buf);
        
        if(bf.limit() != BYTE_LEN){
            return false;
        }    
        ByteBuffer tmpbuf = bf;
        
        tmpbuf.position(0);
        
        AlarmItem = FBS5100_ComBase.changeByteToInt(tmpbuf.get());                        //告警类型
        AlarmType = FBS5100_ComBase.changeByteToInt(tmpbuf.get());                         //1-超出上限 或 产生告警   2-超出下限
        AlarmValue = (float)FBS5100_ComBase.changeShortToFloat(tmpbuf.getShort())/10;    //告警值
        StartTime.putByteBuffer(tmpbuf);                                                //告警开始时间
        EndTime.putByteBuffer(tmpbuf);                                                  //暂未启用,不要显示
        
        tmpbuf.compact();
        tmpbuf.flip();
        
        return true;
    }
 
    
    public int checkDataHead(FileInputStream fis)
    {
        boolean file_end = false;
        byte type_tag = 0;
        byte[] tag = new byte[1];        
        try {
            while(true)
            {
                type_tag = 0;
                int n = 0;
                for(n=0; n<2; n++)
                {
                    if(1 != fis.read(tag, 0, 1))
                    {
                        file_end = true;
                        break;
                    }
                    if((0xAA != (tag[0]&0xFF)))
                    {
                        break;
                    }
                }
                
                if(n >= 2)
                {
                    type_tag = tag[0];
                    break;
                }
                if(true == file_end)
                {
                    type_tag = 1;
                    break;
                }
            }
        } catch (IOException e) {
            //e.printStackTrace();
        }        
        setType(type_tag&0xFF);
        
        return (type_tag&0xFF);
    }
 
 
    private void setType(int synCode) {
        for(int i  = 0 ; i < SYNCode.length ; i++) {
            SYNCode[i] = synCode;
        }
        
    }
 
    @Override
    public String toString() {
        return "FBS5100_Alarm [SYNCode=" + Arrays.toString(SYNCode) + ", AlarmItem=" + AlarmItem + ", AlarmType="
                + AlarmType + ", AlarmValue=" + AlarmValue + ", StartTime=" + StartTime + ", EndTime=" + EndTime + "]";
    }
    
    
    
}