...
|
...
|
@@ -54,6 +54,17 @@ let config = new Config(); |
|
|
*/
|
|
|
let inventory = new Inventory();
|
|
|
|
|
|
import log4js from 'log4js';
|
|
|
|
|
|
let loger = log4js.getLogger('log');
|
|
|
loger.setLevel(config.logLevel); //配置日志
|
|
|
|
|
|
/**
|
|
|
* @mixes 日志记录对象
|
|
|
* @exports util/log
|
|
|
*/
|
|
|
export let log = loger;
|
|
|
|
|
|
/**
|
|
|
* 打开读写器
|
|
|
* @method open
|
...
|
...
|
@@ -83,6 +94,7 @@ export let open = function(host, port, callback) { |
|
|
callback(error);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -130,6 +142,42 @@ export let setFrequency = function(connector, param) { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置频率区域
|
|
|
* @method setFrequencyRegion
|
|
|
* @exports index/setFrequencyRegion
|
|
|
* @param {Connector} connector 连接器
|
|
|
* @param {Object} param 频率区域的值 eg: 0:FCC,1:CCC,2:NCC,3:JPN
|
|
|
*/
|
|
|
export let setFrequencyRegion = function(connector, param) {
|
|
|
config.send(connector, orders.setFrequencyRegion, param);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置速度模式
|
|
|
* @method setSpeedMode
|
|
|
* @exports index/setSpeedMode
|
|
|
* @param {Connector} connector 连接器
|
|
|
* @param {Object} param 速度模式的值 eg: 0:高速,1:正常速度,2:省电模式
|
|
|
*/
|
|
|
export let setSpeedMode = function(connector, param) {
|
|
|
config.send(connector, orders.setSpeedMode, param);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置标签组
|
|
|
* @method setTagGroup
|
|
|
* @exports index/setTagGroup
|
|
|
* @param {Connector} connector 连接器
|
|
|
* @param {Object} param 标签组的值 eg: {'session':0,'target':0,'search_mode':1}
|
|
|
* 其中session:0代表S0,1代表S1,2代表S2,3代表S3
|
|
|
* target:0代表A,1代表B
|
|
|
* search_mode:0代表DUAL_TARGET,1代表SINGLE_TARGET,2代表SINGLE_TARGET_WITH_SUPPRESSION
|
|
|
*/
|
|
|
export let setTagGroup = function(connector, param) {
|
|
|
config.send(connector, orders.setTagGroup, param);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置盘点时长
|
|
|
* @method setInventoryTime
|
|
|
* @exports index/setInventoryTime
|
...
|
...
|
@@ -147,6 +195,7 @@ export let setInventoryTime = function(connector, param) { |
|
|
* @param {Connector} connect 连接器
|
|
|
*/
|
|
|
export let startInventory = function(connector) {
|
|
|
|
|
|
inventory.send(connector, orders.startInventory);
|
|
|
};
|
|
|
|
...
|
...
|
@@ -183,28 +232,50 @@ export let stopInventory = function(connector) { |
|
|
});
|
|
|
*/
|
|
|
let isStop = false;
|
|
|
|
|
|
export let start = function(options, callback) {
|
|
|
var lastRets = [],
|
|
|
rets = [],
|
|
|
goneRets = [];
|
|
|
open(options.host, options.port, function(err, connector) {
|
|
|
if (!options.filter || !options.frequencys || !options.inventoryTime || !options.power || !options.antStayTime) {
|
|
|
if (!options.filter || !options.frequency || !options.inventoryTime || !options.power || !options.antStayTime) {
|
|
|
let error = new Error('Error:灵敏度,定频,盘点时长,功率必须要传!');
|
|
|
callback(error);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//开启灵敏度过滤
|
|
|
setFilter(connector, options.filter);
|
|
|
//设置天线驻留时长
|
|
|
setAntStayTime(connector, options.antStayTime);
|
|
|
connector.on('setFilter', function(data) {
|
|
|
setAntStayTime(connector, options.antStayTime);
|
|
|
});
|
|
|
//设置频率区域
|
|
|
connector.on('setAntStayTime', function(data) {
|
|
|
setFrequencyRegion(connector, 1); // 设置频率区域为CCC
|
|
|
});
|
|
|
//设置速度模式
|
|
|
connector.on('setFrequencyRegion', function(data) {
|
|
|
setSpeedMode(connector, 0); // 设置速度模式为高速
|
|
|
});
|
|
|
|
|
|
//设置标签组
|
|
|
connector.on('setSpeedMode', function(data) {
|
|
|
setTagGroup(connector, {'session':0,'target':0,'search_mode':1}); // 设置标签组:session:S0,target:A,search_mode:单目标
|
|
|
});
|
|
|
|
|
|
//开启固定频率
|
|
|
setFrequency(connector, options.frequency);
|
|
|
connector.on('setTagGroup', function(data) {
|
|
|
setFrequency(connector, options.frequency);
|
|
|
});
|
|
|
|
|
|
//设置盘点时长
|
|
|
setInventoryTime(connector, options.inventoryTime);
|
|
|
connector.on('setFrequency', function(data) {
|
|
|
setInventoryTime(connector, options.inventoryTime);
|
|
|
});
|
|
|
|
|
|
//设置功率
|
|
|
connector.on('setInventoryTime', function(data) {
|
|
|
|
|
|
setPower(connector, options.power);
|
|
|
});
|
|
|
|
...
|
...
|
@@ -216,6 +287,10 @@ export let start = function(options, callback) { |
|
|
connector.on('startInventory', function(data) {
|
|
|
if (data.code !== 2 && !isStop) {
|
|
|
|
|
|
rets = _.filter(rets, function(item){
|
|
|
return item.speed > 1;
|
|
|
});
|
|
|
|
|
|
if (lastRets.length === 0) {
|
|
|
lastRets = rets;
|
|
|
} else {
|
...
|
...
|
@@ -224,15 +299,17 @@ export let start = function(options, callback) { |
|
|
goneRets = compResults.gone;
|
|
|
}
|
|
|
|
|
|
callback(connector.connected, rets, goneRets);
|
|
|
callback(null, connector.connected, rets, goneRets);
|
|
|
|
|
|
rets = [];
|
|
|
goneRets = [];
|
|
|
startInventory(connector);
|
|
|
} else if (data.code === 2) {
|
|
|
|
|
|
rets = procTagInfo(rets, data.data, options.group, options.host);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -263,8 +340,9 @@ function compTags(lastRets, rets, goneRets) { |
|
|
var checkedItem = _.findWhere(rets, {
|
|
|
epc: item.epc
|
|
|
});
|
|
|
|
|
|
if (checkedItem === undefined) { // 上次盘点数据不包含在此次数据中
|
|
|
if (item.speed > 1)
|
|
|
if (item.speed > 2 || item.rssi > -60)
|
|
|
goneRets.push(item);
|
|
|
} else {
|
|
|
lastRets[i] = checkedItem;
|
...
|
...
|
@@ -339,6 +417,7 @@ function receive(client, data, err) { |
|
|
if (err) {
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
className = locateOrder(orders, data).val.directive;
|
|
|
|
|
|
switch (className) {
|
...
|
...
|
|