@ray-js/lamp-schedule-core 1.0.0-beta-1 → 1.0.0-beta-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dpParser/cycle/index.d.ts +6 -0
- package/lib/dpParser/cycle/index.js +74 -68
- package/lib/dpParser/random/index.d.ts +6 -0
- package/lib/dpParser/random/index.js +108 -97
- package/lib/dpParser/rhythms.d.ts +1 -32
- package/lib/dpParser/rhythms.js +41 -36
- package/lib/dpParser/rtcTimer.js +201 -191
- package/lib/dpParser/sleep/sleepCommon.js +88 -91
- package/lib/dpParser/timerReport.js +22 -10
- package/lib/dpParser/wakeup/wakeupCommon.js +85 -75
- package/lib/hooks/useBaseLightDp.d.ts +10 -1
- package/lib/hooks/useBaseLightDp.js +61 -2
- package/lib/hooks/useCountdownDp.js +2 -2
- package/lib/hooks/useTimerReportDp.js +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/dpParser/rtcTimer.js
CHANGED
|
@@ -51,220 +51,230 @@ export class RtcTimerFormatter {
|
|
|
51
51
|
ScheduleLogger.warn('RtcTimerFormatter parser,value is empty, return defaultValue', this.defaultValue);
|
|
52
52
|
return this.defaultValue;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
try {
|
|
55
|
+
const {
|
|
56
|
+
length
|
|
57
|
+
} = val;
|
|
58
|
+
const mixLightLen = 26; // 混光长度
|
|
59
|
+
const colourLightLen = 22; // 彩光长度
|
|
60
|
+
const brightLightLen = 18; // 白光长度
|
|
61
|
+
const powerLen = 14; // 纯开关长度
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
// 删除定时
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
if (length !== 4 && length !== powerLen && length !== brightLightLen && length !== colourLightLen && length !== mixLightLen) {
|
|
66
|
+
// 数据位数不定, 可能是14位或18位22位26位, 删除定时指令为4位
|
|
67
|
+
ScheduleLogger.warn('RtcTimerFormatter parser fail:', RTC_TIMER, '=>', val);
|
|
68
|
+
return this.defaultValue;
|
|
69
|
+
}
|
|
70
|
+
const step = generateDpStrStep(val);
|
|
71
|
+
if (length === powerLen || length === brightLightLen || length === colourLightLen || length === mixLightLen) {
|
|
72
|
+
const id = step(2); // // 定时任务ID, ABBBBBBB:A:定时任务开关,0-关闭,1-开启;BBBBBBB:定时ID:1-10,最多支持10条
|
|
73
|
+
const idBinaryStr = numToBinStrPad8(id.value); // 转为二进制的八位 => ABBBBBBB
|
|
74
|
+
const status = idBinaryStr.slice(0, 1) === '1'; // 0-关闭,1-开启
|
|
75
|
+
const timerId = parseInt(idBinaryStr.slice(1), 2); // 定时ID:1-10
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
78
|
+
step(2).value; // 定时类型, 普通定时选择:0x01
|
|
79
|
+
const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
|
|
80
|
+
const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
+
step(2).value; // 时间类型 => 0x00:精确时间 0x01:日出前 0x02:日出后 0x03:日落前 0x04:日落后 0x05:倒计时
|
|
84
|
+
const time = step(4).value; // 时间 => 一天为 24H*60=1440
|
|
84
85
|
|
|
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
|
-
|
|
86
|
+
/**
|
|
87
|
+
* A:设备动作
|
|
88
|
+
* A=0x00,关灯,
|
|
89
|
+
A=0x01,开灯,
|
|
90
|
+
A=0x02,白光,
|
|
91
|
+
A=0x03,彩光,
|
|
92
|
+
A=0x04,混光,
|
|
93
|
+
A=0x05,情景,
|
|
94
|
+
A=0x06,节能,
|
|
95
|
+
A=0x07,太阳能
|
|
96
|
+
*/
|
|
97
|
+
step(2).value;
|
|
98
|
+
let dps = {}; // 设备动作
|
|
99
|
+
// 白光模式 dp
|
|
100
|
+
if (length === brightLightLen) {
|
|
101
|
+
const bright_value = step(2).value;
|
|
102
|
+
const temp_value = step(2).value;
|
|
103
|
+
dps = {
|
|
104
|
+
[EDpCodes.bright_value]: bright_value,
|
|
105
|
+
[EDpCodes.temp_value]: temp_value
|
|
106
|
+
};
|
|
107
|
+
} else if (length === colourLightLen) {
|
|
108
|
+
// 彩光模式dp
|
|
109
|
+
const hue = step(4).value;
|
|
110
|
+
const saturation = step(2).value;
|
|
111
|
+
const _value = step(2).value;
|
|
112
|
+
dps = {
|
|
113
|
+
[EDpCodes.colour_data]: {
|
|
114
|
+
hue,
|
|
115
|
+
saturation,
|
|
116
|
+
value: _value
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
} else if (length === mixLightLen) {
|
|
120
|
+
// 混光模式
|
|
121
|
+
const hue = step(4).value;
|
|
122
|
+
const saturation = step(2).value;
|
|
123
|
+
const _value = step(2).value;
|
|
124
|
+
const bright_value = step(2).value;
|
|
125
|
+
const temp_value = step(2).value;
|
|
126
|
+
dps = {
|
|
127
|
+
[EDpCodes.colour_data]: {
|
|
128
|
+
hue,
|
|
129
|
+
saturation,
|
|
130
|
+
value: _value
|
|
131
|
+
},
|
|
132
|
+
[EDpCodes.bright_value]: bright_value,
|
|
133
|
+
[EDpCodes.temp_value]: temp_value
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
// 开关灯模式
|
|
137
|
+
// 开灯
|
|
138
|
+
// 01
|
|
139
|
+
const startDpDataInt = step(2).value;
|
|
140
|
+
const startDpDataHex = this.to16(startDpDataInt, 2);
|
|
141
|
+
const switch_led = startDpDataHex.slice(0, 2) === '01';
|
|
142
|
+
dps = {
|
|
143
|
+
[EDpCodes.switch_led]: switch_led
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
timerId: `${timerId}`,
|
|
148
|
+
status,
|
|
149
|
+
loops,
|
|
150
|
+
time: minuteToTime(time),
|
|
151
|
+
dps
|
|
143
152
|
};
|
|
144
153
|
}
|
|
154
|
+
|
|
155
|
+
// 删除时 dp 数据
|
|
156
|
+
const id = step(2).value;
|
|
157
|
+
const idBinaryStr = numToBinStrPad8(id);
|
|
158
|
+
const status = idBinaryStr.slice(0, 1) === '1';
|
|
159
|
+
const timerId = parseInt(idBinaryStr.slice(1), 2);
|
|
145
160
|
return {
|
|
146
161
|
timerId: `${timerId}`,
|
|
147
|
-
status
|
|
148
|
-
loops,
|
|
149
|
-
time: minuteToTime(time),
|
|
150
|
-
dps
|
|
162
|
+
status
|
|
151
163
|
};
|
|
164
|
+
} catch (err) {
|
|
165
|
+
ScheduleLogger.error('RtcTimerFormatter parser fail:', RTC_TIMER, '=>', val, err);
|
|
166
|
+
return this.defaultValue;
|
|
152
167
|
}
|
|
153
|
-
|
|
154
|
-
// 删除时 dp 数据
|
|
155
|
-
const id = step(2).value;
|
|
156
|
-
const idBinaryStr = numToBinStrPad8(id);
|
|
157
|
-
const status = idBinaryStr.slice(0, 1) === '1';
|
|
158
|
-
const timerId = parseInt(idBinaryStr.slice(1), 2);
|
|
159
|
-
return {
|
|
160
|
-
timerId: `${timerId}`,
|
|
161
|
-
status
|
|
162
|
-
};
|
|
163
168
|
}
|
|
164
169
|
to16(value, length) {
|
|
165
170
|
return numToHexString(value, length);
|
|
166
171
|
}
|
|
167
172
|
formatter(data) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
173
|
+
try {
|
|
174
|
+
if (typeof data === 'string') {
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
// 自定义格式转为16进制
|
|
178
|
+
const {
|
|
179
|
+
timerId,
|
|
180
|
+
// 定时任务ID
|
|
181
|
+
status,
|
|
182
|
+
// type, // 定时类型,普通定时选择:0x01
|
|
183
|
+
loops,
|
|
184
|
+
// 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时,0 => 周日
|
|
185
|
+
// startTimeType, // 定时任务开始时间类型,0x00 => 固定时间
|
|
186
|
+
time,
|
|
187
|
+
dps
|
|
188
|
+
} = data;
|
|
189
|
+
ScheduleLogger.debug('rtcTimer formatter data:', data);
|
|
190
|
+
if (loops) {
|
|
191
|
+
const _dps = {};
|
|
192
|
+
Object.keys(dps).forEach(key => {
|
|
193
|
+
// eslint-disable-next-line no-self-compare
|
|
194
|
+
if (+key === +key) {
|
|
195
|
+
const dpCode = getDpCodeByDpId(key);
|
|
196
|
+
dpCode && (_dps[dpCode] = dps[key]);
|
|
197
|
+
} else {
|
|
198
|
+
_dps[key] = dps[key];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
const statusStr = status ? '1' : '0';
|
|
202
|
+
const timerIdStr = padStart(Number(timerId).toString(2), 7, '0');
|
|
203
|
+
const idStr = this.to16(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
|
|
204
|
+
const typeStr = this.to16('01', 2);
|
|
205
|
+
const repeatStr = this.to16(parseInt(loops.split('').reverse().join(''), 2), 2);
|
|
206
|
+
const startTimeTypeStr = this.to16('00', 2);
|
|
207
|
+
let timeNum = +time;
|
|
208
|
+
if (isNaN(time) && typeof time === 'string') {
|
|
209
|
+
const [min, second] = time === null || time === void 0 ? void 0 : time.split(':');
|
|
210
|
+
timeNum = +min * 60 + Number(second);
|
|
211
|
+
}
|
|
212
|
+
const startTimeStr = this.to16(timeNum, 4);
|
|
213
|
+
let dpDataStr;
|
|
214
|
+
/**
|
|
215
|
+
* ABCDEFG 7字节; A:设备动作;BCDEFG:动作参数;
|
|
216
|
+
* A=0x00,关灯,BCDEFG无效;
|
|
217
|
+
* A=0x01,开灯,BCDEFG无效;
|
|
218
|
+
* A=0x02,白光,B:亮度,1-100,C:色温,0-100,DEFG无效;
|
|
219
|
+
* A=0x03,彩光,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,0-100,FG无效;
|
|
220
|
+
* A=0x04,混光,RGBCW全亮,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,1-100,F:白光亮度,1-100,G:色温,0-100;
|
|
221
|
+
* A=0x05,情景,B:场景ID,0-15,CDEFG无效;
|
|
222
|
+
* A=0x06,节能,B:场景ID,0-15,C:节能开关,0-关,1-开,DEFG无效;
|
|
223
|
+
* A=0x07,太阳能,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,1-100,F:白光亮度,1-100,G:色温,0-100;
|
|
224
|
+
* A=0x08,执行定时前状态,BCDEFG无效;
|
|
225
|
+
*/
|
|
226
|
+
if (_dps[EDpCodes.switch_led] === false) {
|
|
227
|
+
dpDataStr = '00';
|
|
228
|
+
} else if (Object.keys(_dps).includes(EDpCodes.colour_data) && Object.keys(_dps).includes(EDpCodes.temp_value)) {
|
|
229
|
+
const bright_value = _dps[EDpCodes.bright_value];
|
|
230
|
+
const temp_value = _dps[EDpCodes.temp_value];
|
|
231
|
+
const {
|
|
232
|
+
hue,
|
|
233
|
+
saturation,
|
|
234
|
+
value
|
|
235
|
+
} = _dps[EDpCodes.colour_data];
|
|
236
|
+
const hueStr = this.to16(hue, 4);
|
|
237
|
+
const saturationStr = this.to16(saturation, 2);
|
|
238
|
+
const valueStr = this.to16(value, 2);
|
|
239
|
+
const brightStr = this.to16(bright_value, 2);
|
|
240
|
+
const tempStr = this.to16(temp_value, 2);
|
|
241
|
+
dpDataStr = `04${hueStr}${saturationStr}${valueStr}${brightStr}${tempStr}`;
|
|
242
|
+
} else if (Object.keys(_dps).includes(EDpCodes.colour_data)) {
|
|
243
|
+
const {
|
|
244
|
+
hue = 0,
|
|
245
|
+
saturation = 100,
|
|
246
|
+
value = 100
|
|
247
|
+
} = _dps[EDpCodes.colour_data];
|
|
248
|
+
const hueStr = this.to16(hue, 4);
|
|
249
|
+
const saturationStr = this.to16(saturation, 2);
|
|
250
|
+
const valueStr = this.to16(value, 2);
|
|
251
|
+
dpDataStr = `03${hueStr}${saturationStr}${valueStr}`;
|
|
252
|
+
} else if (Object.keys(_dps).includes(EDpCodes.bright_value)) {
|
|
253
|
+
var _dps$EDpCodes$bright_, _dps$EDpCodes$temp_va;
|
|
254
|
+
const bright_value = (_dps$EDpCodes$bright_ = _dps[EDpCodes.bright_value]) !== null && _dps$EDpCodes$bright_ !== void 0 ? _dps$EDpCodes$bright_ : 100;
|
|
255
|
+
const temp_value = (_dps$EDpCodes$temp_va = _dps[EDpCodes.temp_value]) !== null && _dps$EDpCodes$temp_va !== void 0 ? _dps$EDpCodes$temp_va : 0;
|
|
256
|
+
const brightStr = this.to16(bright_value, 2);
|
|
257
|
+
const temperatureStr = this.to16(temp_value, 2);
|
|
258
|
+
dpDataStr = `02${brightStr}${temperatureStr}`;
|
|
191
259
|
} else {
|
|
192
|
-
_dps[
|
|
260
|
+
const powerStr = _dps[EDpCodes.switch_led] ? '01' : '00';
|
|
261
|
+
dpDataStr = `${powerStr}`;
|
|
193
262
|
}
|
|
194
|
-
|
|
263
|
+
const _res = `${idStr}${typeStr}${repeatStr}${startTimeTypeStr}${startTimeStr}${dpDataStr}`;
|
|
264
|
+
ScheduleLogger.debug('rtcTimer formatter dpStr1:', dpDataStr);
|
|
265
|
+
ScheduleLogger.debug('rtcTimer formatter dpStr2:', _res);
|
|
266
|
+
return _res;
|
|
267
|
+
}
|
|
195
268
|
const statusStr = status ? '1' : '0';
|
|
196
269
|
const timerIdStr = padStart(Number(timerId).toString(2), 7, '0');
|
|
197
270
|
const idStr = this.to16(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
const startTimeTypeStr = this.to16('00', 2);
|
|
201
|
-
let timeNum = +time;
|
|
202
|
-
if (isNaN(time) && typeof time === 'string') {
|
|
203
|
-
const [min, second] = time === null || time === void 0 ? void 0 : time.split(':');
|
|
204
|
-
timeNum = +min * 60 + Number(second);
|
|
205
|
-
}
|
|
206
|
-
const startTimeStr = this.to16(timeNum, 4);
|
|
207
|
-
let dpDataStr;
|
|
208
|
-
/**
|
|
209
|
-
* ABCDEFG 7字节; A:设备动作;BCDEFG:动作参数;
|
|
210
|
-
* A=0x00,关灯,BCDEFG无效;
|
|
211
|
-
* A=0x01,开灯,BCDEFG无效;
|
|
212
|
-
* A=0x02,白光,B:亮度,1-100,C:色温,0-100,DEFG无效;
|
|
213
|
-
* A=0x03,彩光,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,0-100,FG无效;
|
|
214
|
-
* A=0x04,混光,RGBCW全亮,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,1-100,F:白光亮度,1-100,G:色温,0-100;
|
|
215
|
-
* A=0x05,情景,B:场景ID,0-15,CDEFG无效;
|
|
216
|
-
* A=0x06,节能,B:场景ID,0-15,C:节能开关,0-关,1-开,DEFG无效;
|
|
217
|
-
* A=0x07,太阳能,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,1-100,F:白光亮度,1-100,G:色温,0-100;
|
|
218
|
-
* A=0x08,执行定时前状态,BCDEFG无效;
|
|
219
|
-
*/
|
|
220
|
-
if (_dps[EDpCodes.switch_led] === false) {
|
|
221
|
-
dpDataStr = '00';
|
|
222
|
-
} else if (Object.keys(_dps).includes(EDpCodes.colour_data) && Object.keys(_dps).includes(EDpCodes.temp_value)) {
|
|
223
|
-
const bright_value = _dps[EDpCodes.bright_value];
|
|
224
|
-
const temp_value = _dps[EDpCodes.temp_value];
|
|
225
|
-
const {
|
|
226
|
-
hue,
|
|
227
|
-
saturation,
|
|
228
|
-
value
|
|
229
|
-
} = _dps[EDpCodes.colour_data];
|
|
230
|
-
const hueStr = this.to16(hue, 4);
|
|
231
|
-
const saturationStr = this.to16(saturation, 2);
|
|
232
|
-
const valueStr = this.to16(value, 2);
|
|
233
|
-
const brightStr = this.to16(bright_value, 2);
|
|
234
|
-
const tempStr = this.to16(temp_value, 2);
|
|
235
|
-
dpDataStr = `04${hueStr}${saturationStr}${valueStr}${brightStr}${tempStr}`;
|
|
236
|
-
} else if (Object.keys(_dps).includes(EDpCodes.colour_data)) {
|
|
237
|
-
const {
|
|
238
|
-
hue = 0,
|
|
239
|
-
saturation = 100,
|
|
240
|
-
value = 100
|
|
241
|
-
} = _dps[EDpCodes.colour_data];
|
|
242
|
-
const hueStr = this.to16(hue, 4);
|
|
243
|
-
const saturationStr = this.to16(saturation, 2);
|
|
244
|
-
const valueStr = this.to16(value, 2);
|
|
245
|
-
dpDataStr = `03${hueStr}${saturationStr}${valueStr}`;
|
|
246
|
-
} else if (Object.keys(_dps).includes(EDpCodes.bright_value)) {
|
|
247
|
-
var _dps$EDpCodes$bright_, _dps$EDpCodes$temp_va;
|
|
248
|
-
const bright_value = (_dps$EDpCodes$bright_ = _dps[EDpCodes.bright_value]) !== null && _dps$EDpCodes$bright_ !== void 0 ? _dps$EDpCodes$bright_ : 100;
|
|
249
|
-
const temp_value = (_dps$EDpCodes$temp_va = _dps[EDpCodes.temp_value]) !== null && _dps$EDpCodes$temp_va !== void 0 ? _dps$EDpCodes$temp_va : 0;
|
|
250
|
-
const brightStr = this.to16(bright_value, 2);
|
|
251
|
-
const temperatureStr = this.to16(temp_value, 2);
|
|
252
|
-
dpDataStr = `02${brightStr}${temperatureStr}`;
|
|
253
|
-
} else {
|
|
254
|
-
const powerStr = _dps[EDpCodes.switch_led] ? '01' : '00';
|
|
255
|
-
dpDataStr = `${powerStr}`;
|
|
256
|
-
}
|
|
257
|
-
const _res = `${idStr}${typeStr}${repeatStr}${startTimeTypeStr}${startTimeStr}${dpDataStr}`;
|
|
258
|
-
ScheduleLogger.debug('rtcTimer formatter dpStr1:', dpDataStr);
|
|
259
|
-
ScheduleLogger.debug('rtcTimer formatter dpStr2:', _res);
|
|
271
|
+
const _res = `${idStr}00`;
|
|
272
|
+
ScheduleLogger.debug('rtcTimer remove formatter2 data:', _res);
|
|
260
273
|
return _res;
|
|
274
|
+
} catch (error) {
|
|
275
|
+
ScheduleLogger.error('rtcTimer formatter error', error);
|
|
276
|
+
return '';
|
|
261
277
|
}
|
|
262
|
-
const statusStr = status ? '1' : '0';
|
|
263
|
-
const timerIdStr = padStart(Number(timerId).toString(2), 7, '0');
|
|
264
|
-
const idStr = this.to16(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
|
|
265
|
-
const _res = `${idStr}00`;
|
|
266
|
-
ScheduleLogger.debug('rtcTimer remove formatter2 data:', _res);
|
|
267
|
-
return _res;
|
|
268
278
|
}
|
|
269
279
|
}
|
|
270
280
|
export const rtcTimerParser = new RtcTimerFormatter();
|
|
@@ -17,101 +17,98 @@ export class Sleep {
|
|
|
17
17
|
nodes: []
|
|
18
18
|
};
|
|
19
19
|
parser(dpStr) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
try {
|
|
21
|
+
scheduleLogger.debug('Sleep parser dpStr: ', dpStr);
|
|
22
|
+
if (!dpStr) {
|
|
23
|
+
return this.defaultValue;
|
|
24
|
+
}
|
|
25
|
+
const dpLength = dpStr.length;
|
|
26
|
+
if (!dpLength || (dpLength - 4) % 22 !== 0) {
|
|
27
|
+
scheduleLogger.error('数据有问题,无法解析');
|
|
28
|
+
return this.defaultValue;
|
|
29
|
+
}
|
|
30
|
+
const step = generateDpStrStep(dpStr);
|
|
31
|
+
const version = step(2).value;
|
|
32
|
+
let length = step(2).value;
|
|
33
|
+
length = Math.min(length, 4);
|
|
34
|
+
const nodes = [];
|
|
35
|
+
// 解析循环节点
|
|
36
|
+
for (let i = 0; i < length; i++) {
|
|
37
|
+
const onOff = !!step(2).value;
|
|
38
|
+
const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
|
|
39
|
+
const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
|
|
40
|
+
const stepNum = step(2).value;
|
|
41
|
+
const hour = step(2).value;
|
|
42
|
+
const minute = step(2).value;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
// 解析色相值(组合百位和十个位)
|
|
45
|
+
const hundreds = step(2).value;
|
|
46
|
+
const tensOnes = step(2).value;
|
|
47
|
+
const saturation = step(2).value;
|
|
48
|
+
const val = step(2).value;
|
|
49
|
+
const brightness = step(2).value;
|
|
50
|
+
const temperatureStep = step(2);
|
|
51
|
+
const temperature = temperatureStep.value;
|
|
52
|
+
nodes.push({
|
|
53
|
+
onOff,
|
|
54
|
+
loops,
|
|
55
|
+
step: stepNum,
|
|
56
|
+
hour,
|
|
57
|
+
minute,
|
|
58
|
+
hue: Math.round(hundreds * 100 + tensOnes),
|
|
59
|
+
// 0-360
|
|
60
|
+
saturation,
|
|
61
|
+
value: val,
|
|
62
|
+
brightness,
|
|
63
|
+
temperature,
|
|
64
|
+
index: i
|
|
65
|
+
});
|
|
66
|
+
if (temperatureStep.done) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
67
69
|
}
|
|
70
|
+
return {
|
|
71
|
+
version,
|
|
72
|
+
length,
|
|
73
|
+
nodes
|
|
74
|
+
};
|
|
75
|
+
} catch (error) {
|
|
76
|
+
scheduleLogger.error('Sleep parser error', error);
|
|
77
|
+
return this.defaultValue;
|
|
68
78
|
}
|
|
69
|
-
return {
|
|
70
|
-
version,
|
|
71
|
-
length,
|
|
72
|
-
nodes
|
|
73
|
-
};
|
|
74
79
|
}
|
|
75
80
|
formatter(data) {
|
|
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
|
-
|
|
81
|
+
try {
|
|
82
|
+
var _data$nodes, _data$nodes2;
|
|
83
|
+
const result = [numToHexString(data.version), numToHexString((_data$nodes = data.nodes) === null || _data$nodes === void 0 ? void 0 : _data$nodes.length)];
|
|
84
|
+
scheduleLogger.debug('sleep formatter data', data);
|
|
85
|
+
data === null || data === void 0 || (_data$nodes2 = data.nodes) === null || _data$nodes2 === void 0 || _data$nodes2.forEach(node => {
|
|
86
|
+
// 拆分色相值为百位和十个位
|
|
87
|
+
const hueHundreds = Math.floor(node.hue / 100);
|
|
88
|
+
const hueTensOnes = node.hue % 100;
|
|
89
|
+
const {
|
|
90
|
+
saturation,
|
|
91
|
+
value,
|
|
92
|
+
brightness,
|
|
93
|
+
temperature
|
|
94
|
+
} = node;
|
|
95
|
+
let saturation1 = node.saturation;
|
|
96
|
+
let value1 = node.value;
|
|
97
|
+
let brightness1 = node.brightness;
|
|
98
|
+
let temperature1 = node.temperature;
|
|
99
|
+
if (saturation === 0 && value === 0 && brightness === 0 && temperature === 0) {
|
|
100
|
+
saturation1 = defaultColor.saturation;
|
|
101
|
+
value1 = defaultColor.value;
|
|
102
|
+
brightness1 = defaultColor.brightness;
|
|
103
|
+
temperature1 = defaultColor.temperature;
|
|
104
|
+
}
|
|
105
|
+
result.push(numToHexString(node.onOff ? 1 : 0), numToHexString(parseInt(node.loops.split('').reverse().join(''), 2), 2), numToHexString(node.step), numToHexString(node.hour), numToHexString(node.minute), numToHexString(hueHundreds), numToHexString(hueTensOnes), numToHexString(saturation1), numToHexString(value1), numToHexString(brightness1), numToHexString(temperature1));
|
|
106
|
+
});
|
|
107
|
+
return result.join('');
|
|
108
|
+
} catch (error) {
|
|
109
|
+
scheduleLogger.error('sleep formatter error', error);
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
113
|
}
|
|
104
|
-
export const sleepParser = new Sleep();
|
|
105
|
-
|
|
106
|
-
// if (isInIDEFun()) {
|
|
107
|
-
// // 使用示例
|
|
108
|
-
// const dpStr = '00 01 01 42 01 0b 15 00 00 00 00 00'.replaceAll(' ', '');
|
|
109
|
-
// const result = sleepParser.parser(dpStr);
|
|
110
|
-
// const formatted = sleepParser.formatter(result);
|
|
111
|
-
// console.log(result, 'resultresult');
|
|
112
|
-
// console.log(formatted, 'formattedformatted');
|
|
113
|
-
// console.log(dpStr, 'dpStrdpStr');
|
|
114
|
-
// if (formatted !== dpStr) {
|
|
115
|
-
// throw new Error('sleep dp format error');
|
|
116
|
-
// }
|
|
117
|
-
// }
|
|
114
|
+
export const sleepParser = new Sleep();
|