#
whycq
2025-01-17 8ce9ce72d3e32427d01ebe4bf8bef6aa863979ca
app/src/main/java/com/example/agvcontroller/MainActivity.java
@@ -1,12 +1,12 @@
package com.example.agvcontroller;
import static android.content.ContentValues.TAG;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -16,7 +16,10 @@
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.GridLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import com.example.agvcontroller.action.AllResetAction;
import com.example.agvcontroller.action.BackPaddle;
@@ -32,6 +35,8 @@
import com.example.agvcontroller.action.LiftResetAction;
import com.example.agvcontroller.action.LoadResetAction;
import com.example.agvcontroller.action.RotatopnLeftRight;
import com.example.agvcontroller.action.SingleSwitchAction;
import com.example.agvcontroller.action.SingleSwitchRunAction;
import com.example.agvcontroller.protocol.AgvAction;
import com.example.agvcontroller.action.HandOutAction;
import com.example.agvcontroller.socket.NettyServerHandler;
@@ -80,13 +85,43 @@
    private Button liftResetBtn;
    private Button allResetBtn;
    private Switch switchBtn1;  // 单轴使能
    private Switch switchBtn2;  // 单轴使能
    private Switch switchBtn3;  // 单轴使能
    private Switch switchBtn4;  // 单轴使能
    private Switch switchBtn5;  // 单轴使能
    private Switch switchBtn6;  // 单轴使能
    private Switch switchBtn7;  // 单轴使能
    private Switch switchBtn8;  // 单轴使能
    private Switch switchBtn9;  // 单轴使能
    private Button axleFrontBtn1;
    private Button axleBackBtn1;
    private Button axleFrontBtn2;
    private Button axleBackBtn2;
    private Button axleFrontBtn3;
    private Button axleBackBtn3;
    private Button axleFrontBtn4;
    private Button axleBackBtn4;
    private Button axleFrontBtn5;
    private Button axleBackBtn5;
    private Button axleFrontBtn6;
    private Button axleBackBtn6;
    private Button axleFrontBtn7;
    private Button axleBackBtn7;
    private Button axleFrontBtn8;
    private Button axleBackBtn8;
    private Button axleFrontBtn9;
    private Button axleBackBtn9;
    private Button bodySwitchBtn; // 底盘/货叉切换
    private Socket socket;
    private String AgvNo = "12";
    private String AgvNo = "1";
    private RelativeLayout layout_bottom;
    private RelativeLayout layout_top;
    private RelativeLayout layout_single;
    private GridLayout layout_single;
    private RelativeLayout layout_reset;
    int liftHeight = 400;
@@ -104,19 +139,24 @@
    private boolean isGoBackward = false;
    private boolean isRotatopnRight = false;
    private boolean isRotatopnLeft = false;
    private boolean isFrontPaddleExtendBtn = false;
    private boolean isFrontPaddleCollectBtn = false;
    private boolean isBackPaddleExtendBtn = false;
    private boolean isBackPaddleCollectBtn = false;
    private boolean isRiseBtn = false;
    private boolean isDropBtn = false;
    private boolean isExtendForkBtn = false;
    private boolean isCollectForkBtn = false;
    private boolean isTurnLeftBtn = false;
    private boolean isTurnRightBtn = false;
    private boolean isFront1 = false;
    private boolean isBack1 = false;
    private boolean isFront2 = false;
    private boolean isBack2 = false;
    private boolean isFront3 = false;
    private boolean isBack3 = false;
    private boolean isFront4 = false;
    private boolean isBack4 = false;
    private boolean isFront5 = false;
    private boolean isBack5 = false;
    private boolean isFront6 = false;
    private boolean isBack6 = false;
    private boolean isFront7 = false;
    private boolean isBack7 = false;
    private boolean isFront8 = false;
    private boolean isBack8 = false;
    private boolean isFront9 = false;
    private boolean isBack9 = false;
