完成 东集设备开发

master
wangh 6 months ago
parent de8c0011d1
commit c763aa21ae

@ -15,11 +15,11 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
// SO
//noinspection ChromeOsAbiSupport
abiFilters 'arm64-v8a','armeabi' , 'armeabi-v7a'
}
// ndk {
// // SO
// //noinspection ChromeOsAbiSupport
// abiFilters 'arm64-v8a','armeabi' , 'armeabi-v7a'
// }
}
buildTypes {
@ -43,21 +43,14 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
// implementation files('libs\\c5106\\App_Demo_API.jar')
// implementation files('libs\\c5106\\DeviceAPIver20150204.jar')
// implementation files('libs\\c5106\\logutil-1.5.1.1.jar')
implementation files('libs\\c5106\\ModuleAPI_1.jar')
implementation files('libs\\c5106\\uhfr_v1.8.jar')
// implementation files('libs\\c5106\\reader(1).jar')
// implementation files('libs\\c5106\\UHF67_v3.6.jar')
// implementation files('libs\\ModuleAPI_J.jar')
implementation files('libs\\auto9u\\uhf.jar')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.google.code.gson:gson:2.10.1'
// https://mvnrepository.com/artifact/com.lzy.net/okgo
implementation 'com.lzy.net:okgo:3.0.4'
implementation 'org.litepal.guolindev:core:3.2.3'

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -15,17 +15,18 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.JinYuRFID"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<uses-library
android:name="com.seuic.uhf"
android:required="false" />
<activity
android:name=".BlueToothServerActivity"
android:exported="true" />
<receiver
android:name=".broadcast.ScanERCodeReceiver"
android:enabled="true"
android:exported="true" />
<activity
android:name=".AppLoginActivity"
@ -38,17 +39,19 @@
<activity
android:name=".ReadActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".ReadBlueToothActivity"
android:exported="true" />
<activity
android:name=".WriteUserActivity"
android:exported="true" />
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".ConfigurationTableActivity"
android:exported="false" />

@ -0,0 +1,89 @@
package com.example.jinyu_rfid;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import com.example.jinyu_rfid.adapter.ResultAdapter;
import com.example.jinyu_rfid.base.BaseActivity;
import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityAutoidReadBinding;
import com.example.jinyu_rfid.databinding.ActivityAutoidReadBindingImpl;
import com.example.jinyu_rfid.databinding.ActivityReadBinding;
import com.example.jinyu_rfid.rfid.AutoID9UDevice;
import com.example.jinyu_rfid.rfid.RFIDModel;
import com.example.jinyu_rfid.uitls.ASCIIUtil;
import java.util.ArrayList;
import java.util.List;
public class AutoIDReadActivity extends BaseActivity implements DataReturnCall {
private ResultAdapter adapter;
private RFIDModel rfidModel;
private String[] stringArray;
private List<ReadTyreNoResult> list;
private ActivityAutoidReadBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_autoid_read);
binding.setTitle(getString(R.string.go_read));
adapter = new ResultAdapter(this);
list = new ArrayList<>(11);
adapter.setList(list);
binding.setAdapter(adapter);
// 名称
stringArray = getResources().getStringArray(R.array.project_list);
// rfidModel = new C5106Device(this,this);
rfidModel = new AutoID9UDevice(this, this);
}
// 读取user区
public void readInfo(View view) {
rfidModel.sanUser(80);
}
public void readEPCInfo(View view) {
rfidModel.sanEpc(6);
}
@Override
public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
if (state) {
binding.readTextEpc.setText(info);
music.start();
return;
}
binding.readTextEpc.setText(null);
}
@SuppressLint("NotifyDataSetChanged")
@Override
public void readUserInfo(String user, boolean state, String stateInfo) {
list.clear();
if (state) {
binding.readText.setText(user);
music.start();
String info = ASCIIUtil.hex2Str(user);
Log.e("TAG", "readUserInfo:" + user);
var infos = info.split("~");
for (int i = 0; i < 12; i++) {
list.add(new ReadTyreNoResult(i, stringArray[i], infos[i]));
}
} else {
binding.readText.setText(null);
}
adapter.notifyDataSetChanged();
}
}

