GetAlarmNotificationParser.java
3.99 KB
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
/*
* Copyright (C) 2015 The Telink Bluetooth Light Project
*
*/
package com.telink.bluetooth.light;
import com.telink.util.NumberUtils;
/**
* 闹铃通知解析器
*/
public final class GetAlarmNotificationParser extends NotificationParser<GetAlarmNotificationParser.AlarmInfo> {
private GetAlarmNotificationParser() {
}
public static GetAlarmNotificationParser create() {
return new GetAlarmNotificationParser();
}
@Override
public byte opcode() {
return Opcode.BLE_GATT_OP_CTRL_E7.getValue();
}
@Override
public AlarmInfo parse(NotificationInfo notifyInfo) {
byte[] params = notifyInfo.params;
int offset = 8;
int total = params[offset] & 0xFF;
if (total == 0)
return null;
offset = 1;
int index = params[offset++] & 0xFF;
byte data = (byte) (params[offset] & 0xFF);
offset = 3;
int sceneId = params[offset] & 0xFF;
int action = NumberUtils.byteToInt(data, 0, 3);
int type = NumberUtils.byteToInt(data, 4, 6);
int status = data >> 7 & 0x01;
long time = NumberUtils.bytesToLong(params, 3, 5);
AlarmInfo alarmInfo = new AlarmInfo();
alarmInfo.index = index;
alarmInfo.total = total;
alarmInfo.action = AlarmAction.valueOf(action);
alarmInfo.type = AlarmType.valueOf(type);
alarmInfo.status = AlarmStatus.valueOf(status);
alarmInfo.time = time;
alarmInfo.sceneId = sceneId;
return alarmInfo;
}
public enum AlarmAction {
OFF(0), ON(1), SCENE(2);
private final int value;
AlarmAction(int value) {
this.value = value;
}
static public AlarmAction valueOf(int value) {
AlarmAction[] values = AlarmAction.values();
for (AlarmAction action : values) {
if (value == action.getValue())
return action;
}
return null;
}
public int getValue() {
return value;
}
}
public enum AlarmType {
DAY(0), WEEK(1),;
private final int value;
AlarmType(int value) {
this.value = value;
}
static public AlarmType valueOf(int value) {
AlarmType[] values = AlarmType.values();
for (AlarmType type : values) {
if (value == type.getValue())
return type;
}
return null;
}
public int getValue() {
return value;
}
}
public enum AlarmStatus {
ENABLE(1), DISABLE(0),;
private final int value;
AlarmStatus(int value) {
this.value = value;
}
static public AlarmStatus valueOf(int value) {
AlarmStatus[] values = AlarmStatus.values();
for (AlarmStatus status : values) {
if (value == status.getValue())
return status;
}
return null;
}
public int getValue() {
return value;
}
}
public final class AlarmInfo {
public int index;
public int total;
public AlarmAction action;
public AlarmType type;
public AlarmStatus status;
public long time;
public int sceneId;
public int getMonth() {
return this.type == AlarmType.DAY ? (int) (this.time >> 32 & 0x0C) : 0;
}
public int getDayOrWeek() {
return (int) (this.time >> 24 & 0xFF);
}
public int getHour() {
return (int) (this.time >> 16 & 0xFF);
}
public int getMinute() {
return (int) (this.time >> 8 & 0xFF);
}
public int getSecond() {
return (int) (this.time & 0xFF);
}
}
}