From 1eb6c8b77d99bb43437a974787baea33dc67253c Mon Sep 17 00:00:00 2001 From: whycq <913841844@qq.com> Date: 星期三, 14 八月 2024 17:01:21 +0800 Subject: [PATCH] # --- app/src/main/java/com/example/agvcontroller/MainActivity.java | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/example/agvcontroller/MainActivity.java b/app/src/main/java/com/example/agvcontroller/MainActivity.java index 69d593f..6bda580 100644 --- a/app/src/main/java/com/example/agvcontroller/MainActivity.java +++ b/app/src/main/java/com/example/agvcontroller/MainActivity.java @@ -15,19 +15,16 @@ import android.view.View; import android.widget.Button; -import com.example.agvcontroller.protocol2.AgvPackage; +import com.example.agvcontroller.protocol.AgvAction; +import com.example.agvcontroller.protocol.ForceSwitchAction; import com.example.agvcontroller.protocol2.PackagePart; import com.example.agvcontroller.socket.NettyServerHandler; import com.example.agvcontroller.socket.SocketManager; -import com.example.agvcontroller.socket.SocketTask; +import com.example.agvcontroller.utils.SnowflakeIdWorker; import java.net.Socket; -import java.util.Arrays; import java.util.List; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.util.CharsetUtil; public class MainActivity extends AppCompatActivity { @@ -37,18 +34,27 @@ private Vibrator vibrator; private Button vibrateButton; private Socket socket; + SocketManager socketManager; private boolean isDowm = false; private Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { - // 鍦ㄨ繖閲岃繘琛屾墦鍗拌緭鍑� - System.out.println("鎵撳嵃杈撳嚭"); + String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,3); + + AgvAction agvAction = new AgvAction<>(ForceSwitchAction.class) + .setAgvNo("1") + .setSerialNo(substring) + .setVal(1) + .bodySync((action) -> action.setPwd((short) 21)); + + if (isDowm) { - byte[] message2 = new byte[]{0x01, 0x02, 0x03, 0x06}; // 绀轰緥娑堟伅 - nettyServerHandler.sendMessageToClient(clientId, message2); // 鍙戦�佹秷鎭埌瀹㈡埛绔� - handler.sendEmptyMessageDelayed(0, 100); + System.out.println(agvAction); +// byte[] message2 = new byte[]{0x01, 0x02, 0x03, 0x06}; // 绀轰緥娑堟伅 + nettyServerHandler.sendMessageToClient(clientId, agvAction); // 鍙戦�佹秷鎭埌瀹㈡埛绔� +// handler.sendEmptyMessageDelayed(0, 100); } return false; } -- Gitblit v1.9.1