wushaodong hace 4 años
padre
commit
82012aee23

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

+ 7 - 1
android/app/src/main/java/com/zzliaoyuan/power_sensor/fragment/ProductInfo.java

@@ -1,6 +1,9 @@
 package com.zzliaoyuan.power_sensor.fragment;
 
 public class ProductInfo {
+    // 版本号
+    public int version;
+
     // 产品类型
     public String kind;
 
@@ -8,7 +11,10 @@ public class ProductInfo {
     public String model;
 
     // 用户代码
-    public String district;
+    public short district;
+
+    // 用户地区
+    public String districtText;
 
     // 生产厂家
     public String manufacturer;

+ 87 - 27
android/app/src/main/java/com/zzliaoyuan/power_sensor/fragment/UHFReadTagFragment.java

@@ -1,18 +1,21 @@
 package com.zzliaoyuan.power_sensor.fragment;
 
 // wsdd
+
 import android.app.Fragment;
 
 import android.os.Bundle;
 import android.util.Log;
 
 import android.widget.TextView;
+
 import com.zzliaoyuan.power_sensor.MainApplication;
 import com.zzliaoyuan.power_sensor.activity.MainActivity;
 import com.zzliaoyuan.power_sensor.tools.UIHelper;
 import com.rscja.deviceapi.entity.UHFTAGInfo;
 import com.zzliaoyuan.rifdmastercore.LibCore;
 import com.zzliaoyuan.rifdmastercore.ProductInfo;
+
 import java.util.HashMap;
 
 public class UHFReadTagFragment {
@@ -21,7 +24,7 @@ public class UHFReadTagFragment {
     private boolean isStart = true;
 
     private boolean loopFlag = false;
-    private int inventoryFlag = 0;
+    private int inventoryFlag = 1; // 默认循环读取
     private MainActivity mContext;
 
     public static UHFReadTagFragment getInstance() {
@@ -36,8 +39,7 @@ public class UHFReadTagFragment {
         return mInstance;
     }
 
-    public void setContext(MainActivity context)
-    {
+    public void setContext(MainActivity context) {
         mContext = context;
     }
 
@@ -46,7 +48,7 @@ public class UHFReadTagFragment {
     public void onCheckedChanged(int checkedId) {
         // wsdd 选择单步,还是循环扫描
         // 设置循环盘点同时读取 EPC、TID、USER 模式
-        mContext.mReader.setEPCAndTIDUserMode(0,6);
+        mContext.mReader.setEPCAndTIDUserMode(0, 24);
         if (checkedId == 0) {
             // 单步识别
             inventoryFlag = 0;
@@ -58,6 +60,7 @@ public class UHFReadTagFragment {
 
     private void readTag() {
         // wsdd 点击开始按钮后,开始执行扫描
+
         if (isStart)// 识别标签
         {
 //            UIHelper.ToastMessage(mContext, "开始识别");
@@ -68,21 +71,44 @@ public class UHFReadTagFragment {
                     UHFTAGInfo strUII = mContext.mReader.inventorySingleTag();
                     if (strUII != null) {
                         String strTid = strUII.getTid();
+                        String strUser = strUII.getUser();
 
                         String strHex = "6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52";
-                        String key = "f1b088cbad4f07b5";
-                        byte[] szBuffer = LibCore.HexStringToByteArray(strHex);
-                        ProductInfo product = LibCore.decode(szBuffer, key);//
-
-                        String Data = "{";
-                        Data += "\"userData\":\"" + strHex + "\"";
-                        Data += ",\"assetID\":\"" + product.assetID+ "\"";
-                        Data += ",\"model\":\"" + product.model+ "\"";
-                        Data += ",\"manufacturer\":\"" + product.manufacturer+ "\"";
-                        Data += ",\"kind\":\"" + product.kind+ "\"";
+                        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 += "}";
-                        // wsdd 添加读取的数据,此处应该返回数据strEPC到RN
-                        // 返回给RN的数据格式 {"userData":"6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52","assetID":"4330012800000002178203  ","model":"002型","manufacturer":"北京***公司","kind":"电压互感器"}
                         MainApplication.GetReactPackage().reactModule.sendMsgToRN("MsgFromAndroid", Data);
                         mContext.playSound(1);
                     } else {
@@ -130,27 +156,61 @@ public class UHFReadTagFragment {
         public void run() {
             String epc;
             String strTid;
-            String UserData;
+            String strUser;
             UHFTAGInfo res = null;
             while (loopFlag) {
                 res = mContext.mReader.readTagFromBuffer();
                 if (res != null) {
-//                    epc = res.getEPC();
-//                    Log.e("++++++++++", epc);
                     strTid = res.getTid();
-//                    Log.e("==========", strTid);
-//                    UserData = res.getUser();
-//                    Log.e("----------", UserData);
+                    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 + "\"";
+                    }
+                    Data += "}";
+
                     // wsdd  多线程,循环读取数据,此处应该返回数据epc到RN
-                    // MainApplication.GetReactPackage().reactModule.sendMsgToRN("MsgFromAndroid", strTid);
+                    MainApplication.GetReactPackage().reactModule.sendMsgToRN("MsgFromAndroid", Data);
                     mContext.playSound(1);
                 }
-                try
-                {
+                try {
                     Thread.sleep(100);//毫秒
 //                    Thread.currentThread().sleep(1000);//毫秒
-                }
-                catch(Exception e){
+                } catch (Exception e) {
                     UIHelper.ToastMessage(mContext, "读取标签异常,停止读取");
                     stopInventory();
                 }

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


+ 153 - 73
jscore/pages/Desktop/Home.js

@@ -1,19 +1,26 @@
 import React, {Component} from 'react';
-import {StyleSheet, View, Text, DeviceEventEmitter, TouchableOpacity, ToastAndroid} from 'react-native';
+import {StyleSheet, View, Text, DeviceEventEmitter, TouchableOpacity, ToastAndroid, 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;
 
 class DesktopHome extends Component {
     constructor(props) {
         super(props);
         this.state = {
-            data: [3, 4, 5],
+            data: [],
+            userData: [],
+            isStart: true,
         };
     }
 
     componentDidMount() {
-        ReadUHF.changeFlag(0)
+        ReadUHF.changeFlag(1)
         DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
+        DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
     }
 
     componentWillUnmount() {
@@ -21,39 +28,139 @@ class DesktopHome extends Component {
     }
 
     _addCode = (item) => {
-        console.log(111111111111,item)
-        // let str = '{"userData":"6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52",' +
-        //     '"assetID":"4330012800000002178203"  ,"model":"002型","manufacturer":"北京公司","kind":"电压互感器"}'
-        // let str = '{"name": "cxh", "sex": "man" }';
-        // console.log(2333333333,str)
         const str = JSON.parse(item)
-        console.log(22222222222,str, str['kind'])
-        let {data} = this.state;
-        data.push(item)
-        this.setState({data})
+        // 防止重复扫描
+        let {data, userData} = this.state;
+        const product_index = userData.indexOf(str['userData'])
+        if (product_index < 0) {
+            userData.push(str['userData'])
+            data.push(str)
+            this.setState({data, userData})
+        }
     }
     _start = () => {
         let {isStart} = this.state;
         ReadUHF.doRead()
         this.setState({isStart: !isStart})
     }
+    onKeyDown = () => {
+        let {isStart} = this.state;
+        this.setState({isStart: !isStart})
+    }
 
-    render() {
+    dianYaRender = (item, index) => {
+        const assetID = item.assetID.slice(7, 21)
+        const districtText = item.districtText.split('-')[0]
+        return (
+            <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.secondVoltage}</Text>
+                    <View style={styles.centerWidth}>
+                        <Text style={styles.textColor3}>{item.accuracy}</Text>
+                    </View>
+                    <Text style={styles.textColor3}>{item.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.voltageFactor}</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>
+        )
+    }
+
+    dianLiuRender = (item, index) => {
+        return (
+            <Text>电流</Text>
+        )
+    }
+
+    errorRender = (item, index) => {
+         return (
+            <View
+                key={index}
+                style={[styles.mainView,{padding:10}]}
+            >
+                <Text style={{color:'red'}}>{item.error_msg}</Text>
+            </View>
+        )
+    }
 
+    render() {
+        let {isStart} = this.state;
+        const start_text = isStart ? '开始识别' : '停止识别'
         return (
             <View style={styles.container}>
-                {
-                    this.state.data.map((item, index) => {
+                <View style={styles.container}>
+                    {
+                        this.state.data.map((item, index) => {
+                            if (item.error) {
+                                return this.errorRender(item, index)
+                            }
+                            else if (item.kind.indexOf('电流') > -1) {
+                                return this.dianYaRender(item, index)
+                            }
+                            else if (item.kind.indexOf('电流') > -1) {
+                                return this.dianLiuRender(item, index)
+                            }
 
-                        return (
-                            <Text key={index}>{item}</Text>
-                        )
-                    })
-                }
+                        })
+                    }
+                </View>
                 <Button onPress={() => this._start()}
                         type="primary"
+                        style={[ComponentsStyles.button, {backgroundColor: isStart ? '#0099FF' : 'red',}]}
                 >
-                    开始
+                    <Text style={{color: '#fff'}}>
+                        {start_text}
+                    </Text>
                 </Button>
             </View>
         );
@@ -64,65 +171,38 @@ const styles = StyleSheet.create({
     container: {
         flex: 1
     },
-    userContainer: {
-        height: 50,
-        backgroundColor: '#7ff0ed',
-        flexDirection: 'row',
+    textColor: {
+        color: '#333',
+        textAlign: 'center',
     },
-    userImg: {
-        fontFamily: 'iconfont',
-        color: '#fff',
-        paddingLeft: 10,
-        paddingTop: 5,
-        fontSize: 35,
+    textColor3: {
+        color: '#333',
+        textAlign: 'center',
+        width: (screenW - 9) / 3,
+
     },
-    userInfo: {
-        marginBottom: 5,
-        paddingTop: 5,
-        paddingLeft: 10,
-        flex: 1
+    textColor2: {
+        color: '#333',
+        textAlign: 'center',
+        width: (screenW - 10) / 2,
     },
-    userInfoText: {
-        color: '#fff',
+    mainView: {
+        margin: 5,
+        borderWidth: 0.5,
+        borderColor: '#7b7b7b',
     },
-    loginOut: {
+    betweenView: {
         flexDirection: 'row',
-        width: 80,
-        paddingTop: 15,
-        justifyContent: 'center',
-        backgroundColor: '#23d1ff'
-    },
-    loginOutText: {
-        color: '#fff',
-        fontSize: 16,
-    },
-    gridView: {
-        marginTop: 0,
-        flex: 0,
-        padding: 0
-    },
-    itemContainer: {
-        justifyContent: 'flex-end',
-        padding: 20,
+        justifyContent: 'space-between',
+        borderTopWidth: 0.5,
+        borderTopColor: '#7b7b7b',
         alignItems: 'center',
-        textAlign: 'center',
-        borderRightWidth: 1,
-        borderBottomWidth: 1,
-        borderColor: '#eaeaea'
     },
-    iconFont: {
-        color: '#5eafe4',
-        fontFamily: 'iconfont',
-        fontSize: 30,
-        textAlign: 'center',
-        marginBottom: 5
-    },
-    sizeFont: {
-        color: 'black',
-        fontFamily: 'iconfont',
-        fontSize: 12,
-        textAlign: 'center',
-        marginBottom: 5
+    centerWidth: {
+        borderLeftWidth: 0.5,
+        borderRightWidth: 0.5,
+        borderLeftColor: '#7b7b7b',
+        borderRightColor: '#7b7b7b',
     },
 })
 

+ 1 - 0
package.json

@@ -28,6 +28,7 @@
     "react": "16.9.0",
     "react-dom": "^16.8.1",
     "react-native": "0.61.5",
+    "react-native-barcode-builder": "^2.0.0",
     "react-native-gesture-handler": "^1.3.0",
     "react-native-icon-badge": "^1.1.3",
     "react-native-looped-carousel": "^0.1.13",