修复读写器设置的bug,原因是异步发送多条设置指令时,返回的结果指令会拼接到一起,而拆分函数处理时存在bug
Showing
12 changed files
with
265 additions
and
36 deletions
@@ -11,6 +11,10 @@ title: 读写器的SDK | @@ -11,6 +11,10 @@ title: 读写器的SDK | ||
11 | * 打开读写器(A0 00 00 00 00) | 11 | * 打开读写器(A0 00 00 00 00) |
12 | * 关闭读写器(A1 00 00 00 00) | 12 | * 关闭读写器(A1 00 00 00 00) |
13 | * 设置功率(F3 10 00 00 00) | 13 | * 设置功率(F3 10 00 00 00) |
14 | +* 设置频率区域(F5 00 00 00 00) | ||
15 | +* 设置速度模式(FA 00 00 00 00) | ||
16 | +* 设置标签组(B6 00 00 00 00) | ||
17 | +* 设置天线驻留时长(CA 00 00 00 00) | ||
14 | * 设置定频(BF 00 00 00 00) | 18 | * 设置定频(BF 00 00 00 00) |
15 | * 获取配置(B3 00 00 00 00) | 19 | * 获取配置(B3 00 00 00 00) |
16 | * 开始盘点(F1 00 00 00 00) | 20 | * 开始盘点(F1 00 00 00 00) |
@@ -107,4 +111,5 @@ sdk.start({ | @@ -107,4 +111,5 @@ sdk.start({ | ||
107 | 111 | ||
108 | 1. 对于多个返回结果的拆分(已解决) | 112 | 1. 对于多个返回结果的拆分(已解决) |
109 | 2. 设置定频,没有起作用(待验证) | 113 | 2. 设置定频,没有起作用(待验证) |
110 | -3. socket连接异常处理 | ||
114 | +3. socket连接异常处理 | ||
115 | +4. 读写器有时会返回不到盘点的标签数据 |
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | * inventory_time: 盘点时间 | 8 | * inventory_time: 盘点时间 |
9 | */ | 9 | */ |
10 | var readers = [ | 10 | var readers = [ |
11 | - { | 11 | + /*{ |
12 | id: 1, | 12 | id: 1, |
13 | readerId: 1, | 13 | readerId: 1, |
14 | readerIp: '172.16.13.5', | 14 | readerIp: '172.16.13.5', |
@@ -16,7 +16,7 @@ var readers = [ | @@ -16,7 +16,7 @@ var readers = [ | ||
16 | frequency: 912.75, | 16 | frequency: 912.75, |
17 | stay_time: 200, | 17 | stay_time: 200, |
18 | inventory_time: 500 | 18 | inventory_time: 500 |
19 | - }, | 19 | + },*/ |
20 | { | 20 | { |
21 | id: 2, | 21 | id: 2, |
22 | readerId: 2, | 22 | readerId: 2, |
@@ -48,7 +48,7 @@ var readers = [ | @@ -48,7 +48,7 @@ var readers = [ | ||
48 | id: 5, | 48 | id: 5, |
49 | readerId: 5, | 49 | readerId: 5, |
50 | readerIp: '172.16.13.86', | 50 | readerIp: '172.16.13.86', |
51 | - rssi: -75, | 51 | + rssi: -65, |
52 | frequency: 924.75, | 52 | frequency: 924.75, |
53 | stay_time: 100, | 53 | stay_time: 100, |
54 | inventory_time: 500 | 54 | inventory_time: 500 |
@@ -106,7 +106,7 @@ var readers = [ | @@ -106,7 +106,7 @@ var readers = [ | ||
106 | frequency: 923.75, | 106 | frequency: 923.75, |
107 | stay_time: 100, | 107 | stay_time: 100, |
108 | inventory_time: 500 | 108 | inventory_time: 500 |
109 | - }/*, | 109 | + }, |
110 | { | 110 | { |
111 | id: 12, | 111 | id: 12, |
112 | readerId: 12, | 112 | readerId: 12, |
@@ -115,7 +115,7 @@ var readers = [ | @@ -115,7 +115,7 @@ var readers = [ | ||
115 | frequency: 923.75, | 115 | frequency: 923.75, |
116 | stay_time: 100, | 116 | stay_time: 100, |
117 | inventory_time: 500 | 117 | inventory_time: 500 |
118 | - }*/ | 118 | + } |
119 | ]; | 119 | ]; |
120 | /** | 120 | /** |
121 | * 读写器天线数据 | 121 | * 读写器天线数据 |
@@ -2,7 +2,7 @@ var net = require('net'), | @@ -2,7 +2,7 @@ var net = require('net'), | ||
2 | redis = require('redis'), | 2 | redis = require('redis'), |
3 | _ = require('lodash'), | 3 | _ = require('lodash'), |
4 | async = require('async'), | 4 | async = require('async'), |
5 | - index = require('../src/index.js'), | 5 | + index = require('../index.js'), |
6 | readerConfig = require('./readerConfig.js'); | 6 | readerConfig = require('./readerConfig.js'); |
7 | 7 | ||
8 | var r = redis.createClient(); | 8 | var r = redis.createClient(); |
@@ -127,7 +127,7 @@ function connectAllReaders() | @@ -127,7 +127,7 @@ function connectAllReaders() | ||
127 | var reader = readers[ip]; | 127 | var reader = readers[ip]; |
128 | var filter = { | 128 | var filter = { |
129 | 'on': '1', | 129 | 'on': '1', |
130 | - rssi: reader.rssi*10 | 130 | + rssi: reader.rssi |
131 | }; | 131 | }; |
132 | var frequency = 10; | 132 | var frequency = 10; |
133 | 133 | ||
@@ -167,7 +167,7 @@ function connectReader(host, port, filter, frequency, inventoryTime, antStayTime | @@ -167,7 +167,7 @@ function connectReader(host, port, filter, frequency, inventoryTime, antStayTime | ||
167 | antStayTime: antStayTime, | 167 | antStayTime: antStayTime, |
168 | power: power, | 168 | power: power, |
169 | group: group | 169 | group: group |
170 | - }, function (connected, onTags, goneTags) { | 170 | + }, function (err, connected, onTags, goneTags) { |
171 | 171 | ||
172 | var onEpcs = [], | 172 | var onEpcs = [], |
173 | offEpcs = []; | 173 | offEpcs = []; |
@@ -184,37 +184,38 @@ function connectReader(host, port, filter, frequency, inventoryTime, antStayTime | @@ -184,37 +184,38 @@ function connectReader(host, port, filter, frequency, inventoryTime, antStayTime | ||
184 | try | 184 | try |
185 | { | 185 | { |
186 | var redisEpcs = JSON.parse(epcs); | 186 | var redisEpcs = JSON.parse(epcs); |
187 | - | ||
188 | // 处理在架标签 | 187 | // 处理在架标签 |
189 | _.forEach(redisEpcs, function(item){ | 188 | _.forEach(redisEpcs, function(item){ |
190 | - if(item.speed > 2 && item.host != host && _.findWhere(onTags, {epc: item.epc}) === undefined){ | ||
191 | - onEpcs.push({ | ||
192 | - GroupID: item.group, | ||
193 | - EPC: item.epc, | ||
194 | - updateTime: item.updateTime | ||
195 | - }); | 189 | + if(item.host != host && _.findWhere(onTags, {epc: item.epc}) === undefined){ |
190 | + onEpcs.push(item); | ||
196 | } | 191 | } |
197 | }); | 192 | }); |
198 | _.forEach(onTags, function(item){ | 193 | _.forEach(onTags, function(item){ |
199 | onEpcs.push({ | 194 | onEpcs.push({ |
200 | GroupID: item.group, | 195 | GroupID: item.group, |
201 | EPC: item.epc, | 196 | EPC: item.epc, |
197 | + host: item.host, | ||
198 | + speed: item.speed, | ||
202 | updateTime: item.updateTime | 199 | updateTime: item.updateTime |
203 | }); | 200 | }); |
204 | }); | 201 | }); |
205 | 202 | ||
203 | + r.hset(group, 'on', JSON.stringify(onEpcs), function(){}); | ||
204 | + | ||
206 | // 处理离架标签 | 205 | // 处理离架标签 |
207 | _.forEach(goneTags, function(goneEpc){ | 206 | _.forEach(goneTags, function(goneEpc){ |
208 | - if(!goneEpc || _.findWhere(redisEpcs, {epc: goneEpc.epc}) === undefined){ | 207 | + if(!goneEpc || (_.findWhere(redisEpcs, {EPC: goneEpc.epc}) === undefined && _.findWhere(onTags, {epc: goneEpc.epc}) === undefined)){ |
209 | offEpcs.push({ | 208 | offEpcs.push({ |
210 | GroupID: goneEpc.group, | 209 | GroupID: goneEpc.group, |
211 | EPC: goneEpc.epc, | 210 | EPC: goneEpc.epc, |
211 | + host: goneEpc.host, | ||
212 | + speed: goneEpc.speed, | ||
213 | + rssi: goneEpc.rssi, | ||
212 | updateTime: goneEpc.updateTime | 214 | updateTime: goneEpc.updateTime |
213 | }); | 215 | }); |
214 | } | 216 | } |
215 | }); | 217 | }); |
216 | 218 | ||
217 | - r.hset(group, 'on', JSON.stringify(onEpcs), function(){}); | ||
218 | r.hset(group, 'off', JSON.stringify(offEpcs), function(){}); | 219 | r.hset(group, 'off', JSON.stringify(offEpcs), function(){}); |
219 | 220 | ||
220 | if(connected){ | 221 | if(connected){ |
@@ -233,6 +234,67 @@ function connectReader(host, port, filter, frequency, inventoryTime, antStayTime | @@ -233,6 +234,67 @@ function connectReader(host, port, filter, frequency, inventoryTime, antStayTime | ||
233 | }); | 234 | }); |
234 | } | 235 | } |
235 | 236 | ||
237 | +function processOnTags() | ||
238 | +{ | ||
239 | + // 获取redis中指定组在架标签数据 | ||
240 | + r.hget(group, 'on', function(err, epcs) | ||
241 | + { | ||
242 | + if (err) | ||
243 | + { | ||
244 | + console.error(err); | ||
245 | + } | ||
246 | + else | ||
247 | + { | ||
248 | + try | ||
249 | + { | ||
250 | + var redisEpcs = JSON.parse(epcs); | ||
251 | + // 处理在架标签 | ||
252 | + _.forEach(redisEpcs, function(item){ | ||
253 | + if(item.host != host && _.findWhere(onTags, {epc: item.epc}) === undefined){ | ||
254 | + onEpcs.push(item); | ||
255 | + } | ||
256 | + }); | ||
257 | + _.forEach(onTags, function(item){ | ||
258 | + onEpcs.push({ | ||
259 | + GroupID: item.group, | ||
260 | + EPC: item.epc, | ||
261 | + host: item.host, | ||
262 | + speed: item.speed, | ||
263 | + updateTime: item.updateTime | ||
264 | + }); | ||
265 | + }); | ||
266 | + r.hset(group, 'on', JSON.stringify(onEpcs), function(){}); | ||
267 | + | ||
268 | + // 处理离架标签 | ||
269 | + _.forEach(goneTags, function(goneEpc){ | ||
270 | + if(!goneEpc || _.findWhere(redisEpcs, {EPC: goneEpc.epc}) === undefined){ | ||
271 | + offEpcs.push({ | ||
272 | + GroupID: goneEpc.group, | ||
273 | + EPC: goneEpc.epc, | ||
274 | + host: goneEpc.host, | ||
275 | + speed: goneEpc.speed, | ||
276 | + rssi: goneEpc.rssi, | ||
277 | + updateTime: goneEpc.updateTime | ||
278 | + }); | ||
279 | + } | ||
280 | + }); | ||
281 | + | ||
282 | + r.hset(group, 'off', JSON.stringify(offEpcs), function(){}); | ||
283 | + | ||
284 | + if(connected){ | ||
285 | + callback(null, connected); | ||
286 | + }else{ | ||
287 | + callback(new Error('连接读写器'+host+'错误'), connected); | ||
288 | + } | ||
289 | + } | ||
290 | + catch(er) | ||
291 | + { | ||
292 | + console.error('标签数据JSON格式错误:'+er); | ||
293 | + } | ||
294 | + } | ||
295 | + }); | ||
296 | +} | ||
297 | + | ||
236 | /** | 298 | /** |
237 | * 获取指定时间和当前时间的差异 | 299 | * 获取指定时间和当前时间的差异 |
238 | * @param val 指定的时间 | 300 | * @param val 指定的时间 |
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | "dependencies": { | 7 | "dependencies": { |
8 | "async": "0.9.0", | 8 | "async": "0.9.0", |
9 | "babel": "5.x.x", | 9 | "babel": "5.x.x", |
10 | + "babel-core": "^5.4.3", | ||
10 | "lodash": "3.6.x", | 11 | "lodash": "3.6.x", |
11 | "log4js": "0.6.x", | 12 | "log4js": "0.6.x", |
12 | "pm2": "~0.12.3", | 13 | "pm2": "~0.12.3", |
@@ -29,4 +30,4 @@ | @@ -29,4 +30,4 @@ | ||
29 | "rewire": "*", | 30 | "rewire": "*", |
30 | "babel-plugin-rewire": "*" | 31 | "babel-plugin-rewire": "*" |
31 | } | 32 | } |
32 | -} | ||
33 | +} |
@@ -54,6 +54,17 @@ let config = new Config(); | @@ -54,6 +54,17 @@ let config = new Config(); | ||
54 | */ | 54 | */ |
55 | let inventory = new Inventory(); | 55 | let inventory = new Inventory(); |
56 | 56 | ||
57 | +import log4js from 'log4js'; | ||
58 | + | ||
59 | +let loger = log4js.getLogger('log'); | ||
60 | +loger.setLevel(config.logLevel); //配置日志 | ||
61 | + | ||
62 | +/** | ||
63 | + * @mixes 日志记录对象 | ||
64 | + * @exports util/log | ||
65 | + */ | ||
66 | +export let log = loger; | ||
67 | + | ||
57 | /** | 68 | /** |
58 | * 打开读写器 | 69 | * 打开读写器 |
59 | * @method open | 70 | * @method open |
@@ -83,6 +94,7 @@ export let open = function(host, port, callback) { | @@ -83,6 +94,7 @@ export let open = function(host, port, callback) { | ||
83 | callback(error); | 94 | callback(error); |
84 | } | 95 | } |
85 | }); | 96 | }); |
97 | + | ||
86 | }; | 98 | }; |
87 | 99 | ||
88 | /** | 100 | /** |
@@ -130,6 +142,42 @@ export let setFrequency = function(connector, param) { | @@ -130,6 +142,42 @@ export let setFrequency = function(connector, param) { | ||
130 | }; | 142 | }; |
131 | 143 | ||
132 | /** | 144 | /** |
145 | + * 设置频率区域 | ||
146 | + * @method setFrequencyRegion | ||
147 | + * @exports index/setFrequencyRegion | ||
148 | + * @param {Connector} connector 连接器 | ||
149 | + * @param {Object} param 频率区域的值 eg: 0:FCC,1:CCC,2:NCC,3:JPN | ||
150 | + */ | ||
151 | +export let setFrequencyRegion = function(connector, param) { | ||
152 | + config.send(connector, orders.setFrequencyRegion, param); | ||
153 | +}; | ||
154 | + | ||
155 | +/** | ||
156 | + * 设置速度模式 | ||
157 | + * @method setSpeedMode | ||
158 | + * @exports index/setSpeedMode | ||
159 | + * @param {Connector} connector 连接器 | ||
160 | + * @param {Object} param 速度模式的值 eg: 0:高速,1:正常速度,2:省电模式 | ||
161 | + */ | ||
162 | +export let setSpeedMode = function(connector, param) { | ||
163 | + config.send(connector, orders.setSpeedMode, param); | ||
164 | +}; | ||
165 | + | ||
166 | +/** | ||
167 | + * 设置标签组 | ||
168 | + * @method setTagGroup | ||
169 | + * @exports index/setTagGroup | ||
170 | + * @param {Connector} connector 连接器 | ||
171 | + * @param {Object} param 标签组的值 eg: {'session':0,'target':0,'search_mode':1} | ||
172 | + * 其中session:0代表S0,1代表S1,2代表S2,3代表S3 | ||
173 | + * target:0代表A,1代表B | ||
174 | + * search_mode:0代表DUAL_TARGET,1代表SINGLE_TARGET,2代表SINGLE_TARGET_WITH_SUPPRESSION | ||
175 | + */ | ||
176 | +export let setTagGroup = function(connector, param) { | ||
177 | + config.send(connector, orders.setTagGroup, param); | ||
178 | +}; | ||
179 | + | ||
180 | +/** | ||
133 | * 设置盘点时长 | 181 | * 设置盘点时长 |
134 | * @method setInventoryTime | 182 | * @method setInventoryTime |
135 | * @exports index/setInventoryTime | 183 | * @exports index/setInventoryTime |
@@ -147,6 +195,7 @@ export let setInventoryTime = function(connector, param) { | @@ -147,6 +195,7 @@ export let setInventoryTime = function(connector, param) { | ||
147 | * @param {Connector} connect 连接器 | 195 | * @param {Connector} connect 连接器 |
148 | */ | 196 | */ |
149 | export let startInventory = function(connector) { | 197 | export let startInventory = function(connector) { |
198 | + | ||
150 | inventory.send(connector, orders.startInventory); | 199 | inventory.send(connector, orders.startInventory); |
151 | }; | 200 | }; |
152 | 201 | ||
@@ -183,28 +232,50 @@ export let stopInventory = function(connector) { | @@ -183,28 +232,50 @@ export let stopInventory = function(connector) { | ||
183 | }); | 232 | }); |
184 | */ | 233 | */ |
185 | let isStop = false; | 234 | let isStop = false; |
186 | - | ||
187 | export let start = function(options, callback) { | 235 | export let start = function(options, callback) { |
188 | var lastRets = [], | 236 | var lastRets = [], |
189 | rets = [], | 237 | rets = [], |
190 | goneRets = []; | 238 | goneRets = []; |
191 | open(options.host, options.port, function(err, connector) { | 239 | open(options.host, options.port, function(err, connector) { |
192 | - if (!options.filter || !options.frequencys || !options.inventoryTime || !options.power || !options.antStayTime) { | 240 | + if (!options.filter || !options.frequency || !options.inventoryTime || !options.power || !options.antStayTime) { |
193 | let error = new Error('Error:灵敏度,定频,盘点时长,功率必须要传!'); | 241 | let error = new Error('Error:灵敏度,定频,盘点时长,功率必须要传!'); |
194 | callback(error); | 242 | callback(error); |
243 | + return; | ||
195 | } | 244 | } |
245 | + | ||
196 | //开启灵敏度过滤 | 246 | //开启灵敏度过滤 |
197 | setFilter(connector, options.filter); | 247 | setFilter(connector, options.filter); |
198 | //设置天线驻留时长 | 248 | //设置天线驻留时长 |
199 | - setAntStayTime(connector, options.antStayTime); | 249 | + connector.on('setFilter', function(data) { |
250 | + setAntStayTime(connector, options.antStayTime); | ||
251 | + }); | ||
252 | + //设置频率区域 | ||
253 | + connector.on('setAntStayTime', function(data) { | ||
254 | + setFrequencyRegion(connector, 1); // 设置频率区域为CCC | ||
255 | + }); | ||
256 | + //设置速度模式 | ||
257 | + connector.on('setFrequencyRegion', function(data) { | ||
258 | + setSpeedMode(connector, 0); // 设置速度模式为高速 | ||
259 | + }); | ||
260 | + | ||
261 | + //设置标签组 | ||
262 | + connector.on('setSpeedMode', function(data) { | ||
263 | + setTagGroup(connector, {'session':0,'target':0,'search_mode':1}); // 设置标签组:session:S0,target:A,search_mode:单目标 | ||
264 | + }); | ||
265 | + | ||
200 | //开启固定频率 | 266 | //开启固定频率 |
201 | - setFrequency(connector, options.frequency); | 267 | + connector.on('setTagGroup', function(data) { |
268 | + setFrequency(connector, options.frequency); | ||
269 | + }); | ||
202 | 270 | ||
203 | //设置盘点时长 | 271 | //设置盘点时长 |
204 | - setInventoryTime(connector, options.inventoryTime); | 272 | + connector.on('setFrequency', function(data) { |
273 | + setInventoryTime(connector, options.inventoryTime); | ||
274 | + }); | ||
205 | 275 | ||
206 | //设置功率 | 276 | //设置功率 |
207 | connector.on('setInventoryTime', function(data) { | 277 | connector.on('setInventoryTime', function(data) { |
278 | + | ||
208 | setPower(connector, options.power); | 279 | setPower(connector, options.power); |
209 | }); | 280 | }); |
210 | 281 | ||
@@ -216,6 +287,10 @@ export let start = function(options, callback) { | @@ -216,6 +287,10 @@ export let start = function(options, callback) { | ||
216 | connector.on('startInventory', function(data) { | 287 | connector.on('startInventory', function(data) { |
217 | if (data.code !== 2 && !isStop) { | 288 | if (data.code !== 2 && !isStop) { |
218 | 289 | ||
290 | + rets = _.filter(rets, function(item){ | ||
291 | + return item.speed > 1; | ||
292 | + }); | ||
293 | + | ||
219 | if (lastRets.length === 0) { | 294 | if (lastRets.length === 0) { |
220 | lastRets = rets; | 295 | lastRets = rets; |
221 | } else { | 296 | } else { |
@@ -224,15 +299,17 @@ export let start = function(options, callback) { | @@ -224,15 +299,17 @@ export let start = function(options, callback) { | ||
224 | goneRets = compResults.gone; | 299 | goneRets = compResults.gone; |
225 | } | 300 | } |
226 | 301 | ||
227 | - callback(connector.connected, rets, goneRets); | 302 | + callback(null, connector.connected, rets, goneRets); |
228 | 303 | ||
229 | rets = []; | 304 | rets = []; |
230 | goneRets = []; | 305 | goneRets = []; |
231 | startInventory(connector); | 306 | startInventory(connector); |
232 | } else if (data.code === 2) { | 307 | } else if (data.code === 2) { |
308 | + | ||
233 | rets = procTagInfo(rets, data.data, options.group, options.host); | 309 | rets = procTagInfo(rets, data.data, options.group, options.host); |
234 | } | 310 | } |
235 | }); | 311 | }); |
312 | + | ||
236 | }); | 313 | }); |
237 | }; | 314 | }; |
238 | 315 | ||
@@ -263,8 +340,9 @@ function compTags(lastRets, rets, goneRets) { | @@ -263,8 +340,9 @@ function compTags(lastRets, rets, goneRets) { | ||
263 | var checkedItem = _.findWhere(rets, { | 340 | var checkedItem = _.findWhere(rets, { |
264 | epc: item.epc | 341 | epc: item.epc |
265 | }); | 342 | }); |
343 | + | ||
266 | if (checkedItem === undefined) { // 上次盘点数据不包含在此次数据中 | 344 | if (checkedItem === undefined) { // 上次盘点数据不包含在此次数据中 |
267 | - if (item.speed > 1) | 345 | + if (item.speed > 2 || item.rssi > -60) |
268 | goneRets.push(item); | 346 | goneRets.push(item); |
269 | } else { | 347 | } else { |
270 | lastRets[i] = checkedItem; | 348 | lastRets[i] = checkedItem; |
@@ -339,6 +417,7 @@ function receive(client, data, err) { | @@ -339,6 +417,7 @@ function receive(client, data, err) { | ||
339 | if (err) { | 417 | if (err) { |
340 | throw err; | 418 | throw err; |
341 | } | 419 | } |
420 | + | ||
342 | className = locateOrder(orders, data).val.directive; | 421 | className = locateOrder(orders, data).val.directive; |
343 | 422 | ||
344 | switch (className) { | 423 | switch (className) { |
@@ -55,11 +55,18 @@ class Connector extends events.EventEmitter { | @@ -55,11 +55,18 @@ class Connector extends events.EventEmitter { | ||
55 | 55 | ||
56 | orderName = locateOrder(orders, rets.rets[i]).name; //指令名称 | 56 | orderName = locateOrder(orders, rets.rets[i]).name; //指令名称 |
57 | returnData = receive(client, rets.rets[i]); //接收返回 | 57 | returnData = receive(client, rets.rets[i]); //接收返回 |
58 | - | ||
59 | that.emit(orderName, returnData); //触发接收数据的指令事件 | 58 | that.emit(orderName, returnData); //触发接收数据的指令事件 |
60 | } | 59 | } |
61 | }); | 60 | }); |
62 | 61 | ||
62 | + client.setTimeout(2000, function(){ | ||
63 | + // 读写器连接错误或者突然断开 | ||
64 | + this.connected = false; | ||
65 | + | ||
66 | + // 触发重连事件 | ||
67 | + that.emit('reconnect', config); | ||
68 | + }); | ||
69 | + | ||
63 | //异常处理 | 70 | //异常处理 |
64 | client.on('error', function(error) { | 71 | client.on('error', function(error) { |
65 | log.error('错误:' + error.code); | 72 | log.error('错误:' + error.code); |
@@ -73,6 +80,7 @@ class Connector extends events.EventEmitter { | @@ -73,6 +80,7 @@ class Connector extends events.EventEmitter { | ||
73 | 80 | ||
74 | client.on('close', function() { | 81 | client.on('close', function() { |
75 | log.info('读写器连接断开'); | 82 | log.info('读写器连接断开'); |
83 | + | ||
76 | // 触发重连事件 | 84 | // 触发重连事件 |
77 | that.emit('reconnect'); | 85 | that.emit('reconnect'); |
78 | }); | 86 | }); |
@@ -40,6 +40,7 @@ class Base { | @@ -40,6 +40,7 @@ class Base { | ||
40 | if (this.reproc[order.input]) { | 40 | if (this.reproc[order.input]) { |
41 | sendOrder = this.reproc[order.input](param); | 41 | sendOrder = this.reproc[order.input](param); |
42 | } | 42 | } |
43 | + console.log(sendOrder); | ||
43 | connector.send(sendOrder); | 44 | connector.send(sendOrder); |
44 | let address = connector.client.remoteAddress; | 45 | let address = connector.client.remoteAddress; |
45 | //log.info('读写器(' + address + ')发送指令:' + sendOrder); | 46 | //log.info('读写器(' + address + ')发送指令:' + sendOrder); |
@@ -28,12 +28,18 @@ class Config extends Base { | @@ -28,12 +28,18 @@ class Config extends Base { | ||
28 | let power = info.setPower.input, | 28 | let power = info.setPower.input, |
29 | filter = info.setFilter.input, | 29 | filter = info.setFilter.input, |
30 | stayTime = info.setAntStayTime.input, | 30 | stayTime = info.setAntStayTime.input, |
31 | - frequency = info.setFrequency.input; | 31 | + frequency = info.setFrequency.input, |
32 | + frequencyRegion = info.setFrequencyRegion.input, | ||
33 | + speedMode = info.setSpeedMode.input, | ||
34 | + tagGroup = info.setTagGroup.input; | ||
32 | 35 | ||
33 | this.reproc[power] = this.prePower; | 36 | this.reproc[power] = this.prePower; |
34 | this.reproc[filter] = this.preFilter; | 37 | this.reproc[filter] = this.preFilter; |
35 | this.reproc[stayTime] = this.preStayTime; | 38 | this.reproc[stayTime] = this.preStayTime; |
36 | this.reproc[frequency] = this.preFrequency; | 39 | this.reproc[frequency] = this.preFrequency; |
40 | + this.reproc[frequencyRegion] = this.preFrequencyRegion; | ||
41 | + this.reproc[speedMode] = this.preSpeedMode; | ||
42 | + this.reproc[tagGroup] = this.preTagGroup; | ||
37 | } | 43 | } |
38 | 44 | ||
39 | /** | 45 | /** |
@@ -137,6 +143,42 @@ class Config extends Base { | @@ -137,6 +143,42 @@ class Config extends Base { | ||
137 | freq = freq.length < 2 ? ('0' + freq) : freq; | 143 | freq = freq.length < 2 ? ('0' + freq) : freq; |
138 | return info.setFrequency.input + freq + '000000'; | 144 | return info.setFrequency.input + freq + '000000'; |
139 | } | 145 | } |
146 | + | ||
147 | + /** | ||
148 | + * @method preFrequencyRegion | ||
149 | + * @description 设置频率区域 | ||
150 | + * @param {Object} param 频率区域的值 eg: 0:FCC,1:CCC,2:NCC,3:JPN | ||
151 | + */ | ||
152 | + | ||
153 | + preFrequencyRegion(param) { | ||
154 | + return info.setFrequencyRegion.input + '0' + tenToHex(param).toLocaleUpperCase() + '000000'; | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * @method preSpeedMode | ||
159 | + * @description 设置速度模式 | ||
160 | + * @param {Object} param 速度模式的值 eg: 0:高速,1:正常速度,2:省电模式 | ||
161 | + */ | ||
162 | + | ||
163 | + preSpeedMode(param) { | ||
164 | + return info.setSpeedMode.input + '0' + tenToHex(param).toLocaleUpperCase() + '000000'; | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * @method preTagGroup | ||
169 | + * @description 设置标签组预处理 | ||
170 | + * @param {Object} param 标签组的值 eg: {'session':0,'target':0,'search_mode':1} | ||
171 | + * 其中session:0代表S0,1代表S1,2代表S2,3代表S3 | ||
172 | + * target:0代表A,1代表B | ||
173 | + * search_mode:0代表DUAL_TARGET,1代表SINGLE_TARGET,2代表SINGLE_TARGET_WITH_SUPPRESSION | ||
174 | + */ | ||
175 | + | ||
176 | + preTagGroup(param) { | ||
177 | + let session = '0'+tenToHex(param.session * 10).toLocaleUpperCase(), | ||
178 | + target = '0'+tenToHex(param.target).toLocaleUpperCase(), | ||
179 | + search_mode = '0'+tenToHex(param.search_mode).toLocaleUpperCase(); | ||
180 | + return info.setTagGroup.input + session +target + search_mode + '00'; | ||
181 | + } | ||
140 | } | 182 | } |
141 | /** | 183 | /** |
142 | * @exports lib/directive/Config | 184 | * @exports lib/directive/Config |
@@ -91,6 +91,36 @@ export default { | @@ -91,6 +91,36 @@ export default { | ||
91 | 'bf2ff0': commonMessage.ff0 | 91 | 'bf2ff0': commonMessage.ff0 |
92 | } | 92 | } |
93 | }, | 93 | }, |
94 | + setFrequencyRegion: { | ||
95 | + directive: 'config', | ||
96 | + input: 'F5', | ||
97 | + output: { | ||
98 | + 'f5200': commonMessage['00'], | ||
99 | + 'f52ffff': commonMessage.ffff, | ||
100 | + 'f52fffe': commonMessage.fffe, | ||
101 | + 'f52ff0': commonMessage.ff0 | ||
102 | + } | ||
103 | + }, | ||
104 | + setSpeedMode: { | ||
105 | + directive: 'config', | ||
106 | + input: 'FA', | ||
107 | + output: { | ||
108 | + 'fa200': commonMessage['00'], | ||
109 | + 'fa2ffff': commonMessage.ffff, | ||
110 | + 'fa2fffe': commonMessage.fffe, | ||
111 | + 'fa2ff0': commonMessage.ff0 | ||
112 | + } | ||
113 | + }, | ||
114 | + setTagGroup: { | ||
115 | + directive: 'config', | ||
116 | + input: 'B6', | ||
117 | + output: { | ||
118 | + 'b6200': commonMessage['00'], | ||
119 | + 'b62ffff': commonMessage.ffff, | ||
120 | + 'b62fffe': commonMessage.fffe, | ||
121 | + 'b62ff0': commonMessage.ff0 | ||
122 | + } | ||
123 | + }, | ||
94 | getConfig: { | 124 | getConfig: { |
95 | directive: 'uhf', | 125 | directive: 'uhf', |
96 | input: 'B300000000', | 126 | input: 'B300000000', |
@@ -125,6 +155,10 @@ export default { | @@ -125,6 +155,10 @@ export default { | ||
125 | code: 2, | 155 | code: 2, |
126 | message: '返回信息' | 156 | message: '返回信息' |
127 | }, | 157 | }, |
158 | + '41': { | ||
159 | + code: 3, | ||
160 | + message: '不明飞行物' | ||
161 | + }, | ||
128 | 'f1239': { | 162 | 'f1239': { |
129 | code: 889, | 163 | code: 889, |
130 | message: '未知错误' | 164 | message: '未知错误' |
@@ -76,9 +76,9 @@ export let returnProc = function(data, ip, output) { | @@ -76,9 +76,9 @@ export let returnProc = function(data, ip, output) { | ||
76 | 76 | ||
77 | let ret = data.join(''); | 77 | let ret = data.join(''); |
78 | if (!output[ret]) { | 78 | if (!output[ret]) { |
79 | - return false; | 79 | + return {}; |
80 | } | 80 | } |
81 | - log.info("读写器(" + ip + ")返回:" + output[ret].message + " 返回码:" + ret); | 81 | + //log.info("读写器(" + ip + ")返回:" + output[ret].message + " 返回码:" + ret); |
82 | output[ret].hex = data; | 82 | output[ret].hex = data; |
83 | return output[ret]; | 83 | return output[ret]; |
84 | }; | 84 | }; |
@@ -136,12 +136,12 @@ describe('index.js', function() { | @@ -136,12 +136,12 @@ describe('index.js', function() { | ||
136 | 'on': '1', | 136 | 'on': '1', |
137 | rssi: -60 | 137 | rssi: -60 |
138 | }, | 138 | }, |
139 | - frequencys: 10, | 139 | + frequency: 10, |
140 | antStayTime: 100, | 140 | antStayTime: 100, |
141 | inventoryTime: 400, //设置盘点时长 | 141 | inventoryTime: 400, //设置盘点时长 |
142 | power: [15, 0, 0, 0] //功率设置 | 142 | power: [15, 0, 0, 0] //功率设置 |
143 | }, | 143 | }, |
144 | - function(connected, data) { | 144 | + function(err, connected, data) { |
145 | expect(data).to.have.length(1); | 145 | expect(data).to.have.length(1); |
146 | done(); | 146 | done(); |
147 | }) | 147 | }) |
-
Please register or login to post a comment