inventory.js
2.41 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
/**
* @fileOverview 管理盘点
* @author qiqi.zhou@yoho.cn
*/
import Base from './base';
import _ from 'lodash';
import {
log, returnProc, tenToHex, hexToTen
}
from '../util';
import info from '../interface';
/**
* @class UHF 读写器的指令操作盘点
* @module lib/directive/Inventory
* @extends {Base}
* @member @see {@link Base}
*/
class Inventory extends Base {
constructor() {
super(null);
let setInventoryTime = info.setInventoryTime.input;
this.reproc[setInventoryTime] = this.preSetInventoryTime;
this.proc = {
startInventory: this.start
};
}
/**
* @method preSetInventoryTime
* @description 预处理设置读写器盘点时长
* @param {Number} param 读写时长 eg .1000 (单位:ms)
* @return {String} 指令
*/
preSetInventoryTime(param) {
let time = tenToHex(param).toLocaleUpperCase();
time = _.padLeft(time, 8, '0');
return info.setInventoryTime.input + time;
}
/**
* @method start
* @description 获取读写器信息返回处理
* @param {Array} data 指令数组
* @param {Connector} client socket客户端
*/
start(data, client) {
let retData = [],
retKey,
returnVal,
retEpc,
ip,
output;
//处理返回结果
if (data[1] !== '2') {
var newdata = _.chunk(data, 17);
for(let l = 0; l < newdata.length; l++) {
let item = newdata[l];
for (let i = 0; i < item.length; i++) {
if (item[i].length < 2 && i > 2) {
item[i] = '0' + item[i];
}
}
retEpc = _.slice(item, 5);
retData.push({
ant: Number(item[2]),
rssi: hexToTen(item[3] + item[4], true) / 10,
epc: retEpc.join('')
});
retKey = _.slice(item, 0, 1);
}
} else {
retKey = data;
}
ip = client.remoteAddress;
output = info.startInventory.output;
returnVal = returnProc(retKey, ip, output);
returnVal.data = retData;
return returnVal;
}
}
/**
* @exports lib/directive/Inventory
*/
export default Inventory;