wushaodong hace 3 años
padre
commit
edbb23a4a2

+ 1 - 1
android/app/src/main/java/com/zzliaoyuan/power_sensor/activity/MainActivity.java

@@ -72,7 +72,7 @@ public class MainActivity extends ReactActivity {
 
             if (event.getRepeatCount() == 0) {
                 UHFReadTagFragment.getInstance().myOnKeyDwon();
-                 MainApplication.GetReactPackage().reactModule.sendMsgToRN("onKeyDown", "1");
+                MainApplication.GetReactPackage().reactModule.sendMsgToRN("onKeyDown", "1");
             }
             return true;
         }

+ 3 - 0
android/app/src/main/java/com/zzliaoyuan/power_sensor/fragment/ProductInfo.java

@@ -51,4 +51,7 @@ public class ProductInfo {
 
     // 电压因数
     public String voltageFactor;
+
+    // 功率因数
+    public String powerFactor;
 }

+ 82 - 148
android/app/src/main/java/com/zzliaoyuan/power_sensor/fragment/UHFReadTagFragment.java

@@ -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;
+        }
     }
 
 }

BIN
android/app/src/main/jniLibs/arm64-v8a/libcore.so


BIN
android/app/src/main/jniLibs/arm64-v8a/libcorewrapper.so


BIN
android/app/src/main/jniLibs/armeabi-v7a/libcore.so


BIN
android/app/src/main/jniLibs/armeabi-v7a/libcorewrapper.so


BIN
android/app/src/main/jniLibs/corewrapper.aar


BIN
android/app/src/main/jniLibs/x86/libcore.so


+ 124 - 20
jscore/pages/Desktop/Home.js

@@ -1,8 +1,7 @@
 import React, {Component} from 'react';
-import {StyleSheet, View, Text, DeviceEventEmitter, TouchableOpacity, ToastAndroid, Dimensions} from 'react-native';
+import {StyleSheet, View, Text, DeviceEventEmitter, ScrollView, Dimensions} from 'react-native';
 import {Button} from '@ant-design/react-native';
 import ReadUHF from "../../utils/ReadUHF";
-import {ComponentsStyles} from "../../components"
 import Barcode from "react-native-barcode-builder";
 
 let screenW = Dimensions.get('window').width;
@@ -13,12 +12,14 @@ class DesktopHome extends Component {
         this.state = {
             data: [],
             userData: [],
+            error: 0,
             isStart: true,
+            timerID: [],
         };
     }
 
     componentDidMount() {
-        ReadUHF.changeFlag(1)
+        ReadUHF.changeFlag(0)
         DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
         DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
     }
