...
|
...
|
@@ -2,8 +2,7 @@ package com.yoho.rfid.service; |
|
|
|
|
|
import JW.UHF.*;
|
|
|
import com.yoho.rfid.model.RfidClient;
|
|
|
import com.yoho.rfid.model.YHJWReader;
|
|
|
import com.yoho.rfid.socket.SocketConstant;
|
|
|
import com.yoho.rfid.util.SocketConstant;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
...
|
...
|
@@ -30,14 +29,13 @@ public class RfidManager { |
|
|
public void onTagReported(JWReader jwReader, TagsEventArgs tagsEventArgs) {
|
|
|
// logger.info("data:{},epc:{},port:{},rssi:{}",tagsEventArgs.tag.DATA, tagsEventArgs.tag.EPC, tagsEventArgs.tag.PORT, tagsEventArgs.tag.RSSI);
|
|
|
count++;
|
|
|
YHJWReader myRreader = (YHJWReader)jwReader;
|
|
|
if(null==SocketConstant.allTags.get(myRreader.getIp())){
|
|
|
SocketConstant.allTags.put(myRreader.getIp(), new HashMap<>());
|
|
|
if(null==SocketConstant.allTags.get(jwReader.getIp())){
|
|
|
SocketConstant.allTags.put(jwReader.getIp(), new HashMap<>());
|
|
|
}
|
|
|
SocketConstant.allTags.get(myRreader.getIp()).put(tagsEventArgs.tag.EPC, System.currentTimeMillis());
|
|
|
SocketConstant.allTags.get(jwReader.getIp()).put(tagsEventArgs.tag.EPC, System.currentTimeMillis());
|
|
|
// logger.info("current ip is:{}, all tag is:{}", myRreader.getIp(), SocketConstant.allTags.get(myRreader.getIp()));
|
|
|
if(System.currentTimeMillis()-startTime>SocketConstant.STATISTIC_TIME){
|
|
|
logger.info("current ip is:{}, count is:{}, average is:{}", myRreader.getIp(), count, count*1000/SocketConstant.STATISTIC_TIME);
|
|
|
logger.info("current ip is:{}, count is:{}, average is:{}", jwReader.getIp(), count, count*1000/SocketConstant.STATISTIC_TIME);
|
|
|
count = 0;
|
|
|
startTime = System.currentTimeMillis();
|
|
|
}
|
...
|
...
|
@@ -58,70 +56,40 @@ public class RfidManager { |
|
|
public void openRFID(RfidClient rfidClient, int type) {
|
|
|
JWReader mJwReader = null;
|
|
|
try{
|
|
|
mJwReader = new YHJWReader(rfidClient.getIp(), Integer.valueOf(rfidClient.getPort()));
|
|
|
mJwReader = new JWReader(rfidClient.getIp(), Integer.valueOf(rfidClient.getPort()));
|
|
|
// 参数为是否开启心跳
|
|
|
Result openResult = mJwReader.RFID_Open(true);
|
|
|
if (openResult == Result.OK) {
|
|
|
logger.warn("open RFID success! ip is {}", rfidClient.getIp());
|
|
|
logger.info("RfidManager open RFID success! ip is {}", rfidClient.getIp());
|
|
|
// 配置读写器参数
|
|
|
RfidSetting mRfidSetting = ConfigRFID(rfidClient, type);
|
|
|
Result configResult = mJwReader.RFID_Set_Config(mRfidSetting);
|
|
|
if (configResult == Result.OK) {
|
|
|
logger.warn("config RFID success! ip is {}", rfidClient.getIp());
|
|
|
logger.info("RfidManager config RFID success! ip is {}", rfidClient.getIp());
|
|
|
// 向client集合中插入一个
|
|
|
insertRfidClientMap(rfidClient);
|
|
|
insertRfidClientMap(rfidClient, mJwReader);
|
|
|
|
|
|
mJwReader.addTagListener(mTagListener);
|
|
|
mJwReader.RFID_Start_Inventory();
|
|
|
|
|
|
} else {
|
|
|
logger.warn("config RFID failed! start reopen RFID, ip is {}", rfidClient.getIp());
|
|
|
// 后处理,以及重新连接
|
|
|
handlerAndReopen(mJwReader, rfidClient, type);
|
|
|
logger.warn("RfidManager config RFID failed! start reopen RFID, ip is {}", rfidClient.getIp());
|
|
|
}
|
|
|
} else {
|
|
|
logger.warn("open RFID failed! start reopen RFID, ip is {}", rfidClient.getIp());
|
|
|
// 后处理,以及重新连接
|
|
|
handlerAndReopen(mJwReader, rfidClient, type);
|
|
|
logger.warn("RfidManager open RFID failed! start reopen RFID, ip is {}", rfidClient.getIp());
|
|
|
}
|
|
|
}catch(Exception e){
|
|
|
logger.warn("open RFID exception! ip is {}, e is:{}", rfidClient.getIp(), e);
|
|
|
logger.warn("start reopen RFID, ip is {}", rfidClient.getIp());
|
|
|
// 后处理,以及重新连接
|
|
|
handlerAndReopen(mJwReader, rfidClient, type);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后处理,以及重新连接
|
|
|
*/
|
|
|
private void handlerAndReopen(JWReader mJwReader, RfidClient rfidClient, int type) {
|
|
|
// 关闭连接
|
|
|
if(null!=mJwReader){
|
|
|
mJwReader.RFID_Close();
|
|
|
}
|
|
|
// 从client集合中remove掉
|
|
|
removeRfidClientMap(rfidClient);
|
|
|
// 重新连接
|
|
|
openRFID(rfidClient, type);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从rfid集合中移除一个
|
|
|
*/
|
|
|
private void removeRfidClientMap(RfidClient rfidClient) {
|
|
|
if(null!=SocketConstant.rfidClientValidMap.get(rfidClient.getIp())){
|
|
|
SocketConstant.rfidClientValidMap.remove(rfidClient.getIp());
|
|
|
logger.warn("RfidManager open RFID exception! ip is {}, e is:{}", rfidClient.getIp(), e);
|
|
|
logger.warn("RfidManager start reopen RFID, ip is {}", rfidClient.getIp());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 向rfid集合中插入一个
|
|
|
*/
|
|
|
private void insertRfidClientMap(RfidClient rfidClient) {
|
|
|
if(null==SocketConstant.rfidClientValidMap.get(rfidClient.getIp())){
|
|
|
SocketConstant.rfidClientValidMap.put(rfidClient.getIp(), rfidClient);
|
|
|
}
|
|
|
private void insertRfidClientMap(RfidClient rfidClient, JWReader mJwReader) {
|
|
|
SocketConstant.rfidJWReaderValidMap.remove(rfidClient.getIp());
|
|
|
SocketConstant.rfidJWReaderValidMap.put(rfidClient.getIp(), mJwReader);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -176,12 +144,6 @@ public class RfidManager { |
|
|
return mRfidSetting;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 停止盘点
|
|
|
*/
|
|
|
public void stopInventory() {
|
|
|
// mJwReader.RFID_Stop_Inventory();
|
|
|
}
|
|
|
|
|
|
private void clearData() {
|
|
|
SocketConstant.allTags.clear();
|
...
|
...
|
|