inventory.js
1.66 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
/**
* 管理盘点
*/
import Base from './base';
import _ from 'lodash';
import {
log, returnProc, tenToHex, hexToTen
}
from '../util';
import info from '../interface';
/**
* UHF 读写器的指令操作盘点
*/
class Inventory extends Base {
constructor() {
super(null);
let setInventoryTime = info.setInventoryTime.input;
this.reproc[setInventoryTime] = this.preSetInventoryTime;
this.proc = {
sartInventory: this.start
};
}
/**
* 预处理设置读写器盘点时长
* param:1000 (读写时长,单位:ms)
*/
preSetInventoryTime(param) {
let time = tenToHex(param).toLocaleUpperCase();
time = _.padLeft(time, 8, '0');
return info.setInventoryTime.input + time;
}
/**
* 获取读写器信息返回处理
*/
start(data, client) {
let retData = {},
retKey,
returnVal,
retEpc;
//处理返回结果
if (data[1] !== '2') {
for (let i = 0; i < data.length; i++) {
if (data[i].length < 2 && i > 2) {
data[i] = '0' + data[i];
}
}
retEpc = _.slice(data, 5);
retData = {
ant: Number(data[2]),
rssi: hexToTen(data[3] + data[4], true) / 10,
epc: retEpc.join('')
}
retKey = _.slice(data, 0, 1);
} else {
retKey = data;
}
returnVal = returnProc(retKey, client.remoteAddress, info.sartInventory.output);
returnVal.data = retData;
return returnVal;
}
}
export default Inventory;