List of usage examples for io.netty.buffer ByteBuf readShortLE
public abstract short readShortLE();
From source file:org.traccar.protocol.Gps056ProtocolDecoder.java
License:Apache License
private static void decodeStatus(ByteBuf buf, Position position) { position.set(Position.KEY_INPUT, buf.readUnsignedByte()); position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); position.set(Position.PREFIX_ADC + 1, buf.readShortLE() * 5.06); // mV position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); }
From source file:org.traccar.protocol.GranitProtocolDecoder.java
License:Apache License
private void decodeStructure(ByteBuf buf, Position position) { short flags = buf.readUnsignedByte(); position.setValid(BitUtil.check(flags, 7)); if (BitUtil.check(flags, 1)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); }//ww w . jav a2 s. c om short satDel = buf.readUnsignedByte(); position.set(Position.KEY_SATELLITES, BitUtil.from(satDel, 4)); int pdop = BitUtil.to(satDel, 4); position.set(Position.KEY_PDOP, pdop); int lonDegrees = buf.readUnsignedByte(); int latDegrees = buf.readUnsignedByte(); int lonMinutes = buf.readUnsignedShortLE(); int latMinutes = buf.readUnsignedShortLE(); double latitude = latDegrees + latMinutes / 60000.0; double longitude = lonDegrees + lonMinutes / 60000.0; if (position.getValid()) { if (!BitUtil.check(flags, 4)) { latitude = -latitude; } if (!BitUtil.check(flags, 5)) { longitude = -longitude; } } position.setLongitude(longitude); position.setLatitude(latitude); position.setSpeed(buf.readUnsignedByte()); int course = buf.readUnsignedByte(); if (BitUtil.check(flags, 6)) { course = course | 0x100; } position.setCourse(course); position.set(Position.KEY_DISTANCE, buf.readShortLE()); int analogIn1 = buf.readUnsignedByte(); int analogIn2 = buf.readUnsignedByte(); int analogIn3 = buf.readUnsignedByte(); int analogIn4 = buf.readUnsignedByte(); int analogInHi = buf.readUnsignedByte(); analogIn1 = analogInHi << 8 & 0x300 | analogIn1; analogIn2 = analogInHi << 6 & 0x300 | analogIn2; analogIn3 = analogInHi << 4 & 0x300 | analogIn3; analogIn4 = analogInHi << 2 & 0x300 | analogIn4; position.set(Position.PREFIX_ADC + 1, analogIn1 * adc1Ratio); position.set(Position.PREFIX_ADC + 2, analogIn2 * adc2Ratio); position.set(Position.PREFIX_ADC + 3, analogIn3 * adc3Ratio); position.set(Position.PREFIX_ADC + 4, analogIn4 * adc4Ratio); position.setAltitude(buf.readUnsignedByte() * 10); int output = buf.readUnsignedByte(); for (int i = 0; i < 8; i++) { position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(output, i)); } buf.readUnsignedByte(); // status message buffer }
From source file:org.traccar.protocol.MeitrackProtocolDecoder.java
License:Apache License
private List<Position> decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { List<Position> positions = new LinkedList<>(); buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',') + 1); String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII); buf.skipBytes(1 + 3 + 1);// w w w .j av a 2 s . c om DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; } buf.readUnsignedIntLE(); // remaining cache int count = buf.readUnsignedShortLE(); for (int i = 0; i < count; i++) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); buf.readUnsignedShortLE(); // length buf.readUnsignedShortLE(); // index int paramCount = buf.readUnsignedByte(); for (int j = 0; j < paramCount; j++) { int id = buf.readUnsignedByte(); switch (id) { case 0x01: position.set(Position.KEY_EVENT, buf.readUnsignedByte()); break; case 0x05: position.setValid(buf.readUnsignedByte() > 0); break; case 0x06: position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); break; case 0x07: position.set(Position.KEY_RSSI, buf.readUnsignedByte()); break; default: buf.readUnsignedByte(); break; } } paramCount = buf.readUnsignedByte(); for (int j = 0; j < paramCount; j++) { int id = buf.readUnsignedByte(); switch (id) { case 0x08: position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); break; case 0x09: position.setCourse(buf.readUnsignedShortLE()); break; case 0x0B: position.setAltitude(buf.readShortLE()); break; case 0x19: position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01); break; case 0x1A: position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01); break; default: buf.readUnsignedShortLE(); break; } } paramCount = buf.readUnsignedByte(); for (int j = 0; j < paramCount; j++) { int id = buf.readUnsignedByte(); switch (id) { case 0x02: position.setLatitude(buf.readIntLE() * 0.000001); break; case 0x03: position.setLongitude(buf.readIntLE() * 0.000001); break; case 0x04: position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 2000-01-01 break; case 0x0D: position.set("runtime", buf.readUnsignedIntLE()); break; default: buf.readUnsignedIntLE(); break; } } paramCount = buf.readUnsignedByte(); for (int j = 0; j < paramCount; j++) { buf.readUnsignedByte(); // id buf.skipBytes(buf.readUnsignedByte()); // value } positions.add(position); } return positions; }
From source file:org.traccar.protocol.NavisProtocolDecoder.java
License:Apache License
private Position parseNtcbPosition(DeviceSession deviceSession, ByteBuf buf) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); int format;//from w w w.j ava 2s .c o m if (buf.getUnsignedByte(buf.readerIndex()) == 0) { format = buf.readUnsignedShortLE(); } else { format = buf.readUnsignedByte(); } position.set("format", format); position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); position.set(Position.KEY_EVENT, buf.readUnsignedShortLE()); buf.skipBytes(6); // event time short armedStatus = buf.readUnsignedByte(); if (isFormat(format, F10, F20, F30, F40, F50, F51, F52)) { position.set(Position.KEY_ARMED, BitUtil.to(armedStatus, 7)); if (BitUtil.check(armedStatus, 7)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } } else if (isFormat(format, F60)) { position.set(Position.KEY_ARMED, BitUtil.check(armedStatus, 0)); if (BitUtil.check(armedStatus, 1)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } } position.set(Position.KEY_STATUS, buf.readUnsignedByte()); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); if (isFormat(format, F10, F20, F30)) { int output = buf.readUnsignedShortLE(); position.set(Position.KEY_OUTPUT, output); for (int i = 0; i < 16; i++) { position.set(Position.PREFIX_OUT + (i + 1), BitUtil.check(output, i)); } } else if (isFormat(format, F50, F51, F52)) { short extField = buf.readUnsignedByte(); position.set(Position.KEY_OUTPUT, BitUtil.to(extField, 2)); position.set(Position.PREFIX_OUT + 1, BitUtil.check(extField, 0)); position.set(Position.PREFIX_OUT + 2, BitUtil.check(extField, 1)); position.set(Position.KEY_SATELLITES, BitUtil.from(extField, 2)); } else if (isFormat(format, F40, F60)) { short output = buf.readUnsignedByte(); position.set(Position.KEY_OUTPUT, BitUtil.to(output, 4)); for (int i = 0; i < 4; i++) { position.set(Position.PREFIX_OUT + (i + 1), BitUtil.check(output, i)); } } if (isFormat(format, F10, F20, F30, F40)) { int input = buf.readUnsignedShortLE(); position.set(Position.KEY_INPUT, input); if (!isFormat(format, F40)) { for (int i = 0; i < 16; i++) { position.set(Position.PREFIX_IN + (i + 1), BitUtil.check(input, i)); } } else { position.set(Position.PREFIX_IN + 1, BitUtil.check(input, 0)); position.set(Position.PREFIX_IN + 2, BitUtil.check(input, 1)); position.set(Position.PREFIX_IN + 3, BitUtil.check(input, 2)); position.set(Position.PREFIX_IN + 4, BitUtil.check(input, 3)); position.set(Position.PREFIX_IN + 5, BitUtil.between(input, 4, 7)); position.set(Position.PREFIX_IN + 6, BitUtil.between(input, 7, 10)); position.set(Position.PREFIX_IN + 7, BitUtil.between(input, 10, 12)); position.set(Position.PREFIX_IN + 8, BitUtil.between(input, 12, 14)); } } else if (isFormat(format, F50, F51, F52, F60)) { short input = buf.readUnsignedByte(); position.set(Position.KEY_INPUT, input); for (int i = 0; i < 8; i++) { position.set(Position.PREFIX_IN + (i + 1), BitUtil.check(input, i)); } } position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001); position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); if (isFormat(format, F10, F20, F30)) { position.set(Position.PREFIX_TEMP + 1, buf.readShortLE()); } if (isFormat(format, F10, F20, F50, F51, F52, F60)) { position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE()); } if (isFormat(format, F60)) { position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShortLE()); } // Impulse counters if (isFormat(format, F20, F50, F51, F52, F60)) { buf.readUnsignedIntLE(); buf.readUnsignedIntLE(); } if (isFormat(format, F60)) { // Fuel buf.readUnsignedShortLE(); buf.readUnsignedShortLE(); buf.readByte(); buf.readShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); position.set(Position.PREFIX_TEMP + 1, buf.readByte()); position.set(Position.PREFIX_TEMP + 2, buf.readByte()); position.set(Position.PREFIX_TEMP + 3, buf.readByte()); position.set(Position.PREFIX_TEMP + 4, buf.readByte()); position.set(Position.KEY_AXLE_WEIGHT, buf.readIntLE()); position.set(Position.KEY_RPM, buf.readUnsignedShortLE()); } if (isFormat(format, F20, F50, F51, F52, F60)) { int navSensorState = buf.readUnsignedByte(); position.setValid(BitUtil.check(navSensorState, 1)); if (isFormat(format, F60)) { position.set(Position.KEY_SATELLITES, BitUtil.from(navSensorState, 2)); } DateBuilder dateBuilder = new DateBuilder() .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte() + 1, buf.readUnsignedByte()); position.setTime(dateBuilder.getDate()); if (isFormat(format, F60)) { position.setLatitude(buf.readIntLE() / 600000.0); position.setLongitude(buf.readIntLE() / 600000.0); position.setAltitude(buf.readIntLE() * 0.1); } else { position.setLatitude(buf.readFloatLE() / Math.PI * 180); position.setLongitude(buf.readFloatLE() / Math.PI * 180); } position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE())); position.setCourse(buf.readUnsignedShortLE()); position.set(Position.KEY_ODOMETER, buf.readFloatLE() * 1000); position.set(Position.KEY_DISTANCE, buf.readFloatLE() * 1000); // Segment times buf.readUnsignedShortLE(); buf.readUnsignedShortLE(); } // Other if (isFormat(format, F51, F52)) { buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); buf.readUnsignedShortLE(); buf.readByte(); buf.readUnsignedShortLE(); } // Four temperature sensors if (isFormat(format, F40, F52)) { position.set(Position.PREFIX_TEMP + 1, buf.readByte()); position.set(Position.PREFIX_TEMP + 2, buf.readByte()); position.set(Position.PREFIX_TEMP + 3, buf.readByte()); position.set(Position.PREFIX_TEMP + 4, buf.readByte()); } return position; }
From source file:org.traccar.protocol.NoranProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; buf.readUnsignedShortLE(); // length int type = buf.readUnsignedShortLE(); if (type == MSG_SHAKE_HAND && channel != null) { ByteBuf response = Unpooled.buffer(13); response.writeCharSequence("\r\n*KW", StandardCharsets.US_ASCII); response.writeByte(0);/*from w w w. j a va 2s. com*/ response.writeShortLE(response.capacity()); response.writeShortLE(MSG_SHAKE_HAND_RESPONSE); response.writeByte(1); // status response.writeCharSequence("\r\n", StandardCharsets.US_ASCII); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } else if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW || type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) { boolean newFormat = false; if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48 || type == MSG_ALARM && buf.readableBytes() == 48 || type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57) { newFormat = true; } Position position = new Position(getProtocolName()); if (type == MSG_CONTROL_RESPONSE) { buf.readUnsignedIntLE(); // GIS ip buf.readUnsignedIntLE(); // GIS port } position.setValid(BitUtil.check(buf.readUnsignedByte(), 0)); short alarm = buf.readUnsignedByte(); switch (alarm) { case 1: position.set(Position.KEY_ALARM, Position.ALARM_SOS); break; case 2: position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); break; case 3: position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); break; case 9: position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); break; default: break; } if (newFormat) { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedIntLE())); position.setCourse(buf.readFloatLE()); } else { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedShortLE()); } position.setLongitude(buf.readFloatLE()); position.setLatitude(buf.readFloatLE()); if (!newFormat) { long timeValue = buf.readUnsignedIntLE(); DateBuilder dateBuilder = new DateBuilder().setYear((int) BitUtil.from(timeValue, 26)) .setMonth((int) BitUtil.between(timeValue, 22, 26)) .setDay((int) BitUtil.between(timeValue, 17, 22)) .setHour((int) BitUtil.between(timeValue, 12, 17)) .setMinute((int) BitUtil.between(timeValue, 6, 12)) .setSecond((int) BitUtil.to(timeValue, 6)); position.setTime(dateBuilder.getDate()); } ByteBuf rawId; if (newFormat) { rawId = buf.readSlice(12); } else { rawId = buf.readSlice(11); } String id = rawId.toString(StandardCharsets.US_ASCII).replaceAll("[^\\p{Print}]", ""); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; } position.setDeviceId(deviceSession.getDeviceId()); if (newFormat) { DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); position.setTime(dateFormat.parse(buf.readSlice(17).toString(StandardCharsets.US_ASCII))); buf.readByte(); } if (!newFormat) { position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); } else if (type == MSG_UPLOAD_POSITION_NEW) { position.set(Position.PREFIX_TEMP + 1, buf.readShortLE()); position.set(Position.KEY_ODOMETER, buf.readFloatLE()); } return position; } return null; }
From source file:org.traccar.protocol.NyitechProtocolDecoder.java
License:Apache License
private void decodeLocation(Position position, ByteBuf buf) { DateBuilder dateBuilder = new DateBuilder() .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); position.setTime(dateBuilder.getDate()); int flags = buf.readUnsignedByte(); position.setValid(BitUtil.to(flags, 2) > 0); double lat = buf.readUnsignedIntLE() / 3600000.0; double lon = buf.readUnsignedIntLE() / 3600000.0; position.setLatitude(BitUtil.check(flags, 2) ? lat : -lat); position.setLongitude(BitUtil.check(flags, 3) ? lon : -lon); position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE())); position.setCourse(buf.readUnsignedShortLE() * 0.1); position.setAltitude(buf.readShortLE() * 0.1); }
From source file:org.traccar.protocol.NyitechProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; buf.skipBytes(2); // header buf.readUnsignedShortLE(); // length String id = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString(); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; }/* ww w. j a va2s . c o m*/ int type = buf.readUnsignedShortLE(); if (type != MSG_LOGIN && type != MSG_COMPREHENSIVE_LIVE && type != MSG_COMPREHENSIVE_HISTORY && type != MSG_ALARM && type != MSG_FIXED) { return null; } Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); if (type == MSG_COMPREHENSIVE_LIVE || type == MSG_COMPREHENSIVE_HISTORY) { buf.skipBytes(6); // time boolean includeLocation = buf.readUnsignedByte() > 0; boolean includeObd = buf.readUnsignedByte() > 0; buf.readUnsignedByte(); // include sensor if (includeLocation) { decodeLocation(position, buf); } else { getLastLocation(position, null); } if (includeObd) { int count = buf.readUnsignedByte(); for (int i = 0; i < count; i++) { int pid = buf.readUnsignedShortLE(); int length = buf.readUnsignedByte(); switch (length) { case 1: position.add(ObdDecoder.decodeData(pid, buf.readByte(), true)); break; case 2: position.add(ObdDecoder.decodeData(pid, buf.readShortLE(), true)); break; case 4: position.add(ObdDecoder.decodeData(pid, buf.readIntLE(), true)); break; default: buf.skipBytes(length); break; } } } position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01); position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt()); } else if (type == MSG_ALARM) { buf.readUnsignedShortLE(); // random number buf.readUnsignedByte(); // tag position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); buf.readUnsignedShortLE(); // threshold buf.readUnsignedShortLE(); // value buf.skipBytes(6); // time decodeLocation(position, buf); } else if (type == MSG_FIXED) { buf.skipBytes(6); // time decodeLocation(position, buf); } else { decodeLocation(position, buf); } return position; }
From source file:org.traccar.protocol.OrionProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; buf.skipBytes(2); // header int type = buf.readUnsignedByte() & 0x0f; if (type == MSG_USERLOG) { int header = buf.readUnsignedByte(); if ((header & 0x40) != 0) { sendResponse(channel, buf);// w w w . j ava2 s . c om } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedInt())); if (deviceSession == null) { return null; } List<Position> positions = new LinkedList<>(); for (int i = 0; i < (header & 0x0f); i++) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_EVENT, buf.readUnsignedByte()); buf.readUnsignedByte(); // length position.set(Position.KEY_FLAGS, buf.readUnsignedShortLE()); position.setLatitude(convertCoordinate(buf.readIntLE())); position.setLongitude(convertCoordinate(buf.readIntLE())); position.setAltitude(buf.readShortLE() / 10.0); position.setCourse(buf.readUnsignedShortLE()); position.setSpeed(buf.readUnsignedShortLE() * 0.0539957); DateBuilder dateBuilder = new DateBuilder() .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); position.setTime(dateBuilder.getDate()); int satellites = buf.readUnsignedByte(); position.setValid(satellites >= 3); position.set(Position.KEY_SATELLITES, satellites); positions.add(position); } return positions; } return null; }
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; 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; }/* w w w.jav a 2s . c o m*/ 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; }
From source file:org.traccar.protocol.TzoneProtocolDecoder.java
License:Apache License
private void decodeTags(Position position, ByteBuf buf) { int blockLength = buf.readUnsignedShort(); int blockEnd = buf.readerIndex() + blockLength; if (blockLength > 0) { buf.readUnsignedByte(); // tag type int count = buf.readUnsignedByte(); int tagLength = buf.readUnsignedByte(); for (int i = 1; i <= count; i++) { int tagEnd = buf.readerIndex() + tagLength; buf.readUnsignedByte(); // status buf.readUnsignedShortLE(); // battery voltage position.set(Position.PREFIX_TEMP + i, (buf.readShortLE() & 0x3fff) * 0.1); buf.readUnsignedByte(); // humidity buf.readUnsignedByte(); // rssi buf.readerIndex(tagEnd);/* w ww . j a v a 2 s. c o m*/ } } buf.readerIndex(blockEnd); }