@@ -125,168 +165,220 @@
    private Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
            if (isGoForward) {
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
                Log.d(TAG, "isGoForward: " + isGoForward);
                AgvAction agvAction = new AgvAction<>(ForwardBackAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(1)
                        .bodySync((action) -> action.setPwd((short) 10));
                        .bodySync((action) -> action.setPwd((short) 50));
                Log.d(TAG, "isGoForward: " + clientId);
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);  //  100ms 后发送下一条消息
            }
            if (isGoBackward) {
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
                AgvAction agvAction = new AgvAction<>(ForwardBackAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(1)
                        .bodySync((action) -> action.setPwd((short) -10));
                        .bodySync((action) -> action.setPwd((short) -50));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isRotatopnRight) {
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
                AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(1)
                        .bodySync((action) -> action.setPwd((short) 10));
                        .bodySync((action) -> action.setPwd((short) 50));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isRotatopnLeft) {
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
                AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(1)
                        .bodySync((action) -> action.setPwd((short) -10));
                        .bodySync((action) -> action.setPwd((short) -50 ));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
//            // 前拨杆伸
//            if (isFrontPaddleExtendBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(FrontPaddle.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) 1));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 前拨杆收
//            if (isFrontPaddleCollectBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(FrontPaddle.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) 0));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 后拨杆伸
//            if (isBackPaddleExtendBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(BackPaddle.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) 1));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 后拨杆收
//            if (isBackPaddleCollectBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(BackPaddle.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) 0));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 上升
//            if (isRiseBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(HandLift.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) -10));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 下降
//            if (isDropBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(HandLift.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) -10));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 伸叉
//            if (isExtendForkBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(HandExtendCollect.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) -10));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 收叉
//            if (isCollectForkBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(HandExtendCollect.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) -10));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 货叉左旋
//            if (isTurnLeftBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) -10));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
//            // 货叉右旋
//            if (isTurnRightBtn) {
//                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
//                AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class)
//                        .setAgvNo(AgvNo)
//                        .setSerialNo(substring)
//                        .setVal(1)
//                        .bodySync((action) -> action.setPwd((short) -10));
//                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
//                handler.sendEmptyMessageDelayed(0, 100);
//            }
            if (isFront1) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(1)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack1) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(1)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront2) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(2)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack2) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(2)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront3) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(3)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack3) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(3)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront4) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(4)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack4) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(4)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront5) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(5)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack5) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(5)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront6) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(6)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack6) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(6)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront7) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(7)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack7) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(7)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront8) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(8)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack8) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(8)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isFront9) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(9)
                        .bodySync((action) -> action.setPwd((short) 99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            if (isBack9) {
                AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class)
                        .setAgvNo(AgvNo)
                        .setSerialNo(substring)
                        .setVal(9)
                        .bodySync((action) -> action.setPwd((short) -99));
                nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                handler.sendEmptyMessageDelayed(0, 100);
            }
            return false;
        }
    });
    String clientId;
    static String clientId;
    NettyServerHandler nettyServerHandler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 按钮震动
        vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
@@ -316,6 +408,37 @@
        layout_single = findViewById(R.id.layout_single);
        layout_reset = findViewById(R.id.layout_reset);
        switchBtn1 = findViewById(R.id.switch1);
        switchBtn2 = findViewById(R.id.switch2);
        switchBtn3 = findViewById(R.id.switch3);
        switchBtn4 = findViewById(R.id.switch4);
        switchBtn5 = findViewById(R.id.switch5);
        switchBtn6 = findViewById(R.id.switch6);
        switchBtn7 = findViewById(R.id.switch7);
        switchBtn8 = findViewById(R.id.switch8);
        switchBtn9 = findViewById(R.id.switch9);
        axleFrontBtn1 =findViewById(R.id.btn_axle_1_front);
        axleBackBtn1 =findViewById(R.id.btn_axle_1_back);
        axleFrontBtn2 =findViewById(R.id.btn_axle_2_front);
        axleBackBtn2 =findViewById(R.id.btn_axle_2_back);
        axleFrontBtn3 =findViewById(R.id.btn_axle_3_front);
        axleBackBtn3 =findViewById(R.id.btn_axle_3_back);
        axleFrontBtn4 =findViewById(R.id.btn_axle_4_front);
        axleBackBtn4 =findViewById(R.id.btn_axle_4_back);
        axleFrontBtn5 =findViewById(R.id.btn_axle_5_front);
        axleBackBtn5 =findViewById(R.id.btn_axle_5_back);
        axleFrontBtn6 =findViewById(R.id.btn_axle_6_front);
        axleBackBtn6 =findViewById(R.id.btn_axle_6_back);
        axleFrontBtn7 =findViewById(R.id.btn_axle_7_front);
        axleBackBtn7 =findViewById(R.id.btn_axle_7_back);
        axleFrontBtn8 =findViewById(R.id.btn_axle_8_front);
        axleBackBtn8 =findViewById(R.id.btn_axle_8_back);
        axleFrontBtn9 =findViewById(R.id.btn_axle_9_front);
        axleBackBtn9 =findViewById(R.id.btn_axle_9_back);
        cameraResetBtn = findViewById(R.id.btn_camera_reset);
        loadResetBtn = findViewById(R.id.btn_load_reset);
@@ -327,7 +450,14 @@
        Intent intent = getIntent();
        clientId = intent.getStringExtra("message");
        if (intent != null) {
            String newClientId = intent.getStringExtra("clientId");
            if (newClientId != null) {
                clientId = newClientId;
                AgvNo = intent.getStringExtra("agvNo");
            }
        }
        Log.i("message1",clientId);
        // 前拨杆伸出
