#
whycq
2025-01-21 9c414520fd00319683a0021bb512f5003aff2800
#
1 文件已重命名
6个文件已修改
203 ■■■■ 已修改文件
app/src/main/java/com/example/agvcontroller/AGVCar.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/EditeActivity.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/EditeAdapter.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/ItemAdapter.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/StartActivity.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_main.xml 131 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/AGVCar.java
File was renamed from app/src/main/java/com/example/agvcontroller/Item.java
@@ -1,13 +1,13 @@
package com.example.agvcontroller;
public class Item {
public class AGVCar {
    private String clientId;
    private String ip;
    private int port;
    private String agvNo;
    private int status;
    public Item(String clientId,String ip,int port,String agvNo,int status) {
    public AGVCar(String clientId, String ip, int port, String agvNo, int status) {
        this.clientId = clientId;
        this.ip = ip;
        this.port = port;
app/src/main/java/com/example/agvcontroller/EditeActivity.java
@@ -1,6 +1,6 @@
package com.example.agvcontroller;
import android.content.Intent;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
@@ -22,12 +22,13 @@
public class EditeActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<Item> items;
    private List<AGVCar> items;
    private EditeAdapter adapter;
    private SharedPreferences sharedPreferences;
    private AppCompatImageButton addItem;
    private Button confirm;
    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -52,7 +53,7 @@
            @Override
            public void onClick(View v) {
                items.add(new Item("", "", 0, "", 0));
                items.add(new AGVCar("", "", 0, "", 0));
                adapter.notifyDataSetChanged();
                Log.d("items", items.toString());
            }
@@ -81,11 +82,11 @@
        editor.apply();
    }
    private List<Item> loadItemsFromSharedPreferences() {
    private List<AGVCar> loadItemsFromSharedPreferences() {
        Gson gson = new Gson();
        String json = sharedPreferences.getString("items", null);
        if (json != null) {
            Type type = new TypeToken<List<Item>>(){}.getType();
            Type type = new TypeToken<List<AGVCar>>(){}.getType();
            return gson.fromJson(json, type);
        }
        return new ArrayList<>();
app/src/main/java/com/example/agvcontroller/EditeAdapter.java
@@ -7,9 +7,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageButton;
@@ -19,9 +17,9 @@
public class EditeAdapter  extends RecyclerView.Adapter<EditeAdapter.ViewHolder> {
    private static List<Item> itemList;
    private static List<AGVCar> itemList;
    public EditeAdapter(List<Item> itemList) {
    public EditeAdapter(List<AGVCar> itemList) {
        this.itemList = itemList;
    }
@@ -54,7 +52,7 @@
                    // 文本变化之后
                    int position = getAdapterPosition();
                    if (position != RecyclerView.NO_POSITION) {
                        Item item = itemList.get(position);
                        AGVCar item = itemList.get(position);
                        item.setAgvNo(s.toString()); // 更新数据源
                    }
                }
@@ -77,7 +75,7 @@
                    // 文本变化之后
                    int position = getAdapterPosition();
                    if (position != RecyclerView.NO_POSITION) {
                        Item item = itemList.get(position);
                        AGVCar item = itemList.get(position);
                        item.setIp(s.toString()); // 更新数据源
                    }
                }
@@ -132,7 +130,7 @@
            // 默认显示页面
            //return 1;
        } else {
            Item item = itemList.get(position);
            AGVCar item = itemList.get(position);
            int status = item.getStatus();
            switch (status) {
                case 0:
app/src/main/java/com/example/agvcontroller/ItemAdapter.java
@@ -1,8 +1,5 @@
package com.example.agvcontroller;
import static androidx.core.content.ContextCompat.startActivity;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
@@ -17,9 +14,9 @@
public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ViewHolder> {
    private List<Item> itemList;
    private List<AGVCar> itemList;
    public ItemAdapter(List<Item> itemList) {
    public ItemAdapter(List<AGVCar> itemList) {
        this.itemList = itemList;
    }
@@ -86,7 +83,7 @@
            // 默认显示页面
            //return 1;
        } else {
            Item item = itemList.get(position);
            AGVCar item = itemList.get(position);
            int status = item.getStatus();
            switch (status) {
                case 0:
@@ -114,7 +111,7 @@
        }
    }
    public void addItem (Item item) {
    public void addItem (AGVCar item) {
        itemList.add(item);
        notifyItemInserted(itemList.size() - 1);
    }
app/src/main/java/com/example/agvcontroller/StartActivity.java
@@ -27,7 +27,7 @@
public class StartActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<Item> items;
    private List<AGVCar> items;
    private ItemAdapter adapter;
    private Button addItem;
    private SharedPreferences sharedPreferences;
@@ -48,16 +48,16 @@
            }
        });
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        sharedPreferences = getSharedPreferences("AGVControllerPrefs", MODE_PRIVATE);
        // Load items from SharedPreferences
        items = loadItemsFromSharedPreferences();
        items = new ArrayList<>();
//        items = new ArrayList<>();
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new ItemAdapter(items);
        recyclerView.setAdapter(adapter);
@@ -84,24 +84,25 @@
        socketManager.startServer(8022);
    }
    private List<Item> loadItemsFromSharedPreferences() {
    private List<AGVCar> loadItemsFromSharedPreferences() {
        Gson gson = new Gson();
        String json = sharedPreferences.getString("items", null);
        Log.i("SharedPreferences", "Loading items from shared preferences: " + json);
        if (json != null) {
            Type type = new TypeToken<List<Item>>(){}.getType();
            Type type = new TypeToken<List<AGVCar>>(){}.getType();
            return gson.fromJson(json, type);
        }
        return new ArrayList<>();
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onDeviceConnected(Item deviceAddress) {
    public void onDeviceConnected(AGVCar deviceAddress) {
        Log.i("EventBus", "Received device connected: " + deviceAddress);
        if (!items.isEmpty()) {
            int sameIp = 0;
            for (Item item : items) {
            for (AGVCar item : items) {
                if (item.getIp().equals(deviceAddress.getIp())) {
                    item.setAgvNo(deviceAddress.getAgvNo());
                    item.setPort(deviceAddress.getPort());
@@ -115,14 +116,14 @@
                Log.i("Item",item.getClientId());
            }
            if (sameIp == 0) {
                items.add(new Item(deviceAddress.getClientId()
                items.add(new AGVCar(deviceAddress.getClientId()
                        ,deviceAddress.getIp()
                        ,deviceAddress.getPort()
                        ,deviceAddress.getAgvNo()
                        ,deviceAddress.getStatus()));
            }
        } else {
            items.add(new Item(deviceAddress.getClientId()
            items.add(new AGVCar(deviceAddress.getClientId()
                    ,deviceAddress.getIp()
                    ,deviceAddress.getPort()
                    ,deviceAddress.getAgvNo()
app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
@@ -13,7 +13,7 @@
import android.os.Message;
import android.util.Log;
import com.example.agvcontroller.Item;
import com.example.agvcontroller.AGVCar;
import com.example.agvcontroller.MainActivity;
import com.example.agvcontroller.action.AGV_11_UP;
import com.example.agvcontroller.action.AckMsgBuilder;
@@ -23,7 +23,6 @@
import com.example.agvcontroller.protocol.AGV_A1_DOWN;
import com.example.agvcontroller.protocol.AGV_F0_DOWN;
import com.example.agvcontroller.protocol.AGV_F0_UP;
import com.example.agvcontroller.protocol.AGV_F0_UP8;
import com.example.agvcontroller.protocol.AgvAction;
import com.example.agvcontroller.protocol.AgvPackage;
import com.example.agvcontroller.protocol.ProtocolType;
@@ -58,7 +57,7 @@
        String ip = remoteAddress.getAddress().getHostAddress();
        int port = remoteAddress.getPort();
        channelMap.put(clientId, ctx.channel());
        EventBus.getDefault().post(new Item(clientId,ip,port,"--",0));
        EventBus.getDefault().post(new AGVCar(clientId,ip,port,"--",0));
        Log.d(TAG, "Client connected: " + clientId);
        // 取消延迟删除操作
@@ -150,13 +149,13 @@
                AGV_12_UP agv_12_up = (AGV_12_UP) pac.getBody().getMessageBody();
                agvNo = pac.getHeader().getUniqueNo();
                channelMap.put(clientId, ctx.channel());
                EventBus.getDefault().post(new Item(clientId,ip,port,agvNo,1));
                EventBus.getDefault().post(new AGVCar(clientId,ip,port,agvNo,1));
                break label;
            case DATA_WITHOUT_CODE_REPORT:
                AGV_13_UP agv_13_up = (AGV_13_UP) pac.getBody().getMessageBody();
                agvNo = pac.getHeader().getUniqueNo();
                channelMap.put(clientId, ctx.channel());
                EventBus.getDefault().post(new Item(clientId,ip,port,agvNo,1));
                EventBus.getDefault().post(new AGVCar(clientId,ip,port,agvNo,1));
                break label;
            case LOGIN_REPORT:
                AGV_F0_UP agv_f0_up = (AGV_F0_UP) pac.getBody().getMessageBody();
@@ -167,7 +166,7 @@
                }
                agvNo = pac.getHeader().getUniqueNo();
                channelMap.put(clientId, ctx.channel());
                EventBus.getDefault().post(new Item(clientId,ip,port,agvNo,1));
                EventBus.getDefault().post(new AGVCar(clientId,ip,port,agvNo,1));
                break label;
        }
app/src/main/res/layout/activity_main.xml
@@ -11,7 +11,138 @@
        android:background="#334455"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:padding="10dp"
        android:layout_weight="4">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:orientation="vertical">
            >
            <TextView
                android:id="@+id/agv_battery"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity=""
                android:textSize="14sp"
                android:text="电量:100%"
                android:textColor="#FFFFFF" />
            <TextView
                android:id="@+id/agv_no"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity=""
                android:textSize="14sp"
                android:text="AGV编号:1"
                android:textColor="#FFFFFF" />
            <TextView
                android:id="@+id/agv_status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity=""
                android:textSize="14sp"
                android:text="AGV状态:空闲"
                android:textColor="#FFFFFF" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="当前位置"
                    android:textColor="#FFFFFF" />
                <TextView
                    android:id="@+id/agv_position_id"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="ID:9987"
                    android:textColor="#FFFFFF" />
                <TextView
                    android:id="@+id/agv_position_x"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="(X):123087"
                    android:textColor="#FFFFFF" />
                <TextView
                    android:id="@+id/agv_position_y"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="(Y):432311"
                    android:textColor="#FFFFFF" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
                <TextView
                    android:id="@+id/agv_position_height"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="当前高度:100mm"
                    android:textColor="#FFFFFF" />
                <TextView
                    android:id="@+id/agv_ford"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="货叉伸出距离:30mm"
                    android:textColor="#FFFFFF" />
                <TextView
                    android:id="@+id/agv_ratio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity=""
                    android:textSize="12sp"
                    android:layout_marginRight="10dp"
                    android:text="货叉旋转角度:90°"
                    android:textColor="#FFFFFF" />
            </LinearLayout>
            <TextView
                android:id="@+id/agv_error"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity=""
                android:textSize="12sp"
                android:layout_marginRight="10dp"
                android:text="AGV故障:导航故障 > 待机状态下丢码"
                android:textColor="#FFFFFF" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical"
            android:background="#FFFFFF"
            android:radius="10dp"
            >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="上行:1232132121"
                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="下行:1232132121"
                />
        </LinearLayout>
    </LinearLayout>
    <!--    ****************  底盘  ****************    -->