From 20245e35da8a9d809b2de91f4ec29dd39127f9d5 Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期六, 17 八月 2024 10:07:07 +0800
Subject: [PATCH] #

---
 app/src/main/java/com/example/agvcontroller/MainActivity.java |   66 ++++++++++++++++++++++----------
 1 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/app/src/main/java/com/example/agvcontroller/MainActivity.java b/app/src/main/java/com/example/agvcontroller/MainActivity.java
index b08e87c..1de3e8a 100644
--- a/app/src/main/java/com/example/agvcontroller/MainActivity.java
+++ b/app/src/main/java/com/example/agvcontroller/MainActivity.java
@@ -20,14 +20,13 @@
 import com.example.agvcontroller.action.HandOutAction;
 import com.example.agvcontroller.socket.NettyServerHandler;
 import com.example.agvcontroller.socket.SocketManager;
+import com.example.agvcontroller.utils.DialogUtil;
 import com.example.agvcontroller.utils.SnowflakeIdWorker;
 
 import java.net.Socket;
-import java.sql.Time;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeoutException;
 
 
 public class MainActivity extends AppCompatActivity {
@@ -44,6 +43,7 @@
     private Button rotatopnLeftBtn;  // 宸︽棆杞�
     private Button goForwardBtn;  // 鍓嶈繘
     private Button goBackwardBtn;  // 鍚庨��
+    private Button modelSwitchBtn;  // 杩涘叆銆侀��鍑� 鎵嬪姩
     private Socket socket;
 
     SocketManager socketManager;
@@ -68,25 +68,7 @@
                 nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔�
                 handler.sendEmptyMessageDelayed(0, 100);
 
-                boolean result = false;
-                long timestamp = System.currentTimeMillis();
 
-                while (System.currentTimeMillis() - timestamp < 5000) {
-
-                    Object o = map.get(substring);
-
-                    if (null != o) {
-                        result = true;
-                        map.remove(o);
-                        break;
-                    }
-                }
-
-                if (result) {
-                    // alert ok
-                } else {
-                    throw new TimeoutException("瓒呮椂");
-                }
 
             }
             if (isOpen) {
@@ -117,12 +99,13 @@
         forceSwitchBtn = findViewById(R.id.btn_force_switch);
         goForwardBtn = findViewById(R.id.btn_go_forward);
         goBackwardBtn = findViewById(R.id.btn_go_backward);
+        modelSwitchBtn = findViewById(R.id.btn_model_switch);
 
         Intent intent = getIntent();
         clientId = intent.getStringExtra("message");
         Log.i("message1",clientId);
 
-        // 杩涘嚭鎵嬪姩妯″紡
+        // 寮哄埗妯″紡寮�鍏�
         forceSwitchBtn.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -138,6 +121,47 @@
                 nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔�
             }
         });
+
+        // 寮哄埗妯″紡寮�鍏�
+        modelSwitchBtn.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (vibrator != null && vibrator.hasVibrator()) {
+                    vibrator.vibrate(500);
+                }
+                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
+                AgvAction agvAction = new AgvAction<>(HandOutAction.class)
+                        .setAgvNo("12")
+                        .setSerialNo(substring)
+                        .setVal(1)
+                        .bodySync((action) -> action.setPwd((short) 21));
+                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔�
+
+
+                boolean result = false;
+                long timestamp = System.currentTimeMillis();
+
+                Log.i("substring",substring);
+                while (System.currentTimeMillis() - timestamp < 20000) {
+
+                    Object o = map.get(substring);
+
+                    if (null != o) {
+                        result = true;
+                        map.remove(o);
+                        break;
+                    }
+                }
+
+                if (result) {
+                    // alert ok  淇敼鎸夐挳鏍峰紡 鍚嶇О
+                    modelSwitchBtn.setText("鑷姩妯″紡");
+                } else {
+//                    throw new TimeoutException("瓒呮椂");
+                    DialogUtil.showAlertDialog(MainActivity.this, "鎻愮ず", "璇锋眰搴旂瓟瓒呮椂锛�");
+                }
+            }
+        });
         stopBtn.setOnTouchListener(new CarTouchButton());
         goForwardBtn.setOnTouchListener(new CarTouchButton());
         goBackwardBtn.setOnTouchListener(new CarTouchButton());

--
Gitblit v1.9.1