#
whycq
2025-02-05 c7e1fddc1dab02a992a9c54f55b0e518cd5f973d
app/src/main/java/com/example/agvcontroller/MainActivity.java
@@ -20,6 +20,7 @@
import android.widget.GridLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import com.example.agvcontroller.action.AllResetAction;
import com.example.agvcontroller.action.BackPaddle;
@@ -54,6 +55,8 @@
    public static final Map<String, Object> map = new ConcurrentHashMap();
    public static final Map<String, Object> car_num = new ConcurrentHashMap();
    private static TextView agvBattery;
    private Vibrator vibrator;
    private Button stopBtn;  // 急停按钮
@@ -115,7 +118,7 @@
    private Button bodySwitchBtn; // 底盘/货叉切换
    private Socket socket;
    private String AgvNo = "1";
    private RelativeLayout layout_bottom;
    private RelativeLayout layout_top;
    private GridLayout layout_single;
@@ -367,14 +370,19 @@
            return false;
        }
    });
    static String AgvNo = "1";
    static String clientId;
    NettyServerHandler nettyServerHandler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        agvBattery = findViewById(R.id.agv_battery);
        // 按钮震动
@@ -448,11 +456,9 @@
        Intent intent = getIntent();
        if (intent != null) {
            String newClientId = intent.getStringExtra("clientId");
            if (newClientId != null) {
                clientId = newClientId;
                AgvNo = intent.getStringExtra("agvNo");
            }
            AGVCar car = (AGVCar) intent.getSerializableExtra("item");
            clientId = car.getClientId();
            AgvNo = car.getAgvNo();
        }
        Log.i("message1",clientId);
@@ -1359,7 +1365,16 @@
        //socketManager.stopServer(); // 停止服务器
    }
    public static void upClient(String newClientId) {
        clientId = newClientId;
    public static void upClient(AGVCar agvCar) {
        clientId = agvCar.getClientId();
        AgvNo = agvCar.getAgvNo();
        agvBattery.setText("电量:" + agvCar.getBattery() + "%");
//        updateAgvBatteryText("电量:" + agvCar.getBattery() + "%");
    }
    private static void updateAgvBatteryText(String batteryLevel) {
        if (agvBattery != null) {
            agvBattery.setText(batteryLevel);
        }
    }
}