From df8dae9a5681aa32ac5a2116f8fa2b4d63632fb5 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Thu, 7 May 2026 17:35:25 +0800 Subject: [PATCH] =?UTF-8?q?[FEAT]=EF=BC=9A=E4=B8=B2=E6=8E=A5=E5=88=B7?= =?UTF-8?q?=E5=8D=A1=E6=A9=9F=E9=87=8D=E5=95=9F=E8=88=87=E9=81=A0=E7=AB=AF?= =?UTF-8?q?=E7=B5=90=E5=B8=B3=20MQTT=20=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 在 MqttService 中新增 nfc_reset 指令,對應原本的刷卡機重置邏輯。 2. 在 MqttService 中新增 nfc_checkout 指令,對應原本的刷卡機結帳邏輯。 3. 確保指令執行後會回傳 ACK 狀態至後台。 --- .../smartdevice/service/MqttService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/com/unibuy/smartdevice/service/MqttService.java b/app/src/main/java/com/unibuy/smartdevice/service/MqttService.java index 70fa1cf..8951aa9 100644 --- a/app/src/main/java/com/unibuy/smartdevice/service/MqttService.java +++ b/app/src/main/java/com/unibuy/smartdevice/service/MqttService.java @@ -114,6 +114,28 @@ public class MqttService extends Service { startActivity(restartIntent); android.os.Process.killProcess(android.os.Process.myPid()); }, 500); + } else if ("nfc_reset".equals(cmd)) { + Log.i(TAG, "Executing remote NFC reset command..."); + try { + com.unibuy.smartdevice.devices.Rs232Dev comPort2 = new com.unibuy.smartdevice.devices.Rs232Dev(com.unibuy.smartdevice.MyApp.getInstance().getComPort2ByNFCPay()); + com.unibuy.smartdevice.devices.DevNFCPay devNFCPay = new com.unibuy.smartdevice.devices.DevNFCPay(getApplicationContext()); + comPort2.send(devNFCPay.reset()); + mqttManager.publishCommandAck(cmdId, "success", "NFC reset command sent"); + } catch (Exception e) { + Log.e(TAG, "NFC reset failed: " + e.getMessage()); + mqttManager.publishCommandAck(cmdId, "failed", "NFC reset failed: " + e.getMessage()); + } + } else if ("nfc_checkout".equals(cmd)) { + Log.i(TAG, "Executing remote NFC checkout command..."); + try { + com.unibuy.smartdevice.devices.Rs232Dev comPort2 = new com.unibuy.smartdevice.devices.Rs232Dev(com.unibuy.smartdevice.MyApp.getInstance().getComPort2ByNFCPay()); + com.unibuy.smartdevice.devices.DevNFCPay devNFCPay = new com.unibuy.smartdevice.devices.DevNFCPay(getApplicationContext()); + comPort2.send(devNFCPay.checkout()); + mqttManager.publishCommandAck(cmdId, "success", "NFC checkout command sent"); + } catch (Exception e) { + Log.e(TAG, "NFC checkout failed: " + e.getMessage()); + mqttManager.publishCommandAck(cmdId, "failed", "NFC checkout failed: " + e.getMessage()); + } } else { Log.w(TAG, "Unknown MQTT command: " + cmd); mqttManager.publishCommandAck(cmdId, "failed", "Unknown command");