增加 设置功率

master
wangh 4 months ago
parent 644fb42674
commit f16dd3f01e

@ -48,7 +48,10 @@
<activity <activity
android:name=".WriteUserActivity" 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>
<activity <activity
android:name=".ConfigurationTableActivity" android:name=".ConfigurationTableActivity"
@ -56,10 +59,7 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
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>
</application> </application>

@ -65,7 +65,6 @@ public class ReadActivity extends BaseActivity implements DataReturnCall {
// 名称 // 名称
stringArray = getResources().getStringArray(R.array.project_list); stringArray = getResources().getStringArray(R.array.project_list);
rfidModel = new C5106Device(this,this); rfidModel = new C5106Device(this,this);
// rfidModel=new AutoID9UDevice(this,this);
} }

@ -19,6 +19,8 @@ import com.example.jinyu_rfid.been.ConfigurationTable;
import com.example.jinyu_rfid.been.ReadTyreNoResult; import com.example.jinyu_rfid.been.ReadTyreNoResult;
import com.example.jinyu_rfid.callback.DataReturnCall; import com.example.jinyu_rfid.callback.DataReturnCall;
import com.example.jinyu_rfid.databinding.ActivityWriteUserBinding; 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.AutoID9UDevice;
import com.example.jinyu_rfid.rfid.C5106Device; import com.example.jinyu_rfid.rfid.C5106Device;
import com.example.jinyu_rfid.rfid.RFIDModel; import com.example.jinyu_rfid.rfid.RFIDModel;
@ -37,7 +39,7 @@ import java.util.Optional;
import okhttp3.RequestBody; 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 intent1;
private Intent intent2; private Intent intent2;
private RFIDModel rfidModel; private RFIDModel rfidModel;
@ -45,7 +47,7 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
private ResultAdapter adapter; private ResultAdapter adapter;
private List<ReadTyreNoResult> list; private List<ReadTyreNoResult> list;
private PopupMenu popupMenu; private PopupMenu popupMenu;
private MyAlertDialog myAlertDialog;
@SuppressLint("UnspecifiedRegisterReceiverFlag") @SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -58,13 +60,21 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
popupMenu = new PopupMenu(this, binding.writeMenu); popupMenu = new PopupMenu(this, binding.writeMenu);
popupMenu.setOnMenuItemClickListener(this); popupMenu.setOnMenuItemClickListener(this);
getMenuInflater().inflate(R.menu.activity_menu, popupMenu.getMenu()); getMenuInflater().inflate(R.menu.activity_menu, popupMenu.getMenu());
// rfidModel = new C5106Device(this,this); rfidModel = new C5106Device(this, this);
rfidModel=new AutoID9UDevice(this,this); // rfidModel = new AutoID9UDevice(this, this);
if (rfidModel instanceof C5106Device){ if (rfidModel instanceof C5106Device) {
intent1 = new Intent(this, ReadActivity.class); intent1 = new Intent(this, ReadActivity.class);
}else { } else {
intent1 = new Intent(this, Read2Activity.class); 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; if (epcStr.isEmpty()) return;
// EPC编码~胎号~品牌~规格~花纹~层级~轮胎名称~速度级别~负荷指数~轮辋直径~扁平比~销售区域 // EPC编码~胎号~品牌~规格~花纹~层级~轮胎名称~速度级别~负荷指数~轮辋直径~扁平比~销售区域
List<ConfigurationTable> tagList = LitePal.findAll(ConfigurationTable.class); 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("~"); tagUserStr.append("~");
for (int i = 1; i < 12; i++) { for (int i = 1; i < 12; i++) {
var configuration = tagList.get(i); var configuration = tagList.get(i);
@ -113,9 +123,9 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
map.put("EpcCode", epcStr); map.put("EpcCode", epcStr);
map.put("TyreNo", list.get(0).getPropertyContent()); map.put("TyreNo", list.get(0).getPropertyContent());
map.put("token", "123456"); map.put("token", "123456");
map.put("Language", SharedPreferencesUtils.getstring("languageIndex","0")); map.put("Language", SharedPreferencesUtils.getstring("languageIndex", "0"));
Log.e("TAG", "writeUser:" + 2); Log.e("TAG", "writeUser:" + 2);
OkGo.<MyResult>post("http://"+url + "/rfid/write").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) { OkGo.<MyResult>post("http://" + url + "/rfid/write").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@Override @Override
public void onSuccess(Response<MyResult> response) { public void onSuccess(Response<MyResult> response) {
@ -124,35 +134,34 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
if (body.getSaveFlag().equals("1")) { if (body.getSaveFlag().equals("1")) {
Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show(); Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show();
writeUserState = true; writeUserState = true;
writeUser(user,epcStr); writeUser(user, epcStr);
return; return;
} }
tipDialog.shouDialog(false, body.getSaveMessage()); tipDialog.shouDialog(false, body.getSaveMessage());
} }
}); });
}else { } else {
writeUser(user,epcStr); writeUser(user, epcStr);
} }
} }
private void writeUser(String user ,String epcStr){
private void writeUser(String user, String epcStr) {
Log.e("TAG", "写入"); Log.e("TAG", "写入");
var writeState = rfidModel.writeUser(validateDataLength(user), epcStr); 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) { if (writeState) {
list.clear(); list.clear();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
binding.writeEpcCode.setText(null); binding.writeEpcCode.setText(null);
binding.writeTire.setText(null); binding.writeTire.setText(null);
writeUserState=false; writeUserState = false;
} }
} }
public String validateDataLength(String data) { public String validateDataLength(String data) {
int length = data.length(); int length = data.length();
int remainder = length % 4; int remainder = length % 4;
@ -187,8 +196,8 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("TyreNo", erCode); map.put("TyreNo", erCode);
map.put("token", "123456"); map.put("token", "123456");
map.put("Language", SharedPreferencesUtils.getstring("languageIndex","0")); map.put("Language", SharedPreferencesUtils.getstring("languageIndex", "0"));
OkGo.<MyResult>post("http://"+url + "/rfid/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) { OkGo.<MyResult>post("http://" + url + "/rfid/readTyreNo").upRequestBody(RequestBody.create(JSON, gson.toJson(map))).execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@Override @Override
public void onSuccess(Response<MyResult> response) { public void onSuccess(Response<MyResult> response) {
@ -213,14 +222,30 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_read) {
var itemId = item.getItemId();
if (itemId == R.id.menu_read) {
startActivity(intent1); startActivity(intent1);
} else { } else if (itemId == R.id.menu_configuration) {
startActivity(intent2); startActivity(intent2);
} else if (itemId == R.id.menu_setPower) {
myAlertDialog.show(SharedPreferencesUtils.getInt("power",30));
} }
return true; 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();
}
} }

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

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

@ -36,7 +36,6 @@ public class AutoID9UDevice implements RFIDModel {
if (!uhfService.isopen()) { if (!uhfService.isopen()) {
uhfService.open(); uhfService.open();
} }
Log.e("TAG", "上电:" + uhfService.isopen()); Log.e("TAG", "上电:" + uhfService.isopen());
Log.e("TAG", "功率:" + uhfService.getPower()); Log.e("TAG", "功率:" + uhfService.getPower());
scanERCodeReceiver = new AutoIDdeviceScanERCodeReceiver(); scanERCodeReceiver = new AutoIDdeviceScanERCodeReceiver();
@ -128,6 +127,12 @@ public class AutoID9UDevice implements RFIDModel {
context.unregisterReceiver(scanERCodeReceiver); context.unregisterReceiver(scanERCodeReceiver);
} }
@Override
public boolean setPower(int power) {
var b = uhfService.setPower(power);
return b;
}
class AutoIDdeviceScanERCodeReceiver extends BroadcastReceiver { class AutoIDdeviceScanERCodeReceiver extends BroadcastReceiver {

@ -27,6 +27,7 @@ public class C5106Device implements RFIDModel {
public C5106Device(DataReturnCall call, Context context) { public C5106Device(DataReturnCall call, Context context) {
uhfrManager = UHFRManager.getInstance(); uhfrManager = UHFRManager.getInstance();
Log.e("TAG", "功率:" +uhfrManager.getPower()[0] );
this.call = call; this.call = call;
this.context = context; this.context = context;
scanERCodeReceiver = new ScanERCodeReceiver(); scanERCodeReceiver = new ScanERCodeReceiver();
@ -78,7 +79,6 @@ public class C5106Device implements RFIDModel {
@Override @Override
public void sanUser(int len) { public void sanUser(int len) {
byte[] rdata = new byte[len * 2]; byte[] rdata = new byte[len * 2];
Reader.READER_ERR readerErr = uhfrManager.getTagData(3, 0, len, rdata, accessBytes, (short) 200); 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()); 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); 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 { class ScanERCodeReceiver extends BroadcastReceiver {
@Override @Override

@ -16,4 +16,6 @@ public interface RFIDModel {
} }
void close(); void close();
boolean setPower(int power);
} }

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="@string/tip_set_power"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e1e1e1"/>
<EditText
android:id="@+id/dialog_text"
style="@style/text_name"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_margin="30dp"
android:inputType="number"
android:hint="5~30"
android:background="@drawable/san_text" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e1e1e1"/>
<TextView
android:id="@+id/dialog1_button"
android:layout_width="match_parent"
android:layout_height="55dp"
android:text="@string/configuration_save"
android:textSize="18sp"
android:gravity="center"
android:letterSpacing="0.5"
android:textColor="@color/design_default_color_secondary"/>
</LinearLayout>

@ -7,5 +7,9 @@
<item <item
android:id="@+id/menu_configuration" android:id="@+id/menu_configuration"
android:title="@string/go_configuration" /> android:title="@string/go_configuration" />
<item
android:id="@+id/menu_setPower"
android:title="@string/tip_set_power" />
</group> </group>
</menu> </menu>

@ -40,4 +40,7 @@
<string name="service_addr">service address</string> <string name="service_addr">service address</string>
<string name="server_port">service port</string> <string name="server_port">service port</string>
<string name="label_error">Label error, unable to parse</string> <string name="label_error">Label error, unable to parse</string>
<string name="tip_set_power">Set power</string>
<string name="tip_set_success">Setting successful</string>
<string name="tip_set_failed">Setting failed</string>
</resources> </resources>

@ -41,4 +41,7 @@
<string name="service_addr">Địa chỉ dịch vụ</string> <string name="service_addr">Địa chỉ dịch vụ</string>
<string name="server_port">Cổng dịch vụ</string> <string name="server_port">Cổng dịch vụ</string>
<string name="label_error">Lỗi thẻ, không thể giải quyết</string> <string name="label_error">Lỗi thẻ, không thể giải quyết</string>
<string name="tip_set_power">Đặt điện</string>
<string name="tip_set_success">Thiết lập thành công</string>
<string name="tip_set_failed">Thiết lập thất bại</string>
</resources> </resources>

@ -39,5 +39,8 @@
<string name="bluetooth_open_secess">蓝牙连接成功</string> <string name="bluetooth_open_secess">蓝牙连接成功</string>
<string name="service_addr">服务地址</string> <string name="service_addr">服务地址</string>
<string name="server_port">服务端口</string> <string name="server_port">服务端口</string>
<string name="label_error">标签错误,无法解析</string>> <string name="label_error">标签错误,无法解析</string>
<string name="tip_set_power">设置功率</string>
<string name="tip_set_success">设置成功</string>
<string name="tip_set_failed">设置功率失败</string>>
</resources> </resources>
Loading…
Cancel
Save