@@ -30,12 +31,15 @@ class DesktopHome extends Component {
     _addCode = (item) => {
         const str = JSON.parse(item)
         // 防止重复扫描
-        let {data, userData} = this.state;
+        let {data, userData, error} = this.state;
         const product_index = userData.indexOf(str['userData'])
         if (product_index < 0) {
             userData.push(str['userData'])
             data.push(str)
-            this.setState({data, userData})
+            if (str['error']) {
+                error += 1
+            }
+            this.setState({data, userData, error})
         }
     }
     _start = () => {
@@ -43,6 +47,9 @@ class DesktopHome extends Component {
         ReadUHF.doRead()
         this.setState({isStart: !isStart})
     }
+    _clear = () => {
+        this.setState({userData: [], data: [], error: 0})
+    }
     onKeyDown = () => {
         let {isStart} = this.state;
         this.setState({isStart: !isStart})
@@ -51,6 +58,8 @@ class DesktopHome extends Component {
     dianYaRender = (item, index) => {
         const assetID = item.assetID.slice(7, 21)
         const districtText = item.districtText.split('-')[0]
+        const releaseDates = item.releaseDate.split('-')
+        const releaseDate = releaseDates[0]+"年"+releaseDates[1]+"月"
         return (
             <View
                 key={index}
@@ -76,7 +85,7 @@ class DesktopHome extends Component {
                     <View style={styles.centerWidth}>
                         <Text style={styles.textColor3}>{item.accuracy}</Text>
                     </View>
-                    <Text style={styles.textColor3}>{item.releaseDate}</Text>
+                    <Text style={styles.textColor3}>{releaseDate}</Text>
                 </View>
                 <View style={styles.betweenView}>
                     <Text style={styles.textColor3}>安装场所:{item.place}</Text>
@@ -117,18 +126,82 @@ class DesktopHome extends Component {
     }
 
     dianLiuRender = (item, index) => {
+        const assetID = item.assetID.slice(7, 21)
+        const districtText = item.districtText.split('-')[0]
+        const releaseDates = item.releaseDate.split('-')
+        const releaseDate = releaseDates[0]+"年"+releaseDates[1]+"月"
         return (
-            <Text>电流</Text>
+            <View
+                key={index}
+                style={styles.mainView}
+            >
+                <Text style={styles.textColor}>计量{item.kind}</Text>
+                <View style={styles.betweenView}>
+                    <Text style={styles.textColor3}>型号:{item.model}</Text>
+                    <View style={styles.centerWidth}>
+                        <Text style={styles.textColor3}>电压等级:{item.voltageLevel}</Text>
+                    </View>
+                    <Text style={styles.textColor3}>绕组数量:{item.secondWindingCount}</Text>
+                </View>
+                <View style={styles.betweenView}>
+                    <Text style={styles.textColor3}>一次电流</Text>
+                    <View style={styles.centerWidth}>
+                        <Text style={styles.textColor3}>二次电流</Text>
+                    </View>
+                    <Text style={styles.textColor3}>生产日期</Text>
+                </View>
+                <View style={styles.betweenView}>
+                    <Text style={styles.textColor3}>{item.firstCurrent}</Text>
+                    <View style={styles.centerWidth}>
+                        <Text style={styles.textColor3}>{item.senondCurrent}</Text>
+                    </View>
+                    <Text style={styles.textColor3}>{releaseDate}</Text>
+                </View>
+                <View style={styles.betweenView}>
+                    <Text style={styles.textColor3}>安装场所:{item.place}</Text>
+                    <View style={styles.centerWidth}>
+                        <Text style={styles.textColor3}>额定负荷:{item.ratedLoad}</Text>
+                    </View>
+                    <Text style={styles.textColor3}>准确等级:{item.accuracy}</Text>
+                </View>
+                <View style={styles.betweenView}>
+                    <Text style={styles.textColor3}>{item.manufacturer}</Text>
+                    <View style={{
+                        width: (screenW - 10) / 3 * 2,
+                        borderLeftWidth: 0.5,
+                        borderLeftColor: '#7b7b7b',
+                    }}>
+                        <View style={{
+                            flexDirection: 'row',
+                            marginHorizontal: 3,
+                        }}>
+                            <View style={{
+                                flex: 1,
+                            }}>
+                                <Text style={[styles.textColor, {textAlign: 'left'}]}>国网{districtText}电力</Text>
+                            </View>
+                            <Text style={[styles.textColor, {textAlign: 'right'}]}>NO.{assetID}</Text>
+                        </View>
+                        <View style={{
+                            marginHorizontal: 5,
+                        }}>
+                            <Barcode value={item.assetID} format="CODE128" height={35} width={1.1}/>
+                            <Text style={[styles.textColor]}>{item.assetID}</Text>
+                        </View>
+                    </View>
+                </View>
+
+            </View>
         )
     }
 
     errorRender = (item, index) => {
-         return (
+        return (
             <View
                 key={index}
-                style={[styles.mainView,{padding:10}]}
+                style={[styles.mainView, {padding: 10}]}
             >
-                <Text style={{color:'red'}}>{item.error_msg}</Text>
+                <Text style={{color: 'red'}}>{item.error_msg}</Text>
             </View>
         )
     }
@@ -138,13 +211,13 @@ class DesktopHome extends Component {
         const start_text = isStart ? '开始识别' : '停止识别'
         return (
             <View style={styles.container}>
-                <View style={styles.container}>
+                <ScrollView style={styles.container}>
                     {
                         this.state.data.map((item, index) => {
                             if (item.error) {
                                 return this.errorRender(item, index)
                             }
-                            else if (item.kind.indexOf('电') > -1) {
+                            else if (item.kind.indexOf('电') > -1) {
                                 return this.dianYaRender(item, index)
                             }
                             else if (item.kind.indexOf('电流') > -1) {
@@ -153,15 +226,38 @@ class DesktopHome extends Component {
 
                         })
                     }
+                </ScrollView>
+                <Text
+                    style={{marginLeft: 10, color: '#f77b22'}}>合计:{this.state.data.length} 失败:{this.state.error}</Text>
+                <View style={{flexDirection: 'row'}}>
+                    <Button onPress={() => this._start()}
+                            type="primary"
+                            style={[styles.button, {
+                                backgroundColor: isStart ? '#0099FF' : 'red',
+                                width: '65%'
+                            }]}
+                    >
+                        <Text style={{color: '#fff'}}>
+                            {start_text}
+                        </Text>
+                    </Button>
+                    <Button onPress={() => this._clear()}
+                            type="warning"
+                            style={{
+                                width: '25%',
+                                borderRadius: 5,
+                                marginHorizontal: 10,
+                                marginTop: 5,
+                                marginBottom: 2,
+                                borderWidth: 0,
+                                backgroundColor: "#de7642"
+                            }}
+                    >
+                        <Text style={{color: '#fff'}}>
+                            清除
+                        </Text>
+                    </Button>
                 </View>
-                <Button onPress={() => this._start()}
-                        type="primary"
-                        style={[ComponentsStyles.button, {backgroundColor: isStart ? '#0099FF' : 'red',}]}
-                >
-                    <Text style={{color: '#fff'}}>
-                        {start_text}
-                    </Text>
-                </Button>
             </View>
         );
     }
@@ -171,6 +267,14 @@ const styles = StyleSheet.create({
     container: {
         flex: 1
     },
+    button: {
+        borderRadius: 5,
+        marginHorizontal: 10,
+        marginBottom: 2,
+        marginTop: 5,
+        borderWidth: 0,
+        backgroundColor: "#2b90ea"
+    },
     textColor: {
         color: '#333',
         textAlign: 'center',