| | |
| | | |
| | | |
| | | |
| | | import static com.example.agvcontroller.utils.DateUtils.formatDate; |
| | | |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.ByteBufUtil; |
| | | import io.netty.buffer.Unpooled; |
| | |
| | | import android.os.Message; |
| | | import android.util.Log; |
| | | |
| | | import com.example.agvcontroller.Item; |
| | | import com.example.agvcontroller.AGVApplication; |
| | | import com.example.agvcontroller.AGVCar; |
| | | import com.example.agvcontroller.MainActivity; |
| | | import com.example.agvcontroller.action.AGV_11_UP; |
| | | import com.example.agvcontroller.action.AckMsgBuilder; |
| | |
| | | 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; |
| | | 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; |
| | |
| | | String ip = remoteAddress.getAddress().getHostAddress(); |
| | | int port = remoteAddress.getPort(); |
| | | channelMap.put(clientId, ctx.channel()); |
| | | EventBus.getDefault().post(new Item(clientId,ip,port,"--",0)); |
| | | EventBus.getDefault().post(new AGVCar(clientId,ip,port,"--",0)); |
| | | Log.d(TAG, "Client connected: " + clientId); |
| | | |
| | | // 取消延迟删除操作 |
| | |
| | | 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 Item(clientId,ip,port,agvNo,1)); |
| | | EventBus.getDefault().post(new AGVCar(clientId,ip,port,agvNo,1)); |
| | | 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,ip,port,agvNo,1)); |
| | | EventBus.getDefault().post(new AGVCar(clientId,ip,port,agvNo,1)); |
| | | 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.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 Item(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; |
| | | |
| | | } |
| | |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | // 将十六进制字符串转换为字节数组 |
| | | private byte[] hexStringToByteArray(String s) { |
| | | int len = s.length(); |