|
@@ -88,9 +88,12 @@ exports.stopInventory = function (connector) { |
|
@@ -88,9 +88,12 @@ exports.stopInventory = function (connector) { |
88
|
/**
|
88
|
/**
|
89
|
* 开始间歇盘点封装
|
89
|
* 开始间歇盘点封装
|
90
|
*/
|
90
|
*/
|
91
|
-var isStop = false;
|
91
|
+var isStop = false,
|
|
|
92
|
+ checkInventoryFlag,
|
|
|
93
|
+ checkSpeedFlag;
|
92
|
exports.start = function (options, callback) {
|
94
|
exports.start = function (options, callback) {
|
93
|
var rets = [];
|
95
|
var rets = [];
|
|
|
96
|
+ var countMap = {};
|
94
|
exports.open(options.host, options.port, function (connector) {
|
97
|
exports.open(options.host, options.port, function (connector) {
|
95
|
|
98
|
|
96
|
if (options.filter) { //开启灵敏度过滤
|
99
|
if (options.filter) { //开启灵敏度过滤
|
|
@@ -123,18 +126,28 @@ exports.start = function (options, callback) { |
|
@@ -123,18 +126,28 @@ exports.start = function (options, callback) { |
123
|
if (data.code !== 2 && !isStop) {
|
126
|
if (data.code !== 2 && !isStop) {
|
124
|
exports.sartInventory(connector);
|
127
|
exports.sartInventory(connector);
|
125
|
} else if (data.code === 2) {
|
128
|
} else if (data.code === 2) {
|
126
|
- rets = procTagInfo(rets, data.data);
|
129
|
+ rets = procTagInfo(countMap, rets, data.data);
|
127
|
}
|
130
|
}
|
128
|
callback(rets);
|
131
|
callback(rets);
|
129
|
});
|
132
|
});
|
130
|
|
133
|
|
131
|
- setInterval(function () {
|
134
|
+ checkInventoryFlag = setInterval(function () { //检查是否在架
|
132
|
for (var i = 0; i < rets.length; i++) {
|
135
|
for (var i = 0; i < rets.length; i++) {
|
133
|
if (1 * new Date() - rets[i].updateTime > appConfig.offInventory) {
|
136
|
if (1 * new Date() - rets[i].updateTime > appConfig.offInventory) {
|
134
|
rets[i].state = 'off';
|
137
|
rets[i].state = 'off';
|
|
|
138
|
+ rets[i].speed = 0;
|
135
|
}
|
139
|
}
|
136
|
}
|
140
|
}
|
137
|
- }, appConfig.checkInventory)
|
141
|
+ }, appConfig.checkInventory);
|
|
|
142
|
+
|
|
|
143
|
+ checkSpeedFlag = setInterval(function () { //检查读取速度(times/sec)
|
|
|
144
|
+ for (var i = 0; i < rets.length; i++) {
|
|
|
145
|
+ if (countMap[rets[i].epc]) {
|
|
|
146
|
+ rets[i].speed = Number(countMap[rets[i].epc]) / (appConfig.checkCount / 1000);
|
|
|
147
|
+ countMap[rets[i].epc] = 0;
|
|
|
148
|
+ }
|
|
|
149
|
+ }
|
|
|
150
|
+ }, appConfig.checkCount);
|
138
|
});
|
151
|
});
|
139
|
}
|
152
|
}
|
140
|
|
153
|
|
|
@@ -143,25 +156,31 @@ exports.start = function (options, callback) { |
|
@@ -143,25 +156,31 @@ exports.start = function (options, callback) { |
143
|
*/
|
156
|
*/
|
144
|
exports.stop = function (connector) {
|
157
|
exports.stop = function (connector) {
|
145
|
isStop = true;
|
158
|
isStop = true;
|
|
|
159
|
+ clearInterval(checkInventoryFlag);
|
|
|
160
|
+ clearInterval(checkSpeedFlag);
|
146
|
}
|
161
|
}
|
147
|
|
162
|
|
148
|
/**
|
163
|
/**
|
149
|
* 标签处理
|
164
|
* 标签处理
|
150
|
*/
|
165
|
*/
|
151
|
-function procTagInfo(rets, data) {
|
166
|
+function procTagInfo(countMap, rets, data) {
|
152
|
var isExist = false,
|
167
|
var isExist = false,
|
153
|
now = 1 * new Date();
|
168
|
now = 1 * new Date();
|
154
|
for (var i = 0; i < rets.length; i++) {
|
169
|
for (var i = 0; i < rets.length; i++) {
|
155
|
- if (rets[i].epc === data.epc && rets[i].ant === data.ant) {
|
170
|
+ if (rets[i].epc === data.epc) {
|
156
|
rets[i].rssi = data.rssi;
|
171
|
rets[i].rssi = data.rssi;
|
157
|
rets[i].updateTime = now;
|
172
|
rets[i].updateTime = now;
|
158
|
rets[i].state = 'on';
|
173
|
rets[i].state = 'on';
|
|
|
174
|
+ rets[i].ant = data.ant;
|
|
|
175
|
+ countMap[rets[i].epc] ++;
|
159
|
isExist = true;
|
176
|
isExist = true;
|
160
|
}
|
177
|
}
|
161
|
}
|
178
|
}
|
162
|
if (!isExist) {
|
179
|
if (!isExist) {
|
163
|
data.updateTime = now;
|
180
|
data.updateTime = now;
|
164
|
data.state = 'on';
|
181
|
data.state = 'on';
|
|
|
182
|
+ data.speed = 0;
|
|
|
183
|
+ countMap[data.epc] = 1;
|
165
|
rets.push(data);
|
184
|
rets.push(data);
|
166
|
}
|
185
|
}
|
167
|
return rets;
|
186
|
return rets;
|