Skip to content

Commit 3a017aa

Browse files
fix(vs370): missing function (readResultStatus)
1 parent 75bacc1 commit 3a017aa

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

VS_Series/VS370/VS370_Decoder.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Decoder(bytes, port) {
2626
function milesightDeviceDecode(bytes) {
2727
var decoded = {};
2828

29-
for (var i = 0; i < bytes.length;) {
29+
for (var i = 0; i < bytes.length; ) {
3030
var channel_id = bytes[i++];
3131
var channel_type = bytes[i++];
3232

@@ -102,7 +102,6 @@ function milesightDeviceDecode(bytes) {
102102
return decoded;
103103
}
104104

105-
106105
function handle_downlink_response(channel_type, bytes, offset) {
107106
var decoded = {};
108107

@@ -203,10 +202,12 @@ function handle_downlink_response_ext(code, channel_type, bytes, offset) {
203202
offset += 1;
204203

205204
if (result_value !== 0) {
205+
var request = decoded;
206206
decoded = {};
207207
decoded.device_response_result = {};
208208
decoded.device_response_result.channel_type = channel_type;
209-
decoded.device_response_result.result = readResultStatus(bytes[offset]);
209+
decoded.device_response_result.result = readResultStatus(result_value);
210+
decoded.device_response_result.request = request;
210211
}
211212
}
212213

@@ -217,6 +218,11 @@ function hasResultFlag(code) {
217218
return code === 0xf8;
218219
}
219220

221+
function readResultStatus(status) {
222+
var status_map = { 0: "success", 1: "forbidden", 2: "invalid parameter" };
223+
return getValue(status_map, status);
224+
}
225+
220226
function readProtocolVersion(bytes) {
221227
var major = (bytes & 0xf0) >> 4;
222228
var minor = bytes & 0x0f;
@@ -324,12 +330,12 @@ function readDstConfig(bytes) {
324330
if (enable_value === 1) {
325331
dst_config.start_month = readMonth(bytes[offset + 2]);
326332
var start_week_value = bytes[offset + 3];
327-
dst_config.start_week_num = (start_week_value >> 4);
333+
dst_config.start_week_num = start_week_value >> 4;
328334
dst_config.start_week_day = readWeek(start_week_value & 0x0f);
329335
dst_config.start_time = readUInt16LE(bytes.slice(offset + 4, offset + 6));
330336
dst_config.end_month = readMonth(bytes[offset + 6]);
331337
var end_week_value = bytes[offset + 7];
332-
dst_config.end_week_num = (end_week_value >> 4);
338+
dst_config.end_week_num = end_week_value >> 4;
333339
dst_config.end_week_day = readWeek(end_week_value & 0x0f);
334340
dst_config.end_time = readUInt16LE(bytes.slice(offset + 8, offset + 10));
335341
}
@@ -464,4 +470,4 @@ if (!Object.assign) {
464470
return to;
465471
},
466472
});
467-
}
473+
}

0 commit comments

Comments
 (0)