From a8ee80ce6dc1a644e711f02f437ec9b421d21bb0 Mon Sep 17 00:00:00 2001
From: wangh <123456>
Date: Tue, 21 May 2024 14:31:14 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E8=AF=BB=E5=8F=96epc?=
=?UTF-8?q?=E5=92=8C=E8=A7=84=E5=88=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/build.gradle | 6 ++
app/src/main/AndroidManifest.xml | 26 ++---
.../example/jinyu_rfid/WriteUserActivity.java | 94 ++++++++++++++----
.../jinyu_rfid/adapter/ResultAdapter.java | 69 +++++++++++++
.../example/jinyu_rfid/base/BaseActivity.java | 5 +
.../jinyu_rfid/callback/DataReturnCall.java | 10 +-
.../example/jinyu_rfid/rfid/C5106Device.java | 28 ++++--
.../example/jinyu_rfid/rfid/RFIDModel.java | 2 +-
.../main/res/layout/activity_write_user.xml | 6 +-
app/src/main/res/layout/item_result.xml | 52 ++++++++++
app/src/main/res/raw/msg.mp3 | Bin 0 -> 2924 bytes
11 files changed, 249 insertions(+), 49 deletions(-)
create mode 100644 app/src/main/java/com/example/jinyu_rfid/adapter/ResultAdapter.java
create mode 100644 app/src/main/res/layout/item_result.xml
create mode 100644 app/src/main/res/raw/msg.mp3
diff --git a/app/build.gradle b/app/build.gradle
index c101ac0..bd3a23f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -14,6 +14,12 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
+ ndk {
+ // 设置支持的SO库架构
+ //noinspection ChromeOsAbiSupport
+ abiFilters 'arm64-v8a','armeabi' , 'armeabi-v7a'
+ }
}
buildTypes {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 97c7f0e..8a080c0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -18,30 +18,30 @@
android:enabled="true"
android:exported="true">
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
diff --git a/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java b/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java
index 9de9bf9..8e3f9e3 100644
--- a/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java
+++ b/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java
@@ -2,15 +2,19 @@ package com.example.jinyu_rfid;
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.View;
import android.widget.Toast;
+import com.example.jinyu_rfid.adapter.ResultAdapter;
import com.example.jinyu_rfid.base.BaseActivity;
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;
@@ -21,9 +25,12 @@ import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
+import org.litepal.LitePal;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import okhttp3.RequestBody;
@@ -32,28 +39,61 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
private Intent intent2;
private RFIDModel rfidModel;
private ActivityWriteUserBinding binding;
+ private ResultAdapter adapter;
+ private List list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_write_user);
binding.setTitle(getString(R.string.activity_name_configuration));
- rfidModel = new C5106Device();
+ rfidModel = new C5106Device(this);
intent1 = new Intent(this, ConfigurationTableActivity.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);
}
public void writeReadEPC(View view) {
-
+ rfidModel.sanEpc(6);
}
+ // 写入
public void writeUser(View view) {
-
+ if (list == null || list.isEmpty()) return;
+ var epcStr = binding.writeEpcCode.getText().toString();
+ if (epcStr.isEmpty()) return;
+ // EPC编码~胎号~品牌~规格~花纹~层级~轮胎名称~速度级别~负荷指数~轮辋直径~扁平比~销售区域
+ List tagList = LitePal.findAll(ConfigurationTable.class);
+ StringBuilder tagUserStr = new StringBuilder(tagList.get(0).isState() ? epcStr : "_");
+ for (int i = 1; i < 12; i++) {
+ var configuration = tagList.get(i);
+ var state = configuration.isState();
+ tagUserStr.append("~");
+ /* if (state) {
+ Optional optionalResult = Optional.ofNullable(list.get(i-1));
+ String propertyContent = optionalResult.map(ReadTyreNoResult::getPropertyContent).orElse("_");
+ tagUserStr.append(propertyContent);
+ } else {
+ tagUserStr.append("_");
+ }*/
+ if (state) {
+ try {
+ var result = list.get(i-1);
+ var propertyContent = result.getPropertyContent();
+ tagUserStr.append(propertyContent==null?"_":propertyContent);
+ }catch (IndexOutOfBoundsException e){
+ tagUserStr.append("_");
+ }
+ } else {
+ tagUserStr.append("_");
+ }
+ }
+ Log.e("TAG", "writeUser:" + tagUserStr);
}
@@ -66,8 +106,14 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
}
@Override
- public void readEpcCodeInfo(String epc) {
- binding.writeEpcCode.setText(epc);
+ public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
+ if (state) {
+ binding.writeEpcCode.setText(info);
+ super.music.start();
+ return;
+ }
+ binding.writeEpcCode.setText(null);
+ // Log.e("TAG", "读取状态:" + stateInfo);
}
@Override
@@ -78,22 +124,26 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
@Override
public void readerCodeInfo(String erCode) {
binding.writeTire.setText(erCode);
- Map map=new HashMap<>();
+ Map map = new HashMap<>();
map.put("TyreNo", erCode);
- map.put("token","123456");
- OkGo.post(url + "/readTyreNo")
- .upRequestBody(RequestBody.create(JSON,gson.toJson(map)))
- .execute(new MyRecultCall(dialog, this) {
- @Override
- public void onSuccess(Response response) {
- super.onSuccess(response);
- var body = response.body();
- if (body.getResultFlag().equals("1")){
- List list=gson.fromJson(body.getJson(),new TypeToken>(){}.getType());
- return;
- }
- Toast.makeText(WriteUserActivity.this, body.getResultData().toString(), Toast.LENGTH_SHORT).show();
- }
- });
+ map.put("token", "123456");
+ OkGo.post(url + "/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
+ @SuppressLint("NotifyDataSetChanged")
+ @Override
+ public void onSuccess(Response response) {
+ super.onSuccess(response);
+ var body = response.body();
+ if (body.getResultFlag().equals("1")) {
+
+ list = gson.fromJson(body.getJson(), new TypeToken>() {
+ }.getType());
+ list.remove(0);
+ adapter.setList(list);
+ adapter.notifyDataSetChanged();
+ return;
+ }
+ Toast.makeText(WriteUserActivity.this, body.getResultData().toString(), Toast.LENGTH_SHORT).show();
+ }
+ });
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/jinyu_rfid/adapter/ResultAdapter.java b/app/src/main/java/com/example/jinyu_rfid/adapter/ResultAdapter.java
new file mode 100644
index 0000000..2588bbf
--- /dev/null
+++ b/app/src/main/java/com/example/jinyu_rfid/adapter/ResultAdapter.java
@@ -0,0 +1,69 @@
+package com.example.jinyu_rfid.adapter;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.databinding.DataBindingUtil;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.example.jinyu_rfid.BR;
+import com.example.jinyu_rfid.R;
+import com.example.jinyu_rfid.been.ConfigurationData;
+import com.example.jinyu_rfid.been.ReadTyreNoResult;
+import com.example.jinyu_rfid.databinding.ItemConfigurationBinding;
+import com.example.jinyu_rfid.databinding.ItemResultBinding;
+
+import java.util.List;
+
+/**
+ * @author wanghao
+ * @date 2024/5/17 15:35
+ */
+public class ResultAdapter extends RecyclerView.Adapter {
+ private Context context;
+ private LayoutInflater inflater;
+
+ private List list;
+ public ResultAdapter(Context context) {
+ this.context = context;
+
+ inflater=LayoutInflater.from(context);
+ }
+
+ public void setList(List list) {
+ this.list = list;
+ }
+
+ @NonNull
+ @Override
+ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ ItemResultBinding binding= DataBindingUtil.inflate(inflater, R.layout.item_result,parent,false);
+ return new MyViewHolder(binding);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
+ var item = list.get(position);
+ holder.binding.setVariable(BR.item,item);
+ holder.binding.executePendingBindings();
+ }
+
+ @Override
+ public int getItemCount() {
+ return list==null?0:list.size();
+ }
+
+ class MyViewHolder extends RecyclerView.ViewHolder {
+ private ItemResultBinding binding;
+
+ public MyViewHolder(ItemResultBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ }
+
+
+ }
+
+}
diff --git a/app/src/main/java/com/example/jinyu_rfid/base/BaseActivity.java b/app/src/main/java/com/example/jinyu_rfid/base/BaseActivity.java
index 7118e3b..520bfea 100644
--- a/app/src/main/java/com/example/jinyu_rfid/base/BaseActivity.java
+++ b/app/src/main/java/com/example/jinyu_rfid/base/BaseActivity.java
@@ -10,6 +10,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -23,6 +24,7 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
+import com.example.jinyu_rfid.R;
import com.google.gson.Gson;
import java.io.ByteArrayOutputStream;
@@ -44,6 +46,7 @@ public class BaseActivity extends AppCompatActivity {
public Gson gson;
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private MyReceiver myReceiver;
+ public MediaPlayer music;
public Context context;
@SuppressLint("SimpleDateFormat")
public SimpleDateFormat format= new SimpleDateFormat( "yyyyMMdd_HHmmss");
@@ -55,6 +58,8 @@ public class BaseActivity extends AppCompatActivity {
this.context=this;
initDialog();
+ music = MediaPlayer.create(this, R.raw.msg);
+
}
diff --git a/app/src/main/java/com/example/jinyu_rfid/callback/DataReturnCall.java b/app/src/main/java/com/example/jinyu_rfid/callback/DataReturnCall.java
index 1c91161..870241b 100644
--- a/app/src/main/java/com/example/jinyu_rfid/callback/DataReturnCall.java
+++ b/app/src/main/java/com/example/jinyu_rfid/callback/DataReturnCall.java
@@ -6,11 +6,15 @@ package com.example.jinyu_rfid.callback;
*/
public interface DataReturnCall {
/**
- *读取信息
+ * 读取信息
+ *
* @param code
- * @param mbank 1:epc 3:user 2:barCode
+ * @param mbank 1:epc 3:user 2:barCode
+ * @param info
+ * @param state
+ * @param stateInfo
*/
- void readEpcCodeInfo(String epc );
+ void readEpcCodeInfo(String info, boolean state, String stateInfo );
void readUserInfo(String user);
void readerCodeInfo(String erCode);
}
diff --git a/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java b/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java
index 97953b8..30dea46 100644
--- a/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java
+++ b/app/src/main/java/com/example/jinyu_rfid/rfid/C5106Device.java
@@ -2,23 +2,33 @@ package com.example.jinyu_rfid.rfid;
import android.util.Log;
+import com.example.jinyu_rfid.callback.DataReturnCall;
import com.handheld.uhfr.UHFRManager;
+import com.uhf.api.cls.Reader;
+
+import java.util.List;
+
+import cn.pda.serialport.Tools;
/**
* @author wanghao
* @date 2024/5/16 15:12
*/
-public class C5106Device implements RFIDModel{
+public class C5106Device implements RFIDModel {
private UHFRManager uhfrManager;
-
- public C5106Device() {
- uhfrManager=UHFRManager.getInstance();
+ private DataReturnCall call;
+ public byte[] accessBytes = Tools.HexString2Bytes("00000000");
+ public C5106Device(DataReturnCall call) {
+ uhfrManager = UHFRManager.getInstance();
+ this.call=call;
}
- //
- // public boolean getTagData(int mbank, int startaddr, int len,
- // byte[] rdata, byte[] password, short timeout){
- //
- // }
+
+ @Override
+ public void sanEpc(int len) {
+ byte[] rdata=new byte[len*2];
+ Reader.READER_ERR readerErr = uhfrManager.getTagData(1, 2, len, rdata, accessBytes, (short) 200);
+ call.readEpcCodeInfo(Tools.Bytes2HexString(rdata,rdata.length),readerErr== Reader.READER_ERR.MT_OK_ERR,readerErr.toString());
+ }
}
diff --git a/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java b/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java
index d634ba3..4f0dd24 100644
--- a/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java
+++ b/app/src/main/java/com/example/jinyu_rfid/rfid/RFIDModel.java
@@ -5,5 +5,5 @@ package com.example.jinyu_rfid.rfid;
* @date 2024/5/16 15:12
*/
public interface RFIDModel {
-
+ void sanEpc(int len);
}
diff --git a/app/src/main/res/layout/activity_write_user.xml b/app/src/main/res/layout/activity_write_user.xml
index 5c10a4f..3c522eb 100644
--- a/app/src/main/res/layout/activity_write_user.xml
+++ b/app/src/main/res/layout/activity_write_user.xml
@@ -8,6 +8,9 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/raw/msg.mp3 b/app/src/main/res/raw/msg.mp3
new file mode 100644
index 0000000000000000000000000000000000000000..0d1d5cb9d8e03fd099aab888c87f1dc1208580b1
GIT binary patch
literal 2924
zcmd^B{Zms{8h+2c$xR4}M!pPLkN^oE5y%ArLA&F%3l@yHaa~+dfs4qeRDwnPpq7h+
z$`;!yK|zt4szpH56a`_0dMTEb4;MtBpzRd8Vz(`&5piLwco%lZ{=gs5b!MNLGv|Hh
zoH_4vo@dUSmwUqAf|m&2k(fRc&z~6tfMpt}=OA(}m^rALi@v$w=3u6l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