Authored by 周奇琪

添加速率计算

... ... @@ -5,5 +5,6 @@ export default {
log: './log',
logLevel: 'INFO',
checkInventory: 200,
offInventory: 500
offInventory: 500,
checkCount: 1000
};
\ No newline at end of file
... ...
... ... @@ -88,9 +88,12 @@ exports.stopInventory = function (connector) {
/**
* 开始间歇盘点封装
*/
var isStop = false;
var isStop = false,
checkInventoryFlag,
checkSpeedFlag;
exports.start = function (options, callback) {
var rets = [];
var countMap = {};
exports.open(options.host, options.port, function (connector) {
if (options.filter) { //开启灵敏度过滤
... ... @@ -123,18 +126,28 @@ exports.start = function (options, callback) {
if (data.code !== 2 && !isStop) {
exports.sartInventory(connector);
} else if (data.code === 2) {
rets = procTagInfo(rets, data.data);
rets = procTagInfo(countMap, rets, data.data);
}
callback(rets);
});
setInterval(function () {
checkInventoryFlag = setInterval(function () { //检查是否在架
for (var i = 0; i < rets.length; i++) {
if (1 * new Date() - rets[i].updateTime > appConfig.offInventory) {
rets[i].state = 'off';
rets[i].speed = 0;
}
}
}, appConfig.checkInventory)
}, appConfig.checkInventory);
checkSpeedFlag = setInterval(function () { //检查读取速度(times/sec)
for (var i = 0; i < rets.length; i++) {
if (countMap[rets[i].epc]) {
rets[i].speed = Number(countMap[rets[i].epc]) / (appConfig.checkCount / 1000);
countMap[rets[i].epc] = 0;
}
}
}, appConfig.checkCount);
});
}
... ... @@ -143,25 +156,31 @@ exports.start = function (options, callback) {
*/
exports.stop = function (connector) {
isStop = true;
clearInterval(checkInventoryFlag);
clearInterval(checkSpeedFlag);
}
/**
* 标签处理
*/
function procTagInfo(rets, data) {
function procTagInfo(countMap, rets, data) {
var isExist = false,
now = 1 * new Date();
for (var i = 0; i < rets.length; i++) {
if (rets[i].epc === data.epc && rets[i].ant === data.ant) {
if (rets[i].epc === data.epc) {
rets[i].rssi = data.rssi;
rets[i].updateTime = now;
rets[i].state = 'on';
rets[i].ant = data.ant;
countMap[rets[i].epc] ++;
isExist = true;
}
}
if (!isExist) {
data.updateTime = now;
data.state = 'on';
data.speed = 0;
countMap[data.epc] = 1;
rets.push(data);
}
return rets;
... ...
... ... @@ -4,14 +4,14 @@
"description": "rfid uhf sdk",
"main": "index.js",
"dependencies": {
"async": "0.2.x",
"log4js": "0.6.x",
"lodash":"3.6.x",
"pm2":"~0.12.3"
"babel": "~5.1.9",
"log4js": "0.6.x",
"lodash": "3.6.x",
"pm2": "~0.12.3"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
}
\ No newline at end of file
... ...