| | |
| | | package com.example.agvcontroller.protocol; |
| | | |
| | | import com.example.agvcontroller.socket.RadixTools; |
| | | |
| | | import java.util.logging.Logger; |
| | | |
| | | import io.netty.buffer.ByteBuf; |
| | |
| | | } else if (obj instanceof byte[]){ |
| | | out.writeBytes((byte[]) obj); |
| | | |
| | | |
| | | } else if (obj instanceof AgvAction<?>){ |
| | | |
| | | |
| | | AgvAction action = (AgvAction)obj; |
| | | |
| | | String uniqueNo = action.getAgvNo(); |
| | | |
| | | byte[] uniqueNoBytes = RadixTools.intToBytes(Integer.parseInt(uniqueNo)); // uniqueno |
| | | |
| | | byte[] bodyBytes = action.writeToBytes(); |
| | | |
| | | |
| | | int len = PackagePart.UNIQUENO.getLen() // len |
| | | + PackagePart.TIMESTAMP.getLen() |
| | | + PackagePart.COMMAND_MARK.getLen() |
| | | + bodyBytes.length; |
| | | |
| | | out.writeByte((byte)0xEE) // symbol |
| | | .writeShortLE(len) |
| | | .writeBytes(Utils.reverse(uniqueNoBytes)) // uniqueno |
| | | .writeIntLE((int) (System.currentTimeMillis() / 1000)) // timestamp |
| | | .writeByte(ProtocolPojoType.ACTION_COMMAND.protocolType.getCode()) // type |
| | | .writeBytes(bodyBytes) // body |
| | | .writeShort((short)0) // valid |
| | | ; |
| | | |
| | | int validCode = ValidUtil.calculateValidByteFromBuff(out); |
| | | out.resetReaderIndex(); |
| | | |
| | | out.writerIndex(out.readableBytes() - 2); |
| | | out.writeShortLE(validCode); |
| | | |
| | | } else if (obj instanceof AgvPackage){ |
| | | |
| | | AgvPackage pac = (AgvPackage)obj; |
| | |
| | | |
| | | //String uniqueNo = pac.getHeader().getUniqueNo(); |
| | | |
| | | //byte[] uniquenoBytes = RadixTools.intToBytes(Integer.parseInt(pac.getHeader().getUniqueNo())); // uniqueno |
| | | //byte[] uniquenoBytes = RadixTools.intToBytes(Integer.parseInt(pac.getHeader().getUniqueNo())); // uniqueno |
| | | |
| | | |
| | | int len = PackagePart.UNIQUENO.getLen() // len |
| | |
| | | + PackagePart.COMMAND_MARK.getLen() |
| | | + bodyBytes.length; |
| | | |
| | | //out.writeByte(pac.getHeader().getStartSymbol()) // symbol |
| | | // .writeShortLE(len) |
| | | // .writeBytes(Utils.reverse(uniquenoBytes)) // uniqueno |
| | | // .writeIntLE((int) (System.currentTimeMillis() / 1000)) // timestamp |
| | | // .writeByte(pac.getHeader().getProtocolType().getCode()) // type |
| | | // .writeBytes(bodyBytes) // body |
| | | // .writeShort(pac.getValidCode()) // valid |
| | | //; |
| | | out.writeByte(pac.getHeader().getStartSymbol()) // symbol |
| | | .writeShortLE(len) |
| | | //.writeBytes(Utils.reverse(uniquenoBytes)) // uniqueno |
| | | .writeIntLE((int) (System.currentTimeMillis() / 1000)) // timestamp |
| | | .writeByte(pac.getHeader().getProtocolType().getCode()) // type |
| | | .writeBytes(bodyBytes) // body |
| | | .writeShort(pac.getValidCode()) // valid |
| | | ; |
| | | |
| | | pac.setValidCode(ValidUtil.calculateValidByteFromBuff(out)); |
| | | out.resetReaderIndex(); |