Sfoglia il codice sorgente

注销 - ETC启用、停止 - fixed - 指令执行失败 - 调整实现方案,补充设备厂家的判断

GZBranch
wufasong 1 giorno fa
parent
commit
8c916f82b8

+ 68
- 120
app/src/main/java/com/huntersun/vkyes/etcopencard/project/ui/activity/after/LogoutEtcStep3Activity.java Vedi File

@@ -17,6 +17,7 @@ import com.bumptech.glide.Glide;
import com.google.gson.JsonParseException;
import com.google.gson.internal.LinkedTreeMap;
import com.huntersun.vkyes.etcopencard.R;
import com.huntersun.vkyes.etcopencard.project.bluetooth.BluetoothDialog;
import com.huntersun.vkyes.etcopencard.databinding.ActivityLogoutEtcStep3Binding;
import com.huntersun.vkyes.etcopencard.project.api.MyRetrofit;
import com.huntersun.vkyes.etcopencard.project.api.Result;
@@ -189,9 +190,9 @@ public class LogoutEtcStep3Activity extends AppActivity {
binding.lyBackfeeInfo.setVisibility(View.GONE);
}
// 注销原因固定为"其他",只显示输入框内容
binding.LLInputReason.setVisibility(View.VISIBLE);
binding.tvReason.setText("其他");
binding.etReason.setText(etReason);
binding.LLInputReason.setVisibility(View.VISIBLE);
binding.tvReason.setText("其他");
binding.etReason.setText(etReason);
// 隐藏下拉选择部分
binding.LLReason.setVisibility(View.GONE);
@@ -463,14 +464,15 @@ public class LogoutEtcStep3Activity extends AppActivity {
@Override
public void success() {
Log.i(this.getClass().getSimpleName(), "蓝牙连接成功,开始执行注销指令");
// 蓝牙连接成功,执行注销指令
// 普通设备连接成功,执行注销指令
executeLogoutCommand();
}

@Override
public void success9901(int isPlk) {
Log.i(this.getClass().getSimpleName(), "9901设备连接成功,开始执行注销指令");
Log.i(this.getClass().getSimpleName(), "9901设备连接成功,设备类型: " + isPlk + ",开始执行注销指令");
// 9901设备连接成功,执行注销指令
// 注意:BluetoothDialog.Builder.transCmd 内部会直接使用 isPlk,无需额外设置
executeLogoutCommand();
}

@@ -548,9 +550,9 @@ public class LogoutEtcStep3Activity extends AppActivity {
e.printStackTrace();
ToastUtils.show("解析指令初始化响应失败");
}
}
@Override
}
@Override
public void onError(Response<Result> resp) {
hideDialog();
Log.e(this.getClass().getSimpleName(), "指令初始化失败: " + (resp != null ? resp.message() : "未知错误"));
@@ -565,29 +567,15 @@ public class LogoutEtcStep3Activity extends AppActivity {
private void executeWriteCard(String command, String cmdType, String transOrderId) {
showDialog("正在执行注销指令...");
try {
Log.i(this.getClass().getSimpleName(), "开始执行写卡操作 - command: " + command + ", transOrderId: " + transOrderId);
// 根据指令类型执行不同的操作
String result;
if ("CARD".equals(cmdType)) {
Log.i(this.getClass().getSimpleName(), "执行卡指令");
result = writeCard(command);
} else {
Log.i(this.getClass().getSimpleName(), "执行OBU指令");
result = writeObu(command);
}
Log.i(this.getClass().getSimpleName(), "指令执行完成,结果: " + result);
// 第三步:回传指令结果
callbackLogoutCommand(command, transOrderId, result);
} catch (Exception e) {
hideDialog();
Log.e(this.getClass().getSimpleName(), "写卡操作失败: " + e.getMessage());
e.printStackTrace();
ToastUtils.show("写卡操作失败");
Log.i(this.getClass().getSimpleName(), "开始执行写卡操作 - command: " + command + ", transOrderId: " + transOrderId);
// 根据指令类型执行不同的操作
if ("CARD".equals(cmdType)) {
Log.i(this.getClass().getSimpleName(), "执行卡指令");
writeCard(command, transOrderId);
} else {
Log.i(this.getClass().getSimpleName(), "执行OBU指令");
writeObu(command, transOrderId);
}
}
@@ -608,7 +596,7 @@ public class LogoutEtcStep3Activity extends AppActivity {
Log.i(this.getClass().getSimpleName(), "指令回传 当前步骤:" + currentStepNo + ", 指令:" + command + ", 指令编号:" + transOrderId + ", 指令结果:" + result);
MyRetrofit.newInstanceGZ(this, IFCode.IFCODE_DEVICE_CANCEL_INST_CALLBACK, params, new MyRetrofit.ReturnResult() {
@Override
@Override
public void onSuccess(ResultBean resultBean, ResultBean.BizContent bizContent) {
hideDialog();
Log.i(this.getClass().getSimpleName(), "指令回传 响应数据:" + JSONObject.toJSONString(resultBean));
@@ -655,121 +643,81 @@ public class LogoutEtcStep3Activity extends AppActivity {
hideDialog();
Log.e(this.getClass().getSimpleName(), "指令回传失败: " + (resp != null ? resp.message() : "未知错误"));
ToastUtils.show("指令回传失败");
}
});
}
});
}

/**
* 写卡操作(支持多条指令,用逗号分隔)
* 参考:BluetoothWriteCardWriteTab.writeCard()
* 使用"普通"方式:BluetoothDialog.Builder.transCmd
*/
private String writeCard(String commands) {
private void writeCard(String commands, String transOrderId) {
Log.i(this.getClass().getSimpleName(), "开始写卡操作,指令: " + commands);
try {
// 确保MethodManager已初始化
if (MethodManager.getCls() == null) {
Log.i(this.getClass().getSimpleName(), "MethodManager未初始化,开始初始化");
MethodManager.initData("com.huntersun.vky.obublelib.box.BoxManagers");
if (MethodManager.getCls() == null) {
Log.e(this.getClass().getSimpleName(), "MethodManager初始化失败");
throw new RuntimeException("MethodManager初始化失败");
}
Log.i(this.getClass().getSimpleName(), "MethodManager初始化成功");
}
// 分割多条指令
String[] commands_arry = commands.split(",");
String[] results = new String[commands_arry.length];
int len = results.length;
Log.i(this.getClass().getSimpleName(), "指令总数: " + len);
// 逐条执行指令,先收集所有结果
for (int i = 0; i < len; i++) {
Log.i(this.getClass().getSimpleName(), "执行第 " + (i + 1) + " 条指令: " + commands_arry[i]);
// 透传写卡指令
ServiceStatus resp_string = MethodManager.sendApduICC(commands_arry[i]);
results[i] = resp_string.getServiceInfo();
Log.i(this.getClass().getSimpleName(), "第 " + (i + 1) + " 条指令执行结果: " + results[i] + ", 状态码: " + resp_string.getServiceCode());
}
// 拼接结果
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < len; i++) {
buffer.append(results[i]);
if (i != len - 1) {
buffer.append(",");
Log.i(this.getClass().getSimpleName(), "指令总数: " + commands_arry.length);

// 使用"普通"方式:BluetoothDialog.Builder.transCmd
// 这个方法内部会直接使用 isPlk 变量,无需额外设置
// 直接传递整个指令数组,不需要 for 循环
Log.i(this.getClass().getSimpleName(), "执行指令数组: " + java.util.Arrays.toString(commands_arry));

// 使用 BluetoothDialog.Builder.transCmd,传递 "10" 表示IC卡操作
BluetoothDialog.Builder.transCmd(commands_arry, "10", new BluetoothDialog.PerformCmdCallBack() {
@Override
public void performOnSuccess(String[] strings) {
Log.i(this.getClass().getSimpleName(), "指令执行成功: " + java.util.Arrays.toString(strings));
String result = String.join(",", strings);
Log.i(this.getClass().getSimpleName(), "写卡操作完成,最终结果: " + result);
// 第三步:回传指令结果
callbackLogoutCommand(commands, transOrderId, result);
}
}
String finalResult = buffer.toString();
Log.i(this.getClass().getSimpleName(), "写卡操作完成,最终结果: " + finalResult);
return finalResult;
});

} catch (Exception e) {
Log.e(this.getClass().getSimpleName(), "写卡操作异常: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException("写卡操作异常: " + e.getMessage());
hideDialog();
ToastUtils.show("写卡操作失败: " + e.getMessage());
}
}
/**
* 写OBU操作(支持多条指令,用逗号分隔)
* 参考:OrderUtils.writeObu()
* 使用"普通"方式:BluetoothDialog.Builder.transCmd
*/
private String writeObu(String commands) {
private void writeObu(String commands, String transOrderId) {
Log.i(this.getClass().getSimpleName(), "开始写OBU操作,指令: " + commands);
try {
// 确保MethodManager已初始化
if (MethodManager.getCls() == null) {
Log.i(this.getClass().getSimpleName(), "MethodManager未初始化,开始初始化");
MethodManager.initData("com.huntersun.vky.obublelib.box.BoxManagers");
if (MethodManager.getCls() == null) {
Log.e(this.getClass().getSimpleName(), "MethodManager初始化失败");
throw new RuntimeException("MethodManager初始化失败");
}
Log.i(this.getClass().getSimpleName(), "MethodManager初始化成功");
}
// 分割多条指令
String[] commands_arry = commands.split(",");
String[] results = new String[commands_arry.length];
int len = results.length;
Log.i(this.getClass().getSimpleName(), "指令总数: " + len);
// 逐条执行指令,先收集所有结果
for (int i = 0; i < len; i++) {
Log.i(this.getClass().getSimpleName(), "执行第 " + (i + 1) + " 条指令: " + commands_arry[i]);
// 透传OBU指令
ServiceStatus resp_string = MethodManager.sendApduEsam(commands_arry[i]);
results[i] = resp_string.getServiceInfo();
Log.i(this.getClass().getSimpleName(), "第 " + (i + 1) + " 条指令执行结果: " + results[i] + ", 状态码: " + resp_string.getServiceCode());
}
// 拼接结果
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < len; i++) {
buffer.append(results[i]);
if (i != len - 1) {
buffer.append(",");
Log.i(this.getClass().getSimpleName(), "指令总数: " + commands_arry.length);

// 使用"普通"方式:BluetoothDialog.Builder.transCmd
// 这个方法内部会直接使用 isPlk 变量,无需额外设置
// 直接传递整个指令数组,不需要 for 循环
Log.i(this.getClass().getSimpleName(), "执行指令数组: " + java.util.Arrays.toString(commands_arry));

// 使用 BluetoothDialog.Builder.transCmd,传递 "20" 表示OBU操作
BluetoothDialog.Builder.transCmd(commands_arry, "20", new BluetoothDialog.PerformCmdCallBack() {
@Override
public void performOnSuccess(String[] strings) {
Log.i(this.getClass().getSimpleName(), "指令执行成功: " + java.util.Arrays.toString(strings));
String result = String.join(",", strings);
Log.i(this.getClass().getSimpleName(), "写OBU操作完成,最终结果: " + result);
// 第三步:回传指令结果
callbackLogoutCommand(commands, transOrderId, result);
}
}
String finalResult = buffer.toString();
Log.i(this.getClass().getSimpleName(), "写OBU操作完成,最终结果: " + finalResult);
return finalResult;
});

} catch (Exception e) {
Log.e(this.getClass().getSimpleName(), "写OBU操作异常: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException("写OBU操作异常: " + e.getMessage());
hideDialog();
ToastUtils.show("写OBU操作失败: " + e.getMessage());
}
}


+ 48
- 96
app/src/main/java/com/huntersun/vkyes/etcopencard/project/ui/activity/after/StartStopEtcActivity.java Vedi File

@@ -5,6 +5,7 @@ import android.view.View;

import com.hjq.base.BaseDialog;
import com.huntersun.vkyes.etcopencard.R;
import com.huntersun.vkyes.etcopencard.project.bluetooth.BluetoothDialog;
import com.huntersun.vkyes.etcopencard.databinding.ActivityStartStopEtcBinding;
import com.huntersun.vkyes.etcopencard.project.api.MyRetrofit;
import com.huntersun.vkyes.etcopencard.project.api.Result;
@@ -29,6 +30,7 @@ import com.parkingwang.keyboard.PopupKeyboard;
import com.hjq.toast.ToastUtils;
import com.huntersun.vkyes.etcopencard.project.bluetooth.MethodManager;
import com.huntersun.vkyes.etcopencard.project.bluetooth.ServiceStatus;

import com.huntersun.vkyes.etcopencard.src.aop.SingleClick;
import com.huntersun.vkyes.etcopencard.src.app.AppActivity;
import com.huntersun.vkyes.etcopencard.src.other.AppConfig;
@@ -500,6 +502,7 @@ public class StartStopEtcActivity extends AppActivity {
LogUtils.i("连接ETC设备", "设备类型: 9901设备, isPlk: " + isPlk);
LogUtils.i("连接ETC设备", "开始调用" + (operation == 1 ? "停用" : "启用") + "申请接口");
// 9901设备连接成功,调用申请接口
// 注意:BluetoothDialog.Builder.transCmd 内部会直接使用 isPlk,无需额外设置
callDeviceEnableApply();
}

@@ -539,84 +542,53 @@ public class StartStopEtcActivity extends AppActivity {
private void executeWriteCard(String command, String cmdType, String transOrderId) {
LogUtils.i("执行写卡", "开始写卡操作,指令: " + command + ", 指令类型: " + cmdType + ", 指令编号: " + transOrderId);
try {
String result;
if ("CARD".equals(cmdType)) {
LogUtils.i("执行写卡", "执行卡指令");
result = writeCard(command);
} else {
LogUtils.i("执行写卡", "执行OBU指令");
result = writeObu(command);
}
LogUtils.i("执行写卡", "写卡操作完成,结果: " + result);
// 回传指令结果
callbackEnableDisableCommand(command, transOrderId, result);
} catch (Exception e) {
LogUtils.e("执行写卡", "写卡操作异常: " + e.getMessage());
e.printStackTrace();
ToastUtils.show("写卡操作失败: " + e.getMessage());
if ("CARD".equals(cmdType)) {
LogUtils.i("执行写卡", "执行卡指令");
writeCard(command, transOrderId);
} else {
LogUtils.i("执行写卡", "执行OBU指令");
writeObu(command, transOrderId);
}
}
/**
* 写卡操作(支持多条指令,用逗号分隔)
* 参考:BluetoothWriteCardWriteTab.writeCard()
* 使用"普通"方式:BluetoothDialog.Builder.transCmd
*/
private String writeCard(String commands) {
private void writeCard(String commands, String transOrderId) {
LogUtils.i("写卡操作", "========== 开始写卡操作 ==========");
LogUtils.i("写卡操作", "执行指令: " + commands);
LogUtils.i("写卡操作", "当前步骤号: " + currentStepNo + ", 指令编号: " + transOrderId);
try {
// 确保MethodManager已初始化
if (MethodManager.getCls() == null) {
LogUtils.i("写卡操作", "MethodManager未初始化,开始初始化");
MethodManager.initData("com.huntersun.vky.obublelib.box.BoxManagers");
if (MethodManager.getCls() == null) {
LogUtils.e("写卡操作", "MethodManager初始化失败");
throw new RuntimeException("MethodManager初始化失败");
}
LogUtils.i("写卡操作", "MethodManager初始化成功");
}
// 分割多条指令
String[] commands_arry = commands.split(",");
String[] results = new String[commands_arry.length];
int len = results.length;
LogUtils.i("写卡操作", "指令总数: " + len);
LogUtils.i("写卡操作", "指令总数: " + commands_arry.length);
// 逐条执行指令,先收集所有结果
for (int i = 0; i < len; i++) {
LogUtils.i("写卡操作", "执行第 " + (i + 1) + " 条指令: " + commands_arry[i]);
// 透传写卡指令
ServiceStatus resp_string = MethodManager.sendApduICC(commands_arry[i]);
results[i] = resp_string.getServiceInfo();
LogUtils.i("写卡操作", "第 " + (i + 1) + " 条指令执行结果: " + results[i] + ", 状态码: " + resp_string.getServiceCode());
}
// 使用"普通"方式:BluetoothDialog.Builder.transCmd
// 这个方法内部会直接使用 isPlk 变量,无需额外设置
// 直接传递整个指令数组,不需要 for 循环
LogUtils.i("写卡操作", "执行指令数组: " + java.util.Arrays.toString(commands_arry));
// 拼接结果
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < len; i++) {
buffer.append(results[i]);
if (i != len - 1) {
buffer.append(",");
// 使用 BluetoothDialog.Builder.transCmd,传递 "10" 表示IC卡操作
BluetoothDialog.Builder.transCmd(commands_arry, "10", new BluetoothDialog.PerformCmdCallBack() {
@Override
public void performOnSuccess(String[] strings) {
LogUtils.i("写卡操作", "指令执行成功: " + java.util.Arrays.toString(strings));
String result = String.join(",", strings);
LogUtils.i("写卡操作", "========== 写卡操作完成 ==========");
LogUtils.i("写卡操作", "最终结果: " + result);
// 回传指令结果
callbackEnableDisableCommand(commands, transOrderId, result);
}
}
String finalResult = buffer.toString();
LogUtils.i("写卡操作", "========== 写卡操作完成 ==========");
LogUtils.i("写卡操作", "最终结果: " + finalResult);
return finalResult;
});
} catch (Exception e) {
LogUtils.e("写卡操作", "========== 写卡操作异常 ==========");
LogUtils.e("写卡操作", "异常信息: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException("写卡操作异常: " + e.getMessage());
hideDialog();
ToastUtils.show("写卡操作失败: " + e.getMessage());
}
}
@@ -624,60 +596,40 @@ public class StartStopEtcActivity extends AppActivity {
* 写OBU操作(支持多条指令,用逗号分隔)
* 参考:OrderUtils.writeObu()
*/
private String writeObu(String commands) {
private void writeObu(String commands, String transOrderId) {
LogUtils.i("写OBU操作", "========== 开始写OBU操作 ==========");
LogUtils.i("写OBU操作", "执行指令: " + commands);
LogUtils.i("写OBU操作", "当前步骤号: " + currentStepNo + ", 指令编号: " + transOrderId);
try {
// 确保MethodManager已初始化
if (MethodManager.getCls() == null) {
LogUtils.i("写OBU操作", "MethodManager未初始化,开始初始化");
MethodManager.initData("com.huntersun.vky.obublelib.box.BoxManagers");
if (MethodManager.getCls() == null) {
LogUtils.e("写OBU操作", "MethodManager初始化失败");
throw new RuntimeException("MethodManager初始化失败");
}
LogUtils.i("写OBU操作", "MethodManager初始化成功");
}
// 分割多条指令
String[] commands_arry = commands.split(",");
String[] results = new String[commands_arry.length];
int len = results.length;
LogUtils.i("写OBU操作", "指令总数: " + commands_arry.length);
LogUtils.i("写OBU操作", "指令总数: " + len);
// 使用"普通"方式:BluetoothDialog.Builder.transCmd
// 这个方法内部会直接使用 isPlk 变量,无需额外设置
// 直接传递整个指令数组,不需要 for 循环
LogUtils.i("写OBU操作", "执行指令数组: " + java.util.Arrays.toString(commands_arry));
// 逐条执行指令,先收集所有结果
for (int i = 0; i < len; i++) {
LogUtils.i("写OBU操作", "执行第 " + (i + 1) + " 条指令: " + commands_arry[i]);
// 透传OBU指令
ServiceStatus resp_string = MethodManager.sendApduEsam(commands_arry[i]);
results[i] = resp_string.getServiceInfo();
LogUtils.i("写OBU操作", "第 " + (i + 1) + " 条指令执行结果: " + results[i] + ", 状态码: " + resp_string.getServiceCode());
}
// 拼接结果
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < len; i++) {
buffer.append(results[i]);
if (i != len - 1) {
buffer.append(",");
// 使用 BluetoothDialog.Builder.transCmd,传递 "20" 表示OBU操作
BluetoothDialog.Builder.transCmd(commands_arry, "20", new BluetoothDialog.PerformCmdCallBack() {
@Override
public void performOnSuccess(String[] strings) {
LogUtils.i("写OBU操作", "指令执行成功: " + java.util.Arrays.toString(strings));
String result = String.join(",", strings);
LogUtils.i("写OBU操作", "========== 写OBU操作完成 ==========");
LogUtils.i("写OBU操作", "最终结果: " + result);
// 回传指令结果
callbackEnableDisableCommand(commands, transOrderId, result);
}
}
String finalResult = buffer.toString();
LogUtils.i("写OBU操作", "========== 写OBU操作完成 ==========");
LogUtils.i("写OBU操作", "最终结果: " + finalResult);
return finalResult;
});
} catch (Exception e) {
LogUtils.e("写OBU操作", "========== 写OBU操作异常 ==========");
LogUtils.e("写OBU操作", "异常信息: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException("写OBU操作异常: " + e.getMessage());
hideDialog();
ToastUtils.show("写OBU操作失败: " + e.getMessage());
}
}

Loading…
Annulla
Salva