增加 写入长度判断

master
wangh 8 months ago
parent c38cbed454
commit a5d15780e8

@ -43,12 +43,13 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation files('libs\\c5106\\App_Demo_API.jar')
implementation files('libs\\c5106\\DeviceAPIver20150204.jar')
implementation files('libs\\c5106\\logutil-1.5.1.1.jar')
// implementation files('libs\\c5106\\App_Demo_API.jar')
// implementation files('libs\\c5106\\DeviceAPIver20150204.jar')
// implementation files('libs\\c5106\\logutil-1.5.1.1.jar')
implementation files('libs\\c5106\\ModuleAPI_1.jar')
implementation files('libs\\c5106\\reader(1).jar')
implementation files('libs\\c5106\\UHF67_v3.6.jar')
implementation files('libs\\c5106\\uhfr_v1.8.jar')
// implementation files('libs\\c5106\\reader(1).jar')
// implementation files('libs\\c5106\\UHF67_v3.6.jar')
// implementation files('libs\\ModuleAPI_J.jar')

Binary file not shown.

@ -2,28 +2,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<application
android:name=".base.MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:theme="@style/Theme.JinYuRFID"
tools:targetApi="31">
<activity
android:name=".AppLoginActivity"
android:exported="false" />
<receiver
android:name=".broadcast.ScanERCodeReceiver"
android:enabled="true"
android:exported="true"/>
android:exported="true" />
<activity
android:name=".ReadActivity"
@ -43,11 +40,11 @@
<activity
android:name=".MainActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

@ -0,0 +1,14 @@
package com.example.jinyu_rfid;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class AppLoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_login);
}
}

@ -38,17 +38,17 @@ public class MainActivity extends BaseActivity {
private Resources resources;
private Configuration config;
private int index;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
resources = getResources();
config = resources.getConfiguration();
var equals = SharedPreferencesUtils.getstring("language", "English").equals("中文");
config.locale = equals ? Locale.CHINA : Locale.ENGLISH;
var languageString = SharedPreferencesUtils.getstring("language", "中文");
getLocaleStringXML(languageString);
resources.updateConfiguration(config, resources.getDisplayMetrics());
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
// binding.mainLanguage.setSelection(equals?1:0);
binding.mainLanguage.setSelection(index);
loginVm = new LoginVm();
boolean isRemember = SharedPreferencesUtils.getboolean("isRemember", false);
if (isRemember) {
@ -60,7 +60,18 @@ public class MainActivity extends BaseActivity {
}
private void getLocaleStringXML(String languageString){
if (languageString.equals("中文")){
config.locale = Locale.CHINA;
index=0;
}else if (languageString.equals("English")){
config.locale = Locale.ENGLISH;
index=1;
}else {
config.locale =new Locale("vi","VN");
index=2;
}
}
@Override
public void sanCodeCall(String code) {
@ -71,9 +82,7 @@ public class MainActivity extends BaseActivity {
String pass = loginVm.getPassword();
String name = loginVm.getUsername();
var selectLanguage = binding.mainLanguage.getSelectedItem().toString();
config.locale = selectLanguage.equals("中文") ? Locale.CHINA : Locale.ENGLISH;
getLocaleStringXML(selectLanguage);
Map<String, String> map = new HashMap<>();
map.put("UserID", name);
map.put("UserPass", pass);

@ -103,12 +103,10 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
tagUserStr.append("~");
}
String user = ASCIIUtil.str2Hex(tagUserStr.toString());
Log.e("TAG", "名文:" + tagUserStr);
Log.e("TAG", "ASCII:" + user);
Log.e("TAG", "写入长度:" + user.length());
if (!writeUserState) {
Log.e("TAG", "writeUser:" + 1);
writeUserState = rfidModel.writeUser(user, epcStr);
writeUserState = rfidModel.writeUser(validateDataLength(user), epcStr);
Toast.makeText(context, getString(writeUserState ? R.string.write_success : R.string.write_failed), Toast.LENGTH_SHORT).show();
}
@ -118,38 +116,49 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
map.put("TyreNo", list.get(0).getPropertyContent());
map.put("token", "123456");
Log.e("TAG", "writeUser:" + 2);
OkGo.<MyResult>post(url + "/write")
.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.getSaveFlag().equals("1")) {
list.clear();
adapter.notifyDataSetChanged();
binding.writeEpcCode.setText(null);
binding.writeTire.setText(null);
Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show();
writeUserState=false;
return;
}
Toast.makeText(WriteUserActivity.this, body.getSaveMessage(), Toast.LENGTH_SHORT).show();
}
});
OkGo.<MyResult>post(url + "/write").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.getSaveFlag().equals("1")) {
list.clear();
adapter.notifyDataSetChanged();
binding.writeEpcCode.setText(null);
binding.writeTire.setText(null);
Toast.makeText(WriteUserActivity.this, getString(R.string.binding_success), Toast.LENGTH_SHORT).show();
writeUserState = false;
return;
}
Toast.makeText(WriteUserActivity.this, body.getSaveMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
public void writeGoMenu(View view){
popupMenu.show();
public String validateDataLength(String data) {
int length = data.length();
int remainder = length % 4;
if (remainder != 0) {
int paddingLength = 4 - remainder;
StringBuilder paddedData = new StringBuilder(data);
for (int i = 0; i < paddingLength; i++) {
paddedData.append("0");
}
return paddedData.toString();
}
return data;
}
@Override
public void readEpcCodeInfo(String info, boolean state, String stateInfo) {
if (state) {
@ -161,40 +170,39 @@ public class WriteUserActivity extends BaseActivity implements DataReturnCall, P
// Log.e("TAG", "读取状态:" + stateInfo);
}
// 扫码
@Override
public void readerCodeInfo(String erCode) {
binding.writeTire.setText(erCode);
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) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getResultFlag().equals("1")) {
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();
}
});
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 = 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();
}
});
}
public void writeGoMenu(View view) {popupMenu.show();}
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_read) {
startActivity(intent1);
}else {
startActivity(intent1);
} else {
startActivity(intent2);
}

