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 0000000..0d1d5cb Binary files /dev/null and b/app/src/main/res/raw/msg.mp3 differ