@ -24,6 +24,7 @@ import com.example.jinyu_rfid.base.MyResult;
import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityReadBinding;
import com.example.jinyu_rfid.rfid.AutoID9UDevice;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
import com.example.jinyu_rfid.uitls.ASCIIUtil;
@ -63,7 +64,8 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
binding.setAdapter(adapter);
// 名称
stringArray = getResources().getStringArray(R.array.project_list);
rfidModel = new C5106Device(this);
rfidModel = new C5106Device(this,this);
// rfidModel=new AutoID9UDevice(this,this);
}

@ -180,7 +180,7 @@ public class ReadBlueToothActivity extends BaseActivity {
return;
}
user += receivedData.substring(2).trim();
Log.e("TAG", "handleMessage-:" + "4532383036463132303030303030303234314632323541337E33323433323034303634307E4A494E59557E3338352F36355232322E357E4A593539387E323450527E3338352F36355232322E35203136344B2032345052204A5935393820424C34454A597E4B7E3136347E3535352E307E5F7E5F7E");
// Log.e("TAG", "handleMessage-:" + "4532383036463132303030303030303234314632323541337E33323433323034303634307E4A494E59557E3338352F36355232322E357E4A593539387E323450527E3338352F36355232322E35203136344B2032345052204A5935393820424C34454A597E4B7E3136347E3535352E307E5F7E5F7E");
Log.e("TAG", "handleMessage2:" + user);
readUserInfo(user);
user = null;
@ -225,8 +225,7 @@ public class ReadBlueToothActivity extends BaseActivity {
finish();
}
}
@SuppressLint("NotifyDataSetChanged")
@SuppressLint("NotifyDataSetChanged")
public void readEpcCodeInfo(String info) {
music.start();
list.clear();

@ -4,7 +4,6 @@ import androidx.databinding.DataBindingUtil;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
@ -18,9 +17,9 @@ import com.example.jinyu_rfid.base.MyRecultCall;
import com.example.jinyu_rfid.base.MyResult;
import com.example.jinyu_rfid.been.ConfigurationTable;
import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.broadcast.ScanERCodeReceiver;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding;
import com.example.jinyu_rfid.rfid.AutoID9UDevice;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
import com.example.jinyu_rfid.uitls.ASCIIUtil;
@ -54,14 +53,13 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user);
intent1 = new Intent(this, ReadActivity.class);
intent2 = new Intent(this, ConfigurationTableActivity.class);
ScanERCodeReceiver scanERCodeReceiver = new ScanERCodeReceiver(this);
registerReceiver(scanERCodeReceiver, new IntentFilter("com.rfid.SCAN"));
adapter = new ResultAdapter(this);
binding.setAdapter(adapter);
popupMenu = new PopupMenu(this, binding.writeMenu);
popupMenu.setOnMenuItemClickListener(this);
getMenuInflater().inflate(R.menu.activity_menu, popupMenu.getMenu());
rfidModel = new C5106Device(this);
rfidModel = new C5106Device(this,this);
// rfidModel=new AutoID9UDevice(this,this);
}
@ -85,7 +83,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
if (epcStr.isEmpty()) return;
// EPC编码~胎号~品牌~规格~花纹~层级~轮胎名称~速度级别~负荷指数~轮辋直径~扁平比~销售区域
List<ConfigurationTable> tagList = LitePal.findAll(ConfigurationTable.class);
StringBuilder tagUserStr = new StringBuilder(tagList.get(0).isState() ? epcStr : "_");
StringBuilder tagUserStr = new StringBuilder(tagList.get(0).isState() ? epcStr:"_");
tagUserStr.append("~");
for (int i = 1; i < 12; i++) {
var configuration = tagList.get(i);
@ -123,11 +121,12 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
writeUserState = true;
return;
}
tipDialog.shouDialog(false, body.getSaveMessage());
}
});
}
} //writeUserState = true;
if (writeUserState){
Log.e("TAG", "写入");
var writeState = rfidModel.writeUser(validateDataLength(user), epcStr);
@ -143,6 +142,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
}
public String validateDataLength(String data) {
int length = data.length();
int remainder = length % 4;

@ -1,29 +0,0 @@
package com.example.jinyu_rfid.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.example.jinyu_rfid.callback.DataReturnCall;
public class ScanERCodeReceiver extends BroadcastReceiver {
private DataReturnCall call;
public ScanERCodeReceiver() {
}
public ScanERCodeReceiver(DataReturnCall call) {
this.call = call;
}
@Override
public void onReceive(Context context, Intent intent) {
byte[] data = intent.getByteArrayExtra("data");
if (data != null) {
String barcode = new String(data);
Log.e("", "onReceive, data:" + barcode);
call.readerCodeInfo(barcode);
}
}
}

@ -0,0 +1,128 @@
package com.example.jinyu_rfid.rfid;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.uitls.ASCIIUtil;
import com.seuic.uhf.EPC;
import com.seuic.uhf.UHFService;
import cn.pda.serialport.Tools;
/**
* @author wanghao
* @date 2024/6/7 13:36
*/
public class AutoID9UDevice implements RFIDModel {
private DataReturnCall call;
private UHFService uhfService;
private byte[] password = AutoID9UUtil.getHexByteArray("00000000");
private AutoIDdeviceScanERCodeReceiver scanERCodeReceiver;
private Context context;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
public AutoID9UDevice(DataReturnCall call, Context context) {
this.call = call;
this.context = context;
uhfService = UHFService.getInstance();
uhfService.setParameters(UHFService.PARAMETER_INVENTORY_SESSION,0);
if (!uhfService.isopen()) {
uhfService.open();
}
Log.e("TAG", "上电:" + uhfService.isopen());
Log.e("TAG", "功率:" + uhfService.getPower());
scanERCodeReceiver = new AutoIDdeviceScanERCodeReceiver();
context.registerReceiver(scanERCodeReceiver, new IntentFilter("com.android.server.scannerservice.broadcast"));
}
@Override
public void sanEpc(int len) {
EPC epc = new EPC();
var result = uhfService.inventoryOnce(epc, 100);
Log.e("TAG", "sanEpc:" + result);
String info = null;
if (result) {
var id = epc.getId();
Log.e("TAG", "sanEpc:" + id);
var length = id.length();
var i = len * 4;
if (i < length) {
id = id.substring(0, i);
} else if (i > length) {
var tag = i - length;
for (int j = 0; j < tag; j++) {
id += "0";
}
}
info = id;
}
call.readEpcCodeInfo(info, result, null);
}
@Override
public boolean writeUser(String writeStr, String tagEpc) {
var bytes = AutoID9UUtil.getHexByteArray(writeStr);
Log.e("TAG", "writeUser:" + tagEpc);
var b = uhfService.writeTagData(AutoID9UUtil.getHexByteArray(tagEpc), password,
3, 0, bytes.length, bytes);
return b;
}
String id = null;
@Override
public void sanUser(int len) {
var power = uhfService.getPower();
Log.e("TAG", "设备功率:" + power);
String info = null;
EPC epc=new EPC();
var result = uhfService.inventoryOnce(epc, 100);
Log.e("TAG", "epcid:" + epc.getId());
if (result) {
var i = len * 2;
byte[] data = new byte[i];
result = uhfService.readTagData(AutoID9UUtil.getHexByteArray(epc.getId()), password, 3, 0, i, data);
Log.e("TAG", "按长度读取:" + result);
if (result) {
info = Tools.Bytes2HexString(data, data.length);
}
}
call.readUserInfo(info,result,null);
}
@Override
public void close() {
uhfService.close();
context.unregisterReceiver(scanERCodeReceiver);
}
//
// @Override
// public void loading() {
// uhfService.close();
// uhfService.open();
// Log.e("TAG", "loading:" + uhfService.getPower());
// }
class AutoIDdeviceScanERCodeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String data = intent.getStringExtra("scannerdata");
if (data != null) {
call.readerCodeInfo(data);
}
}
}
}

