uhf.js
2.46 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
/**
* @fileOverview 读写器模块类
* @author qiqi.zhou@yoho.cn
*/
import Base from './base';
import _ from 'lodash';
import {
log, returnProc
}
from '../util';
import info from '../interface';
/**
* @class UHF 读写器的指令操作上
* @extends {Base}
* @member @see {@link Base}
*/
class Uhf extends Base {
constructor() {
super(null);
this.proc = {
getConfig: this.getConfig,
getVersion: this.getVersion
};
}
/**
* @method getConfig
* @description 获取读写器信息返回处理
* @param {Array} data 返回的指令数组
* @param {Socket} client socket客户端
* @return {Object} 标准输出
*/
getConfig(data, client) {
let region = ['FCC', 'CCC', 'NCC', 'JPN'],
power = [],
retData = {},
retKey = null,
returnVal = null,
ip,
output;
for (let val of _.slice(data, 2, 4)) {
power.push(parseInt(val, 16));
}
//处理返回结果
if (data[1] === '16') {
retData = {
power: power,
region: region[Number(data[6])],
speedMode: Number(data[7]),
invTime: parseInt(_.slice(data, 8, 12).join(''), 16),
invCount: data[12]
};
retKey = _.slice(data, 0, 2);
} else {
retKey = data;
}
ip = client.remoteAddress;
output = info.getConfig.output;
returnVal = returnProc(retKey, ip, output);
returnVal.data = retData;
return returnVal;
}
/**
* @method getVersion
* @description 获取版本返回处理
* @param {Array} data 返回指令数组
* @param {Socket} client socket连接客户端
* @return {Object} 标准输出
*/
getVersion(data, client) {
let retData = null,
retKey = _.slice(data, 0, 4),
ip = client.remoteAddress,
output = info.getVersion.output;
let returnVal = returnProc(retKey, ip, output);
if (data[2] === '0' && data[3] === '0') {
returnVal.data = {
majorVersion: parseInt(data[4], 16),
minorVersion: parseInt(data[5], 16)
};
}
return returnVal;
}
}
/**
* @exports lib/directive/Uhf
*/
export default Uhf;