...
|
...
|
@@ -185,14 +185,14 @@ export let stopInventory = function(connector) { |
|
|
let isStop = false;
|
|
|
|
|
|
export let start = function(options, callback) {
|
|
|
var rets = [];
|
|
|
var countMap = {};
|
|
|
var lastRets = [],
|
|
|
rets = [],
|
|
|
goneRets = [];
|
|
|
open(options.host, options.port, function(err, connector) {
|
|
|
if (!options.filter || !options.frequencys || !options.inventoryTime || !options.power || !options.antStayTime) {
|
|
|
let error = new Error('Error:灵敏度,定频,盘点时长,功率必须要传!');
|
|
|
callback(error);
|
|
|
}
|
|
|
|
|
|
//开启灵敏度过滤
|
|
|
setFilter(connector, options.filter);
|
|
|
//设置天线驻留时长
|
...
|
...
|
@@ -215,11 +215,23 @@ export let start = function(options, callback) { |
|
|
|
|
|
connector.on('startInventory', function(data) {
|
|
|
if (data.code !== 2 && !isStop) {
|
|
|
|
|
|
if (lastRets.length === 0) {
|
|
|
lastRets = rets;
|
|
|
} else {
|
|
|
var compResults = compTags(lastRets, rets, goneRets);
|
|
|
lastRets = compResults.last;
|
|
|
goneRets = compResults.gone;
|
|
|
}
|
|
|
|
|
|
callback(connector.connected, rets, goneRets);
|
|
|
|
|
|
rets = [];
|
|
|
goneRets = [];
|
|
|
startInventory(connector);
|
|
|
} else if (data.code === 2) {
|
|
|
rets = procTagInfo(countMap, rets, data.data);
|
|
|
rets = procTagInfo(rets, data.data, options.group, options.host);
|
|
|
}
|
|
|
callback(null, rets);
|
|
|
});
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -234,37 +246,77 @@ export let stop = function() { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 当前盘点到的标签与上次标签对比函数
|
|
|
* @param {Array} lastRets 上次盘点结果集
|
|
|
* @param {Array} rets 盘点结果集
|
|
|
* @param {Array} goneRets 离架标签结果集
|
|
|
* @return {Object} result 包含上次盘点结果集和离架标签结果集的对象
|
|
|
*/
|
|
|
function compTags(lastRets, rets, goneRets) {
|
|
|
var result = {
|
|
|
last: [],
|
|
|
gone: []
|
|
|
};
|
|
|
|
|
|
for (var i = 0; i < lastRets.length; i++) {
|
|
|
var item = lastRets[i];
|
|
|
var checkedItem = _.findWhere(rets, {
|
|
|
epc: item.epc
|
|
|
});
|
|
|
if (checkedItem === undefined) { // 上次盘点数据不包含在此次数据中
|
|
|
if (item.speed > 1)
|
|
|
goneRets.push(item);
|
|
|
} else {
|
|
|
lastRets[i] = checkedItem;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (var j = 0; j < rets.length; j++) {
|
|
|
var ele = rets[j];
|
|
|
if (!_.findWhere(lastRets, {
|
|
|
epc: ele.epc
|
|
|
})) {
|
|
|
lastRets.push(ele);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.last = lastRets;
|
|
|
result.gone = goneRets;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 标签处理
|
|
|
* @method procTagInfo
|
|
|
* @param {Object} countMap 标签读取的次数
|
|
|
* @param {Array} rets 盘点结果集
|
|
|
* @param {Object} data 读取一次的内容
|
|
|
* @param {Number} group 标签所属的群组
|
|
|
* @param {String} host 读写器IP
|
|
|
*/
|
|
|
function procTagInfo(countMap, rets, data) {
|
|
|
let isExist = false,
|
|
|
now = 1 * new Date();
|
|
|
for (var i = 0; i < rets.length; i++) {
|
|
|
for (var j = 0; j < data.length; j++) {
|
|
|
if (rets[i].epc === data[j].epc) {
|
|
|
rets[i].rssi = data[j].rssi;
|
|
|
rets[i].updateTime = now;
|
|
|
rets[i].state = 'on';
|
|
|
rets[i].ant = data[j].ant;
|
|
|
countMap[rets[i].epc] ++;
|
|
|
isExist = true;
|
|
|
}
|
|
|
function procTagInfo(rets, data, group, host) {
|
|
|
var now = 1 * new Date();
|
|
|
|
|
|
for (var j = 0; j < data.length; j++) {
|
|
|
var item = data[j];
|
|
|
var checkedItem = _.findWhere(rets, {
|
|
|
epc: item.epc
|
|
|
});
|
|
|
if (checkedItem === undefined) {
|
|
|
rets.push({
|
|
|
epc: item.epc,
|
|
|
rssi: item.rssi,
|
|
|
ant: item.ant,
|
|
|
group: group,
|
|
|
host: host,
|
|
|
speed: 1,
|
|
|
updateTime: now
|
|
|
});
|
|
|
} else {
|
|
|
checkedItem.speed++;
|
|
|
}
|
|
|
}
|
|
|
if (!isExist) {
|
|
|
_.map(data, function(item) {
|
|
|
item.updateTime = now;
|
|
|
item.state = 'on';
|
|
|
item.speed = 0;
|
|
|
countMap[item.epc] = 1;
|
|
|
});
|
|
|
|
|
|
rets = rets.concat(data);
|
|
|
}
|
|
|
return rets;
|
|
|
}
|
|
|
|
...
|
...
|
|