Authored by ZhouQiqi

恢复代码,修改package的开发gulp依赖

@@ -15,5 +15,12 @@ @@ -15,5 +15,12 @@
15 "test": "echo \"Error: no test specified\" && exit 1" 15 "test": "echo \"Error: no test specified\" && exit 1"
16 }, 16 },
17 "author": "", 17 "author": "",
18 - "license": "ISC" 18 + "license": "ISC",
  19 + "devDependencies": {
  20 + "gulp": "^3.8.11",
  21 + "gulp-babel": "^5.1.0",
  22 + "gulp-doxx": "0.0.4",
  23 + "gulp-jshint": "^1.10.0",
  24 + "jshint-stylish": "^1.0.2"
  25 + }
19 } 26 }
1 /** 1 /**
2 - * 调用入口  
3 - */  
4 -require("babel/register"); //es6 polyfill  
5 -var Connector = require('./lib/connector'); //socket connect  
6 -var orders = require('./lib/interface'); // order config  
7 -var Uhf = require('./lib/directive/uhf'); //uhf dirctive module  
8 -var Config = require('./lib/directive/config'); // config dirctive module  
9 -var Inventory = require('./lib/directive/inventory'); //inventory dirctive module 2 + * @fileOverview 调用入口
  3 + * @author qiqi.zhou@yoho.cn
  4 + */
  5 +//require("babel/register"); //es6 polyfill
  6 +
  7 +/**
  8 + * 连接器
  9 + * @type {Connector}
  10 + */
  11 +var Connector = require('./lib/connector');
  12 +/**
  13 + * order config
  14 + * @type {Object}
  15 + */
  16 +var orders = require('./lib/interface');
  17 +/**
  18 + * uhf dirctive module
  19 + * @type {Uhf}
  20 + */
  21 +var Uhf = require('./lib/directive/uhf');
  22 +/**
  23 + * config dirctive module
  24 + * @type {[Config]}
  25 + */
  26 +var Config = require('./lib/directive/config');
  27 +/**
  28 + * inventory dirctive module
  29 + * @type {Inventory}
  30 + */
  31 +var Inventory = require('./lib/directive/inventory');
  32 +
10 var _ = require('lodash'); 33 var _ = require('lodash');
11 var util = require('./lib/util'); 34 var util = require('./lib/util');
  35 +
12 var appConfig = require('./config'); 36 var appConfig = require('./config');
13 37
14 -//实例化指令模块 38 +/**
  39 + * 读写器初始化模块实例
  40 + * @type {Uhf}
  41 + */
15 var uhf = new Uhf(); 42 var uhf = new Uhf();
  43 +/**
  44 + * 配置读写器实例
  45 + * @type {Config}
  46 + */
16 var config = new Config(); 47 var config = new Config();
  48 +/**
  49 + * 读写器盘点实例
  50 + * @type {Inventory}
  51 + */
