|
|
/**
|
|
|
* 调用入口
|
|
|
*/
|
|
|
require("babel/register"); //es6 polyfill
|
|
|
var Connector = require('./lib/connector'); //socket connect
|
|
|
var orders = require('./lib/interface'); // order config
|
|
|
var Uhf = require('./lib/directive/uhf'); //uhf dirctive module
|
|
|
var Config = require('./lib/directive/config'); // config dirctive module
|
|
|
var Inventory = require('./lib/directive/inventory'); //inventory dirctive module
|
|
|
* @fileOverview 调用入口
|
|
|
* @author qiqi.zhou@yoho.cn
|
|
|
*/
|
|
|
//require("babel/register"); //es6 polyfill
|
|
|
|
|
|
/**
|
|
|
* 连接器
|
|
|
* @type {Connector}
|
|
|
*/
|
|
|
var Connector = require('./lib/connector');
|
|
|
/**
|
|
|
* order config
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
var orders = require('./lib/interface');
|
|
|
/**
|
|
|
* uhf dirctive module
|
|
|
* @type {Uhf}
|
|
|
*/
|
|
|
var Uhf = require('./lib/directive/uhf');
|
|
|
/**
|
|
|
* config dirctive module
|
|
|
* @type {[Config]}
|
|
|
*/
|
|
|
var Config = require('./lib/directive/config');
|
|
|
/**
|
|
|
* inventory dirctive module
|
|
|
* @type {Inventory}
|
|
|
*/
|
|
|
var Inventory = require('./lib/directive/inventory');
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
var util = require('./lib/util');
|
|
|
|
|
|
var appConfig = require('./config');
|
|
|
|
|
|
//实例化指令模块
|
|
|
/**
|
|
|
* 读写器初始化模块实例
|
|
|
* @type {Uhf}
|
|
|
*/
|
|
|
var uhf = new Uhf();
|
|
|
/**
|
|
|
* 配置读写器实例
|
|
|
* @type {Config}
|
|
|
*/
|
|
|
var config = new Config();
|
|
|
/**
|
|
|
* 读写器盘点实例
|
|
|
* @type {Inventory}
|
|
|
*/
|
|
|
var inventory = new Inventory();
|
|
|
|
|
|
/**
|
|
|
* 打开读写器
|
|
|
* @method open
|
|
|
* @exports index/open
|
|
|
* @param {String} host 读写器IP
|
|
|
* @param {Number} port 端口
|
|
|
* @param {Function} callback 打开成功回调
|
|
|
*/
|
|
|
exports.open = function (host, port, callback) {
|
|
|
if (!host || !port) {
|
...
|
...
|
@@ -37,61 +77,104 @@ exports.open = function (host, port, callback) { |
|
|
callback(connector);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 监听重连事件
|
|
|
connector.once('reconnect', function(){
|
|
|
setTimeout(function(){exports.open(host, port, callback);}, 5000);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置功率
|
|
|
* param array eg: [15,15,15,0]
|
|
|
* @method setPower
|
|
|
* @exports index/setPower
|
|
|
* @param {Connector} connector 连接器
|
|
|
* @param {Array} 传参,依次是4个天线的功率 eg: [15,15,15,0]
|
|
|
*/
|
|
|
exports.setPower = function (connector, param) {
|
|
|
config.send(connector, orders.setPower, param);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置灵敏度筛选
|
|
|
* param object eg:{on:'1',rssi:-600}
|
|
|
* @method setFilter
|
|
|
* @exports index/setFilter
|
|
|
* @param {Connector} connect 连接器
|
|
|
* param {Object} 是否开启灵敏度和灵敏度值 eg:{on:'1',rssi:-60}
|
|
|
*/
|
|
|
exports.setFilter = function (connector, param) {
|
|
|
config.send(connector, orders.setFilter, param);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置固定频率
|
|
|
* param object eg: {ant: 0, freq: 10 }
|
|
|
* @method setFrequency
|
|
|
* @exports index/setFrequency
|
|
|
* @param {Connector} connector 连接器
|
|
|
* @param {Object} param 天线端口和定频的值 eg: {ant: 0, freq: 10 }
|
|
|
*/
|
|
|
exports.setFrequency = function (connector, param) {
|
|
|
config.send(connector, orders.setFrequency, param);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置盘点时长
|
|
|
* param number eg: 400
|
|
|
* @method setInventoryTime
|
|
|
* @exports index/setInventoryTime
|
|
|
* @param {Connector} connect 连接器
|
|
|
* @param {Number} param 时长,单位毫秒 eg: 400
|
|
|
*/
|
|
|
exports.setInventoryTime = function (connector, param) {
|
|
|
inventory.send(connector, orders.setInventoryTime, param);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 开始盘点
|
|
|
* @method sartInventory
|
|
|
* @exports index/sartInventory
|
|
|
* @param {Connector} connect 连接器
|
|
|
*/
|
|
|
exports.sartInventory = function (connector) {
|
|
|
inventory.send(connector, orders.sartInventory);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 结束盘点
|
|
|
* @method stopInventory
|
|
|
* @exports index/stopInventory
|
|
|
* @param {Connector} connector 连接器
|
|
|
*/
|
|
|
exports.stopInventory = function (connector) {
|
|
|
inventory.send(connector, orders.stopInventory);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 开始间歇盘点封装
|
|
|
* @method start
|
|
|
* @exports index/start
|
|
|
* @param {Object} options 传入的配置参数
|
|
|
* @param {Function} callback 获取数据的回调
|
|
|
* @example:
|
|
|
exports.start({
|
|
|
host: '172.16.13.6',//IP
|
|
|
port: '9761',//端口
|
|
|
filter: {//设置灵敏度的过滤
|
|
|
'on': '1',
|
|
|
rssi: -60
|
|
|
},
|
|
|
frequencys: [{//天线的定频
|
|
|
ant: 0,
|
|
|
freq: 10
|
|
|
}, {
|
|
|
ant: 1,
|
|
|
freq: 10
|
|
|
}, {
|
|
|
ant: 2,
|
|
|
freq: 10
|
|
|
}, {
|
|
|
ant: 3,
|
|
|
freq: 10
|
|
|
}],
|
|
|
inventoryTime: 400,//设置盘点时长
|
|
|
power: [15, 0, 0, 0]//功率设置
|
|
|
}, function (data) {
|
|
|
//console.log(data);
|
|
|
});
|
|
|
*/
|
|
|
var isStop = false,
|
|
|
checkInventoryFlag,
|
...
|
...
|
@@ -131,14 +214,15 @@ exports.start = function (options, callback) { |
|
|
if (data.code !== 2 && !isStop) {
|
|
|
exports.sartInventory(connector);
|
|
|
} else if (data.code === 2) {
|
|
|
rets = procTagInfo(options.group, countMap, rets, data.data);
|
|
|
rets = procTagInfo(countMap, rets, data.data);
|
|
|
}
|
|
|
callback(connector.connected, rets);
|
|
|
callback(rets);
|
|
|
});
|
|
|
|
|
|
checkInventoryFlag = setInterval(function () { //检查是否在架
|
|
|
for (var i = 0; i < rets.length; i++) {
|
|
|
if (1 * new Date() - rets[i].updateTime > appConfig.offInventory) {
|
|
|
var offTime = 1 * new Date() - rets[i].updateTime;
|
|
|
if (offTime > appConfig.offInventory) {
|
|
|
rets[i].state = 'off';
|
|
|
rets[i].speed = 0;
|
|
|
}
|
...
|
...
|
@@ -148,27 +232,35 @@ exports.start = function (options, callback) { |
|
|
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);
|
|
|
var prevCount = Number(countMap[rets[i].epc]);
|
|
|
rets[i].speed = prevCount / (appConfig.checkCount / 1000);
|
|
|
countMap[rets[i].epc] = 0;
|
|
|
}
|
|
|
}
|
|
|
}, appConfig.checkCount);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 停止间歇盘点
|
|
|
* @method stop
|
|
|
* @exports index/stop
|
|
|
* @param {Connector} connect 连接器
|
|
|
*/
|
|
|
exports.stop = function (connector) {
|
|
|
isStop = true;
|
|
|
clearInterval(checkInventoryFlag);
|
|
|
clearInterval(checkSpeedFlag);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 标签处理
|
|
|
* @method procTagInfo
|
|
|
* @param {Object} countMap 标签读取的次数
|
|
|
* @param {Array} rets 盘点结果集
|
|
|
* @param {Object} data 读取一次的内容
|
|
|
*/
|
|
|
function procTagInfo(group, countMap, rets, data) {
|
|
|
function procTagInfo(countMap, rets, data) {
|
|
|
var isExist = false,
|
|
|
now = 1 * new Date();
|
|
|
for (var i = 0; i < rets.length; i++) {
|
...
|
...
|
@@ -177,7 +269,6 @@ function procTagInfo(group, countMap, rets, data) { |
|
|
rets[i].updateTime = now;
|
|
|
rets[i].state = 'on';
|
|
|
rets[i].ant = data.ant;
|
|
|
rets[i].group = group;
|
|
|
countMap[rets[i].epc] ++;
|
|
|
isExist = true;
|
|
|
}
|
...
|
...
|
@@ -195,6 +286,9 @@ function procTagInfo(group, countMap, rets, data) { |
|
|
|
|
|
/**
|
|
|
* 接收数据处理
|
|
|
* @method receive
|
|
|
* @param {Socket} client socket客户端
|
|
|
* @param {Object} data 接收到的数据
|
|
|
*/
|
|
|
function receive(client, data, err) {
|
|
|
var className = null,
|
...
|
...
|
@@ -219,32 +313,4 @@ function receive(client, data, err) { |
|
|
break;
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
exports.start({
|
|
|
host: '172.16.13.6',
|
|
|
port: '9761',
|
|
|
filter: {
|
|
|
'on': '1',
|
|
|
rssi: -600
|
|
|
},
|
|
|
frequencys: [{
|
|
|
ant: 0,
|
|
|
freq: 10
|
|
|
}, {
|
|
|
ant: 1,
|
|
|
freq: 10
|
|
|
}, {
|
|
|
ant: 2,
|
|
|
freq: 10
|
|
|
}, {
|
|
|
ant: 3,
|
|
|
freq: 10
|
|
|
}],
|
|
|
inventoryTime: 400,
|
|
|
power: [15, 0, 0, 0],
|
|
|
5
|
|
|
}, function (data) {
|
|
|
console.log(data);
|
|
|
});*/ |
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|