@ -0,0 +1,121 @@
package com.example.jinyu_rfid.rfid;
public class AutoID9UUtil {
/**
* Copy the array at the specified location
*/
public static void memcpy(byte[] bytesTo, byte[] bytesFrom, int len) {
memcpy(bytesTo, 0, bytesFrom, 0, len);
}
/**
*
*/
public static void memcpy(byte[] bytesTo, int startIndexTo, byte[] bytesFrom, int startIndexFrom, int len) {
while (len-- > 0) {
bytesTo[startIndexTo++] = bytesFrom[startIndexFrom++];
}
}
/**
* Copy the array from the start
*/
public static boolean memcmp(byte[] bytes1, byte[] bytes2, int len) {
if (len < 1) {
return false;
}
int startIndex = 0;
while (len-- > 0) {
if (bytes1[startIndex] != bytes2[startIndex]) {
return false;
}
startIndex++;
}
return true;
}
/**
* byte array to hexadecimal string
*/
public static String getHexString(byte[] b, int length) {
return getHexString(b, length, "");
}
/**
* Convert the specified splitter
*/
public static String getHexString(byte[] b, int length, String split) {
StringBuilder hex = new StringBuilder("");
String temp = null;
for (int i = 0; i < length; i++) {
temp = Integer.toHexString(b[i] & 0xFF);
if (temp.length() == 1) {
temp = '0' + temp;
}
hex.append(temp + split);
}
return hex.toString().trim().toUpperCase();
}
/**
* String to hexadecimal array
*/
public static byte[] getHexByteArray(String hexString) {
byte[] buffer = new byte[hexString.length() / 2];
if (hexString == null || hexString.equals("")) {
return null;
}
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
char[] hexChars = hexString.toCharArray();
for (int i = 0; i < length; i++) {
int pos = i * 2;
buffer[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return buffer;
}
/**
* String to hexadecimal array (Specified length)
*/
public static int getHexByteArray(String hexString, byte[] buffer, int nSize) {
hexString.replace(" ", "");
if (nSize > hexString.length() / 2) {
nSize = hexString.length() / 2;
if (hexString.length() == 1) {
nSize = 1;
String str = "0";
hexString = str + hexString;
}
}
char[] hexChars = hexString.toCharArray();
for (int i = 0; i < nSize; i++) {
int pos = i * 2;
buffer[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return nSize;
}
/**
*
*/
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
/**
* byte array to hexadecimal string
*/
public static String ByteArrayToString(byte[] bt_ary) {
StringBuilder sb = new StringBuilder();
if (bt_ary != null)
for (byte b : bt_ary) {
sb.append(String.format("%02X ", b));
}
return sb.toString();
}
}

@ -1,5 +1,9 @@
package com.example.jinyu_rfid.rfid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import com.example.jinyu_rfid.callback.DataReturnCall;
@ -18,10 +22,15 @@ public class C5106Device implements RFIDModel {
private UHFRManager uhfrManager;
private DataReturnCall call;
public byte[] accessBytes = Tools.HexString2Bytes("00000000");
private Context context;
private ScanERCodeReceiver scanERCodeReceiver;
public C5106Device(DataReturnCall call) {
public C5106Device(DataReturnCall call, Context context) {
uhfrManager = UHFRManager.getInstance();
this.call = call;
this.context = context;
scanERCodeReceiver = new ScanERCodeReceiver();
context.registerReceiver(scanERCodeReceiver, new IntentFilter("com.rfid.SCAN"));
}
@ -79,5 +88,19 @@ public class C5106Device implements RFIDModel {
public void close() {
if (uhfrManager != null)
uhfrManager.close();
context.unregisterReceiver(scanERCodeReceiver);
}
class ScanERCodeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
byte[] data = intent.getByteArrayExtra("data");
if (data != null) {
String barcode = new String(data);
Log.e("", "onReceive, data:" + barcode);
call.readerCodeInfo(barcode);
}
}
}
}

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="title"
type="String" />
<variable
name="adapter"
type="com.example.jinyu_rfid.adapter.ResultAdapter" />
<import type="android.view.View" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ReadActivity">
<include
layout="@layout/toolbar"
app:title="@{title}" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp">
<TextView
style="@style/text_name"
android:layout_width="120dp"
android:layout_height="match_parent"
android:text="@string/epc_code" />
<TextView
android:id="@+id/read_text_epc"
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/san_text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp">
<TextView
style="@style/text_name"
android:layout_width="120dp"
android:layout_height="match_parent"
android:text="@string/scanning_area" />
<TextView
android:id="@+id/read_text"
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/san_text" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:adapter="@{adapter}"
android:padding="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<Button
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:onClick="readID"
android:text="@string/read_epc"
android:textSize="18sp" />
<Button
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_margin="10dp"
android:onClick="readInfo"
android:text="@string/go_read"
android:textSize="18sp" />
</LinearLayout>
</layout>

@ -55,6 +55,8 @@
android:padding="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<Button
android:layout_width="match_parent"
android:layout_height="55dp"

Loading…
Cancel
Save