Authored by Rock Zhang

修复读写器串扰的bug(由于定频设置错误导致的),并更新一部分测试代码

... ... @@ -8,21 +8,21 @@
* inventory_time: 盘点时间
*/
var readers = [
/*{
{
id: 1,
readerId: 1,
readerIp: '172.16.13.5',
readerIp: '172.16.13.6',
rssi: -60,
frequency: 912.75,
frequency: 43, // 912.75
stay_time: 200,
inventory_time: 500
},*/
},
{
id: 2,
readerId: 2,
readerIp: '172.16.13.82',
rssi: -60,
frequency: 922.75,
frequency: 47, // 922.75
stay_time: 200,
inventory_time: 500
},
... ... @@ -31,7 +31,7 @@ var readers = [
readerId: 3,
readerIp: '172.16.13.83',
rssi: -60,
frequency: 917.75,
frequency: 11, // 917.75
stay_time: 200,
inventory_time: 500
},
... ... @@ -40,7 +40,7 @@ var readers = [
readerId: 4,
readerIp: '172.16.13.84',
rssi: -60,
frequency: 922.75,
frequency: 47, // 922.75
stay_time: 200,
inventory_time: 500
},
... ... @@ -49,7 +49,7 @@ var readers = [
readerId: 5,
readerIp: '172.16.13.86',
rssi: -65,
frequency: 924.75,
frequency: 35, // 924.75
stay_time: 100,
inventory_time: 500
},
... ... @@ -58,7 +58,7 @@ var readers = [
readerId: 6,
readerIp: '172.16.13.87',
rssi: -65,
frequency: 925.75,
frequency: 42, // 925.75
stay_time: 100,
inventory_time: 500
},
... ... @@ -67,7 +67,7 @@ var readers = [
readerId: 7,
readerIp: '172.16.13.88',
rssi: -65,
frequency: 924.75,
frequency: 35, // 924.75
stay_time: 100,
inventory_time: 500
},
... ... @@ -76,7 +76,7 @@ var readers = [
readerId: 8,
readerIp: '172.16.13.89',
rssi: -60,
frequency: 922.75,
frequency: 47, // 922.75
stay_time: 200,
inventory_time: 500
},
... ... @@ -85,7 +85,7 @@ var readers = [
readerId: 9,
readerIp: '172.16.13.90',
rssi: -60,
frequency: 924.75,
frequency: 35, // 924.75
stay_time: 100,
inventory_time: 500
},
... ... @@ -94,7 +94,7 @@ var readers = [
readerId: 10,
readerIp: '172.16.13.91',
rssi: -60,
frequency: 923.25,
frequency: 49, // 923.25
stay_time: 200,
inventory_time: 500
},
... ... @@ -103,16 +103,7 @@ var readers = [
readerId: 11,
readerIp: '172.16.13.92',
rssi: -60,
frequency: 923.75,
stay_time: 100,
inventory_time: 500
},
{
id: 12,
readerId: 12,
readerIp: '172.16.13.6',
rssi: -60,
frequency: 923.75,
frequency: 40, // 923.75
stay_time: 100,
inventory_time: 500
}
... ... @@ -130,49 +121,49 @@ var ants = [
antId: 0,
readerId: 1,
groupId: 1,
nPower: 16
nPower: 18
},
{
id: 2,
antId: 3,
readerId: 1,
groupId: 1,
nPower: 16
nPower: 18
},
{
id: 3,
antId: 0,
readerId: 2,
groupId: 2,
nPower: 16
nPower: 18
},
{
id: 4,
antId: 3,
readerId: 2,
groupId: 2,
nPower: 16
nPower: 18
},
{
id: 5,
antId: 0,
readerId: 3,
groupId: 3,
nPower: 17
nPower: 19
},
{
id: 6,
antId: 3,
readerId: 3,
groupId: 3,
nPower: 18
nPower: 19
},
{
id: 7,
antId: 0,
readerId: 4,
groupId: 4,
nPower: 18
nPower: 17
},
{
id: 8,
... ...
... ... @@ -129,11 +129,10 @@ function connectAllReaders()
'on': '1',
rssi: reader.rssi
};
var frequency = 10;
// 初次连接最多连接5次
async.retry(5, function(cb, results){
connectReader(ip, 9761, filter, frequency, reader.inventory_time, reader.stay_time, reader.ants, reader.group, cb);
connectReader(ip, 9761, filter, reader.frequency, reader.inventory_time, reader.stay_time, reader.ants, reader.group, cb);
}, function(err, results){
if(err){
... ...
... ... @@ -287,9 +287,9 @@ export let start = function(options, callback) {
connector.on('startInventory', function(data) {
if (data.code !== 2 && !isStop) {
rets = _.filter(rets, function(item){
/*rets = _.filter(rets, function(item){
return item.speed > 1;
});
});*/
if (lastRets.length === 0) {
lastRets = rets;
... ...
... ... @@ -59,14 +59,6 @@ class Connector extends events.EventEmitter {
}
});
client.setTimeout(2000, function(){
// 读写器连接错误或者突然断开
this.connected = false;
// 触发重连事件
that.emit('reconnect', config);
});
//异常处理
client.on('error', function(error) {
log.error('错误:' + error.code);
... ... @@ -74,6 +66,19 @@ class Connector extends events.EventEmitter {
// 读写器连接错误或者突然断开
this.connected = false;
// 超时重连
client.setTimeout(6000, function(){
client.connect(config.port, config.host, function() {
that.connected = true;
log.info(config.host + ':' + config.port + ':读写器连接成功!');
send(that);
});
// 触发重连事件
//that.emit('reconnect', config);
});
client.destroy();
receive(client, null, error);
});
... ...
... ... @@ -40,7 +40,6 @@ class Base {
if (this.reproc[order.input]) {
sendOrder = this.reproc[order.input](param);
}
console.log(sendOrder);
connector.send(sendOrder);
let address = connector.client.remoteAddress;
//log.info('读写器(' + address + ')发送指令:' + sendOrder);
... ...
... ... @@ -85,11 +85,34 @@ describe('index.js', function() {
setRet(val);
let index = rewire("../../src")
let index = rewire("../../src");
index.__set__('setFilter', function() {});
index.__set__('setAntStayTime', function() {});
index.__set__('setFrequency', function() {});
index.__set__('setAntStayTime', function(connector, param) {
process.nextTick(function() {
connector.done('setAntStayTime', ret);
});
});
index.__set__('setFrequencyRegion', function(connector, param) {
process.nextTick(function() {
connector.done('setFrequencyRegion', ret);
});
});
index.__set__('setSpeedMode', function(connector, param) {
process.nextTick(function() {
connector.done('setSpeedMode', ret);
});
});
index.__set__('setTagGroup', function(connector, param) {
process.nextTick(function() {
connector.done('setTagGroup', ret);
});
});
index.__set__('setFrequency', function(connector, param) {
process.nextTick(function() {
connector.done('setFrequency', ret);
});
});
index.__set__('setInventoryTime', function(connector, param) {
process.nextTick(function() {
connector.done('setInventoryTime', ret);
... ...
... ... @@ -68,10 +68,10 @@ describe('util.js', function() {
expect(returnProc()).to.be(false);
});
it('returnProc input [1,2] 1.1.1.1 {"1":1} ', function() {
it('returnProc input [1,2] 1.1.1.1 {"1":1} expect {}', function() {
expect(returnProc([1, 2], "1.1.1.1", {
"1": 1
})).to.be(false);
})).to.eql({});
});
it('returnProc input ["0", "1"], "1.1.1.1", {"01": {"message": "test","hex": "01"}}', function() {
... ...
... ... @@ -14,6 +14,10 @@ class FakeSocket extends events.EventEmitter {
this.addEmit('data', data);
}
setTimeout(time, callback) {
callback();
}
addEmit(ev, data) {
let that = this;
process.nextTick(function() {
... ...