@ -54,7 +54,7 @@ public class MyApplication extends Application {
OkGo.getInstance().init(this).setOkHttpClient(builder.build()) // 建议设置OkHttpClient不设置将使用默认的
.setCacheMode(CacheMode.NO_CACHE) // 全局统一缓存模式,默认不使用缓存,可以不传
.setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE) // 全局统一缓存时间,默认永不过期,可以不传
.setRetryCount(3);
.setRetryCount(1);
}

@ -54,9 +54,9 @@ public class C5106Device implements RFIDModel {
public boolean writeUser(String writeStr, String tagEpc) {
var bytes = Tools.HexString2Bytes(writeStr);
var bytesF = Tools.HexString2Bytes(tagEpc);
Reader.READER_ERR readerErr = uhfrManager.writeTagDataByFilter(
Reader.READER_ERR readerErr = uhfrManager.writeTagDataByFilter(
(char) 3, 0, bytes, bytes.length, accessBytes, (short) 500,
bytesF ,1,2,true);
bytesF, 1, 2, true);
/* Reader.READER_ERR readerErr = uhfrManager.writeTagData(

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="user"
type="com.example.jinyu_rfid.been.LoginVm" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".AppLoginActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:src="@mipmap/logo"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="12dp"
android:layout_marginRight="20dp">
<TextView
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="left|center"
android:paddingLeft="14dp"
android:text="@string/work_model_select"
android:textSize="18sp" />
<Spinner
android:id="@+id/main_work"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/language" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="12dp"
android:layout_marginRight="20dp">
<TextView
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="left|center"
android:paddingLeft="14dp"
android:text="@string/language_select"
android:textSize="18sp" />
<Spinner
android:id="@+id/main_language"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/language" />
</LinearLayout>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:checked="@={user.remember}"
android:text="@string/remember_me" />
<Button
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:letterSpacing="0.2"
android:onClick="login_click"
android:text="@string/login_button_name"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</layout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

@ -30,4 +30,5 @@
<string name="write_failed">write failed</string>
<string name="write_success">write success</string>
<string name="binding_success">mes binding success</string>
<string name="work_model_select">working mode</string>
</resources>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RFID của Jinwoo</string>
<string name="user_name">Tên người dùng</string>
<string name="pass_word">Mật khẩu</string>
<string name="login_button_name">Đăng nhập</string>
<string name="remember_me">Ghi nhớ tôi</string>
<string name="language_select">Ngôn ngữ:</string>
<string name="activity_name_configuration">Cấu hình</string>
<string name="configuration_save">Lưu</string>
<string name="tire_number">Số lốp</string>
<string name="read_epc">Đọc EPC</string>
<string name="write_in">Ghi thông tin</string>
<string name="go_read">Đọc thông tin</string>
<string name="go_configuration">Cấu hình</string>
<string name="epc_code">Mã hóa EPC</string>
<string name="configuration_add">Thêm mục</string>
<string name="write_index">Chỉ mục</string>
<string name="write_state">Ghi hay không</string>
<string name="write_project">Viết dự án</string>
<string name="project_list_brand">Thương hiệu</string>
<string name="project_list_specifications">Thông số</string>
<string name="project_list_pattern">Hoa văn</string>
<string name="project_list_hierarchy">Phân cấp</string>
<string name="project_list_name">Tên lốp</string>
<string name="project_list_speed">Tốc độ</string>
<string name="project_list_load">Chỉ số tải</string>
<string name="project_list_rim">Đường kính vành</string>
<string name="project_list_flat">Tỷ lệ phẳng</string>
<string name="project_list_area">Khu vực bán hàng</string>
<string name="write_failed">Lỗi ghi</string>
<string name="write_success">Viết thành công</string>
<string name="binding_success">Kết nối MES thành công</string>
<string name="work_model_select">Chế độ làm việc</string>
</resources>

@ -1,9 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="language">
<item>English</item>
<item>中文</item>
<item>English</item>
<item>Tiếng Việt</item>
</string-array>
<string-array name="work_mode">
<item>English</item>
<item>Tiếng Việt</item>
</string-array>
<string-array name="project_list">
<item>@string/epc_code</item>
<item>@string/tire_number</item>

@ -29,5 +29,6 @@
<string name="project_list_area">销售区域</string>
<string name="write_failed">写入失败</string>
<string name="write_success">写入成功</string>
<string name="binding_success">MES 绑定成功</string>>
<string name="binding_success">MES 绑定成功</string>
<string name="work_model_select">工作模式</string>>
</resources>
Loading…
Cancel
Save