mxpopstar
2022-05-03 e75ef5f04f61aa5fbd89fd5c413dcee1819b7a91
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.dev.bts.data;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Date;
 
public class FBS9100_SysState 
{
    public static final byte SYS_STATE_STOPPED    = 0;
    public static final byte SYS_STATE_DISCHARGING = 1;
    public static final byte SYS_STATE_CHARGING = 2;
    //--------------------------------------------------------//
    private final int BYTE_LEN = 14;
    //--------------------------------------------------------//
    public Date Record_DateTime = new Date();
    //--------------------------------------------------------//
    public FBS9100_DateTime DTime = new FBS9100_DateTime();    //±ê×¼ÈÕÆÚʱ¼ä
    public int         TestType = 0;                              //²âÊÔÀàÐÍ(³äµç»ò·Åµç)
    public int         TestGroupNum = 1;                          //±»²âÊÔÐîµç³Ø×é±àºÅ1-4
    public int         WorkState = SYS_STATE_STOPPED;             //ϵͳ¹¤×÷״̬
    public int         AlarmState = 0;                           //ϵͳ¸æ¾¯×´Ì¬
    public int         ResTestState = 0;                         //ϵͳ¹¤×÷״̬
    public int         OnlineVolLow = 0;                        //ÔÚÏßµçѹ̫µÍ(»ùվͣµç±êʶ)
    public int        CapTestStopType = -1;                    //·ÅµçÍ£Ö¹Ô­Òò
    
    public int         Station_State = 0;
    
    public boolean  BG_1_IsOFFLine = false;                    //µç³Ø×é1ÀëÏß
    public boolean  BG_2_IsOFFLine = false;                    //µç³Ø×é2ÀëÏß
    public boolean  BG_HaveNewData = false;                    //µç³Ø×éÓÐÐÂÊý¾Ý¸üÐÂ
    public boolean  SD_Card_Err = false;                    //BTS SD¿¨¹ÊÕÏ
    
    public boolean Station_Event_poff = false;
    public boolean Station_Event_xuhang = false;
    public boolean Station_Event_diaozhan = false;
    
    public int        CommCount = 0;                            //ͨÐżÆÊý
    public int        ErrCommCount = 0;
    public int        RxNullErrCount = 0;
    public long     Alm_RecId = 0;
    
    //---------------------------------------//
    public int        ResTestCnt;                                //ÄÚ×èÒѲâÊÔ´ÎÊý
    public int        ResBattIndexMax;                        //±»²âÊÔµ¥ÌåµÄ×î´ó±àºÅË÷Òý
    public int      ResBattIndex;                            //±»²âÊÔµ¥ÌåµÄË÷Òý
    //---------------------------------------//
    
    public int         CRC = 0;
    
    public FBS9100_SysState clone()
    {
        FBS9100_SysState obj = new FBS9100_SysState();
        
        obj.DTime = DTime.clone();
        obj.TestType = TestType;
        obj.TestGroupNum = TestGroupNum;
        obj.WorkState = WorkState;
        obj.AlarmState = AlarmState;
        obj.OnlineVolLow = OnlineVolLow;
        
        obj.BG_1_IsOFFLine = BG_1_IsOFFLine;
        obj.BG_2_IsOFFLine = BG_1_IsOFFLine;
        obj.BG_HaveNewData = BG_HaveNewData;
        obj.SD_Card_Err = SD_Card_Err;
        obj.Station_Event_poff = Station_Event_poff;
        obj.Station_Event_xuhang = Station_Event_xuhang;
        obj.Station_Event_diaozhan = Station_Event_diaozhan;
        
        obj.ResTestState = ResTestState;
        obj.CapTestStopType = CapTestStopType;
        obj.CommCount = CommCount;
        obj.ErrCommCount = ErrCommCount;
        obj.RxNullErrCount = RxNullErrCount;
        obj.CRC = CRC;
        
        return obj;
    }
    
    public void setCommCountInc()
    {
        Record_DateTime = new Date();
        
        CommCount += 1;
        if(CommCount >= 90000000) {
            CommCount = 1;
        }
    }
    
    public void setErrCommCountInc(int rx_len)
    {
        if(rx_len < 1) {
            RxNullErrCount += 1;
        }
        ErrCommCount += 1;
        if(ErrCommCount >= 90000000) {
            ErrCommCount = 20;
        }
        if(RxNullErrCount >= 90000000) {
            RxNullErrCount = 20;
        }
    }
    
