#
whycq
2025-02-06 318bd727e2fe02e4f541dfe943f77606af41d509
#
6个文件已修改
145 ■■■■ 已修改文件
app/src/main/AndroidManifest.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/AGVCar.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/MainActivity.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/protocol/AGV_12_UP.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/protocol/AGV_13_UP.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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"
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;
    }
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() + "%");
    }
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;
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
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;