@@ -457,7 +587,7 @@
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(1)
                            .bodySync((action) -> action.setPwd((short) 21));
                            .bodySync((action) -> action.setPwd((short) extendWidth));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    extendWidth += 50;
                } else {
@@ -480,7 +610,7 @@
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(1)
                            .bodySync((action) -> action.setPwd((short) 21));
                            .bodySync((action) -> action.setPwd((short) extendWidth));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端户端
                    extendWidth -= 50;
                } else {
@@ -643,6 +773,7 @@
                if (vibrator != null && vibrator.hasVibrator()) {
                    vibrator.vibrate(500);
                }
                boolean result = false;
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16);
                if (isAuto) {
                    AgvAction agvAction = new AgvAction<>(HandInAction.class)
@@ -651,6 +782,8 @@
                            .setVal(autoVal)
                            .bodySync((action) -> action.setPwd((short) 21));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    result = true;
                    isAuto = !isAuto;
                } else {
                    AgvAction agvAction = new AgvAction<>(HandOutAction.class)
                            .setAgvNo(AgvNo)
@@ -658,21 +791,23 @@
                            .setVal(autoVal)
                            .bodySync((action) -> action.setPwd((short) 21));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    result = true;
                    isAuto = !isAuto;
                }
                boolean result = false;
                long timestamp = System.currentTimeMillis();
                while (System.currentTimeMillis() - timestamp < 5000) {
                    Object o = map.get(substring);
                    if (null != o) {
                        result = true;
                        isAuto = !isAuto;
                        map.remove(o);
                        break;
                    }
                }
//                long timestamp = System.currentTimeMillis();
//                while (System.currentTimeMillis() - timestamp < 5000) {
//
//                    Object o = map.get(substring);
//
//                    if (null != o) {
//                        result = true;
//                        isAuto = !isAuto;
//                        map.remove(o);
//                        break;
//                    }
//                }
                if (result) {
                    // alert ok  修改按钮样式 名称
@@ -692,6 +827,277 @@
            }
        });
        switchBtn1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (vibrator != null && vibrator.hasVibrator()) {
                    vibrator.vibrate(500);
                }
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(1)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn1.setVisibility(View.VISIBLE);
                    axleBackBtn1.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(1)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn1.setVisibility(View.GONE);
                    axleBackBtn1.setVisibility(View.GONE);
                }
            }
        });
        switchBtn2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(2)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn2.setVisibility(View.VISIBLE);
                    axleBackBtn2.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(2)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn2.setVisibility(View.GONE);
                    axleBackBtn2.setVisibility(View.GONE);
                }
            }
        });
        switchBtn3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(3)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn3.setVisibility(View.VISIBLE);
                    axleBackBtn3.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(3)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn3.setVisibility(View.GONE);
                    axleBackBtn3.setVisibility(View.GONE);
                }
            }
        });
        switchBtn4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(4)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn4.setVisibility(View.VISIBLE);
                    axleBackBtn4.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(4)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn4.setVisibility(View.GONE);
                    axleBackBtn4.setVisibility(View.GONE);
                }
            }
        });
        switchBtn5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(5)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn5.setVisibility(View.VISIBLE);
                    axleBackBtn5.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(5)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn5.setVisibility(View.GONE);
                    axleBackBtn5.setVisibility(View.GONE);
                }
            }
        });
        switchBtn6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(6)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn6.setVisibility(View.VISIBLE);
                    axleBackBtn6.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(6)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn6.setVisibility(View.GONE);
                    axleBackBtn6.setVisibility(View.GONE);
                }
            }
        });
        switchBtn7.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(7)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn7.setVisibility(View.VISIBLE);
                    axleBackBtn7.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(7)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn7.setVisibility(View.GONE);
                    axleBackBtn7.setVisibility(View.GONE);
                }
            }
        });
        switchBtn8.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(8)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn8.setVisibility(View.VISIBLE);
                    axleBackBtn8.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(8)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn8.setVisibility(View.GONE);
                    axleBackBtn8.setVisibility(View.GONE);
                }
            }
        });
        switchBtn9.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged: " + isChecked);
                String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0, 16);
                if (isChecked) {
                    if (vibrator != null && vibrator.hasVibrator()) {
                        vibrator.vibrate(500);
                    }
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(9)
                            .bodySync((action) -> action.setPwd((short) 1));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn9.setVisibility(View.VISIBLE);
                    axleBackBtn9.setVisibility(View.VISIBLE);
                } else {
                    AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class)
                            .setAgvNo(AgvNo)
                            .setSerialNo(substring)
                            .setVal(9)
                            .bodySync((action) -> action.setPwd((short) 0));
                    nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端
                    axleFrontBtn9.setVisibility(View.GONE);
                    axleBackBtn9.setVisibility(View.GONE);
                }
            }
        });
        // 点动按钮
        stopBtn.setOnTouchListener(new CarTouchButton());
        goForwardBtn.setOnTouchListener(new CarTouchButton());
