|
@@ -1,7 +1,5 @@
|
|
|
package com.zzliaoyuan.power_sensor.fragment;
|
|
|
|
|
|
-// wsdd
|
|
|
-
|
|
|
import android.app.Fragment;
|
|
|
|
|
|
import android.os.Bundle;
|
|
@@ -17,6 +15,8 @@ import com.zzliaoyuan.rifdmastercore.LibCore;
|
|
|
import com.zzliaoyuan.rifdmastercore.ProductInfo;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
public class UHFReadTagFragment {
|
|
|
|
|
@@ -27,6 +27,12 @@ public class UHFReadTagFragment {
|
|
|
private int inventoryFlag = 1; // 默认循环读取
|
|
|
private MainActivity mContext;
|
|
|
|
|
|
+ private Timer mTimer = null;
|
|
|
+ private TimerTask mTimerTask = null;
|
|
|
+ private static int delayTime = 100; //ms
|
|
|
+ private static int periodTime = 600; //ms
|
|
|
+ private boolean isStop = true;
|
|
|
+
|
|
|
public static UHFReadTagFragment getInstance() {
|
|
|
if (mInstance == null) {
|
|
|
synchronized (UHFReadTagFragment.class) {
|
|
@@ -60,170 +66,98 @@ public class UHFReadTagFragment {
|
|
|
|
|
|
private void readTag() {
|
|
|
// wsdd 点击开始按钮后,开始执行扫描
|
|
|
-
|
|
|
- if (isStart)// 识别标签
|
|
|
- {
|
|
|
-// UIHelper.ToastMessage(mContext, "开始识别");
|
|
|
- switch (inventoryFlag) {
|
|
|
- case 0:// 单步
|
|
|
- {
|
|
|
- // wsdd 单步读取的数据
|
|
|
- UHFTAGInfo strUII = mContext.mReader.inventorySingleTag();
|
|
|
- if (strUII != null) {
|
|
|
- String strTid = strUII.getTid();
|
|
|
- String strUser = strUII.getUser();
|
|
|
-
|
|
|
- String strHex = "6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52";
|
|
|
- String Data = "{\"userData\":\"" + strUser + "\""; // 读取的用户区数据
|
|
|
- if (strUser.length() == 96) {
|
|
|
- String key = "f1b088cbad4f07b5";
|
|
|
- byte[] szBuffer = LibCore.HexStringToByteArray(strUser);
|
|
|
- ProductInfo product = LibCore.decode(szBuffer, strTid);//
|
|
|
- if(product == null){
|
|
|
- Log.e("===========nullnullnull", "nullnull");
|
|
|
- }else {
|
|
|
- Log.e("===========nullnullnull", "yyyyyyynull");
|
|
|
- }
|
|
|
- Data += ",\"error\":\"0\""; // 错误提示
|
|
|
- Data += ",\"assetID\":\"" + product.assetID + "\""; // 资产编号
|
|
|
- Data += ",\"model\":\"" + product.model + "\""; // 型号
|
|
|
- Data += ",\"manufacturer\":\"" + product.manufacturer + "\""; // 生产厂家
|
|
|
- Data += ",\"kind\":\"" + product.kind + "\""; // 产品类型
|
|
|
- Data += ",\"districtText\":\"" + product.districtText + "\""; // 用户地区
|
|
|
- Data += ",\"place\":\"" + product.place + "\""; // 安装场所
|
|
|
- Data += ",\"voltageLevel\":\"" + product.voltageLevel + "\""; // 电压等级
|
|
|
- Data += ",\"secondWindingCount\":\"" + product.secondWindingCount + "\""; // 二次绕组数量
|
|
|
- Data += ",\"secondVoltage\":\"" + product.secondVoltage + "\""; // 二次电压
|
|
|
- Data += ",\"firstCurrent\":\"" + product.firstCurrent + "\""; // 一次电流
|
|
|
- Data += ",\"senondCurrent\":\"" + product.senondCurrent + "\""; // 二次电流
|
|
|
- Data += ",\"accuracy\":\"" + product.accuracy + "\""; // 准确等级
|
|
|
- Data += ",\"ratedLoad\":\"" + product.ratedLoad + "\""; // 额定负荷
|
|
|
- Data += ",\"releaseDate\":\"" + product.releaseDate + "\""; // 二次绕组数量
|
|
|
- Data += ",\"secondWindingCount\":\"" + product.secondWindingCount + "\""; // 出厂日期
|
|
|
- Data += ",\"voltageFactor\":\"" + product.voltageFactor + "\""; // 电压因数
|
|
|
-
|
|
|
- // wsdd 添加读取的数据,此处应该返回数据strEPC到RN
|
|
|
- // 返回给RN的数据格式 {"userData":"6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52","assetID":"4330012800000002178203 ","model":"002型","manufacturer":"北京***公司","kind":"电压互感器"}
|
|
|
- } else {
|
|
|
- Data += ",\"error\":\"1\"";
|
|
|
- Data += ",\"error_msg\":\"格式错误("+ strHex.length() +"):" + strHex + "\"";
|
|
|
- }
|
|
|
- Data += "}";
|
|
|
- MainApplication.GetReactPackage().reactModule.sendMsgToRN("MsgFromAndroid", Data);
|
|
|
- mContext.playSound(1);
|
|
|
- } else {
|
|
|
- UIHelper.ToastMessage(mContext, "识别失败");
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case 1:// 单标签循环 .startInventoryTag((byte) 0, (byte) 0))
|
|
|
- {
|
|
|
- if (mContext.mReader.startInventoryTag()) {
|
|
|
- loopFlag = true;
|
|
|
- isStart = false;
|
|
|
- new TagThread().start();
|
|
|
- } else {
|
|
|
- mContext.mReader.stopInventory();
|
|
|
- UIHelper.ToastMessage(mContext, "开启识别标签失败");
|
|
|
- }
|
|
|
+ // wsdd 单步读取的数据
|
|
|
+ UHFTAGInfo strUII = mContext.mReader.inventorySingleTag();
|
|
|
+ if (strUII != null) {
|
|
|
+ String strTid = strUII.getTid();
|
|
|
+ String strUser = strUII.getUser();
|
|
|
+ if (strUser != null && strTid != null) {
|
|
|
+ String Data = "{\"userData\":\"" + strUser + "\""; // 读取的用户区数据
|
|
|
+ byte[] szBuffer = LibCore.HexStringToByteArray(strUser);
|
|
|
+ ProductInfo product = LibCore.decode(szBuffer, strTid);//
|
|
|
+
|
|
|
+ if (strUser.length() == 96 && product != null) {
|
|
|
+
|
|
|
+ Data += ",\"error\":0"; // 错误提示
|
|
|
+ Data += ",\"assetID\":\"" + product.assetID + "\""; // 资产编号
|
|
|
+ Data += ",\"model\":\"" + product.model + "\""; // 型号
|
|
|
+ Data += ",\"manufacturer\":\"" + product.manufacturer + "\""; // 生产厂家
|
|
|
+ Data += ",\"kind\":\"" + product.kind + "\""; // 产品类型
|
|
|
+ Data += ",\"districtText\":\"" + product.districtText + "\""; // 用户地区
|
|
|
+ Data += ",\"place\":\"" + product.place + "\""; // 安装场所
|
|
|
+ Data += ",\"voltageLevel\":\"" + product.voltageLevel + "\""; // 电压等级
|
|
|
+ Data += ",\"secondWindingCount\":\"" + product.secondWindingCount + "\""; // 二次绕组数量
|
|
|
+ Data += ",\"secondVoltage\":\"" + product.secondVoltage + "\""; // 二次电压
|
|
|
+ Data += ",\"firstCurrent\":\"" + product.firstCurrent + "\""; // 一次电流
|
|
|
+ Data += ",\"senondCurrent\":\"" + product.senondCurrent + "\""; // 二次电流
|
|
|
+ Data += ",\"accuracy\":\"" + product.accuracy + "\""; // 准确等级
|
|
|
+ Data += ",\"ratedLoad\":\"" + product.ratedLoad + "\""; // 额定负荷
|
|
|
+ Data += ",\"releaseDate\":\"" + product.releaseDate + "\""; // 出厂日期
|
|
|
+ Data += ",\"voltageFactor\":\"" + product.voltageFactor + "\""; // 电压因数
|
|
|
+ Data += ",\"version\":\"" + product.version + "\""; // 版本
|
|
|
+ Data += ",\"powerFactor\":\"" + product.powerFactor + "\""; // 功率因数
|
|
|
+
|
|
|
+ // wsdd 添加读取的数据,此处应该返回数据strEPC到RN
|
|
|
+ // 返回给RN的数据格式 {"userData":"6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52","assetID":"4330012800000002178203 ","model":"002型","manufacturer":"北京***公司","kind":"电压互感器"}
|
|
|
+ } else {
|
|
|
+ Data += ",\"error\":1";
|
|
|
+ Data += ",\"error_msg\":\"格式错误(" + strUser.length() + "):" + strUser + "\"";
|
|
|
}
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ Data += "}";
|
|
|
+ MainApplication.GetReactPackage().reactModule.sendMsgToRN("MsgFromAndroid", Data);
|
|
|
+ mContext.playSound(1);
|
|
|
+ } else {
|
|
|
+ mContext.playSound(2);
|
|
|
}
|
|
|
- } else {// 停止识别
|
|
|
- isStart = true;
|
|
|
- stopInventory();
|
|
|
+ } else {
|
|
|
+ UIHelper.ToastMessage(mContext, "识别失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 停止识别
|
|
|
*/
|
|
|
- private void stopInventory() {
|
|
|
- if (loopFlag) {
|
|
|
- loopFlag = false;
|
|
|
- if (mContext.mReader.stopInventory()) {
|
|
|
- // wsdd 停止后,传回停止状态
|
|
|
-// UIHelper.ToastMessage(mContext, "停止识别");
|
|
|
- } else {
|
|
|
- UIHelper.ToastMessage(mContext, "停止识别标签失败");
|
|
|
- }
|
|
|
+ public void myOnKeyDwon() {
|
|
|
+ isStop = !isStop;
|
|
|
+
|
|
|
+ if (!isStop) {
|
|
|
+ startRead();
|
|
|
+ } else {
|
|
|
+ stopRead();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class TagThread extends Thread {
|
|
|
- public void run() {
|
|
|
- String epc;
|
|
|
- String strTid;
|
|
|
- String strUser;
|
|
|
- UHFTAGInfo res = null;
|
|
|
- while (loopFlag) {
|
|
|
- res = mContext.mReader.readTagFromBuffer();
|
|
|
- if (res != null) {
|
|
|
- strTid = res.getTid();
|
|
|
- strUser = res.getUser();
|
|
|
- Log.e("===========strTid", strTid);
|
|
|
- Log.e("===========strUser", strUser);
|
|
|
-
|
|
|
- Log.e("===========", strUser.length()+"pp");
|
|
|
- String Data = "{\"userData\":\"" + strUser + "\""; // 读取的用户区数据
|
|
|
- byte[] szBuffer = LibCore.HexStringToByteArray(strUser);
|
|
|
- ProductInfo product = LibCore.decode(szBuffer, strTid);//
|
|
|
- if(product == null){
|
|
|
- Log.e("===========nullnullnull", "null");
|
|
|
- }else {
|
|
|
- Log.e("===========nullnullnull", "yyyyyyy");
|
|
|
- }
|
|
|
- if (strUser.length() == 96 && product != null) {
|
|
|
-
|
|
|
- Data += ",\"error\":0"; // 错误提示
|
|
|
- Data += ",\"assetID\":\"" + product.assetID + "\""; // 资产编号
|
|
|
- Data += ",\"model\":\"" + product.model + "\""; // 型号
|
|
|
- Data += ",\"manufacturer\":\"" + product.manufacturer + "\""; // 生产厂家
|
|
|
- Data += ",\"kind\":\"" + product.kind + "\""; // 产品类型
|
|
|
- Data += ",\"districtText\":\"" + product.districtText + "\""; // 用户地区
|
|
|
- Data += ",\"place\":\"" + product.place + "\""; // 安装场所
|
|
|
- Data += ",\"voltageLevel\":\"" + product.voltageLevel + "\""; // 电压等级
|
|
|
- Data += ",\"secondWindingCount\":\"" + product.secondWindingCount + "\""; // 二次绕组数量
|
|
|
- Data += ",\"secondVoltage\":\"" + product.secondVoltage + "\""; // 二次电压
|
|
|
- Data += ",\"firstCurrent\":\"" + product.firstCurrent + "\""; // 一次电流
|
|
|
- Data += ",\"senondCurrent\":\"" + product.senondCurrent + "\""; // 二次电流
|
|
|
- Data += ",\"accuracy\":\"" + product.accuracy + "\""; // 准确等级
|
|
|
- Data += ",\"ratedLoad\":\"" + product.ratedLoad + "\""; // 额定负荷
|
|
|
- Data += ",\"releaseDate\":\"" + product.releaseDate + "\""; // 出厂日期
|
|
|
- Data += ",\"voltageFactor\":\"" + product.voltageFactor + "\""; // 电压因数
|
|
|
- Data += ",\"version\":\"" + product.version + "\""; // 版本
|
|
|
-
|
|
|
- // wsdd 添加读取的数据,此处应该返回数据strEPC到RN
|
|
|
- // 返回给RN的数据格式 {"userData":"6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52","assetID":"4330012800000002178203 ","model":"002型","manufacturer":"北京***公司","kind":"电压互感器"}
|
|
|
- } else {
|
|
|
- Data += ",\"error\":1";
|
|
|
- Data += ",\"error_msg\":\"格式错误("+ strUser.length() +"):" + strUser + "\"";
|
|
|
+ public void startRead() {
|
|
|
+ if (mTimer == null) {
|
|
|
+ mTimer = new Timer();
|
|
|
+ }
|
|
|
+ if (mTimerTask == null) {
|
|
|
+ mTimerTask = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ readTag();
|
|
|
+ } catch (Exception e) {
|
|
|
+ UIHelper.ToastMessage(mContext, "识别失败");
|
|
|
}
|
|
|
- Data += "}";
|
|
|
-
|
|
|
- // wsdd 多线程,循环读取数据,此处应该返回数据epc到RN
|
|
|
- MainApplication.GetReactPackage().reactModule.sendMsgToRN("MsgFromAndroid", Data);
|
|
|
- mContext.playSound(1);
|
|
|
- }
|
|
|
- try {
|
|
|
- Thread.sleep(100);//毫秒
|
|
|
-// Thread.currentThread().sleep(1000);//毫秒
|
|
|
- } catch (Exception e) {
|
|
|
- UIHelper.ToastMessage(mContext, "读取标签异常,停止读取");
|
|
|
- stopInventory();
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- public void myOnKeyDwon() {
|
|
|
- readTag();
|
|
|
+ if (mTimer != null && mTimerTask != null) {
|
|
|
+ mTimer.schedule(mTimerTask, delayTime, periodTime);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void stopRead() {
|
|
|
- stopInventory();
|
|
|
+ if (mTimer != null) {
|
|
|
+ mTimer.cancel();
|
|
|
+ mTimer = null;
|
|
|
+ }
|
|
|
+ if (mTimerTask != null) {
|
|
|
+ mTimerTask.cancel();
|
|
|
+ mTimerTask = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|