From 318bd727e2fe02e4f541dfe943f77606af41d509 Mon Sep 17 00:00:00 2001 From: whycq <913841844@qq.com> Date: 星期四, 06 二月 2025 14:30:11 +0800 Subject: [PATCH] # --- app/src/main/java/com/example/agvcontroller/MainActivity.java | 39 +++++++++++++ app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java | 28 +++++++++ app/src/main/AndroidManifest.xml | 1 app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java | 57 +++++++++++++++++- app/src/main/java/com/example/agvcontroller/AGVCar.java | 16 ++-- app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java | 4 6 files changed, 129 insertions(+), 16 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a7fdf4a..12f7997 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AGVController" + android:requestLegacyExternalStorage="true" tools:targetApi="31"> <activity android:name=".LogActivity" diff --git a/app/src/main/java/com/example/agvcontroller/AGVCar.java b/app/src/main/java/com/example/agvcontroller/AGVCar.java index c4acab6..c6f5f37 100644 --- a/app/src/main/java/com/example/agvcontroller/AGVCar.java +++ b/app/src/main/java/com/example/agvcontroller/AGVCar.java @@ -10,11 +10,11 @@ private int status; private int battery; private int agvStatus; - private int positionID; + private String positionID; private int positionX; private int positionY; - private int agvAngle; - private int gyroAngle; + private float agvAngle; + private float gyroAngle; private int forkHeight; private int forkExtend; private int forkAngle; @@ -28,7 +28,7 @@ this.status = status; } - public AGVCar(String clientId, String ip, int port, String agvNo, int status, int battery, int agvStatus, int positionID, int positionX, int positionY, int agvAngle, int gyroAngle, int forkHeight, int forkExtend, int forkAngle, int agvError) { + public AGVCar(String clientId, String ip, int port, String agvNo, int status, int battery, int agvStatus, String positionID, int positionX, int positionY, float agvAngle, float gyroAngle, int forkHeight, int forkExtend, int forkAngle, int agvError) { this.clientId = clientId; this.ip = ip; this.port = port; @@ -63,11 +63,11 @@ this.agvStatus = agvStatus; } - public int getPositionID() { + public String getPositionID() { return positionID; } - public void setPositionID(int positionID) { + public void setPositionID(String positionID) { this.positionID = positionID; } @@ -87,7 +87,7 @@ this.positionY = positionY; } - public int getAgvAngle() { + public float getAgvAngle() { return agvAngle; } @@ -95,7 +95,7 @@ this.agvAngle = agvAngle; } - public int getGyroAngle() { + public float getGyroAngle() { return gyroAngle; } diff --git a/app/src/main/java/com/example/agvcontroller/MainActivity.java b/app/src/main/java/com/example/agvcontroller/MainActivity.java index 19e8749..33187b5 100644 --- a/app/src/main/java/com/example/agvcontroller/MainActivity.java +++ b/app/src/main/java/com/example/agvcontroller/MainActivity.java @@ -68,6 +68,17 @@ private static final int MAX_RECENT_LOGS = 10; // 鏈�澶氭樉绀� 10 鏉℃渶鏂版棩蹇� private static TextView agvBattery; + private static TextView agvNo; + private static TextView agvStatus; + private static TextView agvPositionId; + private static TextView agvPositionX; + private static TextView agvPositionY; + private static TextView agvForkHeight; + private static TextView agvForkExtend; + private static TextView agvForkAngle; + private static TextView agvError; + + private Vibrator vibrator; private Button stopBtn; // 鎬ュ仠鎸夐挳 @@ -395,6 +406,17 @@ setContentView(R.layout.activity_main); agvBattery = findViewById(R.id.agv_battery); + agvNo = findViewById(R.id.agv_no); + agvStatus = findViewById(R.id.agv_status); + agvPositionId = findViewById(R.id.agv_position_id); + agvPositionX = findViewById(R.id.agv_position_x); + agvPositionY = findViewById(R.id.agv_position_y); + agvForkHeight = findViewById(R.id.agv_position_height); + agvForkExtend = findViewById(R.id.agv_ford); + agvForkAngle = findViewById(R.id.agv_ratio); + agvError = findViewById(R.id.agv_error); + + @@ -1425,10 +1447,27 @@ handler.removeCallbacksAndMessages(null); } + + + + + + + + public static void upClient(AGVCar agvCar) { clientId = agvCar.getClientId(); AgvNo = agvCar.getAgvNo(); + agvNo.setText("AGV缂栧彿锛�" + AgvNo); agvBattery.setText("鐢甸噺锛�" + agvCar.getBattery() + "%"); + agvStatus.setText("AGV鐘舵�侊細" + agvCar.getStatus()); + agvPositionId.setText("ID锛�" + agvCar.getPositionID()); + agvPositionX.setText("(X)锛�" + agvCar.getPositionX()); + agvPositionY.setText("(Y)锛�" + agvCar.getPositionY()); + agvForkHeight.setText("褰撳墠楂樺害锛�" + agvCar.getForkHeight() + "mm"); + agvForkExtend.setText("璐у弶浼稿嚭璺濈锛�" + agvCar.getForkExtend() + "mm"); + agvForkAngle.setText("璐у弶鏃嬭浆瑙掑害锛�" + agvCar.getForkAngle() + "掳"); + agvError.setText("AGV鏁呴殰锛�" + agvCar.getAgvError()); // updateAgvBatteryText("鐢甸噺锛�" + agvCar.getBattery() + "%"); } diff --git a/app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java b/app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java index a3a40a5..e094c2a 100644 --- a/app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java +++ b/app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java @@ -140,7 +140,33 @@ this.liftUp = Utils.getBit(bytes[3], 6); this.liftBottom = Utils.getBit(bytes[3], 7); } - + public String getQrCode() { + return qrCode; + } + public int getOffsetX() { + return offsetX; + } + public int getOffsetY() { + return offsetY; + } + public int getStatus() { + return status; + } + public float getAGVCurrentAngle() { + return AGVCurrentAngle; + } + public float getGyroAngle() { + return gyroAngle; + } + public int getCurrentAltitude() { + return currentAltitude; + } + public int getForkLength() { + return forkLength; + } + public int getLoaderTheta() { + return loaderTheta; + } // 鏆傚瓨璐т綅1妫�娴� private boolean tempLoc1; diff --git a/app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java b/app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java index ae6ad54..5753e5d 100644 --- a/app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java +++ b/app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java @@ -44,8 +44,8 @@ //浼犳劅鍣ㄧ姸鎬佹爣蹇� // this.sensorStatusFlags = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 27, 4)); - byte[] sensorStatusBytes = Utils.slice(bytes, 27, 4); - parseSensorStatue(sensorStatusBytes); +// byte[] sensorStatusBytes = Utils.slice(bytes, 27, 4); +// parseSensorStatue(sensorStatusBytes); } @Override 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 9b07744..0c05544 100644 --- a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java +++ b/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java @@ -21,6 +21,7 @@ import com.example.agvcontroller.action.AGV_11_UP; import com.example.agvcontroller.action.AckMsgBuilder; import com.example.agvcontroller.met.AbstractInboundHandler; +import com.example.agvcontroller.protocol.AGV_03_UP; import com.example.agvcontroller.protocol.AGV_12_UP; import com.example.agvcontroller.protocol.AGV_13_UP; import com.example.agvcontroller.protocol.AGV_A1_DOWN; @@ -45,6 +46,18 @@ private static final String TAG = "NettyServerHandler"; private static ConcurrentHashMap<String, Channel> channelMap = new ConcurrentHashMap<>(); private Map<String, Runnable> pendingRemovals = new HashMap<>(); + int battery = 0; + int status = 0; + int agvStatus = 0; + String positionID = "--"; + int positionX = 0; + int positionY = 0; + float agvAngle = 0; + float gyroAngle = 0; + int forkHeight = 0; + int forkExtend = 0; + int forkAngle = 0; + int agvError = 0; private Handler handler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { @@ -138,6 +151,10 @@ ProtocolType ackType = isNeedAck(pac); final String uniqueNo = pac.getHeader().getUniqueNo(); String agvNo; + AGVCar agvCar; + + String log; + label : switch (pac.getHeader().getProtocolType()){ case ACTION_COMPLETE: // 鍔ㄤ綔瀹屾垚鏁版嵁鍖� AGV_11_UP agv_11_up = (AGV_11_UP) pac.getBody().getMessageBody(); @@ -154,20 +171,50 @@ 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 AGVCar(clientId,ip,port,agvNo,1)); + agvStatus = agv_12_up.getStatus(); + positionID = agv_12_up.getQrCode(); + positionX = agv_12_up.getOffsetX(); + positionY = agv_12_up.getOffsetY(); + agvAngle = agv_12_up.getAGVCurrentAngle(); + gyroAngle = agv_12_up.getGyroAngle(); + forkHeight = agv_12_up.getCurrentAltitude(); + forkExtend = agv_12_up.getForkLength(); + forkAngle = agv_12_up.getLoaderTheta(); + agvCar = new AGVCar(clientId, ip, port, agvNo, 1, battery,agvStatus,positionID,positionX,positionY,agvAngle,gyroAngle,forkHeight,forkExtend,forkAngle,agvError); + EventBus.getDefault().post(agvCar); + log = formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + " 涓婅: " + ip + "[鏈夌爜瀹炴椂鏁版嵁鍖匽>>>" + pac.getSourceHexStr(); + Log.d("updown", log); + AGVApplication.addLog(log); 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 AGVCar(clientId,ip,port,agvNo,1)); + agvCar = new AGVCar(clientId, ip, port, agvNo, 1, battery,agvStatus,positionID,positionX,positionY,agvAngle,gyroAngle,forkHeight,forkExtend,forkAngle,agvError); + EventBus.getDefault().post(agvCar); + log = formatDate(new Date(), "yyyy-MM-dd HH:mm:ss:SSS") + " 涓婅: " + ip + "[鏃犵爜瀹炴椂鏁版嵁鍖匽>>>" + pac.getSourceHexStr(); + Log.d("updown", log); + AGVApplication.addLog(log); + break label; + case HEARTBEAT_REPORT: + AGV_03_UP agv_03_up = (AGV_03_UP) pac.getBody().getMessageBody(); + battery = agv_03_up.getBattery(); + agvError = agv_03_up.getError(); +// pac.getBody().getMessageBody() + agvNo = pac.getHeader().getUniqueNo(); + channelMap.put(clientId, ctx.channel()); + agvCar = new AGVCar(clientId, ip, port, agvNo, 1, battery,agvStatus,positionID,positionX,positionY,agvAngle,gyroAngle,forkHeight,forkExtend,forkAngle,agvError); + EventBus.getDefault().post(agvCar); + log = formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + " 涓婅: " + ip + "[蹇冭烦鍖匽>>>" + pac.getSourceHexStr(); + Log.d("updown", log); + AGVApplication.addLog(log); break label; case LOGIN_REPORT: AGV_F0_UP agv_f0_up = (AGV_F0_UP) pac.getBody().getMessageBody(); if (null != ackType) { AgvPackage ackPac = AckMsgBuilder.ofSuccess(pac, ackType); AGV_F0_DOWN agv_f0_down = (AGV_F0_DOWN) ackPac.getBody().getMessageBody(); - String log = formatDate(new Date(), "yyyy-MM-dd HH:mm:ss") + " 涓婅: " + ip + "[鐧诲綍鍖匽>>>" + pac.getSourceHexStr(); + log = formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + " 涓婅: " + ip + "[鐧诲綍鍖匽>>>" + pac.getSourceHexStr(); Log.d("updown", log); AGVApplication.addLog(log); @@ -175,11 +222,11 @@ ctx.writeAndFlush(ackPac); } - final int battery = agv_f0_up.getBattery(); + battery = agv_f0_up.getBattery(); // pac.getBody().getMessageBody() agvNo = pac.getHeader().getUniqueNo(); channelMap.put(clientId, ctx.channel()); - AGVCar agvCar = new AGVCar(clientId, ip, port, agvNo, 1, battery,0,0,0,0,0,0,0,0,0,0); + agvCar = new AGVCar(clientId, ip, port, agvNo, 1, battery,agvStatus,positionID,positionX,positionY,agvAngle,gyroAngle,forkHeight,forkExtend,forkAngle,agvError); EventBus.getDefault().post(agvCar); break label; -- Gitblit v1.9.1