diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2423a0e..1bc6568 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -48,7 +48,10 @@
-
+
+
+
+
-
-
-
-
+
diff --git a/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java b/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java
index ff4aa26..000087f 100644
--- a/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java
+++ b/app/src/main/java/com/example/jinyu_rfid/ReadActivity.java
@@ -65,7 +65,6 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
// 名称
stringArray = getResources().getStringArray(R.array.project_list);
rfidModel = new C5106Device(this,this);
- // rfidModel=new AutoID9UDevice(this,this);
}
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 46a707f..1852171 100644
--- a/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java
+++ b/app/src/main/java/com/example/jinyu_rfid/WriteUserActivity.java
@@ -19,6 +19,8 @@ import com.example.jinyu_rfid.been.ConfigurationTable;
import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding;
+import com.example.jinyu_rfid.dialog.DialogCall;
+import com.example.jinyu_rfid.dialog.MyAlertDialog;
import com.example.jinyu_rfid.rfid.AutoID9UDevice;
import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel;
@@ -37,7 +39,7 @@ import java.util.Optional;
import okhttp3.RequestBody;
-public class WriteUserActivity extends BaseActivity implements DataReturnCall, PopupMenu.OnMenuItemClickListener {
+public class WriteUserActivity extends BaseActivity implements DataReturnCall, PopupMenu.OnMenuItemClickListener, DialogCall {
private Intent intent1;
private Intent intent2;
private RFIDModel rfidModel;
@@ -45,7 +47,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
private ResultAdapter adapter;
private List list;
private PopupMenu popupMenu;
-
+ private MyAlertDialog myAlertDialog;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -58,13 +60,21 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
popupMenu = new PopupMenu(this, binding.writeMenu);
popupMenu.setOnMenuItemClickListener(this);
getMenuInflater().inflate(R.menu.activity_menu, popupMenu.getMenu());
- // rfidModel = new C5106Device(this,this);
- rfidModel=new AutoID9UDevice(this,this);
- if (rfidModel instanceof C5106Device){
+ rfidModel = new C5106Device(this, this);
+ // rfidModel = new AutoID9UDevice(this, this);
+ if (rfidModel instanceof C5106Device) {
intent1 = new Intent(this, ReadActivity.class);
- }else {
+ } else {
intent1 = new Intent(this, Read2Activity.class);
}
+
+ myAlertDialog = new MyAlertDialog(this);
+ myAlertDialog.setDialogCall(this);
+ var power = SharedPreferencesUtils.getInt("power", 30);
+ Log.e("TAG", "记忆功率:" + power);
+ if (power!=30){
+ rfidModel.setPower(power);
+ }
}
@@ -88,7 +98,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
if (epcStr.isEmpty()) return;
// EPC编码~胎号~品牌~规格~花纹~层级~轮胎名称~速度级别~负荷指数~轮辋直径~扁平比~销售区域
List 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);
@@ -113,9 +123,9 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
map.put("EpcCode", epcStr);
map.put("TyreNo", list.get(0).getPropertyContent());
map.put("token", "123456");
- map.put("Language", SharedPreferencesUtils.getstring("languageIndex","0"));
+ map.put("Language", SharedPreferencesUtils.getstring("languageIndex", "0"));
Log.e("TAG", "writeUser:" + 2);
- OkGo.post("http://"+url + "/rfid/write").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
+ OkGo.post("http://" + url + "/rfid/write").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response response) {
@@ -124,35 +134,34 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
if (body.getSaveFlag().equals("1")) {
Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show();
writeUserState = true;
- writeUser(user,epcStr);
+ writeUser(user, epcStr);
return;
}
tipDialog.shouDialog(false, body.getSaveMessage());
}
});
- }else {
- writeUser(user,epcStr);
+ } else {
+ writeUser(user, epcStr);
}
-
}
- private void writeUser(String user ,String epcStr){
+
+ private void writeUser(String user, String epcStr) {
Log.e("TAG", "写入");
var writeState = rfidModel.writeUser(validateDataLength(user), epcStr);
- tipDialog.shouDialog(writeState,getString(writeState ? R.string.write_success : R.string.write_failed));
+ tipDialog.shouDialog(writeState, getString(writeState ? R.string.write_success : R.string.write_failed));
if (writeState) {
list.clear();
adapter.notifyDataSetChanged();
binding.writeEpcCode.setText(null);
binding.writeTire.setText(null);
- writeUserState=false;
+ writeUserState = false;
}
}
-
public String validateDataLength(String data) {
int length = data.length();
int remainder = length % 4;
@@ -187,8 +196,8 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
Map map = new HashMap<>();
map.put("TyreNo", erCode);
map.put("token", "123456");
- map.put("Language", SharedPreferencesUtils.getstring("languageIndex","0"));
- OkGo.post("http://"+url + "/rfid/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
+ map.put("Language", SharedPreferencesUtils.getstring("languageIndex", "0"));
+ OkGo.post("http://" + url + "/rfid/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response response) {
@@ -213,14 +222,30 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
@Override
public boolean onMenuItemClick(MenuItem item) {
- if (item.getItemId() == R.id.menu_read) {
+
+
+ var itemId = item.getItemId();
+ if (itemId == R.id.menu_read) {
startActivity(intent1);
- } else {
+ } else if (itemId == R.id.menu_configuration) {
startActivity(intent2);
+ } else if (itemId == R.id.menu_setPower) {
+ myAlertDialog.show(SharedPreferencesUtils.getInt("power",30));
}
return true;
}
+
+ @Override
+ public void returnData(int power) {
+ if (rfidModel.setPower(power)){
+ Toast.makeText(context, getString(R.string.tip_set_success), Toast.LENGTH_SHORT).show();
+ SharedPreferencesUtils.putInt("power",power);
+ myAlertDialog.dismiss();
+ return;
+ }
+ Toast.makeText(context, getString(R.string.tip_set_failed), Toast.LENGTH_SHORT).show();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/jinyu_rfid/dialog/DialogCall.java b/app/src/main/java/com/example/jinyu_rfid/dialog/DialogCall.java
new file mode 100644
index 0000000..c77b8a3
--- /dev/null
+++ b/app/src/main/java/com/example/jinyu_rfid/dialog/DialogCall.java
@@ -0,0 +1,9 @@
+package com.example.jinyu_rfid.dialog;
+
+/**
+ * @author wanghao
+ * @date 2024/4/25 9:12
+ */
+public interface DialogCall {
+ void returnData(int power );
+}
diff --git a/app/src/main/java/com/example/jinyu_rfid/dialog/MyAlertDialog.java b/app/src/main/java/com/example/jinyu_rfid/dialog/MyAlertDialog.java
new file mode 100644
index 0000000..dbae486
--- /dev/null
+++ b/app/src/main/java/com/example/jinyu_rfid/dialog/MyAlertDialog.java
@@ -0,0 +1,59 @@
+package com.example.jinyu_rfid.dialog;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import com.example.jinyu_rfid.dialog.DialogCall;
+import com.example.jinyu_rfid.R;
+
+/**
+ * @author wanghao
+ * @date 2024/4/25 9:07
+ */
+public class MyAlertDialog extends Dialog {
+ private DialogCall dialogCall;
+ private int power;
+
+ public void setPower(int power) {
+ this.power = power;
+ }
+
+ public void setDialogCall(DialogCall dialogCall) {
+ this.dialogCall = dialogCall;
+ }
+
+ public MyAlertDialog(Context context) {
+ super(context, R.style.dialog);
+ }
+ private EditText editText;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.dialog_power_layout);
+
+ editText = findViewById(R.id.dialog_text);
+ TextView textView = findViewById(R.id.dialog1_button);
+ textView.setOnClickListener(view -> {
+ String string = editText.getText().toString();
+ if (!string.isEmpty()) {
+ int power = Integer.parseInt(string);
+ Log.e("TAG", "onCreate:" + power);
+ if (power < 5 || power > 30) return;
+ dialogCall.returnData(power);
+ }
+
+ });
+
+ }
+ public void show(int power){
+ super.show();
+ editText.setText(power+"");
+ }
+
+}
diff --git a/app/src/main/java/com/example/jinyu_rfid/rfid/AutoID9UDevice.java b/app/src/main/java/com/example/jinyu_rfid/rfid/AutoID9UDevice.java
index e41807c..03df74d 100644
--- a/app/src/main/java/com/example/jinyu_rfid/rfid/AutoID9UDevice.java
+++ b/app/src/main/java/com/example/jinyu_rfid/rfid/AutoID9UDevice.java
@@ -36,7 +36,6 @@ public class AutoID9UDevice implements RFIDModel {
if (!uhfService.isopen()) {
uhfService.open();
}
-
Log.e("TAG", "上电:" + uhfService.isopen());
Log.e("TAG", "功率:" + uhfService.getPower());
scanERCodeReceiver = new AutoIDdeviceScanERCodeReceiver();
@@ -128,6 +127,12 @@ public class AutoID9UDevice implements RFIDModel {
context.unregisterReceiver(scanERCodeReceiver);
}
+ @Override
+ public boolean setPower(int power) {
+ var b = uhfService.setPower(power);
+ return b;
+ }
+
class AutoIDdeviceScanERCodeReceiver extends BroadcastReceiver {
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 04b7ca2..d5b15c2 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
@@ -27,6 +27,7 @@ public class C5106Device implements RFIDModel {
public C5106Device(DataReturnCall call, Context context) {
uhfrManager = UHFRManager.getInstance();
+ Log.e("TAG", "功率:" +uhfrManager.getPower()[0] );
this.call = call;
this.context = context;
scanERCodeReceiver = new ScanERCodeReceiver();
@@ -78,7 +79,6 @@ public class C5106Device implements RFIDModel {
@Override
public void sanUser(int len) {
-
byte[] rdata = new byte[len * 2];
Reader.READER_ERR readerErr = uhfrManager.getTagData(3, 0, len, rdata, accessBytes, (short) 200);
call.readUserInfo(Tools.Bytes2HexString(rdata, rdata.length), readerErr == Reader.READER_ERR.MT_OK_ERR, readerErr.toString());
@@ -91,6 +91,13 @@ public class C5106Device implements RFIDModel {
context.unregisterReceiver(scanERCodeReceiver);
}
+ @Override
+ public boolean setPower(int power) {
+ Log.e("TAG", "开始设置功率:"+power );
+ var readerErr = uhfrManager.setPower(power, power);
+ return readerErr == Reader.READER_ERR.MT_OK_ERR;
+ }
+
class ScanERCodeReceiver extends BroadcastReceiver {
@Override
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 9334b46..4415df6 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
@@ -16,4 +16,6 @@ public interface RFIDModel {
}
void close();
+
+ boolean setPower(int power);
}
diff --git a/app/src/main/res/layout/dialog_power_layout.xml b/app/src/main/res/layout/dialog_power_layout.xml
new file mode 100644
index 0000000..2f0cbe7
--- /dev/null
+++ b/app/src/main/res/layout/dialog_power_layout.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/activity_menu.xml b/app/src/main/res/menu/activity_menu.xml
index 3f69df8..aac6948 100644
--- a/app/src/main/res/menu/activity_menu.xml
+++ b/app/src/main/res/menu/activity_menu.xml
@@ -7,5 +7,9 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml
index 2504ec3..d0fd8e4 100644
--- a/app/src/main/res/values-en-rUS/strings.xml
+++ b/app/src/main/res/values-en-rUS/strings.xml
@@ -40,4 +40,7 @@
service address
service port
Label error, unable to parse
+ Set power
+ Setting successful
+ Setting failed
\ No newline at end of file
diff --git a/app/src/main/res/values-vi-rVN/strings.xml b/app/src/main/res/values-vi-rVN/strings.xml
index 4c1ddda..af06c82 100644
--- a/app/src/main/res/values-vi-rVN/strings.xml
+++ b/app/src/main/res/values-vi-rVN/strings.xml
@@ -41,4 +41,7 @@
Địa chỉ dịch vụ
Cổng dịch vụ
Lỗi thẻ, không thể giải quyết
+ Đặt điện
+ Thiết lập thành công
+ Thiết lập thất bại
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0ff65a4..a9947df 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -39,5 +39,8 @@
蓝牙连接成功
服务地址
服务端口
- 标签错误,无法解析>
+ 标签错误,无法解析
+ 设置功率
+ 设置成功
+ 设置功率失败>
\ No newline at end of file