List of usage examples for io.netty.buffer ByteBuf readIntLE
public abstract int readIntLE();
From source file:org.traccar.protocol.DmtProtocolDecoder.java
License:Apache License
private List<Position> decodeFixed64(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; }// ww w. j a va 2s. com List<Position> positions = new LinkedList<>(); while (buf.readableBytes() >= 64) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); buf.readByte(); // type position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); long time = buf.readUnsignedIntLE(); position.setTime( new DateBuilder().setYear((int) (2000 + (time & 0x3F))).setMonth((int) (time >> 6) & 0xF) .setDay((int) (time >> 10) & 0x1F).setHour((int) (time >> 15) & 0x1F) .setMinute((int) (time >> 20) & 0x3F).setSecond((int) (time >> 26) & 0x3F).getDate()); position.setLongitude(buf.readIntLE() * 0.0000001); position.setLatitude(buf.readIntLE() * 0.0000001); position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE())); position.setCourse(buf.readUnsignedByte() * 2); position.setAltitude(buf.readShortLE()); buf.readUnsignedShortLE(); // position accuracy buf.readUnsignedByte(); // speed accuracy position.set(Position.KEY_EVENT, buf.readUnsignedByte()); position.setValid(BitUtil.check(buf.readByte(), 0)); position.set(Position.KEY_INPUT, buf.readUnsignedIntLE()); position.set(Position.KEY_OUTPUT, buf.readUnsignedShortLE()); for (int i = 1; i <= 5; i++) { position.set(Position.PREFIX_ADC + i, buf.readShortLE()); } position.set(Position.KEY_DEVICE_TEMP, buf.readByte()); buf.readShortLE(); // accelerometer x buf.readShortLE(); // accelerometer y buf.readShortLE(); // accelerometer z buf.skipBytes(8); // device id position.set(Position.KEY_PDOP, buf.readUnsignedShortLE() * 0.01); buf.skipBytes(2); // reserved buf.readUnsignedShortLE(); // checksum positions.add(position); } return positions; }
From source file:org.traccar.protocol.DmtProtocolDecoder.java
License:Apache License
private List<Position> decodeStandard(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; }/*from w ww.j av a 2 s .co m*/ List<Position> positions = new LinkedList<>(); while (buf.isReadable()) { int recordEnd = buf.readerIndex() + buf.readUnsignedShortLE(); Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); position.setDeviceTime(new Date(1356998400000L + buf.readUnsignedIntLE() * 1000)); // since 1 Jan 2013 position.set(Position.KEY_EVENT, buf.readUnsignedByte()); while (buf.readerIndex() < recordEnd) { int fieldId = buf.readUnsignedByte(); int fieldLength = buf.readUnsignedByte(); int fieldEnd = buf.readerIndex() + (fieldLength == 255 ? buf.readUnsignedShortLE() : fieldLength); if (fieldId == 0) { position.setFixTime(new Date(1356998400000L + buf.readUnsignedIntLE() * 1000)); position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); position.setAltitude(buf.readShortLE()); position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE())); buf.readUnsignedByte(); // speed accuracy position.setCourse(buf.readUnsignedByte() * 2); position.set(Position.KEY_PDOP, buf.readUnsignedByte() * 0.1); position.setAccuracy(buf.readUnsignedByte()); position.setValid(buf.readUnsignedByte() != 0); } else if (fieldId == 2) { int input = buf.readIntLE(); int output = buf.readUnsignedShortLE(); int status = buf.readUnsignedShortLE(); position.set(Position.KEY_IGNITION, BitUtil.check(input, 0)); position.set(Position.KEY_INPUT, input); position.set(Position.KEY_OUTPUT, output); position.set(Position.KEY_STATUS, status); } else if (fieldId == 6) { while (buf.readerIndex() < fieldEnd) { switch (buf.readUnsignedByte()) { case 1: position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); break; case 2: position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01); break; case 3: position.set(Position.KEY_DEVICE_TEMP, buf.readShortLE() * 0.01); break; case 4: position.set(Position.KEY_RSSI, buf.readUnsignedShortLE()); break; case 5: position.set("solarPower", buf.readUnsignedShortLE() * 0.001); break; default: break; } } } buf.readerIndex(fieldEnd); } if (position.getFixTime() == null) { getLastLocation(position, position.getDeviceTime()); } positions.add(position); } return positions; }
From source file:org.traccar.protocol.GalileoProtocolDecoder.java
License:Apache License
private Object decodePositions(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { int length = (buf.readUnsignedShortLE() & 0x7fff) + 3; List<Position> positions = new LinkedList<>(); Set<Integer> tags = new HashSet<>(); boolean hasLocation = false; DeviceSession deviceSession = null;/* w ww . j a v a 2s . co m*/ Position position = new Position(getProtocolName()); while (buf.readerIndex() < length) { int tag = buf.readUnsignedByte(); if (tags.contains(tag)) { if (hasLocation && position.getFixTime() != null) { positions.add(position); } tags.clear(); hasLocation = false; position = new Position(getProtocolName()); // new position starts } tags.add(tag); if (tag == 0x03) { deviceSession = getDeviceSession(channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); } else if (tag == 0x30) { hasLocation = true; position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00); position.setLatitude(buf.readIntLE() / 1000000.0); position.setLongitude(buf.readIntLE() / 1000000.0); } else { decodeTag(position, buf, tag); } } if (deviceSession == null) { deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; } } if (hasLocation && position.getFixTime() != null) { positions.add(position); } else if (position.getAttributes().containsKey(Position.KEY_RESULT)) { position.setDeviceId(deviceSession.getDeviceId()); getLastLocation(position, null); positions.add(position); } sendReply(channel, 0x02, buf.readUnsignedShortLE()); for (Position p : positions) { p.setDeviceId(deviceSession.getDeviceId()); } return positions.isEmpty() ? null : positions; }
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; }// w w w .j a v a 2 s . co 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);//from www. java 2s. com 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; }/*ww w . j a v a 2s . c om*/ 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.NavigilProtocolDecoder.java
License:Apache License
private Position parseUnitReport(DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) { Position position = new Position(getProtocolName()); position.setValid(true);//from w ww . j a v a 2 s. com 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; }
From source file:org.traccar.protocol.NavigilProtocolDecoder.java
License:Apache License
private Position parseTg2Report(DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) { Position position = new Position(getProtocolName()); position.setValid(true);/*from w w w .j a va2 s. c om*/ position.set(Position.KEY_INDEX, sequenceNumber); position.setDeviceId(deviceSession.getDeviceId()); buf.readUnsignedShortLE(); // report trigger buf.readUnsignedByte(); // reserved buf.readUnsignedByte(); // assisted GPS age position.setTime(convertTimestamp(buf.readUnsignedIntLE())); position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); position.setAltitude(buf.readUnsignedShortLE()); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); position.setSpeed(buf.readUnsignedShortLE() * 0.194384); position.setCourse(buf.readUnsignedShortLE()); position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); position.set("maximumSpeed", buf.readUnsignedShortLE()); position.set("minimumSpeed", buf.readUnsignedShortLE()); position.set(Position.PREFIX_IO + 1, buf.readUnsignedShortLE()); // VSAUT1 voltage position.set(Position.PREFIX_IO + 2, buf.readUnsignedShortLE()); // VSAUT2 voltage position.set(Position.PREFIX_IO + 3, buf.readUnsignedShortLE()); // solar voltage position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); return position; }
From source file:org.traccar.protocol.NavigilProtocolDecoder.java
License:Apache License
private Position parsePositionReport2(DeviceSession deviceSession, ByteBuf buf, int sequenceNumber, long timestamp) { Position position = new Position(getProtocolName()); position.set(Position.KEY_INDEX, sequenceNumber); position.setDeviceId(deviceSession.getDeviceId()); position.setTime(convertTimestamp(timestamp)); position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); buf.readUnsignedByte(); // report trigger position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); short flags = buf.readUnsignedByte(); position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); return position; }
From source file:org.traccar.protocol.NavigilProtocolDecoder.java
License:Apache License
private Position parseSnapshot4(DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) { Position position = new Position(getProtocolName()); position.set(Position.KEY_INDEX, sequenceNumber); position.setDeviceId(deviceSession.getDeviceId()); buf.readUnsignedByte(); // report trigger buf.readUnsignedByte(); // position fix source buf.readUnsignedByte(); // GNSS fix quality buf.readUnsignedByte(); // GNSS assistance age long flags = buf.readUnsignedIntLE(); position.setValid((flags & 0x0400) == 0x0400); position.setTime(convertTimestamp(buf.readUnsignedIntLE())); position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); position.setAltitude(buf.readUnsignedShortLE()); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); position.setSpeed(buf.readUnsignedShortLE() * 0.194384); position.setCourse(buf.readUnsignedShortLE() * 0.1); position.set("maximumSpeed", buf.readUnsignedByte()); position.set("minimumSpeed", buf.readUnsignedByte()); position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); // supply voltage 1 position.set(Position.PREFIX_IO + 2, buf.readUnsignedByte()); // supply voltage 2 position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); return position; }