List of usage examples for io.netty.buffer ByteBuf readUnsignedMedium
public abstract int readUnsignedMedium();
From source file:org.traccar.protocol.PricolProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; buf.readUnsignedByte(); // header DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, buf.readSlice(7).toString(StandardCharsets.US_ASCII)); if (deviceSession == null) { return null; }//from w w w. j a va 2 s . c om Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.set("eventType", buf.readUnsignedByte()); position.set("packetVersion", buf.readUnsignedByte()); position.set(Position.KEY_STATUS, buf.readUnsignedByte()); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); position.set(Position.KEY_GPS, buf.readUnsignedByte()); position.setTime(new DateBuilder() .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate()); position.setValid(true); double lat = buf.getUnsignedShort(buf.readerIndex()) / 100; lat += (buf.readUnsignedShort() % 100 * 10000 + buf.readUnsignedShort()) / 600000.0; position.setLatitude(buf.readUnsignedByte() == 'S' ? -lat : lat); double lon = buf.getUnsignedMedium(buf.readerIndex()) / 100; lon += (buf.readUnsignedMedium() % 100 * 10000 + buf.readUnsignedShort()) / 600000.0; position.setLongitude(buf.readUnsignedByte() == 'W' ? -lon : lon); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.set(Position.KEY_INPUT, buf.readUnsignedShort()); position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); position.set("analogAlerts", buf.readUnsignedByte()); position.set("customAlertTypes", buf.readUnsignedShort()); for (int i = 1; i <= 5; i++) { position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort()); } position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium()); position.set(Position.KEY_RPM, buf.readUnsignedShort()); if (channel != null) { channel.writeAndFlush( new NetworkMessage(Unpooled.copiedBuffer("ACK", StandardCharsets.US_ASCII), remoteAddress)); } return position; }
From source file:org.traccar.protocol.TytanProtocolDecoder.java
License:Apache License
private void decodeExtraData(Position position, ByteBuf buf, int end) { while (buf.readerIndex() < end) { int type = buf.readUnsignedByte(); int length = buf.readUnsignedByte(); if (length == 255) { length += buf.readUnsignedByte(); }// ww w . ja v a 2s . c o m int n; switch (type) { case 2: position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedMedium()); break; case 5: position.set(Position.KEY_INPUT, buf.readUnsignedByte()); break; case 6: n = buf.readUnsignedByte() >> 4; if (n < 2) { position.set(Position.PREFIX_ADC + n, buf.readFloat()); } else { position.set("di" + (n - 2), buf.readFloat()); } break; case 7: int alarm = buf.readUnsignedByte(); buf.readUnsignedByte(); if (BitUtil.check(alarm, 5)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } break; case 8: position.set("antihijack", buf.readUnsignedByte()); break; case 9: position.set("unauthorized", ByteBufUtil.hexDump(buf.readSlice(8))); break; case 10: position.set("authorized", ByteBufUtil.hexDump(buf.readSlice(8))); break; case 24: for (int i = 0; i < length / 2; i++) { position.set(Position.PREFIX_TEMP + buf.readUnsignedByte(), buf.readByte()); } break; case 28: position.set(Position.KEY_AXLE_WEIGHT, buf.readUnsignedShort()); buf.readUnsignedByte(); break; case 90: position.set(Position.KEY_POWER, buf.readFloat()); break; case 101: position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); break; case 102: position.set(Position.KEY_RPM, buf.readUnsignedByte() * 50); break; case 107: int fuel = buf.readUnsignedShort(); int fuelFormat = fuel >> 14; if (fuelFormat == 1) { position.set("fuelValue", (fuel & 0x3fff) * 0.4 + "%"); } else if (fuelFormat == 2) { position.set("fuelValue", (fuel & 0x3fff) * 0.5 + " l"); } else if (fuelFormat == 3) { position.set("fuelValue", (fuel & 0x3fff) * -0.5 + " l"); } break; case 108: position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); break; case 150: position.set(Position.KEY_DOOR, buf.readUnsignedByte()); break; default: buf.skipBytes(length); break; } } }
From source file:org.traccar.protocol.TytanProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; buf.readUnsignedByte(); // protocol buf.readUnsignedShort(); // length int index = buf.readUnsignedByte() >> 3; if (channel != null) { ByteBuf response = Unpooled.copiedBuffer("^" + index, StandardCharsets.US_ASCII); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); }/* ww w . ja v a 2 s . c o m*/ String id = String.valueOf(buf.readUnsignedInt()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; } List<Position> positions = new LinkedList<>(); while (buf.readableBytes() > 2) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); int end = buf.readerIndex() + buf.readUnsignedByte(); position.setTime(new Date(buf.readUnsignedInt() * 1000)); int flags = buf.readUnsignedByte(); position.set(Position.KEY_SATELLITES, BitUtil.from(flags, 2)); position.setValid(BitUtil.to(flags, 2) > 0); // Latitude double lat = buf.readUnsignedMedium(); lat = lat * -180 / 16777216 + 90; position.setLatitude(lat); // Longitude double lon = buf.readUnsignedMedium(); lon = lon * 360 / 16777216 - 180; position.setLongitude(lon); // Status flags = buf.readUnsignedByte(); position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0)); position.set(Position.KEY_RSSI, BitUtil.between(flags, 2, 5)); position.setCourse((BitUtil.from(flags, 5) * 45 + 180) % 360); // Speed int speed = buf.readUnsignedByte(); if (speed < 250) { position.setSpeed(UnitsConverter.knotsFromKph(speed)); } decodeExtraData(position, buf, end); positions.add(position); } return positions; }
From source file:org.traccar.protocol.TzoneProtocolDecoder.java
License:Apache License
private boolean decodeGps(Position position, ByteBuf buf, int hardware) { int blockLength = buf.readUnsignedShort(); int blockEnd = buf.readerIndex() + blockLength; if (blockLength < 22) { return false; }/*from w w w. jav a2 s. co m*/ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); double lat; double lon; if (hardware == 0x10A || hardware == 0x10B) { lat = buf.readUnsignedInt() / 600000.0; lon = buf.readUnsignedInt() / 600000.0; } else { lat = buf.readUnsignedInt() / 100000.0 / 60.0; lon = buf.readUnsignedInt() / 100000.0 / 60.0; } position.setFixTime( new DateBuilder().setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate()); position.setSpeed(buf.readUnsignedShort() * 0.01); position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium()); int flags = buf.readUnsignedShort(); position.setCourse(BitUtil.to(flags, 9)); if (!BitUtil.check(flags, 10)) { lat = -lat; } position.setLatitude(lat); if (BitUtil.check(flags, 9)) { lon = -lon; } position.setLongitude(lon); position.setValid(BitUtil.check(flags, 11)); buf.readerIndex(blockEnd); return true; }
From source file:org.traccar.protocol.TzoneProtocolDecoder.java
License:Apache License
private void decodePassengers(Position position, ByteBuf buf) { int blockLength = buf.readUnsignedShort(); int blockEnd = buf.readerIndex() + blockLength; if (blockLength > 0) { position.set("passengersOn", buf.readUnsignedMedium()); position.set("passengersOff", buf.readUnsignedMedium()); }/*w w w . j av a 2 s . co m*/ buf.readerIndex(blockEnd); }
From source file:org.virtue.network.protocol.ondemand.OnDemandDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception { if (buf.readableBytes() < 6) { return;/*from www . j ava 2 s . c o m*/ } int opcode = buf.readUnsignedByte(); if (opcode == 0 || opcode == 1) {// file priority request || normal request out.add(new OnDemandRequestMessage(opcode == 1, buf.readUnsignedByte(), buf.readInt())); } else if (opcode == 2 || opcode == 3) {// client logged in || logged out out.add(new OnDemandStateMessage(opcode == 2, (buf.readUnsignedByte() | buf.readInt()))); } else if (opcode == 4) {// encryption change out.add(new OnDemandEncryptionMessage(buf.readUnsignedByte(), buf.readInt())); } else if (opcode == 6) {// init connection out.add(new OnDemandInitMessage(buf.readUnsignedMedium(), buf.readShort())); } else if (opcode == 7) {// drop requests queue out.add(new OnDemandDropMessage(buf.readUnsignedByte() | buf.readInt())); } }
From source file:sas.systems.imflux.packet.rtcp.ReceptionReport.java
License:Apache License
public static ReceptionReport decode(ByteBuf buffer) { ReceptionReport block = new ReceptionReport(); block.setSsrc(buffer.readUnsignedInt()); block.setFractionLost(buffer.readUnsignedByte()); block.setCumulativeNumberOfPacketsLost(buffer.readUnsignedMedium()); block.setExtendedHighestSequenceNumberReceived(buffer.readUnsignedInt()); block.setInterArrivalJitter(buffer.readUnsignedInt()); block.setLastSenderReport(buffer.readUnsignedInt()); block.setDelaySinceLastSenderReport(buffer.readUnsignedInt()); return block; }