From 00fd3eb5037f07763d4e8d3e5729066d3dc097ea Mon Sep 17 00:00:00 2001 From: whycq <913841844@qq.com> Date: 星期三, 08 一月 2025 14:47:43 +0800 Subject: [PATCH] # --- app/src/main/java/com/example/agvcontroller/MainActivity.java | 10 app/src/main/java/com/example/agvcontroller/StartActivity.java | 12 + app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java | 241 +++++++++++++++++++++ app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java | 38 ++- app/src/main/res/layout/activity_main.xml | 4 app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java | 226 ++++++++++++++++++++ app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP.java | 115 ++++++++++ app/src/main/java/com/example/agvcontroller/protocol/AgvAction.java | 2 app/src/main/java/com/example/agvcontroller/ItemAdapter.java | 2 9 files changed, 627 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/example/agvcontroller/ItemAdapter.java b/app/src/main/java/com/example/agvcontroller/ItemAdapter.java index c981707..db65138 100644 --- a/app/src/main/java/com/example/agvcontroller/ItemAdapter.java +++ b/app/src/main/java/com/example/agvcontroller/ItemAdapter.java @@ -89,7 +89,7 @@ // 鏁版嵁鏄剧ず椤甸潰 Item item = itemList.get(position); holder.ip.setText("璁惧IP锛� " + item.getIp()); - holder.title.setText("璁惧缂栧彿锛� " + item.getText()); + holder.title.setText("璁惧缂栧彿锛� " + item.getAgvNo()); holder.itemView.setTag(position); } diff --git a/app/src/main/java/com/example/agvcontroller/MainActivity.java b/app/src/main/java/com/example/agvcontroller/MainActivity.java index 110138d..3fb66dc 100644 --- a/app/src/main/java/com/example/agvcontroller/MainActivity.java +++ b/app/src/main/java/com/example/agvcontroller/MainActivity.java @@ -83,7 +83,7 @@ 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; @@ -131,7 +131,7 @@ .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); // 100ms 鍚庡彂閫佷笅涓�鏉℃秷鎭� } @@ -141,7 +141,7 @@ .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); } @@ -151,7 +151,7 @@ .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); } @@ -161,7 +161,7 @@ .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); } diff --git a/app/src/main/java/com/example/agvcontroller/StartActivity.java b/app/src/main/java/com/example/agvcontroller/StartActivity.java index adb74d2..e2b4401 100644 --- a/app/src/main/java/com/example/agvcontroller/StartActivity.java +++ b/app/src/main/java/com/example/agvcontroller/StartActivity.java @@ -58,11 +58,21 @@ @Subscribe(threadMode = ThreadMode.MAIN) public void onDeviceConnected(Item deviceAddress) { Log.i("EventBus", "Received device connected: " + deviceAddress); - items.add(new Item("1",deviceAddress.getIp(),"3")); + + if (items.size() > 0) { + int sameIp = 0; for (Item item : items) { + if (item.getIp().equals(deviceAddress.getIp())) { + sameIp++; + } Log.i("Item",item.getIp()); } + if (sameIp == 0) { + items.add(new Item(deviceAddress.getText(),deviceAddress.getIp(),deviceAddress.getAgvNo())); + } + } else { + items.add(new Item(deviceAddress.getText(),deviceAddress.getIp(),deviceAddress.getAgvNo())); } adapter.notifyDataSetChanged(); } 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 new file mode 100644 index 0000000..a3a40a5 --- /dev/null +++ b/app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java @@ -0,0 +1,241 @@ +package com.example.agvcontroller.protocol; + + +import com.example.agvcontroller.action.CommonConstant; +import com.example.agvcontroller.socket.RadixTools; + +import java.io.Serializable; +import java.nio.ByteBuffer; + +/** + * 瀹炴椂鏁版嵁鍖�1 + * Created by vincent on 2023/3/16 + */ +public class AGV_12_UP implements IMessageBody, Serializable { + + private static final long serialVersionUID = 7485846034848121068L; + + @Override + public byte[] writeToBytes() { + return new byte[0]; + } + + @Override + public void readFromBytes(byte[] bytes) { + //鍦伴潰鐮両D + this.qrCode = Utils.zeroFill(String.valueOf(RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 0, 4))), CommonConstant.QR_CODE_LEN);; + //鍦伴潰鐮佸亸绉粁 + this.offsetX = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 4 , 2)); + //鍦伴潰鐮佸亸绉粂 + this.offsetY = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 6, 2)); + //鍦伴潰鐮佸亸绉晃� + this.groundCodeOffset0 = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 8, 4)); + //褰撳墠鐘舵�� + this.status = Utils.slice(bytes, 12, 1)[0]; + //鐩磋鏂瑰悜鍧愭爣 + this.straightDirectionPosition = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 13, 4)); + //AGV褰撳墠瑙掑害 +// this.AGVCurrentAngle = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 17, 4)); + this.AGVCurrentAngle = ByteBuffer.wrap(Utils.sliceWithReverse(bytes, 17, 4)).getFloat(); + //闄�铻轰华瑙掑害 + this.gyroAngle = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 21, 4)); + //缂栫爜鍣ㄨ搴� + this.encoderAngle = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 25, 4)); + //褰撳墠楂樺害 + this.currentAltitude = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 29, 2)); + //璐у弶浼稿嚭璺濈 + this.forkLength = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 31, 2)); + //杞借揣鍙版棆杞搴� + this.loaderTheta = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 33, 2)); + //浼犳劅鍣ㄧ姸鎬佹爣蹇� +// this.sensorStatusFlags = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 35, 4)); + +// byte[] sensorStatusBytes = Utils.slice(bytes, 35, 4); +// parseSensorStatue(sensorStatusBytes); + } + + @Override + public String getSerialNo() { + return ""; + } + + //鍦伴潰鐮両D + private String qrCode; + + //鍦伴潰鐮佸亸绉粁 + private int offsetX; + + //鍦伴潰鐮佸亸绉粂 + private int offsetY; + + //鍦伴潰鐮佸亸绉晃� + private int groundCodeOffset0; + + //褰撳墠鐘舵�� + private int status; + + //鐩磋鏂瑰悜鍧愭爣-鍗曚綅锛歮m + private int straightDirectionPosition; + + //AGV褰撳墠瑙掑害-鍗曚綅锛毬� + private float AGVCurrentAngle; + + //闄�铻轰华瑙掑害-鍗曚綅锛毬� + private int gyroAngle; + + //缂栫爜鍣ㄨ搴�-鍗曚綅锛毬� + private int encoderAngle; + + //褰撳墠楂樺害 + private int currentAltitude; + + // 璐у弶浼稿嚭璺濈 + private int forkLength; + + // 杞借揣鍙版棆杞搴� + private int loaderTheta; + + //浼犳劅鍣ㄧ姸鎬佹爣蹇� + private int sensorStatusFlags; + + // 鍙栨斁璐х姸鎬� + private byte inOutFlag; + + private void parseSensorStatue(byte[] bytes) { + this.tempLoc1 = Utils.getBit(bytes[0], 0); + this.tempLoc2 = Utils.getBit(bytes[0], 1); + this.tempLoc3 = Utils.getBit(bytes[0], 2); + this.tempLoc4 = Utils.getBit(bytes[0], 3); + this.tempLoc5 = Utils.getBit(bytes[0], 4); + this.tempLoc6 = Utils.getBit(bytes[0], 5); + this.tempLoc7 = Utils.getBit(bytes[0], 6); + this.tempLoc8 = Utils.getBit(bytes[0], 7); + + this.inOutFlag = bytes[1]; + +// this.tempLoc9 = Utils.getBit(bytes[1], 0); +// this.tempLoc10 = Utils.getBit(bytes[1], 1); +// this.tempLoc11 = Utils.getBit(bytes[1], 2); +// this.tempLoc12 = Utils.getBit(bytes[1], 3); +// this.tempLoc13 = Utils.getBit(bytes[1], 4); +// this.tempLoc14 = Utils.getBit(bytes[1], 5); +// this.tempLoc15 = Utils.getBit(bytes[1], 6); +// this.tempLoc16 = Utils.getBit(bytes[1], 7); + + this.expandFront = Utils.getBit(bytes[2], 0); + this.expandBack = Utils.getBit(bytes[2], 1); + this.expandLeft = Utils.getBit(bytes[2], 2); + this.expandRight = Utils.getBit(bytes[2], 3); + this.finger1 = Utils.getBit(bytes[2], 4); + this.finger2 = Utils.getBit(bytes[2], 5); + this.finger3 = Utils.getBit(bytes[2], 6); + this.finger4 = Utils.getBit(bytes[2], 7); + + this.rotaLeft = Utils.getBit(bytes[3], 0); + this.rotaRight = Utils.getBit(bytes[3], 1); + this.loaderFront = Utils.getBit(bytes[3], 2); + this.loaderBack = Utils.getBit(bytes[3], 3); + this.loaderMid = Utils.getBit(bytes[3], 4); + this.liftMid = Utils.getBit(bytes[3], 5); + this.liftUp = Utils.getBit(bytes[3], 6); + this.liftBottom = Utils.getBit(bytes[3], 7); + } + + + // 鏆傚瓨璐т綅1妫�娴� + private boolean tempLoc1; + + // 鏆傚瓨璐т綅2妫�娴� + private boolean tempLoc2; + + // 鏆傚瓨璐т綅3妫�娴� + private boolean tempLoc3; + + // 鏆傚瓨璐т綅4妫�娴� + private boolean tempLoc4; + + // 鏆傚瓨璐т綅5妫�娴� + private boolean tempLoc5; + + // 鏆傚瓨璐т綅6妫�娴� + private boolean tempLoc6; + + // 鏆傚瓨璐т綅7妫�娴� + private boolean tempLoc7; + + // 鏆傚瓨璐т綅8妫�娴� + private boolean tempLoc8; + + // 鏆傚瓨璐т綅9妫�娴� + private boolean tempLoc9; + + // 鏆傚瓨璐т綅10妫�娴� + private boolean tempLoc10; + + // 鏆傚瓨璐т綅11妫�娴� + private boolean tempLoc11; + + // 鏆傚瓨璐т綅12妫�娴� + private boolean tempLoc12; + + // 鏆傚瓨璐т綅13妫�娴� + private boolean tempLoc13; + + // 鏆傚瓨璐т綅14妫�娴� + private boolean tempLoc14; + + // 鏆傚瓨璐т綅15妫�娴� + private boolean tempLoc15; + + // 鏆傚瓨璐т綅16妫�娴� + private boolean tempLoc16; + + // 浼哥缉鍓嶉檺浣� + private boolean expandFront; + + // 浼哥缉鍚庨檺浣� + private boolean expandBack; + + // 浼哥缉宸﹂浂浣� + private boolean expandLeft; + + // 浼哥缉鍙抽浂浣� + private boolean expandRight; + + // 鎷ㄦ寚1浣嶇疆 + private boolean finger1; + + // 鎷ㄦ寚2浣嶇疆 + private boolean finger2; + + // 鎷ㄦ寚3浣嶇疆 + private boolean finger3; + + // 鎷ㄦ寚4浣嶇疆 + private boolean finger4; + + // 鍥炶浆宸﹀埌浣� + private boolean rotaLeft; + + // 鍥炶浆鍙冲埌浣� + private boolean rotaRight; + + // 杞借揣鍙板墠鎺㈣揣 + private boolean loaderFront; + + // 杞借揣鍙板悗鎺㈣揣 + private boolean loaderBack; + + // 杞借揣鍙拌揣鐗╂娴� + private boolean loaderMid; + + // 鍗囬檷闆朵綅 + private boolean liftMid; + + // 鍗囬檷涓婇檺浣� + private boolean liftUp; + + // 鍗囬檷涓嬮檺浣� + private boolean liftBottom; + +} 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 new file mode 100644 index 0000000..ae6ad54 --- /dev/null +++ b/app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java @@ -0,0 +1,226 @@ +package com.example.agvcontroller.protocol; + + +import com.example.agvcontroller.action.CommonConstant; +import com.example.agvcontroller.socket.RadixTools; + +import java.io.Serializable; +import java.nio.ByteBuffer; + +/** + * 瀹炴椂鏁版嵁鍖�2 + * Created by vincent on 2023/3/16 + */ +public class AGV_13_UP implements IMessageBody, Serializable { + + private static final long serialVersionUID = 6993991304425938465L; + + @Override + public byte[] writeToBytes() { + return new byte[0]; + } + + @Override + public void readFromBytes(byte[] bytes) { + //鍦伴潰鐮両D + this.qrCode = Utils.zeroFill(String.valueOf(RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 0, 4))), CommonConstant.QR_CODE_LEN);; + //褰撳墠鐘舵�� + this.status = Utils.slice(bytes, 4, 1)[0]; + //鐩磋鏂瑰悜鍧愭爣 + this.straightDirectionPosition = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 5, 4)); + //AGV褰撳墠瑙掑害 +// this.AGVCurrentAngle = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 9, 4)); + this.AGVCurrentAngle = ByteBuffer.wrap(Utils.sliceWithReverse(bytes, 9, 4)).getFloat(); + //闄�铻轰华瑙掑害 + this.gyroAngle = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 13, 4)); + //缂栫爜鍣ㄨ搴� + this.encoderAngle = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 17, 4)); + //褰撳墠楂樺害 + this.currentAltitude = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 21, 2)); + //璐у弶浼稿嚭璺濈 + this.forkLength = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 23, 2)); + //杞借揣鍙版棆杞搴� + this.loaderTheta = RadixTools.byteToShort(Utils.sliceWithReverse(bytes, 25, 2)); + //浼犳劅鍣ㄧ姸鎬佹爣蹇� +// this.sensorStatusFlags = RadixTools.bytesToInt(Utils.sliceWithReverse(bytes, 27, 4)); + + byte[] sensorStatusBytes = Utils.slice(bytes, 27, 4); + parseSensorStatue(sensorStatusBytes); + } + + @Override + public String getSerialNo() { + return ""; + } + + //鍦伴潰鐮両D + private String qrCode; + + //褰撳墠鐘舵�� + private int status; + + //鐩磋鏂瑰悜鍧愭爣-鍗曚綅锛歮m + private int straightDirectionPosition; + + //AGV褰撳墠瑙掑害-鍗曚綅锛毬� + private float AGVCurrentAngle; + + //闄�铻轰华瑙掑害-鍗曚綅锛毬� + private int gyroAngle; + + //缂栫爜鍣ㄨ搴�-鍗曚綅锛毬� + private int encoderAngle; + + //褰撳墠楂樺害 + private int currentAltitude; + + // 璐у弶浼稿嚭璺濈 + private int forkLength; + + // 杞借揣鍙版棆杞搴� + private int loaderTheta; + + //浼犳劅鍣ㄧ姸鎬佹爣蹇� + private int sensorStatusFlags; + + // 鍙栨斁璐х姸鎬� + private byte inOutFlag; + + private void parseSensorStatue(byte[] bytes) { + this.tempLoc1 = Utils.getBit(bytes[0], 0); + this.tempLoc2 = Utils.getBit(bytes[0], 1); + this.tempLoc3 = Utils.getBit(bytes[0], 2); + this.tempLoc4 = Utils.getBit(bytes[0], 3); + this.tempLoc5 = Utils.getBit(bytes[0], 4); + this.tempLoc6 = Utils.getBit(bytes[0], 5); + this.tempLoc7 = Utils.getBit(bytes[0], 6); + this.tempLoc8 = Utils.getBit(bytes[0], 7); + + this.inOutFlag = bytes[1]; + +// this.tempLoc9 = Utils.getBit(bytes[1], 0); +// this.tempLoc10 = Utils.getBit(bytes[1], 1); +// this.tempLoc11 = Utils.getBit(bytes[1], 2); +// this.tempLoc12 = Utils.getBit(bytes[1], 3); +// this.tempLoc13 = Utils.getBit(bytes[1], 4); +// this.tempLoc14 = Utils.getBit(bytes[1], 5); +// this.tempLoc15 = Utils.getBit(bytes[1], 6); +// this.tempLoc16 = Utils.getBit(bytes[1], 7); + + this.expandFront = Utils.getBit(bytes[2], 0); + this.expandBack = Utils.getBit(bytes[2], 1); + this.expandLeft = Utils.getBit(bytes[2], 2); + this.expandRight = Utils.getBit(bytes[2], 3); + this.finger1 = Utils.getBit(bytes[2], 4); + this.finger2 = Utils.getBit(bytes[2], 5); + this.finger3 = Utils.getBit(bytes[2], 6); + this.finger4 = Utils.getBit(bytes[2], 7); + + this.rotaLeft = Utils.getBit(bytes[3], 0); + this.rotaRight = Utils.getBit(bytes[3], 1); + this.loaderFront = Utils.getBit(bytes[3], 2); + this.loaderBack = Utils.getBit(bytes[3], 3); + this.loaderMid = Utils.getBit(bytes[3], 4); + this.liftMid = Utils.getBit(bytes[3], 5); + this.liftUp = Utils.getBit(bytes[3], 6); + this.liftBottom = Utils.getBit(bytes[3], 7); + } + + + // 鏆傚瓨璐т綅1妫�娴� + private boolean tempLoc1; + + // 鏆傚瓨璐т綅2妫�娴� + private boolean tempLoc2; + + // 鏆傚瓨璐т綅3妫�娴� + private boolean tempLoc3; + + // 鏆傚瓨璐т綅4妫�娴� + private boolean tempLoc4; + + // 鏆傚瓨璐т綅5妫�娴� + private boolean tempLoc5; + + // 鏆傚瓨璐т綅6妫�娴� + private boolean tempLoc6; + + // 鏆傚瓨璐т綅7妫�娴� + private boolean tempLoc7; + + // 鏆傚瓨璐т綅8妫�娴� + private boolean tempLoc8; + + // 鏆傚瓨璐т綅9妫�娴� + private boolean tempLoc9; + + // 鏆傚瓨璐т綅10妫�娴� + private boolean tempLoc10; + + // 鏆傚瓨璐т綅11妫�娴� + private boolean tempLoc11; + + // 鏆傚瓨璐т綅12妫�娴� + private boolean tempLoc12; + + // 鏆傚瓨璐т綅13妫�娴� + private boolean tempLoc13; + + // 鏆傚瓨璐т綅14妫�娴� + private boolean tempLoc14; + + // 鏆傚瓨璐т綅15妫�娴� + private boolean tempLoc15; + + // 鏆傚瓨璐т綅16妫�娴� + private boolean tempLoc16; + + // 浼哥缉鍓嶉檺浣� + private boolean expandFront; + + // 浼哥缉鍚庨檺浣� + private boolean expandBack; + + // 浼哥缉宸﹂浂浣� + private boolean expandLeft; + + // 浼哥缉鍙抽浂浣� + private boolean expandRight; + + // 鎷ㄦ寚1浣嶇疆 + private boolean finger1; + + // 鎷ㄦ寚2浣嶇疆 + private boolean finger2; + + // 鎷ㄦ寚3浣嶇疆 + private boolean finger3; + + // 鎷ㄦ寚4浣嶇疆 + private boolean finger4; + + // 鍥炶浆宸﹀埌浣� + private boolean rotaLeft; + + // 鍥炶浆鍙冲埌浣� + private boolean rotaRight; + + // 杞借揣鍙板墠鎺㈣揣 + private boolean loaderFront; + + // 杞借揣鍙板悗鎺㈣揣 + private boolean loaderBack; + + // 杞借揣鍙拌揣鐗╂娴� + private boolean loaderMid; + + // 鍗囬檷闆朵綅 + private boolean liftMid; + + // 鍗囬檷涓婇檺浣� + private boolean liftUp; + + // 鍗囬檷涓嬮檺浣� + private boolean liftBottom; + +} diff --git a/app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP.java b/app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP.java new file mode 100644 index 0000000..ba3a925 --- /dev/null +++ b/app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP.java @@ -0,0 +1,115 @@ +package com.example.agvcontroller.protocol; + + +import java.io.Serializable; + +public class AGV_F0_UP implements IMessageBody, Serializable { + + private static final long serialVersionUID = 8403019742104020004L; + + @Override + public byte[] writeToBytes() { + return new byte[0]; + } + + @Override + public void readFromBytes(byte[] bytes) { + this.password = ""; + this.carType = 0; + this.baseVersion = ""; + this.bothData = ""; + this.softwareVersion = ""; + this.optData = ""; + this.totalTime = 0; + this.totalDistance = 0; + this.batteryType = 0; + this.maxChargeCurrent = 0; + this.batteryVoltage = 0; + this.remainingBattery = 0; + this.soh = 0; + this.groundCode = ""; + this.qrCode = ""; + this.offsetX = 0; + this.offsetY = 0; + this.groundCodeOffset0 = 0; + this.status = 0; + this.faultFlag = 0; + this.intrusionCount = 0; + this.spareSpaceCount = 0; + } + + @Override + public String getSerialNo() { + return ""; + } + + // 瀵嗙爜 + private String password; + + // 璁惧绫诲瀷 + private int carType; + + // 纭欢鐗堟湰 + private String baseVersion; + + // 鍑哄巶鏃ユ湡 + private String bothData; + + // 杞欢鐗堟湰 + private String softwareVersion; + + // 鍙戝竷鏃ユ湡 + private String optData; + + // 绱宸ヤ綔鏃堕棿 + private int totalTime; + + // 绱琛岃蛋璺濈 + private int totalDistance; + // 鐢垫睜绫诲瀷 + private int batteryType; + + // 鏈�澶у厖鐢电數娴� + private int maxChargeCurrent; + + // 鐢垫睜鐢靛帇 + private int batteryVoltage; + + // 鍓╀綑鐢甸噺 + private int remainingBattery; + + // soh + private int soh; + + // 鍦伴潰鐮� + private String groundCode; + + //鍦伴潰鐮両D + private String qrCode; + + //鍦伴潰鐮佸亸绉粁 + private int offsetX; + + //鍦伴潰鐮佸亸绉粂 + private int offsetY; + + //鍦伴潰鐮佸亸绉晃� + private int groundCodeOffset0; + + //褰撳墠鐘舵�� + private int status; + + // 鏁呴殰鏍囧織 + private int faultFlag; + + // 鍏ヤ镜妫�娴嬫鏁� + private int intrusionCount; + + // 鏆傚瓨璐т綅鏁伴噺 + private int spareSpaceCount; + + + + + +} diff --git a/app/src/main/java/com/example/agvcontroller/protocol/AgvAction.java b/app/src/main/java/com/example/agvcontroller/protocol/AgvAction.java index b18ce49..4113844 100644 --- a/app/src/main/java/com/example/agvcontroller/protocol/AgvAction.java +++ b/app/src/main/java/com/example/agvcontroller/protocol/AgvAction.java @@ -36,7 +36,7 @@ byte valByte = (byte) val; // 灞炴�у�� - byte[] bytes = actionBody.writeToBytes(); // 鍛戒护鍙傛暟 + byte[] bytes = Utils.reverse(actionBody.writeToBytes()); // 鍛戒护鍙傛暟 return Utils.merge(serialNoBytes,cmdCode, valByte, bytes); } 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 a33faad..81dd64f 100644 --- a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java +++ b/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java @@ -14,7 +14,10 @@ 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_12_UP; +import com.example.agvcontroller.protocol.AGV_13_UP; import com.example.agvcontroller.protocol.AGV_A1_DOWN; +import com.example.agvcontroller.protocol.AGV_F0_UP; import com.example.agvcontroller.protocol.AgvAction; import com.example.agvcontroller.protocol.AgvPackage; import com.example.agvcontroller.protocol.ProtocolType; @@ -32,10 +35,10 @@ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - String clientId = ctx.channel().remoteAddress().toString(); - channelMap.put(clientId, ctx.channel()); - EventBus.getDefault().post(new Item("1",clientId,"3")); - Log.d(TAG, "Client connected: " + clientId); +// String clientId = ctx.channel().remoteAddress().toString(); +// channelMap.put(clientId, ctx.channel()); +// EventBus.getDefault().post(new Item("",clientId,"3")); +// Log.d(TAG, "Client connected: " + clientId); } @Override @@ -66,33 +69,42 @@ @Override protected boolean channelRead0(ChannelHandlerContext ctx, AgvPackage pac) throws Exception { - + String clientId = ctx.channel().remoteAddress().toString(); + Log.i("clientId--->",clientId); + Log.i("substring",pac.toString()); String serialNum = pac.getBody().getMessageBody().getSerialNo(); Log.i("substring",serialNum); MainActivity.map.put(serialNum, Boolean.TRUE); // ack ProtocolType ackType = isNeedAck(pac); final String uniqueNo = pac.getHeader().getUniqueNo(); + String agvNo; label : switch (pac.getHeader().getProtocolType()){ case ACTION_COMPLETE: // 鍔ㄤ綔瀹屾垚鏁版嵁鍖� - - AGV_11_UP agv_11_up = (AGV_11_UP) pac.getBody().getMessageBody(); // redis.push(RedisConstant.AGV_COMPLETE_FLAG, AgvProtocol.build(uniqueNo).setMessageBody(agv_11_up)); - // 鍔ㄤ綔瀹屾垚搴旂瓟 if (null != ackType) { AgvPackage ackPac = AckMsgBuilder.ofSuccess(pac, ackType); - AGV_A1_DOWN agv_a1_down = (AGV_A1_DOWN) ackPac.getBody().getMessageBody(); agv_a1_down.setAckSign((byte) agv_11_up.getCompleteCode()); - ctx.writeAndFlush(ackPac); } - - - break label; + case DATA_CODE_REPORT: + AGV_12_UP agv_12_up = (AGV_12_UP) pac.getBody().getMessageBody(); + agvNo = pac.getHeader().getUniqueNo(); + EventBus.getDefault().post(new Item("",clientId,agvNo)); + break label; + case DATA_WITHOUT_CODE_REPORT: + AGV_13_UP agv_13_up = (AGV_13_UP) pac.getBody().getMessageBody(); + break label; + case LOGIN_REPORT: + AGV_F0_UP agv_f0_up = (AGV_F0_UP) pac.getBody().getMessageBody(); + agvNo = pac.getHeader().getUniqueNo(); + EventBus.getDefault().post(new Item("",clientId,agvNo)); + break label; + } return false; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3adc450..ccb3535 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -94,7 +94,7 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="6" - android:visibility="gone"> + android:visibility="visible"> <Button android:id="@+id/btn_stop2" @@ -471,7 +471,7 @@ <!-- **************** 18杞� **************** --> <GridLayout android:id="@+id/layout_18" - android:visibility="visible" + android:visibility="gone" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="6" -- Gitblit v1.9.1