@@ -699,16 +1105,25 @@
        rotatopnLeftBtn.setOnTouchListener(new CarTouchButton());
        rotatopnRightBtn.setOnTouchListener(new CarTouchButton());
//        frontPaddleExtendBtn.setOnTouchListener(new CarTouchButton());
//        frontPaddleCollectBtn.setOnTouchListener(new CarTouchButton());
//        backPaddleExtendBtn.setOnTouchListener(new CarTouchButton());
//        backPaddleCollectBtn.setOnTouchListener(new CarTouchButton());
//        riseBtn.setOnTouchListener(new CarTouchButton());
//        dropBtn.setOnTouchListener(new CarTouchButton());
//        extendForkBtn.setOnTouchListener(new CarTouchButton());
//        collectForkBtn.setOnTouchListener(new CarTouchButton());
//        turnLeftBtn.setOnTouchListener(new CarTouchButton());
//        turnRightBtn.setOnTouchListener(new CarTouchButton());
        axleFrontBtn1.setOnTouchListener(new CarTouchButton());
        axleBackBtn1.setOnTouchListener(new CarTouchButton());
        axleFrontBtn2.setOnTouchListener(new CarTouchButton());
        axleBackBtn2.setOnTouchListener(new CarTouchButton());
        axleFrontBtn3.setOnTouchListener(new CarTouchButton());
        axleBackBtn3.setOnTouchListener(new CarTouchButton());
        axleFrontBtn4.setOnTouchListener(new CarTouchButton());
        axleBackBtn4.setOnTouchListener(new CarTouchButton());
        axleFrontBtn5.setOnTouchListener(new CarTouchButton());
        axleBackBtn5.setOnTouchListener(new CarTouchButton());
        axleFrontBtn6.setOnTouchListener(new CarTouchButton());
        axleBackBtn6.setOnTouchListener(new CarTouchButton());
        axleFrontBtn7.setOnTouchListener(new CarTouchButton());
        axleBackBtn7.setOnTouchListener(new CarTouchButton());
        axleFrontBtn8.setOnTouchListener(new CarTouchButton());
        axleBackBtn8.setOnTouchListener(new CarTouchButton());
        axleFrontBtn9.setOnTouchListener(new CarTouchButton());
        axleBackBtn9.setOnTouchListener(new CarTouchButton());
    }
@@ -716,7 +1131,6 @@
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (view.getId() == R.id.btn_go_forward) {
                // 前进
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
@@ -725,7 +1139,6 @@
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isGoForward = false;
                }
            } else if (view.getId() == R.id.btn_go_backward) {
                // 后退
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
@@ -752,7 +1165,152 @@
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isRotatopnRight = false;
                }
            } else if (view.getId() == R.id.btn_axle_1_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront1 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront1 = false;
                }
            } else if (view.getId() == R.id.btn_axle_1_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack1 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack1 = false;
                }
            } else if (view.getId() == R.id.btn_axle_2_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront2 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront2 = false;
                }
            } else if (view.getId() == R.id.btn_axle_2_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack2 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack2 = false;
                }
            } else if (view.getId() == R.id.btn_axle_3_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront3 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront3 = false;
                }
            } else if (view.getId() == R.id.btn_axle_3_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack3 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack3 = false;
                }
            } else if (view.getId() == R.id.btn_axle_4_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront4 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront4 = false;
                }
            } else if (view.getId() == R.id.btn_axle_4_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack4 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack4 = false;
                }
            } else if (view.getId() == R.id.btn_axle_5_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront5 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront5 = false;
                }
            } else if (view.getId() == R.id.btn_axle_5_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack5 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack5 = false;
                }
            } else if (view.getId() == R.id.btn_axle_6_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront6 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront6 = false;
                }
            } else if (view.getId() == R.id.btn_axle_6_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack6 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack6 = false;
                }
            } else if (view.getId() == R.id.btn_axle_7_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront7 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront7 = false;
                }
            } else if (view.getId() == R.id.btn_axle_7_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack7 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack7 = false;
                }
            } else if (view.getId() == R.id.btn_axle_8_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront8 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront8 = false;
                }
            } else if (view.getId() == R.id.btn_axle_8_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack8 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack8 = false;
                }
            } else if (view.getId() == R.id.btn_axle_9_front) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isFront9 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isFront9 = false;
                }
            } else if (view.getId() == R.id.btn_axle_9_back) {
                // 轴动按钮
                if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    isBack9 = true;
                    handler.sendEmptyMessage(0);
                } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) {
                    isBack9 = false;
                }
            }
            return false;
@@ -803,4 +1361,8 @@
        //SocketManager.getInstance().stopServer();
        //socketManager.stopServer(); // 停止服务器
    }
    public static void upClient(String newClientId) {
        clientId = newClientId;
    }
}