#
whycq
2025-02-06 17bb52d9337328323f5f8d2a806cf4f445673b4a
app/src/main/java/com/example/agvcontroller/socket/NettyServerHandler.java
@@ -2,6 +2,8 @@
import static com.example.agvcontroller.utils.DateUtils.formatDate;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
@@ -13,6 +15,7 @@
import android.os.Message;
import android.util.Log;
import com.example.agvcontroller.AGVApplication;
import com.example.agvcontroller.AGVCar;
import com.example.agvcontroller.MainActivity;
import com.example.agvcontroller.action.AGV_11_UP;
@@ -26,11 +29,13 @@
import com.example.agvcontroller.protocol.AgvAction;
import com.example.agvcontroller.protocol.AgvPackage;
import com.example.agvcontroller.protocol.ProtocolType;
import com.example.agvcontroller.utils.DateUtils;
import org.greenrobot.eventbus.EventBus;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -162,11 +167,20 @@
                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.d("updown", log);
                    AGVApplication.addLog(log);
//                    EventBus.getDefault().post(log);
                    ctx.writeAndFlush(ackPac);
                }
                final int battery = agv_f0_up.getBattery();
//                pac.getBody().getMessageBody()
                agvNo = pac.getHeader().getUniqueNo();
                channelMap.put(clientId, ctx.channel());
                EventBus.getDefault().post(new AGVCar(clientId,ip,port,agvNo,1));
                 AGVCar agvCar = new AGVCar(clientId, ip, port, agvNo, 1, battery,0,0,0,0,0,0,0,0,0,0);
                EventBus.getDefault().post(agvCar);
                break label;
        }
@@ -180,6 +194,7 @@
        }
        return sb.toString();
    }
    // 将十六进制字符串转换为字节数组
    private byte[] hexStringToByteArray(String s) {
        int len = s.length();