List of usage examples for io.netty.buffer ByteBuf writeIntLE
public abstract ByteBuf writeIntLE(int value);
From source file:org.traccar.protocol.ProgressProtocolDecoder.java
License:Apache License
private void requestArchive(Channel channel) { if (lastIndex == 0) { lastIndex = newIndex;/* w w w .j av a 2s.co m*/ } else if (newIndex > lastIndex) { ByteBuf request = Unpooled.buffer(12); request.writeShortLE(MSG_LOG_SYNC); request.writeShortLE(4); request.writeIntLE((int) lastIndex); request.writeIntLE(0); channel.writeAndFlush(new NetworkMessage(request, channel.remoteAddress())); } }
From source file:org.traccar.protocol.SanulProtocolDecoder.java
License:Apache License
private void sendResponse(Channel channel, int type) { if (channel != null) { ByteBuf response = Unpooled.buffer(); response.writeByte(0xaa); // header response.writeShortLE(0x85da); // reserved response.writeShortLE(15); // length response.writeByte(1); // edition response.writeShortLE(MSG_RESPONSE); response.writeShortLE(type);/*from w w w . ja va2 s . c om*/ response.writeIntLE(0); // command id response.writeByte(0); // status response.writeByte(0); // result length response.writeIntLE(0x20000); // result data ? channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); } }
From source file:org.traccar.protocol.SatsolProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg;/*from w w w. ja va 2 s .c o m*/ buf.readUnsignedShortLE(); // checksum buf.readUnsignedShortLE(); // preamble long id = buf.readUnsignedIntLE(); buf.readUnsignedShortLE(); // length DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id)); if (deviceSession == null) { return null; } List<Position> positions = new LinkedList<>(); while (buf.isReadable()) { buf.readUnsignedShortLE(); // checksum buf.readUnsignedShortLE(); // checksum buf.readUnsignedShortLE(); // type int length = buf.readUnsignedShortLE(); Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); position.setLatitude(buf.readUnsignedIntLE() * 0.000001); position.setLongitude(buf.readUnsignedIntLE() * 0.000001); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE() * 0.01)); position.setAltitude(buf.readShortLE()); position.setCourse(buf.readUnsignedShortLE()); position.setValid(buf.readUnsignedByte() > 0); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_EVENT, buf.readUnsignedByte()); if (BitUtil.check(buf.readUnsignedByte(), 0)) { position.set(Position.KEY_ARCHIVE, true); } positions.add(position); buf.skipBytes(length); } if (channel != null) { ByteBuf response = Unpooled.buffer(); response.writeShortLE(0); response.writeShortLE(0x4CBF); // preamble response.writeIntLE((int) id); response.writeShortLE(0); response.setShortLE(0, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, response.nioBuffer(2, response.readableBytes() - 2))); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return positions; }