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) { //地面码ID 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 ""; } //地面码ID private String qrCode; //当前状态 private int status; //直行方向坐标-单位:mm 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; }