    public void setDateTime(FBS9100_DateTime dt)
    {
        DTime = dt;
    }
    
    public void setResTestCnt(int res_cnt)
    {
        ResTestCnt = res_cnt;
    }
    public int getResTestCnt()
    {
        return ResTestCnt;
    }
    
    public boolean putByteBuffer(final ByteBuffer bf)
    {
        if(bf.limit() < BYTE_LEN)
            return false;
        
        ByteBuffer tmpbuf = bf;
        int crc0 = tmpbuf.getShort(BYTE_LEN-2) & 0xFFFF;
        int crc1 = FBS9100_Crc16.CalCRC16(tmpbuf, BYTE_LEN-2);
        if(crc0 != crc1)
            return false;
        
        tmpbuf.position(0);
        DTime.putByteBuffer(tmpbuf);
        TestType = FBS9100_ComBase.changeByteToInt(bf.get());
        TestGroupNum = FBS9100_ComBase.changeByteToInt(bf.get());
        
        WorkState = FBS9100_ComBase.changeByteToInt(bf.get());
        ResTestState = WorkState & 0xF0;
        WorkState &= 0x0F;
        
        AlarmState = FBS9100_ComBase.changeByteToInt(bf.get());
        
        OnlineVolLow = FBS9100_ComBase.changeByteToInt(bf.get());
        BG_1_IsOFFLine = ((OnlineVolLow&(1<<4)) > 0);
        BG_2_IsOFFLine = ((OnlineVolLow&(1<<5)) > 0);
        BG_HaveNewData = ((OnlineVolLow&(1<<1)) > 0);
        SD_Card_Err = ((OnlineVolLow&(1<<6)) > 0);
        
        Station_Event_diaozhan = ((OnlineVolLow&(1<<3)) > 0);
        Station_Event_xuhang = ((OnlineVolLow&(1<<2)) > 0);
        Station_Event_poff = ((OnlineVolLow&(1<<0)) > 0);
        
        OnlineVolLow &= 0x01;
        
        CapTestStopType = FBS9100_ComBase.changeByteToInt(bf.get());
        CRC = FBS9100_ComBase.changeShortToInt(bf.getShort());
        tmpbuf.compact();
        tmpbuf.flip();
        return true;
    }
    
    public ByteBuffer getDateTimeByteBuffer()
    {
        ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        bytebuffer.put(DTime.getPCDateTimeBytes());
        
        CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
        bytebuffer.flip();
        //System.out.println(bytebuffer.limit()+"&&&&&&&&&&&&&&&&");
        return bytebuffer;
    }
    
    public ByteBuffer getByteBuffer() {
        ByteBuffer bytebuffer = ByteBuffer.allocate(BYTE_LEN);
        bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
        
        bytebuffer.put(DTime.getPCDateTimeBytes());
        bytebuffer.put(FBS9100_ComBase.changeIntToByte(TestType));
        bytebuffer.put(FBS9100_ComBase.changeIntToByte(TestGroupNum));
        bytebuffer.put(FBS9100_ComBase.changeIntToByte(WorkState));
        bytebuffer.put(FBS9100_ComBase.changeIntToByte(AlarmState));
        bytebuffer.put(FBS9100_ComBase.changeIntToByte(OnlineVolLow));
        bytebuffer.put(FBS9100_ComBase.changeIntToByte(CapTestStopType));
        
        CRC = FBS9100_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
        bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(CRC));
        bytebuffer.flip();
        //System.out.println(bytebuffer.limit()+"&&&&&&&&&&&&&&&&");
        return bytebuffer;
    }
 
    @Override
    public String toString() {
        return "FBS9100_SysState [BYTE_LEN=" + BYTE_LEN + ", DTime=" + DTime + ", TestType=" + TestType
                + ", TestGroupNum=" + TestGroupNum + ", WorkState=" + WorkState + ", AlarmState=" + AlarmState
                + ", OnlineVolLow=" + OnlineVolLow + ", CommCount=" + CommCount + ", ErrCommCount=" + ErrCommCount
                + ", Alm_RecId=" + Alm_RecId + ", ResBattIndexMax=" + ResBattIndexMax + ", ResBattIndex=" + ResBattIndex
                + ", CRC=" + CRC + "]";
    }
}
/***************************************************************************************
****************************** end of file (FBS_SysState) ******************************
***************************************************************************************/