JLChen
2021-11-05 de72a7843ceb868c89fc11983e315849caa28573
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
package com.hdl.sdk.ttl.HDLAppliances.HDLSecurity.Parser;
 
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
 
/**
 * Created by JLChen on 2019/7/29
 */
public class SecurityParser {
 
    public static final int fail = 0;
    /**
     * 布防设置
     */
    //布防类型   6 =撤防 5 = 白天布防 4 = 晚上有客布防 3 = 夜间布防 2 = 离开布防 1 = 假期布防
    public static final int ARMING_HOLIDAY = 1;
    public static final int ARMING_LEAVE = 2;
    public static final int ARMING_AT_NIGHT = 3;
    public static final int ARMING_AT_NIGHT_WITH_GUEST = 4;
    public static final int ARMING_DURING_THE_DAY = 5;
    public static final int ARMING_DISARMING = 6;
 
    public static final int ARMING_FAIL = 7;//布防失败
//    public static final int ARMING_UNKNOWM = -1;//未知状态
 
    //获取布防 bytes数据
    public static byte[] getArmingByte(AppliancesInfo appliancesInfo, int state) {
        try {
            if (state < 0 || state > 6) {//参数错误默认撤防
                state = 6;
            }
            byte[] addBytes = new byte[2];
            addBytes[0] = (byte) appliancesInfo.getChannelNum();
            addBytes[1] = (byte) state;
            return addBytes;
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
 
    }
 
 
//        Bit 4 0 = 正常状态 , 1 = 电流报警
//        Bit 3 0 =正常状态, 1 = 紧急报警
//        Bit 2 0 =正常状态, 1 = 突发报警
//        Bit 1 0 =正常状态, 1 =煤气报警
//        Bit 0 0 =正常状态, 1 = 火警 3
//
// Encode Bit Value
//        Bit 7 0 =正常状态, 1 = 温度报警
//        Bit 6 0 =正常状态, 1 = 功率报警
//        Bit 5 0 =正常状态, 1 = 无声报警
//private int CurrentAlarm;   //电流报警
//    private int EmergencyAlarm; //紧急报警
//    private int SuddenAlarm;    //突发报警
//    private int FireAlarm;      //火警 3
//
//    private int TemperatureAlarm;//温度报警
//    private int PowerAlarm;     //功率报警
//    private int SilentAlarm;    //无声报警
    /**
     * 报警设置 ALARM
     */
    public static final int ALARM_CURRENT = 4;      //电流报警
    public static final int ALARM_EMERGENCY = 3;    //紧急报警
    public static final int ALARM_SUDDEN = 2;       //突发报警
    public static final int ALARM_GAS = 1;          //煤气报警
    public static final int ALARM_FIRE = 0;         //火警 3
    public static final int ALARM_TEMPERATURE = 7;  //温度报警
    public static final int ALARM_POWER = 6;        //功率报警
    public static final int ALARM_SILENT = 5;       //无声报警
 
    //获取报警设置 bytes数据 只报警一种情况
    public static byte[] getAlarmByte(AppliancesInfo appliancesInfo, int state) {
        try {
            byte[] addBytes = new byte[3];
            addBytes[0] = (byte) appliancesInfo.getChannelNum();
            switch (state) {
                case ALARM_FIRE:
                    addBytes[1] = 0x01;
                    break;
                case ALARM_GAS:
                    addBytes[1] = (byte) (1 << 1);
                    break;
                case ALARM_SUDDEN:
                    addBytes[1] = (byte) (1 << 2);
                    break;
                case ALARM_EMERGENCY:
                    addBytes[1] = (byte) (1 << 3);
                    break;
                case ALARM_CURRENT:
                    addBytes[1] = (byte) (1 << 4);
                    break;
 
                case ALARM_SILENT:
                    addBytes[2] = (byte) (1 << 5);
                    break;
                case ALARM_POWER:
                    addBytes[2] = (byte) (1 << 6);
                    break;
                case ALARM_TEMPERATURE:
                    addBytes[2] = (byte) (1 << 7);
                    break;
                default:
                    break;
            }
 
            return addBytes;
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
 
    }
 
}