Authored by Rock Zhang

修改在架和离架标签的判定逻辑,另外修复盘点返回标签数据的处理bug

... ... @@ -8,7 +8,7 @@
* inventory_time: 盘点时间
*/
var readers = [
/*{
{
id: 1,
readerId: 1,
readerIp: '172.16.13.5',
... ... @@ -106,7 +106,7 @@ var readers = [
frequency: 923.75,
stay_time: 100,
inventory_time: 500
},*/
}/*,
{
id: 12,
readerId: 12,
... ... @@ -115,7 +115,7 @@ var readers = [
frequency: 923.75,
stay_time: 100,
inventory_time: 500
}
}*/
];
/**
* 读写器天线数据
... ... @@ -334,14 +334,14 @@ var ants = [
readerId: 11,
groupId: 8,
nPower: 15
},
}/*,
{
id: 31,
antId: 0,
readerId: 12,
groupId: 12,
nPower: 15
}
}*/
];
// 获取读写器配置
... ...
... ... @@ -81,7 +81,7 @@ function main()
_.forEach(epcs, function(tagData){
if(tagData && getMillTimeDiffNow(tagData.updateTime) < 30000)
{
console.log('groupId:%s ------- %s', tagData.group, tagData.EPC);
console.log('groupId:%s ------- %s', tagData.GroupID, tagData.EPC);
tags.push(tagData);
}
});
... ... @@ -129,23 +129,11 @@ function connectAllReaders()
'on': '1',
rssi: reader.rssi*10
};
var frequencys = [{
ant: 0,
freq: 10
},{
ant: 1,
freq: 10
},{
ant: 2,
freq: 10
},{
ant: 3,
freq: 10
}];
var frequency = 10;
// 初次连接最多连接5次
async.retry(5, function(cb, results){
connectReader(ip, 9761, filter, frequencys, reader.inventory_time, reader.ants, reader.group, cb);
connectReader(ip, 9761, filter, frequency, reader.inventory_time, reader.stay_time, reader.ants, reader.group, cb);
}, function(err, results){
if(err){
... ... @@ -161,23 +149,26 @@ function connectAllReaders()
* @param host 读写器的的IP
* @param port 读写器的的端口
* @param filter 读写器的RSSI过滤有关数据
* @param frequencys 读写器的定频有关数据
* @param frequency 读写器的定频有关数据
* @param inventoryTime 盘点时间
* @param antStayTime 天线驻留时间
* @param power 各天线的功率
* @param group 读写器所在组
* @param callback 回调函数
*/
function connectReader(host, port, filter, frequencys, inventoryTime, power, group, callback)
function connectReader(host, port, filter, frequency, inventoryTime, antStayTime, power, group, callback)
{
index.start({
host: host,
port: port,
filter: filter,
frequencys: frequencys,
frequency: frequency,
inventoryTime: inventoryTime,
antStayTime: antStayTime,
power: power,
group: group
}, function (connected, dat) {
//console.log(dat);
var onEpcs = [],
offEpcs = [],
redisEpcs = [];
... ... @@ -204,7 +195,7 @@ function connectReader(host, port, filter, frequencys, inventoryTime, power, gro
_.forEach(dat, function(item){
if(item.state == 'on' && !_.findWhere(redisEpcs, {EPC: item.epc}))
if(item.state == 'on' && item.speed > 2 && !_.findWhere(redisEpcs, {EPC: item.epc}))
{
onEpcs.push({
EPC: item.epc,
... ... @@ -213,7 +204,7 @@ function connectReader(host, port, filter, frequencys, inventoryTime, power, gro
});
}
if(item.state == 'off' && item.speed > 1 && !_.findWhere(redisEpcs, {EPC: item.epc}))
if(item.state == 'off' && !_.findWhere(redisEpcs, {EPC: item.epc}))
{
offEpcs.push({
EPC: item.epc,
... ... @@ -263,7 +254,7 @@ function getCommand(data)
}
var params = {};
if(data.Key != 12345)
if(data.Key != '123456')
{
params.commandType = 'error';
return params;
... ...
... ... @@ -2,7 +2,7 @@
* @fileOverview 调用入口
* @author qiqi.zhou@yoho.cn
*/
//require("babel/register"); //es6 polyfill
require("babel/register"); //es6 polyfill
/**
* 连接器
... ... @@ -102,11 +102,22 @@ exports.setFilter = function (connector, param) {
};
/**
* 设置天线驻留时长
* @method setAntStayTime
* @exports index/setAntStayTime
* @param {Connector} connect 连接器
* @param {Number} param 时长,单位毫秒 eg: 100
*/
exports.setAntStayTime = function (connector, param) {
config.send(connector, orders.setAntStayTime, param);
};
/**
* 设置固定频率
* @method setFrequency
* @exports index/setFrequency
* @param {Connector} connector 连接器
* @param {Object} param 天线端口和定频的值 eg: {ant: 0, freq: 10 }
* @param {Object} param 天线端口和定频的值 eg: 10
*/
exports.setFrequency = function (connector, param) {
config.send(connector, orders.setFrequency, param);
... ... @@ -157,20 +168,9 @@ exports.stopInventory = function (connector) {
'on': '1',
rssi: -60
},
frequencys: [{//天线的定频
ant: 0,
freq: 10
}, {
ant: 1,
freq: 10
}, {
ant: 2,
freq: 10
}, {
ant: 3,
freq: 10
}],
frequencys: 10, //天线的定频
inventoryTime: 400,//设置盘点时长
antStayTime: 100,//设置天线驻留时长
power: [15, 0, 0, 0]//功率设置
}, function (data) {
//console.log(data);
... ... @@ -188,10 +188,12 @@ exports.start = function (options, callback) {
exports.setFilter(connector, options.filter);
}
if (options.frequencys) { //开启固定频率
_.forIn(options.frequencys, function (val, key) {
exports.setFrequency(connector, val);
});
if (options.antStayTime) { //设置天线驻留时长
exports.setAntStayTime(connector, options.antStayTime);
}
if (options.frequency) { //开启固定频率
exports.setFrequency(connector, options.frequency);
}
if (options.inventoryTime) { //设置盘点时长
... ... @@ -210,13 +212,12 @@ exports.start = function (options, callback) {
});
connector.on('sartInventory', function (data) {
//console.log(data.code);
if (data.code !== 2 && !isStop) {
exports.sartInventory(connector);
} else if (data.code === 2) {
rets = procTagInfo(countMap, rets, data.data);
}
callback(rets);
callback(connector.connected, rets);
});
checkInventoryFlag = setInterval(function () { //检查是否在架
... ... @@ -264,21 +265,26 @@ 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].rssi = data.rssi;
rets[i].updateTime = now;
rets[i].state = 'on';
rets[i].ant = data.ant;
countMap[rets[i].epc] ++;
isExist = true;
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;
}
}
}
if (!isExist) {
data.updateTime = now;
data.state = 'on';
data.speed = 0;
countMap[data.epc] = 1;
rets.push(data);
_.map(data, function(item){
item.updateTime = now;
item.state = 'on';
item.speed = 0;
countMap[item.epc] = 1;
});
rets = rets.concat(data);
}
return rets;
}
... ... @@ -313,4 +319,4 @@ function receive(client, data, err) {
break;
}
return ret;
}
\ No newline at end of file
}
... ...
... ... @@ -42,7 +42,7 @@ class Base {
}
connector.send(sendOrder);
let address = connector.client.remoteAddress;
log.info('读写器(' + address + ')发送指令:' + sendOrder);
//log.info('读写器(' + address + ')发送指令:' + sendOrder);
}
/**
... ... @@ -61,7 +61,7 @@ class Base {
return;
}
log.info('读写器(' + client.remoteAddress + ')接收指令:' + data.join(' '));
//log.info('读写器(' + client.remoteAddress + ')接收指令:' + data.join(' '));
//读取命令配置
order = locateOrder(orders, data);
... ...
... ... @@ -27,10 +27,12 @@ class Config extends Base {
let power = info.setPower.input,
filter = info.setFilter.input,
stayTime = info.setAntStayTime.input,
frequency = info.setFrequency.input;
this.reproc[power] = this.prePower;
this.reproc[filter] = this.preFilter;
this.reproc[stayTime] = this.preStayTime;
this.reproc[frequency] = this.preFrequency;
}
... ... @@ -64,6 +66,18 @@ class Config extends Base {
}
/**
* @method preStayTime
* @description 设置天线驻留时间预处理
* @param {Object} param param 读写时长 eg 100 (单位:ms)
* @return {String} 指令
*/
preStayTime(param) {
let time = tenToHex(param).toLocaleUpperCase();
time = _.padLeft(time, 8, '0');
return info.setAntStayTime.input + time;
}
/**
* @method preFrequency
* @description 设置频率预处理
0 915.75
... ... @@ -119,10 +133,9 @@ class Config extends Base {
* @param {Number} param ant标示天线的端口,freq标示频率(使用枚举值)
*/
preFrequency(param) {
let ant = param.ant < 10 ? ('0' + param.ant) : param.ant,
freq = tenToHex(param.freq).toLocaleUpperCase();
let freq = tenToHex(param).toLocaleUpperCase();
freq = freq.length < 2 ? ('0' + freq) : freq;
return info.setFrequency.input + ant + '0000' + freq;
return info.setFrequency.input + freq + '000000';
}
}
/**
... ...
... ... @@ -45,7 +45,7 @@ class Inventory extends Base {
* @param {Connector} client socket客户端
*/
start(data, client) {
let retData = {},
let retData = [],
retKey,
returnVal,
retEpc,
... ... @@ -54,20 +54,24 @@ class Inventory extends Base {
//处理返回结果
if (data[1] !== '2') {
for (let i = 0; i < data.length; i++) {
if (data[i].length < 2 && i > 2) {
data[i] = '0' + data[i];
var newdata = _.chunk(data, 17);
for(let l = 0; l < newdata.length; l++) {
let data = newdata[l];
for (let i = 0; i < data.length; i++) {
if (data[i].length < 2 && i > 2) {
data[i] = '0' + data[i];
}
}
}
retEpc = _.slice(data, 5);
retEpc = _.slice(data, 5);
retData = {
ant: Number(data[2]),
rssi: hexToTen(data[3] + data[4], true) / 10,
epc: retEpc.join('')
};
retKey = _.slice(data, 0, 1);
retData.push({
ant: Number(data[2]),
rssi: hexToTen(data[3] + data[4], true) / 10,
epc: retEpc.join('')
});
retKey = _.slice(data, 0, 1);
}
} else {
retKey = data;
}
... ...
... ... @@ -71,6 +71,16 @@ export default {
'b72ff0': commonMessage.ff0
}
},
setAntStayTime: {
directive: 'config',
input: 'CA',
output: {
'ca200': commonMessage['00'],
'ca2ffff': commonMessage.ffff,
'ca2fffe': commonMessage.fffe,
'ca2ff0': commonMessage.ff0
}
},
setFrequency: {
directive: 'config',
input: 'BF',
... ... @@ -118,6 +128,10 @@ export default {
'f1239': {
code: 889,
message: '未知错误'
},
'f12014': {
code: 890,
message: '连接失败'
}
}
... ...
... ... @@ -78,7 +78,7 @@ export let returnProc = function (data, ip, output) {
if (!output[ret]) {
return false;
}
log.info("读写器(" + ip + ")返回:" + output[ret].message + " 返回码:" + ret);
//log.info("读写器(" + ip + ")返回:" + output[ret].message + " 返回码:" + ret);
output[ret].hex = data;
return output[ret];
};
... ...