List of usage examples for io.netty.buffer ByteBuf readUnsignedIntLE
public abstract long readUnsignedIntLE();
From source file:org.traccar.protocol.DmtProtocolDecoder.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(); int length = buf.readUnsignedShortLE(); if (type == MSG_HELLO) { buf.readUnsignedIntLE(); // device serial number DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); ByteBuf response = Unpooled.buffer(); if (length == 51) { response.writeByte(0); // reserved response.writeIntLE(0); // reserved } else {// www .ja v a2s. c om response.writeIntLE((int) ((System.currentTimeMillis() - 1356998400000L) / 1000)); response.writeIntLE(deviceSession != null ? 0 : 1); // flags } sendResponse(channel, MSG_HELLO_RESPONSE, response); } else if (type == MSG_COMMIT) { ByteBuf response = Unpooled.buffer(0); response.writeByte(1); // flags (success) sendResponse(channel, MSG_COMMIT_RESPONSE, response); } else if (type == MSG_CANNED_REQUEST_1) { ByteBuf response = Unpooled.buffer(0); response.writeBytes(new byte[12]); sendResponse(channel, MSG_CANNED_RESPONSE_1, response); } else if (type == MSG_CANNED_REQUEST_2) { sendResponse(channel, MSG_CANNED_RESPONSE_2, null); } else if (type == MSG_DATA_RECORD_64) { return decodeFixed64(channel, remoteAddress, buf); } else if (type == MSG_DATA_RECORD) { return decodeStandard(channel, remoteAddress, buf); } return null; }
From source file:org.traccar.protocol.EgtsProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; int index = buf.getUnsignedShort(buf.readerIndex() + 5 + 2); buf.skipBytes(buf.getUnsignedByte(buf.readerIndex() + 3)); List<Position> positions = new LinkedList<>(); while (buf.readableBytes() > 2) { int length = buf.readUnsignedShortLE(); int recordIndex = buf.readUnsignedShortLE(); int recordFlags = buf.readUnsignedByte(); if (BitUtil.check(recordFlags, 0)) { buf.readUnsignedIntLE(); // object id }/*from ww w . j a v a 2 s. com*/ if (BitUtil.check(recordFlags, 1)) { buf.readUnsignedIntLE(); // event id } if (BitUtil.check(recordFlags, 2)) { buf.readUnsignedIntLE(); // time } int serviceType = buf.readUnsignedByte(); buf.readUnsignedByte(); // recipient service type int recordEnd = buf.readerIndex() + length; Position position = new Position(getProtocolName()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession != null) { position.setDeviceId(deviceSession.getDeviceId()); } ByteBuf response = Unpooled.buffer(); response.writeShortLE(recordIndex); response.writeByte(0); // success sendResponse(channel, PT_RESPONSE, index, serviceType, MSG_RECORD_RESPONSE, response); while (buf.readerIndex() < recordEnd) { int type = buf.readUnsignedByte(); int end = buf.readUnsignedShortLE() + buf.readerIndex(); if (type == MSG_TERM_IDENTITY) { buf.readUnsignedIntLE(); // object id int flags = buf.readUnsignedByte(); if (BitUtil.check(flags, 0)) { buf.readUnsignedShortLE(); // home dispatcher identifier } if (BitUtil.check(flags, 1)) { getDeviceSession(channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim()); } if (BitUtil.check(flags, 2)) { getDeviceSession(channel, remoteAddress, buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim()); } if (BitUtil.check(flags, 3)) { buf.skipBytes(3); // language identifier } if (BitUtil.check(flags, 5)) { buf.skipBytes(3); // network identifier } if (BitUtil.check(flags, 6)) { buf.readUnsignedShortLE(); // buffer size } if (BitUtil.check(flags, 7)) { getDeviceSession(channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim()); } response = Unpooled.buffer(); response.writeByte(0); // success sendResponse(channel, PT_APPDATA, 0, serviceType, MSG_RESULT_CODE, response); } else if (type == MSG_POS_DATA) { position.setTime(new Date((buf.readUnsignedIntLE() + 1262304000) * 1000)); // since 2010-01-01 position.setLatitude(buf.readUnsignedIntLE() * 90.0 / 0xFFFFFFFFL); position.setLongitude(buf.readUnsignedIntLE() * 180.0 / 0xFFFFFFFFL); int flags = buf.readUnsignedByte(); position.setValid(BitUtil.check(flags, 0)); if (BitUtil.check(flags, 5)) { position.setLatitude(-position.getLatitude()); } if (BitUtil.check(flags, 6)) { position.setLongitude(-position.getLongitude()); } int speed = buf.readUnsignedShortLE(); position.setSpeed(UnitsConverter.knotsFromKph(BitUtil.to(speed, 14) * 0.1)); position.setCourse(buf.readUnsignedByte() + (BitUtil.check(speed, 15) ? 0x100 : 0)); position.set(Position.KEY_ODOMETER, buf.readUnsignedMediumLE() * 100); position.set(Position.KEY_INPUT, buf.readUnsignedByte()); position.set(Position.KEY_EVENT, buf.readUnsignedByte()); if (BitUtil.check(flags, 7)) { position.setAltitude(buf.readMediumLE()); } } else if (type == MSG_EXT_POS_DATA) { int flags = buf.readUnsignedByte(); if (BitUtil.check(flags, 0)) { position.set(Position.KEY_VDOP, buf.readUnsignedShortLE()); } if (BitUtil.check(flags, 1)) { position.set(Position.KEY_HDOP, buf.readUnsignedShortLE()); } if (BitUtil.check(flags, 2)) { position.set(Position.KEY_PDOP, buf.readUnsignedShortLE()); } if (BitUtil.check(flags, 3)) { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); } } else if (type == MSG_AD_SENSORS_DATA) { buf.readUnsignedByte(); // inputs flags position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); buf.readUnsignedByte(); // adc flags } buf.readerIndex(end); } if (serviceType == SERVICE_TELEDATA && deviceSession != null) { positions.add(position); } } return positions.isEmpty() ? null : positions; }
From source file:org.traccar.protocol.GalileoProtocolDecoder.java
License:Apache License
private void decodeTag(Position position, ByteBuf buf, int tag) { if (tag >= 0x50 && tag <= 0x57) { position.set(Position.PREFIX_ADC + (tag - 0x50), buf.readUnsignedShortLE()); } else if (tag >= 0x60 && tag <= 0x62) { position.set("fuel" + (tag - 0x60), buf.readUnsignedShortLE()); } else if (tag >= 0xa0 && tag <= 0xaf) { position.set("can8BitR" + (tag - 0xa0 + 15), buf.readUnsignedByte()); } else if (tag >= 0xb0 && tag <= 0xb9) { position.set("can16BitR" + (tag - 0xb0 + 5), buf.readUnsignedShortLE()); } else if (tag >= 0xc4 && tag <= 0xd2) { position.set("can8BitR" + (tag - 0xc4), buf.readUnsignedByte()); } else if (tag >= 0xd6 && tag <= 0xda) { position.set("can16BitR" + (tag - 0xd6), buf.readUnsignedShortLE()); } else if (tag >= 0xdb && tag <= 0xdf) { position.set("can32BitR" + (tag - 0xdb), buf.readUnsignedIntLE()); } else if (tag >= 0xe2 && tag <= 0xe9) { position.set("userData" + (tag - 0xe2), buf.readUnsignedIntLE()); } else if (tag >= 0xf0 && tag <= 0xf9) { position.set("can32BitR" + (tag - 0xf0 + 5), buf.readUnsignedIntLE()); } else {/*from w w w .j ava2s. c o m*/ decodeTagOther(position, buf, tag); } }
From source file:org.traccar.protocol.GalileoProtocolDecoder.java
License:Apache License
private void decodeTagOther(Position position, ByteBuf buf, int tag) { switch (tag) { case 0x01:// ww w . j a v a2 s . co m position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte()); break; case 0x02: position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); break; case 0x04: position.set("deviceId", buf.readUnsignedShortLE()); break; case 0x10: position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); break; case 0x20: position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); break; case 0x33: position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE() * 0.1)); position.setCourse(buf.readUnsignedShortLE() * 0.1); break; case 0x34: position.setAltitude(buf.readShortLE()); break; case 0x35: position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); break; case 0x40: position.set(Position.KEY_STATUS, buf.readUnsignedShortLE()); break; case 0x41: position.set(Position.KEY_POWER, buf.readUnsignedShortLE() / 1000.0); break; case 0x42: position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() / 1000.0); break; case 0x43: position.set(Position.KEY_DEVICE_TEMP, buf.readByte()); break; case 0x44: position.set(Position.KEY_ACCELERATION, buf.readUnsignedIntLE()); break; case 0x45: position.set(Position.KEY_OUTPUT, buf.readUnsignedShortLE()); break; case 0x46: position.set(Position.KEY_INPUT, buf.readUnsignedShortLE()); break; case 0x48: position.set("statusExtended", buf.readUnsignedShortLE()); break; case 0x58: position.set("rs2320", buf.readUnsignedShortLE()); break; case 0x59: position.set("rs2321", buf.readUnsignedShortLE()); break; case 0x90: position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE())); break; case 0xc0: position.set("fuelTotal", buf.readUnsignedIntLE() * 0.5); break; case 0xc1: position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4); position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() - 40); position.set(Position.KEY_RPM, buf.readUnsignedShortLE() * 0.125); break; case 0xc2: position.set("canB0", buf.readUnsignedIntLE()); break; case 0xc3: position.set("canB1", buf.readUnsignedIntLE()); break; case 0xd4: position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); break; case 0xe0: position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); break; case 0xe1: position.set(Position.KEY_RESULT, buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); break; case 0xea: position.set("userDataArray", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))); position.set("userDataArray", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))); break; default: buf.skipBytes(getTagLength(tag)); break; } }
From source file:org.traccar.protocol.GranitProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '~'); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession != null && indexTilde == -1) { String bufString = buf.toString(StandardCharsets.US_ASCII); Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date()); getLastLocation(position, new Date()); position.setValid(false);// ww w .jav a2 s. c o m position.set(Position.KEY_RESULT, bufString); return position; } if (buf.readableBytes() < HEADER_LENGTH) { return null; } String header = buf.readSlice(HEADER_LENGTH).toString(StandardCharsets.US_ASCII); if (header.equals("+RRCB~")) { buf.skipBytes(2); // binary length 26 int deviceId = buf.readUnsignedShortLE(); deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId)); if (deviceSession == null) { return null; } long unixTime = buf.readUnsignedIntLE(); if (channel != null) { sendResponseCurrent(channel, deviceId, unixTime); } Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date(unixTime * 1000)); decodeStructure(buf, position); return position; } else if (header.equals("+DDAT~")) { buf.skipBytes(2); // binary length int deviceId = buf.readUnsignedShortLE(); deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId)); if (deviceSession == null) { return null; } byte format = buf.readByte(); if (format != 4) { return null; } byte nblocks = buf.readByte(); int packNum = buf.readUnsignedShortLE(); if (channel != null) { sendResponseArchive(channel, deviceId, packNum); } List<Position> positions = new ArrayList<>(); while (nblocks > 0) { nblocks--; long unixTime = buf.readUnsignedIntLE(); int timeIncrement = buf.getUnsignedShortLE(buf.readerIndex() + 120); for (int i = 0; i < 6; i++) { if (buf.getUnsignedByte(buf.readerIndex()) != 0xFE) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date((unixTime + i * timeIncrement) * 1000)); decodeStructure(buf, position); position.set(Position.KEY_ARCHIVE, true); positions.add(position); } else { buf.skipBytes(20); // skip filled 0xFE structure } } buf.skipBytes(2); // increment } return positions; } return null; }
From source file:org.traccar.protocol.MeitrackProtocolDecoder.java
License:Apache License
private List<Position> decodeBinaryC(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { List<Position> positions = new LinkedList<>(); String flag = buf.toString(2, 1, StandardCharsets.US_ASCII); int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ','); String imei = buf.toString(index + 1, 15, StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; }//from ww w. j a v a2s.c o m buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4); while (buf.readableBytes() >= 0x34) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_EVENT, buf.readUnsignedByte()); position.setLatitude(buf.readIntLE() * 0.000001); position.setLongitude(buf.readIntLE() * 0.000001); position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 946684800 = 2000-01-01 position.setValid(buf.readUnsignedByte() == 1); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); int rssi = buf.readUnsignedByte(); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); position.setCourse(buf.readUnsignedShortLE()); position.set(Position.KEY_HDOP, buf.readUnsignedShortLE() * 0.1); position.setAltitude(buf.readUnsignedShortLE()); position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); position.set("runtime", buf.readUnsignedIntLE()); position.setNetwork(new Network(CellTower.from(buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi))); position.set(Position.KEY_STATUS, buf.readUnsignedShortLE()); position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01); position.set(Position.KEY_POWER, buf.readUnsignedShortLE()); buf.readUnsignedIntLE(); // geo-fence positions.add(position); } if (channel != null) { StringBuilder command = new StringBuilder("@@"); command.append(flag).append(27 + positions.size() / 10).append(","); command.append(imei).append(",CCC,").append(positions.size()).append("*"); int checksum = 0; for (int i = 0; i < command.length(); i += 1) { checksum += command.charAt(i); } command.append(String.format("%02x", checksum & 0xff).toUpperCase()); command.append("\r\n"); channel.writeAndFlush(new NetworkMessage(command.toString(), remoteAddress)); // delete processed data } return positions; }
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);/* ww w . j a v a 2s. co m*/ 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.MxtProtocolDecoder.java
License:Apache License
@Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; buf.readUnsignedByte(); // start int device = buf.readUnsignedByte(); // device descriptor int type = buf.readUnsignedByte(); long id = buf.readUnsignedIntLE(); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id)); if (deviceSession == null) { return null; }/* w ww .jav a2s. com*/ if (type == MSG_POSITION) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); buf.readUnsignedByte(); // protocol int infoGroups = buf.readUnsignedByte(); position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); DateBuilder dateBuilder = new DateBuilder().setDate(2000, 1, 1); long date = buf.readUnsignedIntLE(); long days = BitUtil.from(date, 6 + 6 + 5); long hours = BitUtil.between(date, 6 + 6, 6 + 6 + 5); long minutes = BitUtil.between(date, 6, 6 + 6); long seconds = BitUtil.to(date, 6); dateBuilder.addMillis((((days * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000); position.setTime(dateBuilder.getDate()); position.setValid(true); position.setLatitude(buf.readIntLE() / 1000000.0); position.setLongitude(buf.readIntLE() / 1000000.0); long flags = buf.readUnsignedIntLE(); position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0)); if (BitUtil.check(flags, 1)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } position.set(Position.KEY_INPUT, BitUtil.between(flags, 2, 7)); position.set(Position.KEY_OUTPUT, BitUtil.between(flags, 7, 10)); position.setCourse(BitUtil.between(flags, 10, 13) * 45); // position.setValid(BitUtil.check(flags, 15)); position.set(Position.KEY_CHARGE, BitUtil.check(flags, 20)); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); buf.readUnsignedByte(); // input mask if (BitUtil.check(infoGroups, 0)) { buf.skipBytes(8); // waypoints } if (BitUtil.check(infoGroups, 1)) { buf.skipBytes(8); // wireless accessory } if (BitUtil.check(infoGroups, 2)) { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_HDOP, buf.readUnsignedByte()); position.setAccuracy(buf.readUnsignedByte()); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); buf.readUnsignedShortLE(); // time since boot position.set(Position.KEY_POWER, buf.readUnsignedByte()); position.set(Position.PREFIX_TEMP + 1, buf.readByte()); } if (BitUtil.check(infoGroups, 3)) { position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); } if (BitUtil.check(infoGroups, 4)) { position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(buf.readUnsignedIntLE())); } if (BitUtil.check(infoGroups, 5)) { buf.readUnsignedIntLE(); // reason } if (BitUtil.check(infoGroups, 6)) { position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001); position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE()); } if (BitUtil.check(infoGroups, 7)) { position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE())); } buf.readerIndex(buf.writerIndex() - 3); sendResponse(channel, device, id, buf.readUnsignedShortLE()); return position; } return null; }
From source file:org.traccar.protocol.NavigilFrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { // Check minimum length if (buf.readableBytes() < MESSAGE_HEADER) { return null; }/*from www. ja v a 2 s . c o m*/ // Check for preamble boolean hasPreamble = false; if (buf.getUnsignedIntLE(buf.readerIndex()) == PREAMBLE) { hasPreamble = true; } // Check length and return buffer int length = buf.getUnsignedShortLE(buf.readerIndex() + 6); if (buf.readableBytes() >= length) { if (hasPreamble) { buf.readUnsignedIntLE(); length -= 4; } return buf.readRetainedSlice(length); } return null; }
From source file:org.traccar.protocol.NavigilProtocolDecoder.java
License:Apache License
private Position parseUnitReport(DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) { Position position = new Position(getProtocolName()); position.setValid(true);/*from ww w .j a va 2s . co m*/ position.set(Position.KEY_INDEX, sequenceNumber); position.setDeviceId(deviceSession.getDeviceId()); buf.readUnsignedShortLE(); // report trigger position.set(Position.KEY_FLAGS, buf.readUnsignedShortLE()); position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); position.setAltitude(buf.readUnsignedShortLE()); position.set(Position.KEY_SATELLITES, buf.readUnsignedShortLE()); position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShortLE()); position.set("gpsAntennaState", buf.readUnsignedShortLE()); position.setSpeed(buf.readUnsignedShortLE() * 0.194384); position.setCourse(buf.readUnsignedShortLE()); position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); position.set(Position.KEY_DISTANCE, buf.readUnsignedIntLE()); position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); position.set(Position.KEY_CHARGE, buf.readUnsignedShortLE()); position.setTime(convertTimestamp(buf.readUnsignedIntLE())); return position; }