完成 读取epc和规则

master
wangh 6 months ago
parent a88d5e017f
commit a8ee80ce6d

@ -14,6 +14,12 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
// SO
//noinspection ChromeOsAbiSupport
abiFilters 'arm64-v8a','armeabi' , 'armeabi-v7a'
}
}
buildTypes {

@ -24,25 +24,25 @@
<activity
android:name=".WriteUserActivity"
android:exported="false" />
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" />
<activity
android:name=".MainActivity"
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=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

@ -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<ReadTyreNoResult> 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<ConfigurationTable> 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<ReadTyreNoResult> 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
@ -81,15 +127,19 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall {
Map<String, String> map = new HashMap<>();
map.put("TyreNo", erCode);
map.put("token", "123456");
OkGo.<MyResult>post(url + "/readTyreNo")
.upRequestBody(RequestBody.create(JSON,gson.toJson(map)))
.execute(new MyRecultCall(dialog, this) {
OkGo.<MyResult>post(url + "/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getResultFlag().equals("1")) {
List<ReadTyreNoResult> list=gson.fromJson(body.getJson(),new TypeToken<List<ReadTyreNoResult>>(){}.getType());
list = gson.fromJson(body.getJson(), new TypeToken<List<ReadTyreNoResult>>() {
}.getType());
list.remove(0);
adapter.setList(list);
adapter.notifyDataSetChanged();
return;
}
Toast.makeText(WriteUserActivity.this, body.getResultData().toString(), Toast.LENGTH_SHORT).show();

@ -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<ResultAdapter.MyViewHolder> {
private Context context;
private LayoutInflater inflater;
private List<ReadTyreNoResult> list;
public ResultAdapter(Context context) {
this.context = context;
inflater=LayoutInflater.from(context);
}
public void setList(List<ReadTyreNoResult> 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;
}
}
}

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

@ -7,10 +7,14 @@ package com.example.jinyu_rfid.callback;
public interface DataReturnCall {
/**
*
*
* @param code
* @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);
}

@ -2,7 +2,13 @@ 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
@ -10,15 +16,19 @@ import com.handheld.uhfr.UHFRManager;
*/
public class C5106Device implements RFIDModel {
private UHFRManager uhfrManager;
public C5106Device() {
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());
}
}

@ -5,5 +5,5 @@ package com.example.jinyu_rfid.rfid;
* @date 2024/5/16 15:12
*/
public interface RFIDModel {
void sanEpc(int len);
}

@ -8,6 +8,9 @@
<variable
name="title"
type="String" />
<variable
name="adapter"
type="com.example.jinyu_rfid.adapter.ResultAdapter" />
</data>
<LinearLayout
@ -43,12 +46,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:adapter="@{adapter}"
android:padding="5dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp">
<TextView

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="item"
type="com.example.jinyu_rfid.been.ReadTyreNoResult" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_marginTop="2dp"
android:background="#DEE3E6"
android:orientation="horizontal">
<TextView
android:id="@+id/item_index"
style="@style/item_text_style"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text='@{item.propertyIndex+""}' />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
style="@style/item_text_style"
android:layout_width="120dp"
android:layout_height="match_parent"
android:text="@{item.propertyName}"/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
style="@style/item_text_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@{item.propertyContent}" />
</LinearLayout>
</layout>

Binary file not shown.
Loading…
Cancel
Save