17 var inventory = new Inventory(); 52 var inventory = new Inventory();
18 53
19 /** 54 /**
20 * 打开读写器 55 * 打开读写器
  56 + * @method open
  57 + * @exports index/open
  58 + * @param {String} host 读写器IP
  59 + * @param {Number} port 端口
  60 + * @param {Function} callback 打开成功回调
21 */ 61 */
22 exports.open = function (host, port, callback) { 62 exports.open = function (host, port, callback) {
23 if (!host || !port) { 63 if (!host || !port) {
@@ -37,61 +77,104 @@ exports.open = function (host, port, callback) { @@ -37,61 +77,104 @@ exports.open = function (host, port, callback) {
37 callback(connector); 77 callback(connector);
38 } 78 }
39 }); 79 });
40 -  
41 - // 监听重连事件  
42 - connector.once('reconnect', function(){  
43 - setTimeout(function(){exports.open(host, port, callback);}, 5000);  
44 - });  
45 -} 80 +};
46 81
47 /** 82 /**
48 * 设置功率 83 * 设置功率
49 - * param array eg: [15,15,15,0] 84 + * @method setPower
  85 + * @exports index/setPower
  86 + * @param {Connector} connector 连接器
  87 + * @param {Array} 传参,依次是4个天线的功率 eg: [15,15,15,0]
50 */ 88 */
51 exports.setPower = function (connector, param) { 89 exports.setPower = function (connector, param) {
52 config.send(connector, orders.setPower, param); 90 config.send(connector, orders.setPower, param);
53 -} 91 +};
54 92
55 /** 93 /**
56 * 设置灵敏度筛选 94 * 设置灵敏度筛选
57 - * param object eg:{on:'1',rssi:-600} 95 + * @method setFilter
  96 + * @exports index/setFilter
  97 + * @param {Connector} connect 连接器
  98 + * param {Object} 是否开启灵敏度和灵敏度值 eg:{on:'1',rssi:-60}
58 */ 99 */
59 exports.setFilter = function (connector, param) { 100 exports.setFilter = function (connector, param) {
60 config.send(connector, orders.setFilter, param); 101 config.send(connector, orders.setFilter, param);
61 -} 102 +};
62 103
63 /** 104 /**
64 * 设置固定频率 105 * 设置固定频率
65 - * param object eg: {ant: 0, freq: 10 } 106 + * @method setFrequency
  107 + * @exports index/setFrequency
  108 + * @param {Connector} connector 连接器
  109 + * @param {Object} param 天线端口和定频的值 eg: {ant: 0, freq: 10 }
66 */ 110 */
67 exports.setFrequency = function (connector, param) { 111 exports.setFrequency = function (connector, param) {
68 config.send(connector, orders.setFrequency, param); 112 config.send(connector, orders.setFrequency, param);
69 -} 113 +};
70 114
71 /** 115 /**
72 * 设置盘点时长 116 * 设置盘点时长
73 - * param number eg: 400 117 + * @method setInventoryTime
  118 + * @exports index/setInventoryTime
  119 + * @param {Connector} connect 连接器
  120 + * @param {Number} param 时长,单位毫秒 eg: 400
74 */ 121 */
75 exports.setInventoryTime = function (connector, param) { 122 exports.setInventoryTime = function (connector, param) {
76 inventory.send(connector, orders.setInventoryTime, param); 123 inventory.send(connector, orders.setInventoryTime, param);
77 -} 124 +};
78 125
79 /** 126 /**
80 * 开始盘点 127 * 开始盘点
  128 + * @method sartInventory
  129 + * @exports index/sartInventory
  130 + * @param {Connector} connect 连接器
81 */ 131 */
82 exports.sartInventory = function (connector) { 132 exports.sartInventory = function (connector) {
83 inventory.send(connector, orders.sartInventory); 133 inventory.send(connector, orders.sartInventory);
84 -} 134 +};
85 135
86 /** 136 /**
87 * 结束盘点 137 * 结束盘点
  138 + * @method stopInventory
  139 + * @exports index/stopInventory
  140 + * @param {Connector} connector 连接器
88 */ 141 */
89 exports.stopInventory = function (connector) { 142 exports.stopInventory = function (connector) {
90 inventory.send(connector, orders.stopInventory); 143 inventory.send(connector, orders.stopInventory);
91 -} 144 +};
92 145
93 /** 146 /**
94 * 开始间歇盘点封装 147 * 开始间歇盘点封装
  148 + * @method start
  149 + * @exports index/start
  150 + * @param {Object} options 传入的配置参数
  151 + * @param {Function} callback 获取数据的回调
  152 + * @example:
  153 + exports.start({
  154 + host: '172.16.13.6',//IP
  155 + port: '9761',//端口
  156 + filter: {//设置灵敏度的过滤
  157 + 'on': '1',
  158 + rssi: -60
  159 + },
  160 + frequencys: [{//天线的定频
  161 + ant: 0,
  162 + freq: 10
  163 + }, {
  164 + ant: 1,
  165 + freq: 10
  166 + }, {
  167 + ant: 2,
  168 + freq: 10
  169 + }, {
  170 + ant: 3,
  171 + freq: 10
  172 + }],
  173 + inventoryTime: 400,//设置盘点时长
  174 + power: [15, 0, 0, 0]//功率设置
  175 + }, function (data) {
  176 + //console.log(data);
  177 + });
95 */ 178 */
96 var isStop = false, 179 var isStop = false,
97 checkInventoryFlag, 180 checkInventoryFlag,
@@ -131,14 +214,15 @@ exports.start = function (options, callback) { @@ -131,14 +214,15 @@ exports.start = function (options, callback) {
131 if (data.code !== 2 && !isStop) { 214 if (data.code !== 2 && !isStop) {
132 exports.sartInventory(connector); 215 exports.sartInventory(connector);
133 } else if (data.code === 2) { 216 } else if (data.code === 2) {
134 - rets = procTagInfo(options.group, countMap, rets, data.data); 217 + rets = procTagInfo(countMap, rets, data.data);
135 } 218 }
136 - callback(connector.connected, rets); 219 + callback(rets);
137 }); 220 });
138 221
139 checkInventoryFlag = setInterval(function () { //检查是否在架 222 checkInventoryFlag = setInterval(function () { //检查是否在架
140 for (var i = 0; i < rets.length; i++) { 223 for (var i = 0; i < rets.length; i++) {
141 - if (1 * new Date() - rets[i].updateTime > appConfig.offInventory) { 224 + var offTime = 1 * new Date() - rets[i].updateTime;
  225 + if (offTime > appConfig.offInventory) {
142 rets[i].state = 'off'; 226 rets[i].state = 'off';
143 rets[i].speed = 0; 227 rets[i].speed = 0;
144 } 228 }
@@ -148,27 +232,35 @@ exports.start = function (options, callback) { @@ -148,27 +232,35 @@ exports.start = function (options, callback) {
148 checkSpeedFlag = setInterval(function () { //检查读取速度(times/sec) 232 checkSpeedFlag = setInterval(function () { //检查读取速度(times/sec)
149 for (var i = 0; i < rets.length; i++) { 233 for (var i = 0; i < rets.length; i++) {
150 if (countMap[rets[i].epc]) { 234 if (countMap[rets[i].epc]) {
151 - rets[i].speed = Number(countMap[rets[i].epc]) / (appConfig.checkCount / 1000); 235 + var prevCount = Number(countMap[rets[i].epc]);
  236 + rets[i].speed = prevCount / (appConfig.checkCount / 1000);
152 countMap[rets[i].epc] = 0; 237 countMap[rets[i].epc] = 0;
153 } 238 }
154 } 239 }
155 }, appConfig.checkCount); 240 }, appConfig.checkCount);
156 }); 241 });
157 -} 242 +};
158 243
159 /** 244 /**
160 * 停止间歇盘点 245 * 停止间歇盘点
  246 + * @method stop
  247 + * @exports index/stop
  248 + * @param {Connector} connect 连接器
161 */ 249 */
162 exports.stop = function (connector) { 250 exports.stop = function (connector) {
163 isStop = true; 251 isStop = true;
164 clearInterval(checkInventoryFlag); 252 clearInterval(checkInventoryFlag);
165 clearInterval(checkSpeedFlag); 253 clearInterval(checkSpeedFlag);
166 -} 254 +};
167 255
168 /** 256 /**
169 * 标签处理 257 * 标签处理
  258 + * @method procTagInfo
  259 + * @param {Object} countMap 标签读取的次数
  260 + * @param {Array} rets 盘点结果集
  261 + * @param {Object} data 读取一次的内容
170 */ 262 */
171 -function procTagInfo(group, countMap, rets, data) { 263 +function procTagInfo(countMap, rets, data) {
172 var isExist = false, 264 var isExist = false,
173 now = 1 * new Date(); 265 now = 1 * new Date();
174 for (var i = 0; i < rets.length; i++) { 266 for (var i = 0; i < rets.length; i++) {
@@ -177,7 +269,6 @@ function procTagInfo(group, countMap, rets, data) { @@ -177,7 +269,6 @@ function procTagInfo(group, countMap, rets, data) {
177 rets[i].updateTime = now; 269 rets[i].updateTime = now;
178 rets[i].state = 'on'; 270 rets[i].state = 'on';
179 rets[i].ant = data.ant; 271 rets[i].ant = data.ant;
180 - rets[i].group = group;  
181 countMap[rets[i].epc] ++; 272 countMap[rets[i].epc] ++;
182 isExist = true; 273 isExist = true;
183 } 274 }
@@ -195,6 +286,9 @@ function procTagInfo(group, countMap, rets, data) { @@ -195,6 +286,9 @@ function procTagInfo(group, countMap, rets, data) {
195 286
196 /** 287 /**
197 * 接收数据处理 288 * 接收数据处理
  289 + * @method receive
  290 + * @param {Socket} client socket客户端
  291 + * @param {Object} data 接收到的数据
198 */ 292 */
199 function receive(client, data, err) { 293 function receive(client, data, err) {
200 var className = null, 294 var className = null,
@@ -219,32 +313,4 @@ function receive(client, data, err) { @@ -219,32 +313,4 @@ function receive(client, data, err) {
219 break; 313 break;
220 } 314 }
221 return ret; 315 return ret;
222 -}  
223 -  
224 -/*  
225 -exports.start({  
226 - host: '172.16.13.6',  
227 - port: '9761',  
228 - filter: {  
229 - 'on': '1',  
230 - rssi: -600  
231 - },  
232 - frequencys: [{  
233 - ant: 0,  
234 - freq: 10  
235 - }, {  
236 - ant: 1,  
237 - freq: 10  
238 - }, {  
239 - ant: 2,  
240 - freq: 10  
241 - }, {  
242 - ant: 3,  
243 - freq: 10  
244 - }],  
245 - inventoryTime: 400,  
246 - power: [15, 0, 0, 0],  
247 - 5  
248 -}, function (data) {  
249 - console.log(data);  
250 -});*/ 316 +}
1 /** 1 /**
2 - * 管理盘点 2 + * @fileOverview 管理盘点
  3 + * @author qiqi.zhou@yoho.cn
3 */ 4 */
4 import Base from './base'; 5 import Base from './base';
5 import _ from 'lodash'; 6 import _ from 'lodash';
@@ -10,7 +11,10 @@ from '../util'; @@ -10,7 +11,10 @@ from '../util';
10 import info from '../interface'; 11 import info from '../interface';
11 12
12 /** 13 /**
13 - * UHF 读写器的指令操作盘点 14 + * @class UHF 读写器的指令操作盘点
  15 + * @module lib/directive/Inventory
  16 + * @extends {Base}
  17 + * @member @see {@link Base}
14 */ 18 */
15 class Inventory extends Base { 19 class Inventory extends Base {
16 constructor() { 20 constructor() {
@@ -23,8 +27,10 @@ class Inventory extends Base { @@ -23,8 +27,10 @@ class Inventory extends Base {
23 } 27 }
24 28
25 /** 29 /**
26 - * 预处理设置读写器盘点时长  
27 - * param:1000 (读写时长,单位:ms) 30 + * @method preSetInventoryTime
  31 + * @description 预处理设置读写器盘点时长
  32 + * @param {Number} param 读写时长 eg .1000 (单位:ms)
  33 + * @return {String} 指令
28 */ 34 */
29 preSetInventoryTime(param) { 35 preSetInventoryTime(param) {
30 let time = tenToHex(param).toLocaleUpperCase(); 36 let time = tenToHex(param).toLocaleUpperCase();
@@ -33,13 +39,18 @@ class Inventory extends Base { @@ -33,13 +39,18 @@ class Inventory extends Base {
33 } 39 }
34 40
35 /** 41 /**
36 - * 获取读写器信息返回处理 42 + * @method start
  43 + * @description 获取读写器信息返回处理
  44 + * @param {Array} data 指令数组
  45 + * @param {Connector} client socket客户端
37 */ 46 */
38 start(data, client) { 47 start(data, client) {
39 let retData = {}, 48 let retData = {},
40 retKey, 49 retKey,
41 returnVal, 50 returnVal,
42 - retEpc; 51 + retEpc,
  52 + ip,
  53 + output;
43 54
44 //处理返回结果 55 //处理返回结果
45 if (data[1] !== '2') { 56 if (data[1] !== '2') {
@@ -55,16 +66,21 @@ class Inventory extends Base { @@ -55,16 +66,21 @@ class Inventory extends Base {
55 ant: Number(data[2]), 66 ant: Number(data[2]),
56 rssi: hexToTen(data[3] + data[4], true) / 10, 67 rssi: hexToTen(data[3] + data[4], true) / 10,
57 epc: retEpc.join('') 68 epc: retEpc.join('')
58 - } 69 + };
59 retKey = _.slice(data, 0, 1); 70 retKey = _.slice(data, 0, 1);
60 } else { 71 } else {
61 retKey = data; 72 retKey = data;
62 } 73 }
63 - returnVal = returnProc(retKey, client.remoteAddress, info.sartInventory.output); 74 + ip = client.remoteAddress;
  75 + output = info.sartInventory.output;
  76 + returnVal = returnProc(retKey, ip, output);
64 77
65 returnVal.data = retData; 78 returnVal.data = retData;
66 return returnVal; 79 return returnVal;
67 } 80 }
68 81
69 } 82 }
  83 +/**
  84 + * @exports lib/directive/Inventory
  85 + */
70 export default Inventory; 86 export default Inventory;