From 6f1275502e0d7be1b919f9d6eb308436cc8958fa Mon Sep 17 00:00:00 2001 From: whycq <913841844@qq.com> Date: 星期四, 16 一月 2025 09:22:01 +0800 Subject: [PATCH] # --- app/src/main/java/com/example/agvcontroller/MainActivity.java | 303 ++++++++++++++++++-------------------------------- app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java | 5 app/src/main/java/com/example/agvcontroller/protocol/PacBody.java | 9 app/src/main/java/com/example/agvcontroller/protocol/ProtocolEncoder.java | 16 +- app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP8.java | 2 5 files changed, 129 insertions(+), 206 deletions(-) diff --git a/app/src/main/java/com/example/agvcontroller/MainActivity.java b/app/src/main/java/com/example/agvcontroller/MainActivity.java index 7b34b4c..5e68826 100644 --- a/app/src/main/java/com/example/agvcontroller/MainActivity.java +++ b/app/src/main/java/com/example/agvcontroller/MainActivity.java @@ -38,6 +38,7 @@ import com.example.agvcontroller.action.LoadResetAction; import com.example.agvcontroller.action.RotatopnLeftRight; import com.example.agvcontroller.action.SingleSwitchAction; +import com.example.agvcontroller.action.SingleSwitchRunAction; import com.example.agvcontroller.protocol.AgvAction; import com.example.agvcontroller.action.HandOutAction; import com.example.agvcontroller.socket.NettyServerHandler; @@ -140,19 +141,24 @@ private boolean isGoBackward = false; private boolean isRotatopnRight = false; private boolean isRotatopnLeft = false; - - private boolean isFrontPaddleExtendBtn = false; - private boolean isFrontPaddleCollectBtn = false; - private boolean isBackPaddleExtendBtn = false; - private boolean isBackPaddleCollectBtn = false; - private boolean isRiseBtn = false; - private boolean isDropBtn = false; - private boolean isExtendForkBtn = false; - private boolean isCollectForkBtn = false; - private boolean isTurnLeftBtn = false; - private boolean isTurnRightBtn = false; - - + private boolean isFront1 = false; + private boolean isBack1 = false; + private boolean isFront2 = false; + private boolean isBack2 = false; + private boolean isFront3 = false; + private boolean isBack3 = false; + private boolean isFront4 = false; + private boolean isBack4 = false; + private boolean isFront5 = false; + private boolean isBack5 = false; + private boolean isFront6 = false; + private boolean isBack6 = false; + private boolean isFront7 = false; + private boolean isBack7 = false; + private boolean isFront8 = false; + private boolean isBack8 = false; + private boolean isFront9 = false; + private boolean isBack9 = false; @@ -161,8 +167,9 @@ private Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { + String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); + short pwd = 0; if (isGoForward) { - String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); AgvAction agvAction = new AgvAction<>(ForwardBackAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) @@ -172,7 +179,6 @@ handler.sendEmptyMessageDelayed(0, 100); // 100ms 鍚庡彂閫佷笅涓�鏉℃秷鎭� } if (isGoBackward) { - String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); AgvAction agvAction = new AgvAction<>(ForwardBackAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) @@ -182,7 +188,6 @@ handler.sendEmptyMessageDelayed(0, 100); } if (isRotatopnRight) { - String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class) .setAgvNo(AgvNo) .setSerialNo(substring) @@ -192,7 +197,6 @@ handler.sendEmptyMessageDelayed(0, 100); } if (isRotatopnLeft) { - String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class) .setAgvNo(AgvNo) .setSerialNo(substring) @@ -202,116 +206,24 @@ handler.sendEmptyMessageDelayed(0, 100); } -// // 鍓嶆嫧鏉嗕几 -// if (isFrontPaddleExtendBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(FrontPaddle.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) 1)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 鍓嶆嫧鏉嗘敹 -// if (isFrontPaddleCollectBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(FrontPaddle.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) 0)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 鍚庢嫧鏉嗕几 -// if (isBackPaddleExtendBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(BackPaddle.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) 1)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 鍚庢嫧鏉嗘敹 -// if (isBackPaddleCollectBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(BackPaddle.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) 0)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 涓婂崌 -// if (isRiseBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(HandLift.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) -10)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 涓嬮檷 -// if (isDropBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(HandLift.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) -10)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 浼稿弶 -// if (isExtendForkBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(HandExtendCollect.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) -10)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 鏀跺弶 -// if (isCollectForkBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(HandExtendCollect.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) -10)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 璐у弶宸︽棆 -// if (isTurnLeftBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) -10)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } -// // 璐у弶鍙虫棆 -// if (isTurnRightBtn) { -// String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); -// AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) -// .setAgvNo(AgvNo) -// .setSerialNo(substring) -// .setVal(1) -// .bodySync((action) -> action.setPwd((short) -10)); -// nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� -// handler.sendEmptyMessageDelayed(0, 100); -// } + if (isRotatopnRight) { + AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class) + .setAgvNo(AgvNo) + .setSerialNo(substring) + .setVal(1) + .bodySync((action) -> action.setPwd((short) 50)); + nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� + handler.sendEmptyMessageDelayed(0, 100); + } + if (isRotatopnLeft) { + AgvAction agvAction = new AgvAction<>(RotatopnLeftRight.class) + .setAgvNo(AgvNo) + .setSerialNo(substring) + .setVal(1) + .bodySync((action) -> action.setPwd((short) -50 )); + nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� + handler.sendEmptyMessageDelayed(0, 100); + } return false; } }); @@ -525,7 +437,7 @@ .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(1) - .bodySync((action) -> action.setPwd((short) 21)); + .bodySync((action) -> action.setPwd((short) extendWidth)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� extendWidth += 50; } else { @@ -548,7 +460,7 @@ .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(1) - .bodySync((action) -> action.setPwd((short) 21)); + .bodySync((action) -> action.setPwd((short) extendWidth)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔埛绔� extendWidth -= 50; } else { @@ -711,6 +623,7 @@ if (vibrator != null && vibrator.hasVibrator()) { vibrator.vibrate(500); } + boolean result = false; String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); if (isAuto) { AgvAction agvAction = new AgvAction<>(HandInAction.class) @@ -719,6 +632,8 @@ .setVal(autoVal) .bodySync((action) -> action.setPwd((short) 21)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� + result = true; + isAuto = !isAuto; } else { AgvAction agvAction = new AgvAction<>(HandOutAction.class) .setAgvNo(AgvNo) @@ -726,21 +641,23 @@ .setVal(autoVal) .bodySync((action) -> action.setPwd((short) 21)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� + result = true; + isAuto = !isAuto; } - boolean result = false; - long timestamp = System.currentTimeMillis(); - while (System.currentTimeMillis() - timestamp < 5000) { - Object o = map.get(substring); - - if (null != o) { - result = true; - isAuto = !isAuto; - map.remove(o); - break; - } - } +// long timestamp = System.currentTimeMillis(); +// while (System.currentTimeMillis() - timestamp < 5000) { +// +// Object o = map.get(substring); +// +// if (null != o) { +// result = true; +// isAuto = !isAuto; +// map.remove(o); +// break; +// } +// } if (result) { // alert ok 淇敼鎸夐挳鏍峰紡 鍚嶇О @@ -881,15 +798,19 @@ .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(5) - .bodySync((action) -> action.setPwd((short) 0)); + .bodySync((action) -> action.setPwd((short) 1)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� + axleFrontBtn5.setVisibility(View.VISIBLE); + axleBackBtn5.setVisibility(View.VISIBLE); } else { AgvAction agvAction = new AgvAction<>(SingleSwitchAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(5) - .bodySync((action) -> action.setPwd((short) 1)); + .bodySync((action) -> action.setPwd((short) 0)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� + axleFrontBtn5.setVisibility(View.GONE); + axleBackBtn5.setVisibility(View.GONE); } } }); @@ -999,23 +920,6 @@ }); - axleFrontBtn2 =findViewById(R.id.btn_axle_2_front); - axleBackBtn2 =findViewById(R.id.btn_axle_2_back); - axleFrontBtn3 =findViewById(R.id.btn_axle_3_front); - axleBackBtn3 =findViewById(R.id.btn_axle_3_back); - axleFrontBtn4 =findViewById(R.id.btn_axle_4_front); - axleBackBtn4 =findViewById(R.id.btn_axle_4_back); - axleFrontBtn5 =findViewById(R.id.btn_axle_5_front); - axleBackBtn5 =findViewById(R.id.btn_axle_5_back); - axleFrontBtn6 =findViewById(R.id.btn_axle_6_front); - axleBackBtn6 =findViewById(R.id.btn_axle_6_back); - axleFrontBtn7 =findViewById(R.id.btn_axle_7_front); - axleBackBtn7 =findViewById(R.id.btn_axle_7_back); - axleFrontBtn8 =findViewById(R.id.btn_axle_8_front); - axleBackBtn8 =findViewById(R.id.btn_axle_8_back); - axleFrontBtn9 =findViewById(R.id.btn_axle_9_front); - axleBackBtn9 =findViewById(R.id.btn_axle_9_back); - axleFrontBtn1.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { @@ -1023,7 +927,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(1) @@ -1039,7 +943,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(1) @@ -1055,7 +959,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(2) @@ -1071,7 +975,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(2) @@ -1087,7 +991,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(3) @@ -1103,7 +1007,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(3) @@ -1119,7 +1023,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(4) @@ -1135,7 +1039,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(4) @@ -1151,11 +1055,11 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(5) - .bodySync((action) -> action.setPwd((short) 100)); + .bodySync((action) -> action.setPwd((short) 99)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� } }); @@ -1167,11 +1071,11 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(5) - .bodySync((action) -> action.setPwd((short) -100)); + .bodySync((action) -> action.setPwd((short) -99)); nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� } }); @@ -1183,7 +1087,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(6) @@ -1199,7 +1103,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(6) @@ -1215,7 +1119,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(7) @@ -1231,7 +1135,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(7) @@ -1247,7 +1151,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(8) @@ -1263,7 +1167,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(8) @@ -1279,7 +1183,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(9) @@ -1295,7 +1199,7 @@ vibrator.vibrate(500); } String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); - AgvAction agvAction = new AgvAction<>(HandForkRotatopn.class) + AgvAction agvAction = new AgvAction<>(SingleSwitchRunAction.class) .setAgvNo(AgvNo) .setSerialNo(substring) .setVal(9) @@ -1311,16 +1215,25 @@ rotatopnLeftBtn.setOnTouchListener(new CarTouchButton()); rotatopnRightBtn.setOnTouchListener(new CarTouchButton()); -// frontPaddleExtendBtn.setOnTouchListener(new CarTouchButton()); -// frontPaddleCollectBtn.setOnTouchListener(new CarTouchButton()); -// backPaddleExtendBtn.setOnTouchListener(new CarTouchButton()); -// backPaddleCollectBtn.setOnTouchListener(new CarTouchButton()); -// riseBtn.setOnTouchListener(new CarTouchButton()); -// dropBtn.setOnTouchListener(new CarTouchButton()); -// extendForkBtn.setOnTouchListener(new CarTouchButton()); -// collectForkBtn.setOnTouchListener(new CarTouchButton()); -// turnLeftBtn.setOnTouchListener(new CarTouchButton()); -// turnRightBtn.setOnTouchListener(new CarTouchButton()); + axleFrontBtn1.setOnTouchListener(new CarTouchButton()); + axleBackBtn1.setOnTouchListener(new CarTouchButton()); + axleFrontBtn2.setOnTouchListener(new CarTouchButton()); + axleBackBtn2.setOnTouchListener(new CarTouchButton()); + axleFrontBtn3.setOnTouchListener(new CarTouchButton()); + axleBackBtn3.setOnTouchListener(new CarTouchButton()); + axleFrontBtn4.setOnTouchListener(new CarTouchButton()); + axleBackBtn4.setOnTouchListener(new CarTouchButton()); + axleFrontBtn5.setOnTouchListener(new CarTouchButton()); + axleBackBtn5.setOnTouchListener(new CarTouchButton()); + axleFrontBtn6.setOnTouchListener(new CarTouchButton()); + axleBackBtn6.setOnTouchListener(new CarTouchButton()); + axleFrontBtn7.setOnTouchListener(new CarTouchButton()); + axleBackBtn7.setOnTouchListener(new CarTouchButton()); + axleFrontBtn8.setOnTouchListener(new CarTouchButton()); + axleBackBtn8.setOnTouchListener(new CarTouchButton()); + axleFrontBtn9.setOnTouchListener(new CarTouchButton()); + axleBackBtn9.setOnTouchListener(new CarTouchButton()); + } @@ -1328,7 +1241,6 @@ @Override public boolean onTouch(View view, MotionEvent motionEvent) { - if (view.getId() == R.id.btn_go_forward) { // 鍓嶈繘 if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { @@ -1337,7 +1249,6 @@ } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { isGoForward = false; } - } else if (view.getId() == R.id.btn_go_backward) { // 鍚庨�� if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { @@ -1364,6 +1275,14 @@ } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { isRotatopnRight = false; } + } else if (view.getId() == R.id.btn_rotatopn_right) { + // 杞村姩鎸夐挳 + if (motionEvent.getAction() == KeyEvent.ACTION_DOWN) { + isRotatopnRight = true; + handler.sendEmptyMessage(0); + } else if (motionEvent.getAction() == KeyEvent.ACTION_UP) { + isRotatopnRight = false; + } } 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_UP8.java similarity index 96% rename from app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP.java rename to app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP8.java index ba3a925..431f39a 100644 --- a/app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP.java +++ b/app/src/main/java/com/example/agvcontroller/protocol/AGV_F0_UP8.java @@ -3,7 +3,7 @@ import java.io.Serializable; -public class AGV_F0_UP implements IMessageBody, Serializable { +public class AGV_F0_UP8 implements IMessageBody, Serializable { private static final long serialVersionUID = 8403019742104020004L; diff --git a/app/src/main/java/com/example/agvcontroller/protocol/PacBody.java b/app/src/main/java/com/example/agvcontroller/protocol/PacBody.java index bdcd9ed..55da002 100644 --- a/app/src/main/java/com/example/agvcontroller/protocol/PacBody.java +++ b/app/src/main/java/com/example/agvcontroller/protocol/PacBody.java @@ -30,9 +30,10 @@ this.messageBody = messageBody; } - @Override - public String toString() { - return ByteBufUtil.hexDump(content); - } +// @Override +// public String toString() { +// return ""; +//// return ByteBufUtil.hexDump(content); +// } } diff --git a/app/src/main/java/com/example/agvcontroller/protocol/ProtocolEncoder.java b/app/src/main/java/com/example/agvcontroller/protocol/ProtocolEncoder.java index 9cb2cd5..15f2a0a 100644 --- a/app/src/main/java/com/example/agvcontroller/protocol/ProtocolEncoder.java +++ b/app/src/main/java/com/example/agvcontroller/protocol/ProtocolEncoder.java @@ -1,5 +1,6 @@ package com.example.agvcontroller.protocol; + import com.example.agvcontroller.socket.RadixTools; import java.util.logging.Logger; @@ -32,9 +33,11 @@ out.writeBytes((ByteBuf) obj); } else if (obj instanceof byte[]){ - out.writeBytes((byte[]) obj); +// out.writeBytes((byte[]) obj); - + out.writeBytes((byte[]) new byte[]{ + 0x0D, 0x0A + }); } else if (obj instanceof AgvAction<?>){ @@ -77,7 +80,7 @@ //String uniqueNo = pac.getHeader().getUniqueNo(); - //byte[] uniquenoBytes = RadixTools.intToBytes(Integer.parseInt(pac.getHeader().getUniqueNo())); // uniqueno + byte[] uniquenoBytes = RadixTools.intToBytes(Integer.parseInt(pac.getHeader().getUniqueNo())); // uniqueno int len = PackagePart.UNIQUENO.getLen() // len @@ -87,7 +90,7 @@ out.writeByte(pac.getHeader().getStartSymbol()) // symbol .writeShortLE(len) - //.writeBytes(Utils.reverse(uniquenoBytes)) // uniqueno + .writeBytes(Utils.reverse(uniquenoBytes)) // uniqueno .writeIntLE((int) (System.currentTimeMillis() / 1000)) // timestamp .writeByte(pac.getHeader().getProtocolType().getCode()) // type .writeBytes(bodyBytes) // body @@ -99,11 +102,6 @@ out.writerIndex(out.readableBytes() - 2); out.writeShortLE(pac.getValidCode()); - - - if (systemProperties.isPrintPacLog()){ - //log.info("Agv [{}] 涓嬭 [{}] >>> {}", uniqueNo, pac.getHeader().getProtocolType().getDes(), ByteBufUtil.hexDump(out).toUpperCase()); - } } 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 921875a..5df8f0e 100644 --- a/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java +++ b/app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java @@ -19,6 +19,7 @@ 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; @@ -100,11 +101,15 @@ 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,agvNo)); 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(); ctx.writeAndFlush(ackPac); } agvNo = pac.getHeader().getUniqueNo(); -- Gitblit v1.9.1