From 9c414520fd00319683a0021bb512f5003aff2800 Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期二, 21 一月 2025 14:40:53 +0800
Subject: [PATCH] #
---
app/src/main/java/com/example/agvcontroller/StartActivity.java | 23 +++--
app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java | 11 +-
app/src/main/res/layout/activity_main.xml | 131 ++++++++++++++++++++++++++++++++
app/src/main/java/com/example/agvcontroller/AGVCar.java | 4
app/src/main/java/com/example/agvcontroller/EditeActivity.java | 11 +-
app/src/main/java/com/example/agvcontroller/EditeAdapter.java | 12 +-
app/src/main/java/com/example/agvcontroller/ItemAdapter.java | 11 +-
7 files changed, 165 insertions(+), 38 deletions(-)
diff --git a/app/src/main/java/com/example/agvcontroller/Item.java b/app/src/main/java/com/example/agvcontroller/AGVCar.java
similarity index 89%
rename from app/src/main/java/com/example/agvcontroller/Item.java
rename to app/src/main/java/com/example/agvcontroller/AGVCar.java
index dfa7a7a..3d04798 100644
--- a/app/src/main/java/com/example/agvcontroller/Item.java
+++ b/app/src/main/java/com/example/agvcontroller/AGVCar.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;
diff --git a/app/src/main/java/com/example/agvcontroller/EditeActivity.java b/app/src/main/java/com/example/agvcontroller/EditeActivity.java
index 784ae80..ec0186f 100644
--- a/app/src/main/java/com/example/agvcontroller/EditeActivity.java
+++ b/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<>();
diff --git a/app/src/main/java/com/example/agvcontroller/EditeAdapter.java b/app/src/main/java/com/example/agvcontroller/EditeAdapter.java
index 3f6fa2f..60d7986 100644
--- a/app/src/main/java/com/example/agvcontroller/EditeAdapter.java
+++ b/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:
diff --git a/app/src/main/java/com/example/agvcontroller/ItemAdapter.java b/app/src/main/java/com/example/agvcontroller/ItemAdapter.java
index f494425..d919fd1 100644
--- a/app/src/main/java/com/example/agvcontroller/ItemAdapter.java
+++ b/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);
}
diff --git a/app/src/main/java/com/example/agvcontroller/StartActivity.java b/app/src/main/java/com/example/agvcontroller/StartActivity.java
index 628ccb8..c6eef62 100644
--- a/app/src/main/java/com/example/agvcontroller/StartActivity.java
+++ b/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()
diff --git a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java b/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
index 6496e59..28297aa 100644
--- a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
+++ b/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;
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index ca2b410..ddf4c71 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/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>
<!-- **************** 搴曠洏 **************** -->
--
Gitblit v1.9.1