bug_id
stringlengths 22
44
| func_before
stringlengths 101
9.03k
| func_after
stringlengths 161
12.3k
|
---|---|---|
traccar-traccar-d797671b2ce6 | private Position decodeTransparent(DeviceSession deviceSession, ByteBuf buf) {
int type = buf.readUnsignedByte();
if (type == 0xF0) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
Date time = readDate(buf, deviceSession.get(DeviceSession.KEY_TIMEZONE));
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_ARCHIVE, true);
}
buf.readUnsignedByte();
int count;
int subtype = buf.readUnsignedByte();
switch (subtype) {
case 0x01:
count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
int id = buf.readUnsignedShort();
int length = buf.readUnsignedByte();
switch (id) {
case 0x0102:
case 0x0528:
case 0x0546:
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
break;
case 0x0103:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedInt() * 0.01);
break;
case 0x052A:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.01);
break;
case 0x0105:
case 0x052C:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01);
break;
case 0x014A:
case 0x0537:
case 0x0538:
case 0x0539:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
break;
case 0x052D:
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40);
break;
case 0x0530:
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
break;
case 0x0535:
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1);
break;
case 0x0536:
position.set(Position.KEY_RPM, buf.readUnsignedShort());
break;
case 0x0547:
case 0x0548:
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
default:
switch (length) {
case 1:
position.set(Position.PREFIX_IO + id, buf.readUnsignedByte());
break;
case 2:
position.set(Position.PREFIX_IO + id, buf.readUnsignedShort());
break;
case 4:
position.set(Position.PREFIX_IO + id, buf.readUnsignedInt());
break;
default:
buf.skipBytes(length);
break;
}
break;
}
}
getLastLocation(position, time);
decodeCoordinates(position, buf);
break;
case 0x02:
count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
buf.readUnsignedInt();
int codeCount = buf.readUnsignedShort();
for (int j = 0; j < codeCount; j++) {
buf.skipBytes(16);
}
}
getLastLocation(position, time);
decodeCoordinates(position, buf);
break;
case 0x03:
count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
int id = buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x1A:
position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
break;
case 0x1B:
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
break;
case 0x1C:
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
break;
case 0x1D:
case 0x1E:
case 0x1F:
position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE);
break;
case 0x23:
position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING);
break;
default:
break;
}
buf.skipBytes(length);
}
getLastLocation(position, time);
decodeCoordinates(position, buf);
break;
case 0x0B:
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_VIN, buf.readCharSequence(17, StandardCharsets.US_ASCII).toString());
}
getLastLocation(position, time);
break;
default:
return null;
}
return position;
}
return null;
}
| private Position decodeTransparent(DeviceSession deviceSession, ByteBuf buf) {
int type = buf.readUnsignedByte();
if (type == 0xF0) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
Date time = readDate(buf, deviceSession.get(DeviceSession.KEY_TIMEZONE));
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_ARCHIVE, true);
}
buf.readUnsignedByte();
int count;
int subtype = buf.readUnsignedByte();
switch (subtype) {
case 0x01:
count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
int id = buf.readUnsignedShort();
int length = buf.readUnsignedByte();
switch (id) {
case 0x0102:
case 0x0528:
case 0x0546:
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
break;
case 0x0103:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedInt() * 0.01);
break;
case 0x052A:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.01);
break;
case 0x0105:
case 0x052C:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01);
break;
case 0x014A:
case 0x0537:
case 0x0538:
case 0x0539:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
break;
case 0x052D:
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40);
break;
case 0x0530:
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
break;
case 0x0535:
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1);
break;
case 0x0536:
position.set(Position.KEY_RPM, buf.readUnsignedShort());
break;
case 0x0547:
case 0x0548:
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
default:
switch (length) {
case 1:
position.set(Position.PREFIX_IO + id, buf.readUnsignedByte());
break;
case 2:
position.set(Position.PREFIX_IO + id, buf.readUnsignedShort());
break;
case 4:
position.set(Position.PREFIX_IO + id, buf.readUnsignedInt());
break;
default:
buf.skipBytes(length);
break;
}
break;
}
}
getLastLocation(position, time);
decodeCoordinates(position, buf);
position.setTime(time);
break;
case 0x02:
count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
buf.readUnsignedInt();
int codeCount = buf.readUnsignedShort();
for (int j = 0; j < codeCount; j++) {
buf.skipBytes(16);
}
}
getLastLocation(position, time);
decodeCoordinates(position, buf);
position.setTime(time);
break;
case 0x03:
count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
int id = buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x1A:
position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
break;
case 0x1B:
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
break;
case 0x1C:
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
break;
case 0x1D:
case 0x1E:
case 0x1F:
position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE);
break;
case 0x23:
position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING);
break;
default:
break;
}
buf.skipBytes(length);
}
getLastLocation(position, time);
decodeCoordinates(position, buf);
position.setTime(time);
break;
case 0x0B:
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_VIN, buf.readCharSequence(17, StandardCharsets.US_ASCII).toString());
}
getLastLocation(position, time);
break;
default:
return null;
}
return position;
}
return null;
}
|
traccar-traccar-779486a30483 | protected Object decodeAvrmc(
String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_AVRMC, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession =
getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
String deviceModel = null;
Device device = getCacheManager().getObject(Device.class, deviceSession.getDeviceId());
if (device != null) {
deviceModel = device.getModel();
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
String status = parser.next();
String upperCaseStatus = status.toUpperCase();
position.setValid(upperCaseStatus.equals("A") || upperCaseStatus.equals("R") || upperCaseStatus.equals("P"));
position.set(Position.KEY_STATUS, status);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
String event = parser.next();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, decodeEvent(event, position, deviceModel));
position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001);
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_GPS, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);
if ("AVL110".equals(deviceModel) || "AVL120".equals(deviceModel)) {
position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);
}
Integer lac = parser.nextHexInt();
Integer cid = parser.nextHexInt();
Integer mcc = parser.nextInt();
Integer mnc = parser.nextInt();
if (lac != null && cid != null && mcc != null && mnc != null) {
position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
}
parser.next();
String checksum = parser.next();
if (channel != null) {
sendAcknowledge(status, event, checksum, channel, remoteAddress);
String devicePassword = AttributeUtil.getDevicePassword(
getCacheManager(), deviceSession.getDeviceId(), getProtocolName(), DEFAULT_DEVICE_PASSWORD);
sendEventResponse(event, devicePassword, channel, remoteAddress);
}
return position;
}
| protected Object decodeAvrmc(
String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_AVRMC, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession =
getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
String deviceModel = null;
Device device = getCacheManager().getObject(Device.class, deviceSession.getDeviceId());
if (device != null) {
deviceModel = device.getModel();
}
if (deviceModel == null) {
deviceModel = "";
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
String status = parser.next();
String upperCaseStatus = status.toUpperCase();
position.setValid(upperCaseStatus.equals("A") || upperCaseStatus.equals("R") || upperCaseStatus.equals("P"));
position.set(Position.KEY_STATUS, status);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
String event = parser.next();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, decodeEvent(event, position, deviceModel));
position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001);
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_GPS, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);
if ("AVL110".equals(deviceModel) || "AVL120".equals(deviceModel)) {
position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);
} else {
parser.next();
}
Integer lac = parser.nextHexInt();
Integer cid = parser.nextHexInt();
Integer mcc = parser.nextInt();
Integer mnc = parser.nextInt();
if (lac != null && cid != null && mcc != null && mnc != null) {
position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
}
parser.next();
String checksum = parser.next();
if (channel != null) {
sendAcknowledge(status, event, checksum, channel, remoteAddress);
String devicePassword = AttributeUtil.getDevicePassword(
getCacheManager(), deviceSession.getDeviceId(), getProtocolName(), DEFAULT_DEVICE_PASSWORD);
sendEventResponse(event, devicePassword, channel, remoteAddress);
}
return position;
}
|
traccar-traccar-4ece72558c80 | private List<Position> parseData(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) {
List<Position> positions = new LinkedList<>();
if (!connectionless) {
buf.readUnsignedInt();
}
int codec = buf.readUnsignedByte();
int count = buf.readUnsignedByte();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
if (codec == CODEC_13) {
buf.readUnsignedByte();
int length = buf.readInt() - 4;
getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
if (isPrintable(buf, length)) {
position.set(Position.KEY_RESULT,
buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim());
} else {
position.set(Position.KEY_RESULT,
ByteBufUtil.hexDump(buf.readSlice(length)));
}
} else if (codec == CODEC_12) {
decodeSerial(channel, remoteAddress, deviceSession, position, buf);
} else {
decodeLocation(position, buf, codec, model);
}
if (!position.getOutdated() || !position.getAttributes().isEmpty()) {
positions.add(position);
}
}
if (channel != null && codec != CODEC_12 && codec != CODEC_13) {
ByteBuf response = Unpooled.buffer();
if (connectionless) {
response.writeShort(5);
response.writeShort(0);
response.writeByte(0x01);
response.writeByte(locationPacketId);
response.writeByte(count);
} else {
response.writeInt(count);
}
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
return positions.isEmpty() ? null : positions;
}
| private List<Position> parseData(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) {
List<Position> positions = new LinkedList<>();
if (!connectionless) {
buf.readUnsignedInt();
}
int codec = buf.readUnsignedByte();
int count = buf.readUnsignedByte();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
if (codec == CODEC_13) {
buf.readUnsignedByte();
int length = buf.readInt() - 4;
getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
if (isPrintable(buf, length)) {
String data = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim();
if (data.startsWith("GTSL")) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, data.split("\\|")[4]);
} else {
position.set(Position.KEY_RESULT, data);
}
} else {
position.set(Position.KEY_RESULT,
ByteBufUtil.hexDump(buf.readSlice(length)));
}
} else if (codec == CODEC_12) {
decodeSerial(channel, remoteAddress, deviceSession, position, buf);
} else {
decodeLocation(position, buf, codec, model);
}
if (!position.getOutdated() || !position.getAttributes().isEmpty()) {
positions.add(position);
}
}
if (channel != null && codec != CODEC_12 && codec != CODEC_13) {
ByteBuf response = Unpooled.buffer();
if (connectionless) {
response.writeShort(5);
response.writeShort(0);
response.writeByte(0x01);
response.writeByte(locationPacketId);
response.writeByte(count);
} else {
response.writeInt(count);
}
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
return positions.isEmpty() ? null : positions;
}
|
jhy-jsoup-6ccd158754e2 | private static void appendToAscii(String s, boolean spaceAsPlus, StringBuilder sb) throws UnsupportedEncodingException {
for (int i = 0; i < s.length(); i++) {
int c = s.codePointAt(i);
if (c == ' ') {
sb.append(spaceAsPlus ? '+' : "%20");
} else if (c > 127) {
sb.append(URLEncoder.encode(new String(Character.toChars(c)), UTF_8.name()));
} else {
sb.append((char) c);
}
}
}
| private static void appendToAscii(String s, boolean spaceAsPlus, StringBuilder sb) throws UnsupportedEncodingException {
for (int i = 0; i < s.length(); i++) {
int c = s.codePointAt(i);
if (c == ' ') {
sb.append(spaceAsPlus ? '+' : "%20");
} else if (c > 127) {
sb.append(URLEncoder.encode(new String(Character.toChars(c)), UTF_8.name()));
if (Character.charCount(c) == 2) i++;
} else {
sb.append((char) c);
}
}
}
|
snowflakedb-snowflake-jdbc-f2c8eba73535 | static boolean isNonRetryableHTTPCode(CloseableHttpResponse response, boolean retryHTTP403) {
return response != null
&& (response.getStatusLine().getStatusCode() < 500
||
response.getStatusLine().getStatusCode() >= 600)
&&
response.getStatusLine().getStatusCode() != 408
&&
(!retryHTTP403 || response.getStatusLine().getStatusCode() != 403);
}
| static boolean isNonRetryableHTTPCode(CloseableHttpResponse response, boolean retryHTTP403) {
return response != null
&& (response.getStatusLine().getStatusCode() < 500
||
response.getStatusLine().getStatusCode() >= 600)
&&
response.getStatusLine().getStatusCode() != 408
&&
response.getStatusLine().getStatusCode() != 429
&&
(!retryHTTP403 || response.getStatusLine().getStatusCode() != 403);
}
|
traccar-traccar-4a5b8d79b560 | @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
sentence = sentence.substring(sentence.indexOf('|') + 1, sentence.lastIndexOf('|'));
Position position = new Position();
position.setProtocol(getProtocolName());
for (String entry : sentence.split(",")) {
int delimiter = entry.indexOf('=');
String key = entry.substring(0, delimiter);
String value = entry.substring(delimiter + 1);
switch (key) {
case "unit":
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession != null) {
position.setDeviceId(deviceSession.getDeviceId());
}
break;
case "gps_valid":
position.setValid(Integer.parseInt(value) != 0);
break;
case "datetime_actual":
position.setTime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value));
break;
case "latitude":
position.setLatitude(Double.parseDouble(value));
break;
case "longitude":
position.setLongitude(Double.parseDouble(value));
break;
case "altitude":
position.setAltitude(Double.parseDouble(value));
break;
case "velocity":
position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value)));
break;
case "heading":
position.setCourse(Integer.parseInt(value));
break;
case "eventid":
position.set(Position.KEY_EVENT, Integer.parseInt(value));
break;
case "mileage":
position.set(Position.KEY_ODOMETER, (long) (Double.parseDouble(value) * 1000));
break;
case "satellites":
position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
break;
case "ignition":
position.set(Position.KEY_IGNITION, Integer.parseInt(value) != 0);
break;
case "door":
position.set(Position.KEY_DOOR, Integer.parseInt(value) != 0);
break;
case "arm":
position.set(Position.KEY_ARMED, Integer.parseInt(value) != 0);
break;
case "fuel":
position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(value));
break;
case "rpm":
position.set(Position.KEY_RPM, Integer.parseInt(value));
break;
case "main_voltage":
position.set(Position.KEY_POWER, Double.parseDouble(value));
break;
case "backup_voltage":
position.set(Position.KEY_BATTERY, Double.parseDouble(value));
break;
case "analog1":
case "analog2":
case "analog3":
position.set(Position.PREFIX_ADC + (key.charAt(key.length() - 1) - '0'), Double.parseDouble(value));
break;
case "extra1":
case "extra2":
case "extra3":
default:
position.set(key, value);
break;
}
}
return position;
}
| @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
sentence = sentence.substring(sentence.indexOf('|') + 1, sentence.lastIndexOf('|'));
Position position = new Position();
position.setProtocol(getProtocolName());
for (String entry : sentence.split(",")) {
int delimiter = entry.indexOf('=');
String key = entry.substring(0, delimiter);
String value = entry.substring(delimiter + 1);
switch (key) {
case "unit":
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession != null) {
position.setDeviceId(deviceSession.getDeviceId());
}
break;
case "gps_valid":
position.setValid(Integer.parseInt(value) != 0);
break;
case "datetime_actual":
position.setTime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value));
break;
case "latitude":
position.setLatitude(Double.parseDouble(value));
break;
case "longitude":
position.setLongitude(Double.parseDouble(value));
break;
case "altitude":
position.setAltitude(Double.parseDouble(value));
break;
case "velocity":
position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value)));
break;
case "heading":
position.setCourse(Integer.parseInt(value));
break;
case "eventid":
position.set(Position.KEY_EVENT, Integer.parseInt(value));
break;
case "mileage":
case "odometer":
position.set(Position.KEY_ODOMETER, (long) (Double.parseDouble(value) * 1000));
break;
case "satellites":
position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
break;
case "ignition":
position.set(Position.KEY_IGNITION, Integer.parseInt(value) != 0);
break;
case "door":
position.set(Position.KEY_DOOR, Integer.parseInt(value) != 0);
break;
case "arm":
position.set(Position.KEY_ARMED, Integer.parseInt(value) != 0);
break;
case "fuel":
position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(value));
break;
case "rpm":
position.set(Position.KEY_RPM, Integer.parseInt(value));
break;
case "main_voltage":
position.set(Position.KEY_POWER, Double.parseDouble(value));
break;
case "backup_voltage":
position.set(Position.KEY_BATTERY, Double.parseDouble(value));
break;
case "analog1":
case "analog2":
case "analog3":
position.set(Position.PREFIX_ADC + (key.charAt(key.length() - 1) - '0'), Double.parseDouble(value));
break;
case "extra1":
case "extra2":
case "extra3":
default:
position.set(key, value);
break;
}
}
return position;
}
|
traccar-traccar-6631d7c4b352 | @Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
int endIndex = -1;
for (int i = buf.writerIndex() - 1; i >= buf.readerIndex(); i--) {
if (buf.getByte(i) == ']') {
endIndex = i + 1;
break;
}
}
if (endIndex > 0) {
ByteBuf frame = Unpooled.buffer();
while (buf.readerIndex() < endIndex) {
byte b1 = buf.readByte();
if (b1 == '}') {
byte b2 = buf.readByte();
switch (b2) {
case 0x01:
frame.writeByte('}');
break;
case 0x02:
frame.writeByte('[');
break;
case 0x03:
frame.writeByte(']');
break;
case 0x04:
frame.writeByte(',');
break;
case 0x05:
frame.writeByte('*');
break;
default:
throw new IllegalArgumentException(String.format(
"unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, b2));
}
} else {
frame.writeByte(b1);
}
}
return frame;
}
return null;
}
| @Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
int brackets = 0;
int endIndex = -1;
for (int i = buf.readerIndex(); i < buf.writerIndex(); i++) {
byte b = buf.getByte(i);
switch (b) {
case '[':
brackets += 1;
break;
case ']':
brackets -= 1;
break;
default:
break;
}
if (brackets == 0 && i > buf.readerIndex()) {
endIndex = i + 1;
break;
}
}
if (endIndex > 0) {
ByteBuf frame = Unpooled.buffer();
while (buf.readerIndex() < endIndex) {
byte b1 = buf.readByte();
if (b1 == '}') {
byte b2 = buf.readByte();
switch (b2) {
case 0x01:
frame.writeByte('}');
break;
case 0x02:
frame.writeByte('[');
break;
case 0x03:
frame.writeByte(']');
break;
case 0x04:
frame.writeByte(',');
break;
case 0x05:
frame.writeByte('*');
break;
default:
throw new IllegalArgumentException(String.format(
"unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, b2));
}
} else {
frame.writeByte(b1);
}
}
return frame;
}
return null;
}
|
jhy-jsoup-9e5869b6e1e2 | void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
boolean trimLeading = false;
boolean trimTrailing = false;
if (normaliseWhite) {
trimLeading = (siblingIndex == 0 && parent != null && parent.tag().isBlock()) ||
parentNode instanceof Document;
trimTrailing = nextSibling() == null && parent != null && parent.tag().isBlock();
Node next = nextSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()));
if (couldSkip && isBlank) return;
Node prev = previousSibling();
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && prev instanceof Element && ((Element) prev).normalName().equals("br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
| void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
final boolean trimLikeBlock = parent != null && (parent.tag().isBlock() || parent.tag().formatAsBlock());
boolean trimLeading = false, trimTrailing = false;
if (normaliseWhite) {
trimLeading = (trimLikeBlock && siblingIndex == 0) || parentNode instanceof Document;
trimTrailing = trimLikeBlock && nextSibling() == null;
Node next = nextSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()));
if (couldSkip && isBlank) return;
Node prev = previousSibling();
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && prev instanceof Element && ((Element) prev).normalName().equals("br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
|
stellar-java-stellar-sdk-15cc6d2c8131 | @Override
public boolean equals(Object object) {
if (!(object instanceof KeyPair)) {
return false;
}
KeyPair other = (KeyPair) object;
return this.mPrivateKey.equals(other.mPrivateKey) &&
this.mPublicKey.equals(other.mPublicKey);
}
| @Override
public boolean equals(Object object) {
if (!(object instanceof KeyPair)) {
return false;
}
KeyPair other = (KeyPair) object;
return Objects.equal(this.mPrivateKey, other.mPrivateKey) &&
this.mPublicKey.equals(other.mPublicKey);
}
|
jhy-jsoup-9bb07d2ab43c | protected void replaceChild(Node out, Node in) {
Validate.isTrue(out.parentNode == this);
Validate.notNull(in);
if (in.parentNode != null)
in.parentNode.removeChild(in);
final int index = out.siblingIndex;
ensureChildNodes().set(index, in);
in.parentNode = this;
in.setSiblingIndex(index);
out.parentNode = null;
}
| protected void replaceChild(Node out, Node in) {
Validate.isTrue(out.parentNode == this);
Validate.notNull(in);
if (out == in) return;
if (in.parentNode != null)
in.parentNode.removeChild(in);
final int index = out.siblingIndex;
ensureChildNodes().set(index, in);
in.parentNode = this;
in.setSiblingIndex(index);
out.parentNode = null;
}
|
jhy-jsoup-29be991198d3 | void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
boolean trimLeading = false;
boolean trimTrailing = false;
if (normaliseWhite) {
trimLeading = (siblingIndex == 0 && parent != null && parent.tag().isBlock()) ||
parentNode instanceof Document;
trimTrailing = nextSibling() == null && parent != null && parent.tag().isBlock();
Node next = this.nextSibling();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()));
if (couldSkip && isBlank()) return;
if ((siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank()) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank()))
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
| void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
boolean trimLeading = false;
boolean trimTrailing = false;
if (normaliseWhite) {
trimLeading = (siblingIndex == 0 && parent != null && parent.tag().isBlock()) ||
parentNode instanceof Document;
trimTrailing = nextSibling() == null && parent != null && parent.tag().isBlock();
Node next = nextSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()));
if (couldSkip && isBlank) return;
Node prev = previousSibling();
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && prev instanceof Element && ((Element) prev).normalName().equals("br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
|
LMAX-Exchange-Simple-DSL-81182e58bd80 | void consume(final RepeatingArgGroup groupArg, final Deque<NameValuePair> arguments)
{
final Map<DslArg, List<String>> valuesByArg = new HashMap<>();
final SimpleArgumentProcessor processor = new SimpleArgumentProcessor(valuesByArg, "Did not supply a value for %s in group " + groupArg.getName());
processor.consume(groupArg.getIdentity(), arguments);
final Map<String, SimpleDslArg> argsByName = new HashMap<>();
argsByName.put(groupArg.getIdentity().getName(), groupArg.getIdentity());
for (SimpleDslArg dslArg : groupArg.getOtherArgs())
{
if (argsByName.put(dslArg.getName().toLowerCase(), dslArg) != null)
{
throw new IllegalArgumentException("Duplicate parameter '" + dslArg.getName() + "' in group " + groupArg.getName());
}
}
while (!arguments.isEmpty())
{
final NameValuePair argument = arguments.peekFirst();
if (argument == NameValuePair.NULL)
{
arguments.pollFirst();
continue;
}
if (argument.name == null)
{
throw new IllegalArgumentException("Unexpected ambiguous argument " + argument.originalValue);
}
final DslArg arg = argsByName.get(argument.name.toLowerCase());
if (arg == null)
{
break;
}
final List<String> argValues = valuesByArg.computeIfAbsent(arg, k -> new ArrayList<>());
if (!argValues.isEmpty() && !arg.isAllowMultipleValues())
{
break;
}
checkValidValue(arg, argument.value);
argValues.add(argument.value);
arguments.pollFirst();
}
final Map<String, List<String>> valuesByName = new HashMap<>();
for (final SimpleDslArg simpleDslArg : argsByName.values())
{
final SimpleDslParam param = processor.collect(simpleDslArg);
if (param.hasValue())
{
valuesByName.put(param.getName().toLowerCase(), param.getValuesAsList());
}
}
final DslArg[] dslArgs = new DslArg[groupArg.getOtherArgs().length + 1];
dslArgs[0] = groupArg.getIdentity();
System.arraycopy(groupArg.getOtherArgs(), 0, dslArgs, 1, groupArg.getOtherArgs().length);
groupsByArg.computeIfAbsent(groupArg, k -> new ArrayList<>()).add(new RepeatingParamValues(dslArgs, valuesByName));
}
| void consume(final RepeatingArgGroup groupArg, final Deque<NameValuePair> arguments)
{
final Map<DslArg, List<String>> valuesByArg = new HashMap<>();
final SimpleArgumentProcessor processor = new SimpleArgumentProcessor(valuesByArg, "Did not supply a value for %s in group " + groupArg.getName());
processor.consume(groupArg.getIdentity(), arguments);
final Map<String, SimpleDslArg> argsByName = new HashMap<>();
argsByName.put(groupArg.getIdentity().getName(), groupArg.getIdentity());
for (SimpleDslArg dslArg : groupArg.getOtherArgs())
{
if (argsByName.put(dslArg.getName().toLowerCase(), dslArg) != null)
{
throw new IllegalArgumentException("Duplicate parameter '" + dslArg.getName() + "' in group " + groupArg.getName());
}
}
while (!arguments.isEmpty())
{
final NameValuePair argument = arguments.peekFirst();
if (argument == NameValuePair.NULL)
{
arguments.pollFirst();
continue;
}
if (argument.name == null)
{
throw new IllegalArgumentException("Unexpected ambiguous argument " + argument.originalValue);
}
final DslArg arg = argsByName.get(argument.name.toLowerCase());
if (arg == null)
{
break;
}
final List<String> argValues = valuesByArg.computeIfAbsent(arg, k -> new ArrayList<>());
if (!argValues.isEmpty() && !arg.isAllowMultipleValues())
{
break;
}
SimpleArgumentProcessor.addValue(arg, argument.value, argValues);
arguments.pollFirst();
}
final Map<String, List<String>> valuesByName = new HashMap<>();
for (final SimpleDslArg simpleDslArg : argsByName.values())
{
final SimpleDslParam param = processor.collect(simpleDslArg);
if (param.hasValue())
{
valuesByName.put(param.getName().toLowerCase(), param.getValuesAsList());
}
}
final DslArg[] dslArgs = new DslArg[groupArg.getOtherArgs().length + 1];
dslArgs[0] = groupArg.getIdentity();
System.arraycopy(groupArg.getOtherArgs(), 0, dslArgs, 1, groupArg.getOtherArgs().length);
groupsByArg.computeIfAbsent(groupArg, k -> new ArrayList<>()).add(new RepeatingParamValues(dslArgs, valuesByName));
}
|
jhy-jsoup-111919256590 | private boolean isInlineable(Document.OutputSettings out) {
if (!tag.isInline())
return false;
return (parent() == null || parent().isBlock())
&& !isEffectivelyFirst()
&& !out.outline();
}
| private boolean isInlineable(Document.OutputSettings out) {
if (!tag.isInline())
return false;
return (parent() == null || parent().isBlock())
&& !isEffectivelyFirst()
&& !out.outline()
&& !isNode("br");
}
|
traccar-traccar-d244b4bc4999 | public String getString(String key, String defaultValue) {
if (attributes.containsKey(key)) {
Object value = attributes.containsKey(key);
return value != null ? value.toString() : null;
} else {
return defaultValue;
}
}
| public String getString(String key, String defaultValue) {
if (attributes.containsKey(key)) {
Object value = attributes.get(key);
return value != null ? value.toString() : null;
} else {
return defaultValue;
}
}
|
traccar-traccar-4722f9b6b648 | private Position decodeIridiumPosition(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
buf.readUnsignedShortLE();
buf.skipBytes(3);
buf.readUnsignedIntLE();
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII));
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte();
buf.skipBytes(4);
buf.readUnsignedIntLE();
buf.skipBytes(23);
buf.skipBytes(3);
decodeMinimalDataSet(position, buf);
return position;
}
| private Position decodeIridiumPosition(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
buf.readUnsignedShort();
buf.skipBytes(3);
buf.readUnsignedInt();
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII));
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte();
buf.skipBytes(4);
position.setTime(new Date(buf.readUnsignedInt() * 1000));
buf.skipBytes(3);
int flags = buf.readUnsignedByte();
double latitude = buf.readUnsignedByte() + buf.readUnsignedShort() / 60000.0;
double longitude = buf.readUnsignedByte() + buf.readUnsignedShort() / 60000.0;
position.setLatitude(BitUtil.check(flags, 1) ? -latitude : latitude);
position.setLongitude(BitUtil.check(flags, 0) ? -longitude : longitude);
buf.readUnsignedInt();
buf.readUnsignedByte();
return position;
}
|
jhy-jsoup-d126488db626 | private String consumeSubQuery() {
StringBuilder sq = StringUtil.borrowBuilder();
while (!tq.isEmpty()) {
if (tq.matches("("))
sq.append("(").append(tq.chompBalanced('(', ')')).append(")");
else if (tq.matches("["))
sq.append("[").append(tq.chompBalanced('[', ']')).append("]");
else if (tq.matchesAny(Combinators))
if (sq.length() > 0)
break;
else
tq.consume();
else
sq.append(tq.consume());
}
return StringUtil.releaseBuilder(sq);
}
| private String consumeSubQuery() {
StringBuilder sq = StringUtil.borrowBuilder();
boolean seenNonCombinator = false;
while (!tq.isEmpty()) {
if (tq.matches("("))
sq.append("(").append(tq.chompBalanced('(', ')')).append(")");
else if (tq.matches("["))
sq.append("[").append(tq.chompBalanced('[', ']')).append("]");
else if (tq.matchesAny(Combinators))
if (seenNonCombinator)
break;
else
sq.append(tq.consume());
else {
seenNonCombinator = true;
sq.append(tq.consume());
}
}
return StringUtil.releaseBuilder(sq);
}
|
traccar-traccar-6f59f756a7d3 | private Position decodePosition(
Channel channel, DeviceSession deviceSession, ByteBuf buf, int type, int index, ByteBuf imei) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
if (header != 0x2727) {
buf.readUnsignedShort();
buf.readUnsignedShort();
buf.readUnsignedByte();
buf.readUnsignedShort();
position.set(Position.KEY_RSSI, BitUtil.to(buf.readUnsignedShort(), 7));
}
int status = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, BitUtil.to(status, 5));
if (header != 0x2727) {
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedShort();
int io = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(io, 14));
position.set("ac", BitUtil.check(io, 13));
position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 12));
position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 11));
if (type == MSG_GPS_2 || type == MSG_ALARM_2) {
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
buf.readUnsignedByte();
} else {
position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 7));
position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 8));
position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 9));
}
if (header != 0x2626) {
int adcCount = type == MSG_GPS_2 || type == MSG_ALARM_2 ? 5 : 2;
for (int i = 1; i <= adcCount; i++) {
String value = ByteBufUtil.hexDump(buf.readSlice(2));
if (!value.equals("ffff")) {
position.set(Position.PREFIX_ADC + i, Integer.parseInt(value) * 0.01);
}
}
}
}
int alarm = buf.readUnsignedByte();
position.set(Position.KEY_ALARM, header != 0x2727 ? decodeAlarm1(alarm) : decodeAlarm2(alarm));
position.set("alarmCode", alarm);
if (header != 0x2727) {
buf.readUnsignedByte();
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
int battery = BcdUtil.readInteger(buf, 2);
position.set(Position.KEY_BATTERY_LEVEL, battery > 0 ? battery : 100);
}
if (BitUtil.check(status, 6)) {
position.setValid(true);
position.setTime(readDate(buf));
position.setAltitude(buf.readFloatLE());
position.setLongitude(buf.readFloatLE());
position.setLatitude(buf.readFloatLE());
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
position.setCourse(buf.readUnsignedShort());
} else {
getLastLocation(position, readDate(buf));
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedShortLE();
if (mcc != 0xffff && mnc != 0xffff) {
Network network = new Network();
for (int i = 0; i < 3; i++) {
network.addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE()));
}
position.setNetwork(network);
}
}
if (header == 0x2727) {
byte[] accelerationBytes = new byte[5];
buf.readBytes(accelerationBytes);
long acceleration = new BigInteger(accelerationBytes).longValue();
double accelerationZ = BitUtil.between(acceleration, 8, 15) + BitUtil.between(acceleration, 4, 8) * 0.1;
if (!BitUtil.check(acceleration, 15)) {
accelerationZ = -accelerationZ;
}
double accelerationY = BitUtil.between(acceleration, 20, 27) + BitUtil.between(acceleration, 16, 20) * 0.1;
if (!BitUtil.check(acceleration, 27)) {
accelerationY = -accelerationY;
}
double accelerationX = BitUtil.between(acceleration, 28, 32) + BitUtil.between(acceleration, 32, 39) * 0.1;
if (!BitUtil.check(acceleration, 39)) {
accelerationX = -accelerationX;
}
position.set(Position.KEY_G_SENSOR, "[" + accelerationX + "," + accelerationY + "," + accelerationZ + "]");
int battery = BcdUtil.readInteger(buf, 2);
position.set(Position.KEY_BATTERY_LEVEL, battery > 0 ? battery : 100);
position.set(Position.KEY_DEVICE_TEMP, (int) buf.readByte());
position.set("lightSensor", BcdUtil.readInteger(buf, 2) * 0.1);
position.set(Position.KEY_BATTERY, BcdUtil.readInteger(buf, 2) * 0.1);
position.set("solarPanel", BcdUtil.readInteger(buf, 2) * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
int inputStatus = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(inputStatus, 2));
position.set(Position.KEY_RSSI, BitUtil.between(inputStatus, 4, 11));
position.set(Position.KEY_INPUT, inputStatus);
buf.readUnsignedShort();
buf.readUnsignedInt();
buf.readUnsignedByte();
buf.readUnsignedShort();
buf.readUnsignedByte();
} else {
if (buf.readableBytes() >= 2) {
position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
}
if (buf.readableBytes() >= 19) {
position.set(Position.KEY_OBD_SPEED, BcdUtil.readInteger(buf, 4) * 0.01);
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.001);
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt() * 0.001);
position.set(Position.KEY_RPM, buf.readUnsignedShort());
int value;
value = buf.readUnsignedByte();
if (value != 0xff) {
position.set("airInput", value);
}
if (value != 0xff) {
position.set("airPressure", value);
}
if (value != 0xff) {
position.set(Position.KEY_COOLANT_TEMP, value - 40);
}
if (value != 0xff) {
position.set("airTemp", value - 40);
}
if (value != 0xff) {
position.set(Position.KEY_ENGINE_LOAD, value);
}
if (value != 0xff) {
position.set(Position.KEY_THROTTLE, value);
}
if (value != 0xff) {
position.set(Position.KEY_FUEL_LEVEL, value);
}
}
}
boolean acknowledgement = AttributeUtil.lookup(
getCacheManager(), Keys.PROTOCOL_ACK.withPrefix(getProtocolName()), deviceSession.getDeviceId());
if (acknowledgement || type == MSG_ALARM || type == MSG_ALARM_2) {
sendResponse(channel, header, type, index, imei, alarm);
}
return position;
}
| private Position decodePosition(
Channel channel, DeviceSession deviceSession, ByteBuf buf, int type, int index, ByteBuf imei) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
if (header != 0x2727) {
buf.readUnsignedShort();
buf.readUnsignedShort();
buf.readUnsignedByte();
buf.readUnsignedShort();
position.set(Position.KEY_RSSI, BitUtil.to(buf.readUnsignedShort(), 7));
}
int status = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, BitUtil.to(status, 5));
if (header != 0x2727) {
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedShort();
int io = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(io, 14));
position.set("ac", BitUtil.check(io, 13));
position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 12));
position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 11));
if (type == MSG_GPS_2 || type == MSG_ALARM_2) {
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
buf.readUnsignedByte();
} else {
position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 7));
position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 8));
position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 9));
}
if (header != 0x2626) {
int adcCount = type == MSG_GPS_2 || type == MSG_ALARM_2 ? 5 : 2;
for (int i = 1; i <= adcCount; i++) {
String value = ByteBufUtil.hexDump(buf.readSlice(2));
if (!value.equals("ffff")) {
position.set(Position.PREFIX_ADC + i, Integer.parseInt(value, 16) * 0.01);
}
}
}
}
int alarm = buf.readUnsignedByte();
position.set(Position.KEY_ALARM, header != 0x2727 ? decodeAlarm1(alarm) : decodeAlarm2(alarm));
position.set("alarmCode", alarm);
if (header != 0x2727) {
buf.readUnsignedByte();
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
int battery = BcdUtil.readInteger(buf, 2);
position.set(Position.KEY_BATTERY_LEVEL, battery > 0 ? battery : 100);
}
if (BitUtil.check(status, 6)) {
position.setValid(true);
position.setTime(readDate(buf));
position.setAltitude(buf.readFloatLE());
position.setLongitude(buf.readFloatLE());
position.setLatitude(buf.readFloatLE());
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
position.setCourse(buf.readUnsignedShort());
} else {
getLastLocation(position, readDate(buf));
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedShortLE();
if (mcc != 0xffff && mnc != 0xffff) {
Network network = new Network();
for (int i = 0; i < 3; i++) {
network.addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE()));
}
position.setNetwork(network);
}
}
if (header == 0x2727) {
byte[] accelerationBytes = new byte[5];
buf.readBytes(accelerationBytes);
long acceleration = new BigInteger(accelerationBytes).longValue();
double accelerationZ = BitUtil.between(acceleration, 8, 15) + BitUtil.between(acceleration, 4, 8) * 0.1;
if (!BitUtil.check(acceleration, 15)) {
accelerationZ = -accelerationZ;
}
double accelerationY = BitUtil.between(acceleration, 20, 27) + BitUtil.between(acceleration, 16, 20) * 0.1;
if (!BitUtil.check(acceleration, 27)) {
accelerationY = -accelerationY;
}
double accelerationX = BitUtil.between(acceleration, 28, 32) + BitUtil.between(acceleration, 32, 39) * 0.1;
if (!BitUtil.check(acceleration, 39)) {
accelerationX = -accelerationX;
}
position.set(Position.KEY_G_SENSOR, "[" + accelerationX + "," + accelerationY + "," + accelerationZ + "]");
int battery = BcdUtil.readInteger(buf, 2);
position.set(Position.KEY_BATTERY_LEVEL, battery > 0 ? battery : 100);
position.set(Position.KEY_DEVICE_TEMP, (int) buf.readByte());
position.set("lightSensor", BcdUtil.readInteger(buf, 2) * 0.1);
position.set(Position.KEY_BATTERY, BcdUtil.readInteger(buf, 2) * 0.1);
position.set("solarPanel", BcdUtil.readInteger(buf, 2) * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
int inputStatus = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(inputStatus, 2));
position.set(Position.KEY_RSSI, BitUtil.between(inputStatus, 4, 11));
position.set(Position.KEY_INPUT, inputStatus);
buf.readUnsignedShort();
buf.readUnsignedInt();
buf.readUnsignedByte();
buf.readUnsignedShort();
buf.readUnsignedByte();
} else {
if (buf.readableBytes() >= 2) {
position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
}
if (buf.readableBytes() >= 19) {
position.set(Position.KEY_OBD_SPEED, BcdUtil.readInteger(buf, 4) * 0.01);
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.001);
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt() * 0.001);
position.set(Position.KEY_RPM, buf.readUnsignedShort());
int value;
value = buf.readUnsignedByte();
if (value != 0xff) {
position.set("airInput", value);
}
if (value != 0xff) {
position.set("airPressure", value);
}
if (value != 0xff) {
position.set(Position.KEY_COOLANT_TEMP, value - 40);
}
if (value != 0xff) {
position.set("airTemp", value - 40);
}
if (value != 0xff) {
position.set(Position.KEY_ENGINE_LOAD, value);
}
if (value != 0xff) {
position.set(Position.KEY_THROTTLE, value);
}
if (value != 0xff) {
position.set(Position.KEY_FUEL_LEVEL, value);
}
}
}
boolean acknowledgement = AttributeUtil.lookup(
getCacheManager(), Keys.PROTOCOL_ACK.withPrefix(getProtocolName()), deviceSession.getDeviceId());
if (acknowledgement || type == MSG_ALARM || type == MSG_ALARM_2) {
sendResponse(channel, header, type, index, imei, alarm);
}
return position;
}
|
traccar-traccar-105873ab5256 | @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte();
int flags = buf.readUnsignedByte();
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
int type = buf.readUnsignedByte();
if (BitUtil.check(flags, 4)) {
sendResponse(channel, remoteAddress, index, type, buf.slice());
}
if (type == MSG_DATA || type == MSG_SERVICES) {
List<Position> positions = new LinkedList<>();
Set<Integer> keys = new HashSet<>();
boolean hasLocation = false;
Position position = new Position(getProtocolName());
DeviceSession deviceSession = null;
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
if (keys.contains(key)) {
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
keys.clear();
hasLocation = false;
position = new Position(getProtocolName());
}
keys.add(key);
switch (key) {
case 0x01:
deviceSession = getDeviceSession(
channel, remoteAddress, buf.readCharSequence(15, StandardCharsets.US_ASCII).toString());
if (deviceSession == null) {
return null;
}
break;
case 0x02:
long alarm = buf.readUnsignedIntLE();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (BitUtil.check(alarm, 31)) {
position.set("bark", true);
}
break;
case 0x14:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
break;
case 0x20:
hasLocation = true;
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.setAltitude(buf.readShortLE());
int hdop = buf.readUnsignedShortLE();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x21:
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedByte();
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
position.getNetwork().addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi));
}
break;
case 0x22:
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.getNetwork().addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), rssi));
}
break;
case 0x23:
position.set("tagId", readTagId(buf));
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x24:
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
long status = buf.readUnsignedIntLE();
if (BitUtil.check(status, 4)) {
position.set(Position.KEY_CHARGE, true);
}
if (BitUtil.check(status, 7)) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_MOTION, BitUtil.check(status, 9));
position.set(Position.KEY_RSSI, BitUtil.between(status, 19, 24));
position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(status, 24));
position.set(Position.KEY_STATUS, status);
break;
case 0x28:
int beaconFlags = buf.readUnsignedByte();
position.set("tagId", readTagId(buf));
position.set("tagRssi", (int) buf.readByte());
position.set("tag1mRssi", (int) buf.readByte());
if (BitUtil.check(beaconFlags, 7)) {
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
}
if (BitUtil.check(beaconFlags, 6)) {
position.set("description", buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString());
}
break;
case 0x2A:
buf.readUnsignedByte();
buf.skipBytes(6);
buf.readUnsignedByte();
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x30:
buf.readUnsignedIntLE();
position.set(Position.KEY_STEPS, buf.readUnsignedIntLE());
break;
case 0x31:
int i = 1;
while (buf.readerIndex() < endIndex) {
position.set("activity" + i + "Time", buf.readUnsignedIntLE());
position.set("activity" + i, buf.readUnsignedIntLE());
i += 1;
}
break;
case 0x37:
buf.readUnsignedIntLE();
long barking = buf.readUnsignedIntLE();
if (BitUtil.check(barking, 31)) {
position.set("barkStop", true);
}
position.set("barkCount", BitUtil.to(barking, 31));
break;
case 0x40:
buf.readUnsignedIntLE();
int heartRate = buf.readUnsignedByte();
if (heartRate > 1) {
position.set(Position.KEY_HEART_RATE, heartRate);
}
break;
default:
break;
}
buf.readerIndex(endIndex);
}
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
if (deviceSession != null) {
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
}
} else {
return null;
}
return positions;
}
return null;
}
| @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte();
int flags = buf.readUnsignedByte();
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
int type = buf.readUnsignedByte();
if (BitUtil.check(flags, 4)) {
sendResponse(channel, remoteAddress, index, type, buf.slice());
}
if (type == MSG_DATA || type == MSG_SERVICES) {
List<Position> positions = new LinkedList<>();
Set<Integer> keys = new HashSet<>();
boolean hasLocation = false;
Position position = new Position(getProtocolName());
DeviceSession deviceSession = null;
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
if (keys.contains(key)) {
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
keys.clear();
hasLocation = false;
position = new Position(getProtocolName());
}
keys.add(key);
switch (key) {
case 0x01:
deviceSession = getDeviceSession(
channel, remoteAddress, buf.readCharSequence(15, StandardCharsets.US_ASCII).toString());
if (deviceSession == null) {
return null;
}
break;
case 0x02:
long alarm = buf.readUnsignedIntLE();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (BitUtil.check(alarm, 31)) {
position.set("bark", true);
}
break;
case 0x14:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
break;
case 0x20:
hasLocation = true;
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.setAltitude(buf.readShortLE());
int hdop = buf.readUnsignedShortLE();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x21:
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedByte();
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
position.getNetwork().addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi));
}
break;
case 0x22:
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.getNetwork().addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), rssi));
}
break;
case 0x23:
position.set("tagId", readTagId(buf));
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x24:
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
long status = buf.readUnsignedIntLE();
if (BitUtil.check(status, 4)) {
position.set(Position.KEY_CHARGE, true);
}
if (BitUtil.check(status, 7)) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_MOTION, BitUtil.check(status, 9));
position.set(Position.KEY_RSSI, BitUtil.between(status, 19, 24));
position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(status, 24));
position.set(Position.KEY_STATUS, status);
break;
case 0x28:
int beaconFlags = buf.readUnsignedByte();
position.set("tagId", readTagId(buf));
position.set("tagRssi", (int) buf.readByte());
position.set("tag1mRssi", (int) buf.readByte());
if (BitUtil.check(beaconFlags, 7)) {
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
}
if (BitUtil.check(beaconFlags, 6)) {
position.set("description", buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString());
}
break;
case 0x2A:
buf.readUnsignedByte();
buf.skipBytes(6);
buf.readUnsignedByte();
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x30:
buf.readUnsignedIntLE();
position.set(Position.KEY_STEPS, buf.readUnsignedIntLE());
break;
case 0x31:
int i = 1;
while (buf.readerIndex() < endIndex) {
position.set("activity" + i + "Time", buf.readUnsignedIntLE());
position.set("activity" + i, buf.readUnsignedIntLE());
i += 1;
}
break;
case 0x37:
buf.readUnsignedIntLE();
long barking = buf.readUnsignedIntLE();
if (BitUtil.check(barking, 31)) {
position.set("barkStop", true);
}
position.set("barkCount", BitUtil.to(barking, 31));
break;
case 0x40:
buf.readUnsignedIntLE();
int heartRate = buf.readUnsignedByte();
if (heartRate > 1) {
position.set(Position.KEY_HEART_RATE, heartRate);
}
break;
default:
break;
}
buf.readerIndex(endIndex);
}
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
if (deviceSession != null) {
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
}
} else {
return null;
}
return positions;
} else if (type == MSG_RESPONSE) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
buf.readUnsignedByte();
position.set(Position.KEY_RESULT, String.valueOf(buf.readUnsignedByte()));
return position;
}
return null;
}
|
traccar-traccar-1b8993293646 | private Object decodeLocationNew(
Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_NEW, sentence);
if (!parser.matches()) {
return null;
}
String imei = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
String index = parser.next();
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt()));
position.setDeviceTime(parser.nextDateTime());
Network network = new Network();
network.addCellTower(CellTower.from(
parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt()));
position.set(Position.KEY_BATTERY, parser.nextDouble());
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_STATUS, parser.nextHexInt());
if (parser.hasNext(5)) {
position.setValid(parser.next().equals("A"));
position.setFixTime(position.getDeviceTime());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
} else {
String[] points = parser.next().split("\\|");
for (String point : points) {
String[] wifi = point.split(":");
String mac = wifi[0].replaceAll("(..)", "$1:");
network.addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), Integer.parseInt(wifi[1])));
}
}
position.setNetwork(network);
DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String response = index + ",A03," + dateFormat.format(new Date());
sendResponse(channel, remoteAddress, imei, response);
return position;
}
| private Object decodeLocationNew(
Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_NEW, sentence);
if (!parser.matches()) {
return null;
}
String imei = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
String index = parser.next();
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt()));
position.setDeviceTime(parser.nextDateTime());
Network network = new Network();
network.addCellTower(CellTower.from(
parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt()));
position.set(Position.KEY_BATTERY, parser.nextDouble());
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_STATUS, parser.nextHexInt());
if (parser.hasNext(5)) {
position.setValid(parser.next().equals("A"));
position.setFixTime(position.getDeviceTime());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
} else {
String[] points = parser.next().split("\\|");
for (String point : points) {
String[] wifi = point.split(":");
String mac = wifi[0].replaceAll("(..)", "$1:");
network.addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), Integer.parseInt(wifi[1])));
}
}
position.setNetwork(network);
DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String response = index + ",A03," + dateFormat.format(new Date());
sendResponse(channel, remoteAddress, imei, response);
return position;
}
|
revelc-formatter-maven-plugin-3e9843d2ab99 | @Override
protected String doFormat(final String code, final LineEnding ending) throws IOException {
final var source = new InputSource(new StringReader(code));
final var parser = new CSSOMParser(new SACParserCSS3());
final var sheet = (CSSStyleSheetImpl) parser.parseStyleSheet(source, null, null);
var formattedCode = sheet.getCssText(this.formatter);
formattedCode = formattedCode.replace("\t;", "\\9;");
if (code.equals(formattedCode)) {
return null;
}
return formattedCode;
}
| @Override
protected String doFormat(final String code, final LineEnding ending) throws IOException {
final var source = new InputSource(new StringReader(code));
final var parser = new CSSOMParser(new SACParserCSS3());
final var sheet = (CSSStyleSheetImpl) parser.parseStyleSheet(source, null, null);
var formattedCode = sheet.getCssText(this.formatter);
formattedCode = formattedCode.replace("\t;", "\\9;");
String[] lines = formattedCode.split(ending.getChars());
if (!lines[lines.length - 1].equals(ending.getChars())) {
formattedCode = formattedCode + ending.getChars();
}
if (code.equals(formattedCode)) {
return null;
}
return formattedCode;
}
|
traccar-traccar-3b6900a95342 | @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte();
int flags = buf.readUnsignedByte();
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
int type = buf.readUnsignedByte();
if (BitUtil.check(flags, 4)) {
sendResponse(channel, remoteAddress, index, type, buf);
}
if (type == MSG_DATA) {
List<Position> positions = new LinkedList<>();
Set<Integer> keys = new HashSet<>();
boolean hasLocation = false;
Position position = new Position(getProtocolName());
DeviceSession deviceSession = null;
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
if (keys.contains(key)) {
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
keys.clear();
hasLocation = false;
position = new Position(getProtocolName());
}
keys.add(key);
switch (key) {
case 0x01:
deviceSession = getDeviceSession(
channel, remoteAddress, buf.readCharSequence(15, StandardCharsets.US_ASCII).toString());
position.setDeviceId(deviceSession.getDeviceId());
break;
case 0x02:
long alarm = buf.readUnsignedIntLE();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (BitUtil.check(alarm, 31)) {
position.set("bark", true);
}
break;
case 0x14:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
break;
case 0x20:
hasLocation = true;
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.setAltitude(buf.readShortLE());
int hdop = buf.readUnsignedShortLE();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x21:
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedByte();
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
position.getNetwork().addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi));
}
break;
case 0x22:
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.getNetwork().addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), rssi));
}
break;
case 0x23:
position.set("tagId", readTagId(buf));
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x24:
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
long status = buf.readUnsignedIntLE();
if (BitUtil.check(status, 4)) {
position.set(Position.KEY_CHARGE, true);
}
if (BitUtil.check(status, 7)) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_MOTION, BitUtil.check(status, 9));
position.set(Position.KEY_RSSI, BitUtil.between(status, 19, 24));
position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(status, 24));
position.set(Position.KEY_STATUS, status);
break;
case 0x28:
int beaconFlags = buf.readUnsignedByte();
position.set("tagId", readTagId(buf));
position.set("tagRssi", (int) buf.readByte());
position.set("tag1mRssi", (int) buf.readByte());
if (BitUtil.check(beaconFlags, 7)) {
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
}
if (BitUtil.check(beaconFlags, 6)) {
position.set("description", buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString());
}
break;
case 0x2A:
buf.readUnsignedByte();
buf.skipBytes(6);
buf.readUnsignedByte();
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x30:
buf.readUnsignedIntLE();
position.set(Position.KEY_STEPS, buf.readUnsignedIntLE());
break;
case 0x31:
int i = 1;
while (buf.readerIndex() < endIndex) {
position.set("activity" + i + "Time", buf.readUnsignedIntLE());
position.set("activity" + i, buf.readUnsignedIntLE());
i += 1;
}
break;
case 0x37:
buf.readUnsignedIntLE();
long barking = buf.readUnsignedIntLE();
if (BitUtil.check(barking, 31)) {
position.set("barkStop", true);
}
position.set("barkCount", BitUtil.to(barking, 31));
break;
case 0x40:
buf.readUnsignedIntLE();
int heartRate = buf.readUnsignedByte();
if (heartRate > 1) {
position.set(Position.KEY_HEART_RATE, heartRate);
}
break;
default:
break;
}
buf.readerIndex(endIndex);
}
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
if (deviceSession != null) {
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
}
} else {
return null;
}
return positions;
}
return null;
}
| @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte();
int flags = buf.readUnsignedByte();
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
int type = buf.readUnsignedByte();
if (BitUtil.check(flags, 4)) {
sendResponse(channel, remoteAddress, index, type, buf);
}
if (type == MSG_DATA || type == MSG_SERVICES) {
List<Position> positions = new LinkedList<>();
Set<Integer> keys = new HashSet<>();
boolean hasLocation = false;
Position position = new Position(getProtocolName());
DeviceSession deviceSession = null;
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
if (keys.contains(key)) {
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
keys.clear();
hasLocation = false;
position = new Position(getProtocolName());
}
keys.add(key);
switch (key) {
case 0x01:
deviceSession = getDeviceSession(
channel, remoteAddress, buf.readCharSequence(15, StandardCharsets.US_ASCII).toString());
position.setDeviceId(deviceSession.getDeviceId());
break;
case 0x02:
long alarm = buf.readUnsignedIntLE();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (BitUtil.check(alarm, 31)) {
position.set("bark", true);
}
break;
case 0x14:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
break;
case 0x20:
hasLocation = true;
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.setAltitude(buf.readShortLE());
int hdop = buf.readUnsignedShortLE();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x21:
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedByte();
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
position.getNetwork().addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi));
}
break;
case 0x22:
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.getNetwork().addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), rssi));
}
break;
case 0x23:
position.set("tagId", readTagId(buf));
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x24:
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
long status = buf.readUnsignedIntLE();
if (BitUtil.check(status, 4)) {
position.set(Position.KEY_CHARGE, true);
}
if (BitUtil.check(status, 7)) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_MOTION, BitUtil.check(status, 9));
position.set(Position.KEY_RSSI, BitUtil.between(status, 19, 24));
position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(status, 24));
position.set(Position.KEY_STATUS, status);
break;
case 0x28:
int beaconFlags = buf.readUnsignedByte();
position.set("tagId", readTagId(buf));
position.set("tagRssi", (int) buf.readByte());
position.set("tag1mRssi", (int) buf.readByte());
if (BitUtil.check(beaconFlags, 7)) {
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
}
if (BitUtil.check(beaconFlags, 6)) {
position.set("description", buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString());
}
break;
case 0x2A:
buf.readUnsignedByte();
buf.skipBytes(6);
buf.readUnsignedByte();
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x30:
buf.readUnsignedIntLE();
position.set(Position.KEY_STEPS, buf.readUnsignedIntLE());
break;
case 0x31:
int i = 1;
while (buf.readerIndex() < endIndex) {
position.set("activity" + i + "Time", buf.readUnsignedIntLE());
position.set("activity" + i, buf.readUnsignedIntLE());
i += 1;
}
break;
case 0x37:
buf.readUnsignedIntLE();
long barking = buf.readUnsignedIntLE();
if (BitUtil.check(barking, 31)) {
position.set("barkStop", true);
}
position.set("barkCount", BitUtil.to(barking, 31));
break;
case 0x40:
buf.readUnsignedIntLE();
int heartRate = buf.readUnsignedByte();
if (heartRate > 1) {
position.set(Position.KEY_HEART_RATE, heartRate);
}
break;
default:
break;
}
buf.readerIndex(endIndex);
}
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
if (deviceSession != null) {
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
}
} else {
return null;
}
return positions;
}
return null;
}
|
retel-io-ari-proxy-610e9b6725e1 | public static Try<Done> registerCallContext(
final ActorRef<CallContextProviderMessage> callContextProvider,
final String callContext,
final AriCommand ariCommand) {
if (!ariCommand.extractCommandType().isCreationCommand()) {
return Try.success(Done.done());
}
final Option<AriResource> maybeResource =
ariCommand
.extractResourceRelations()
.find(AriResourceRelation::isCreated)
.map(AriResourceRelation::getResource);
if (maybeResource.isEmpty()) {
return Try.failure(
new RuntimeException(
String.format(
"Failed to extract resourceId from command '%s'", ariCommand.toString())));
}
final AriResource resource = maybeResource.get();
callContextProvider.tell(new RegisterCallContext(resource.getId(), callContext));
return Try.success(Done.done());
}
| public static Try<Done> registerCallContext(
final ActorRef<CallContextProviderMessage> callContextProvider,
final String callContext,
final AriCommand ariCommand) {
if (!(ariCommand.extractCommandType().isCreationCommand()
&& "POST".equals(ariCommand.getMethod()))) {
return Try.success(Done.done());
}
final Option<AriResource> maybeResource =
ariCommand
.extractResourceRelations()
.find(AriResourceRelation::isCreated)
.map(AriResourceRelation::getResource);
if (maybeResource.isEmpty()) {
return Try.failure(
new RuntimeException(
String.format(
"Failed to extract resourceId from command '%s'", ariCommand.toString())));
}
final AriResource resource = maybeResource.get();
callContextProvider.tell(new RegisterCallContext(resource.getId(), callContext));
return Try.success(Done.done());
}
|
spring-projects-spring-retry-e6091f790c64 | public BackOffPolicy build() {
if (this.multiplier != null && this.multiplier > 0 || this.multiplierSupplier != null) {
ExponentialBackOffPolicy policy;
if (Boolean.TRUE.equals(this.random)) {
policy = new ExponentialRandomBackOffPolicy();
}
else {
policy = new ExponentialBackOffPolicy();
}
if (this.delay != null) {
policy.setInitialInterval(this.delay);
}
if (this.delaySupplier != null) {
policy.initialIntervalSupplier(this.delaySupplier);
}
if (this.multiplier != null) {
policy.setMultiplier(this.multiplier);
}
if (this.multiplierSupplier != null) {
policy.multiplierSupplier(this.multiplierSupplier);
}
if (this.maxDelay != null && this.delay != null) {
policy.setMaxInterval(
this.maxDelay > this.delay ? this.maxDelay : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL);
}
if (this.maxDelaySupplier != null) {
policy.maxIntervalSupplier(this.maxDelaySupplier);
}
if (this.sleeper != null) {
policy.setSleeper(this.sleeper);
}
return policy;
}
if (this.maxDelay != null && this.delay != null && this.maxDelay > this.delay) {
UniformRandomBackOffPolicy policy = new UniformRandomBackOffPolicy();
if (this.delay != null) {
policy.setMinBackOffPeriod(this.delay);
}
if (this.delaySupplier != null) {
policy.minBackOffPeriodSupplier(this.delaySupplier);
}
if (this.maxDelay != null) {
policy.setMaxBackOffPeriod(this.maxDelay);
}
if (this.maxDelaySupplier != null) {
policy.maxBackOffPeriodSupplier(this.maxDelaySupplier);
}
if (this.sleeper != null) {
policy.setSleeper(this.sleeper);
}
return policy;
}
FixedBackOffPolicy policy = new FixedBackOffPolicy();
if (this.delay != null) {
policy.setBackOffPeriod(this.delay);
}
if (this.sleeper != null) {
policy.setSleeper(this.sleeper);
}
return policy;
}
| public BackOffPolicy build() {
if (this.multiplier != null && this.multiplier > 0 || this.multiplierSupplier != null) {
ExponentialBackOffPolicy policy;
if (Boolean.TRUE.equals(this.random)) {
policy = new ExponentialRandomBackOffPolicy();
}
else {
policy = new ExponentialBackOffPolicy();
}
if (this.delay != null) {
policy.setInitialInterval(this.delay);
}
if (this.delaySupplier != null) {
policy.initialIntervalSupplier(this.delaySupplier);
}
if (this.multiplier != null) {
policy.setMultiplier(this.multiplier);
}
if (this.multiplierSupplier != null) {
policy.multiplierSupplier(this.multiplierSupplier);
}
if (this.maxDelay != null && this.delay != null) {
policy.setMaxInterval(
this.maxDelay > this.delay ? this.maxDelay : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL);
}
if (this.maxDelaySupplier != null) {
policy.maxIntervalSupplier(this.maxDelaySupplier);
}
if (this.sleeper != null) {
policy.setSleeper(this.sleeper);
}
return policy;
}
if (this.maxDelay != null && this.delay != null && this.maxDelay > this.delay) {
UniformRandomBackOffPolicy policy = new UniformRandomBackOffPolicy();
if (this.delay != null) {
policy.setMinBackOffPeriod(this.delay);
}
if (this.delaySupplier != null) {
policy.minBackOffPeriodSupplier(this.delaySupplier);
}
if (this.maxDelay != null) {
policy.setMaxBackOffPeriod(this.maxDelay);
}
if (this.maxDelaySupplier != null) {
policy.maxBackOffPeriodSupplier(this.maxDelaySupplier);
}
if (this.sleeper != null) {
policy.setSleeper(this.sleeper);
}
return policy;
}
FixedBackOffPolicy policy = new FixedBackOffPolicy();
if (this.delaySupplier != null) {
policy.backOffPeriodSupplier(this.delaySupplier);
}
else if (this.delay != null) {
policy.setBackOffPeriod(this.delay);
}
if (this.sleeper != null) {
policy.setSleeper(this.sleeper);
}
return policy;
}
|
jhy-jsoup-1e69577e358c | URL build() {
try {
URI uri = new URI(
u.getProtocol(),
u.getUserInfo(),
IDN.toASCII(decodePart(u.getHost())),
u.getPort(),
decodePart(u.getPath()),
null, null
);
String normUrl = uri.toASCIIString();
if (q != null || u.getRef() != null) {
StringBuilder sb = StringUtil.borrowBuilder().append(normUrl);
if (q != null) {
sb.append('?');
appendToAscii(StringUtil.releaseBuilder(q), true, sb);
}
if (u.getRef() != null) {
sb.append('#');
appendToAscii(u.getRef(), false, sb);
}
normUrl = StringUtil.releaseBuilder(sb);
}
u = new URL(normUrl);
return u;
} catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) {
assert Validate.assertFail(e.toString());
return u;
}
}
| URL build() {
try {
URI uri = new URI(
u.getProtocol(),
u.getUserInfo(),
IDN.toASCII(decodePart(u.getHost())),
u.getPort(),
null, null, null
);
StringBuilder normUrl = StringUtil.borrowBuilder().append(uri.toASCIIString());
appendToAscii(u.getPath(), false, normUrl);
if (q != null) {
normUrl.append('?');
appendToAscii(StringUtil.releaseBuilder(q), true, normUrl);
}
if (u.getRef() != null) {
normUrl.append('#');
appendToAscii(u.getRef(), false, normUrl);
}
u = new URL(StringUtil.releaseBuilder(normUrl));
return u;
} catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) {
assert Validate.assertFail(e.toString());
return u;
}
}
|
traccar-traccar-b77131f4be38 | @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.skipBytes(1);
manufacturer = buf.readSlice(2).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1);
int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
String id = buf.readSlice(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
buf.skipBytes(1);
String index = null;
int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
if (contentIndex + 5 < buf.writerIndex() && buf.getByte(contentIndex + 5) == '*'
&& buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
hasIndex = true;
index = buf.readSlice(indexLength).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1);
}
buf.skipBytes(4);
buf.skipBytes(1);
buf.writerIndex(buf.writerIndex() - 1);
contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
if (contentIndex < 0) {
contentIndex = buf.writerIndex();
}
String type = buf.readSlice(contentIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
if (contentIndex < buf.writerIndex()) {
buf.readerIndex(contentIndex + 1);
}
if (type.equals("INIT")) {
sendResponse(channel, id, index, "INIT,1");
} else if (type.equals("LK")) {
sendResponse(channel, id, index, "LK");
if (buf.isReadable()) {
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
if (values.length >= 3) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[2]));
position.set(Position.KEY_STEPS, Integer.parseInt(values[0]));
return position;
}
}
} else if (type.startsWith("UD") || type.startsWith("AL") || type.startsWith("WT")) {
Position position = decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII));
if (type.startsWith("AL")) {
if (position != null) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
sendResponse(channel, id, index, "AL");
}
return position;
} else if (type.equals("TKQ") || type.equals("TKQ2")) {
sendResponse(channel, id, index, type);
} else if (type.equalsIgnoreCase("PULSE")
|| type.equalsIgnoreCase("HEART")
|| type.equalsIgnoreCase("BLOOD")
|| type.equalsIgnoreCase("BPHRT")
|| type.equalsIgnoreCase("btemp2")) {
if (buf.isReadable()) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, new Date());
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
int valueIndex = 0;
if (type.equalsIgnoreCase("btemp2")) {
if (Integer.parseInt(values[valueIndex++]) > 0) {
position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex]));
}
} else {
if (type.equalsIgnoreCase("BPHRT") || type.equalsIgnoreCase("BLOOD")) {
position.set("pressureHigh", values[valueIndex++]);
position.set("pressureLow", values[valueIndex++]);
}
if (valueIndex <= values.length - 1) {
position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[valueIndex]));
}
}
return position;
}
} else if (type.equals("img")) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
int timeIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
buf.readerIndex(timeIndex + 12 + 2);
position.set(Position.KEY_IMAGE, writeMediaFile(id, buf, "jpg"));
return position;
} else if (type.equals("JXTK")) {
int dataIndex = BufferUtil.indexOf(buf, buf.readerIndex(), buf.writerIndex(), (byte) ',', 4) + 1;
String[] values = buf.readCharSequence(
dataIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString().split(",");
int current = Integer.parseInt(values[2]);
int total = Integer.parseInt(values[3]);
if (audio == null) {
audio = Unpooled.buffer();
}
audio.writeBytes(buf);
sendResponse(channel, id, index, "JXTKR,1");
if (current < total) {
return null;
} else {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_AUDIO, writeMediaFile(id, audio, "amr"));
audio.release();
audio = null;
return position;
}
} else if (type.equals("TK")) {
if (buf.readableBytes() == 1) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_AUDIO, writeMediaFile(id, buf, "amr"));
return position;
}
return null;
}
| @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.skipBytes(1);
manufacturer = buf.readSlice(2).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1);
int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
String id = buf.readSlice(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
buf.skipBytes(1);
String index = null;
int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
if (contentIndex + 5 < buf.writerIndex() && buf.getByte(contentIndex + 5) == '*'
&& buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
hasIndex = true;
index = buf.readSlice(indexLength).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1);
}
buf.skipBytes(4);
buf.skipBytes(1);
buf.writerIndex(buf.writerIndex() - 1);
contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
if (contentIndex < 0) {
contentIndex = buf.writerIndex();
}
String type = buf.readSlice(contentIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
if (contentIndex < buf.writerIndex()) {
buf.readerIndex(contentIndex + 1);
}
if (type.equals("INIT")) {
sendResponse(channel, id, index, "INIT,1");
} else if (type.equals("LK")) {
sendResponse(channel, id, index, "LK");
if (buf.isReadable()) {
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
if (values.length >= 3) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[2]));
position.set(Position.KEY_STEPS, Integer.parseInt(values[0]));
return position;
}
}
} else if (type.startsWith("UD") || type.startsWith("AL") || type.startsWith("WT")) {
Position position = decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII));
if (type.startsWith("AL")) {
if (position != null && !position.hasAttribute(Position.KEY_ALARM)) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
sendResponse(channel, id, index, "AL");
}
return position;
} else if (type.equals("TKQ") || type.equals("TKQ2")) {
sendResponse(channel, id, index, type);
} else if (type.equalsIgnoreCase("PULSE")
|| type.equalsIgnoreCase("HEART")
|| type.equalsIgnoreCase("BLOOD")
|| type.equalsIgnoreCase("BPHRT")
|| type.equalsIgnoreCase("TEMP")
|| type.equalsIgnoreCase("btemp2")) {
if (buf.isReadable()) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, new Date());
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
int valueIndex = 0;
if (type.equalsIgnoreCase("TEMP")) {
position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex]));
} else if (type.equalsIgnoreCase("btemp2")) {
if (Integer.parseInt(values[valueIndex++]) > 0) {
position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex]));
}
} else {
if (type.equalsIgnoreCase("BPHRT") || type.equalsIgnoreCase("BLOOD")) {
position.set("pressureHigh", values[valueIndex++]);
position.set("pressureLow", values[valueIndex++]);
}
if (valueIndex <= values.length - 1) {
position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[valueIndex]));
}
}
return position;
}
} else if (type.equals("img")) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
int timeIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
buf.readerIndex(timeIndex + 12 + 2);
position.set(Position.KEY_IMAGE, writeMediaFile(id, buf, "jpg"));
return position;
} else if (type.equals("JXTK")) {
int dataIndex = BufferUtil.indexOf(buf, buf.readerIndex(), buf.writerIndex(), (byte) ',', 4) + 1;
String[] values = buf.readCharSequence(
dataIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString().split(",");
int current = Integer.parseInt(values[2]);
int total = Integer.parseInt(values[3]);
if (audio == null) {
audio = Unpooled.buffer();
}
audio.writeBytes(buf);
sendResponse(channel, id, index, "JXTKR,1");
if (current < total) {
return null;
} else {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_AUDIO, writeMediaFile(id, audio, "amr"));
audio.release();
audio = null;
return position;
}
} else if (type.equals("TK")) {
if (buf.readableBytes() == 1) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_AUDIO, writeMediaFile(id, buf, "amr"));
return position;
}
return null;
}
|
traccar-traccar-6e5481ebb185 | private boolean decodeLbs(Position position, ByteBuf buf, int type, boolean hasLength) {
int length = 0;
if (hasLength) {
length = buf.readUnsignedByte();
if (length == 0) {
boolean zeroedData = true;
for (int i = buf.readerIndex() + 9; i < buf.readerIndex() + 45 && i < buf.writerIndex(); i++) {
if (buf.getByte(i) != 0) {
zeroedData = false;
break;
}
}
if (zeroedData) {
buf.skipBytes(Math.min(buf.readableBytes(), 45));
}
return false;
}
}
int mcc = buf.readUnsignedShort();
int mnc;
if (BitUtil.check(mcc, 15) || type == MSG_GPS_LBS_6) {
mnc = buf.readUnsignedShort();
} else {
mnc = buf.readUnsignedByte();
}
int lac;
if (type == MSG_LBS_ALARM) {
lac = buf.readInt();
} else {
lac = buf.readUnsignedShort();
}
long cid;
if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7) {
cid = buf.readLong();
} else if (type == MSG_GPS_LBS_6) {
cid = buf.readUnsignedInt();
} else {
cid = buf.readUnsignedMedium();
}
position.setNetwork(new Network(CellTower.from(BitUtil.to(mcc, 15), mnc, lac, cid)));
if (length > 9) {
buf.skipBytes(length - 9);
}
return true;
}
| private boolean decodeLbs(Position position, ByteBuf buf, int type, boolean hasLength) {
int length = 0;
if (hasLength) {
length = buf.readUnsignedByte();
if (length == 0) {
boolean zeroedData = true;
for (int i = buf.readerIndex() + 9; i < buf.readerIndex() + 45 && i < buf.writerIndex(); i++) {
if (buf.getByte(i) != 0) {
zeroedData = false;
break;
}
}
if (zeroedData) {
buf.skipBytes(Math.min(buf.readableBytes(), 45));
}
return false;
}
}
int mcc = buf.readUnsignedShort();
int mnc;
if (BitUtil.check(mcc, 15) || type == MSG_GPS_LBS_6) {
mnc = buf.readUnsignedShort();
} else {
mnc = buf.readUnsignedByte();
}
int lac;
if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7) {
lac = buf.readInt();
} else {
lac = buf.readUnsignedShort();
}
long cid;
if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7) {
cid = buf.readLong();
} else if (type == MSG_GPS_LBS_6) {
cid = buf.readUnsignedInt();
} else {
cid = buf.readUnsignedMedium();
}
position.setNetwork(new Network(CellTower.from(BitUtil.to(mcc, 15), mnc, lac, cid)));
if (length > 9) {
buf.skipBytes(length - 9);
}
return true;
}
|
traccar-traccar-413d9a49c41a | private Position decodePosition(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int index) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 15));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
int event = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString();
DateBuilder dateBuilder = new DateBuilder()
.setYear(Integer.parseInt(time.substring(0, 2)))
.setMonth(Integer.parseInt(time.substring(2, 4)))
.setDay(Integer.parseInt(time.substring(4, 6)))
.setHour(Integer.parseInt(time.substring(6, 8)))
.setMinute(Integer.parseInt(time.substring(8, 10)))
.setSecond(Integer.parseInt(time.substring(10, 12)));
position.setTime(dateBuilder.getDate());
position.setLongitude(buf.readInt() * 0.00001);
position.setLatitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
Network network = new Network();
while (buf.readableBytes() > 4) {
int subtype = buf.readUnsignedShort();
int length = buf.readUnsignedShort() - 4;
int endIndex = buf.readerIndex() + length;
switch (subtype) {
case 0x0001:
int coolantTemperature = buf.readUnsignedByte() - 40;
if (coolantTemperature <= 215) {
position.set(Position.KEY_COOLANT_TEMP, coolantTemperature);
}
int rpm = buf.readUnsignedShort();
if (rpm <= 65535) {
position.set(Position.KEY_RPM, rpm);
}
position.set("averageSpeed", buf.readUnsignedByte());
buf.readUnsignedShort();
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
buf.readUnsignedInt();
if (buf.readerIndex() < endIndex) {
position.set("adBlueLevel", buf.readUnsignedByte() * 0.4);
}
break;
case 0x0005:
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
buf.readUnsignedInt();
break;
case 0x0009:
position.set(
Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
break;
case 0x0011:
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 0.05);
break;
case 0x0014:
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() / 255.0);
position.set("timingAdvance", buf.readUnsignedByte() * 0.5);
position.set("airTemp", buf.readUnsignedByte() - 40);
position.set("airFlow", buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() / 255.0);
break;
case 0x0020:
String[] cells = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String cell : cells) {
String[] values = cell.split("@");
network.addCellTower(CellTower.from(
Integer.parseInt(values[0]), Integer.parseInt(values[1]),
Integer.parseInt(values[2], 16), Long.parseLong(values[3], 16)));
}
break;
case 0x0021:
String[] points = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String point : points) {
String[] values = point.split("@");
network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
}
break;
default:
buf.skipBytes(length);
break;
}
buf.readerIndex(endIndex);
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
sendResponse(channel, MSG_POSITION_RSP, index, null);
return position;
}
| private Position decodePosition(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int index) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 15));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
int event = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString();
DateBuilder dateBuilder = new DateBuilder()
.setYear(Integer.parseInt(time.substring(0, 2)))
.setMonth(Integer.parseInt(time.substring(2, 4)))
.setDay(Integer.parseInt(time.substring(4, 6)))
.setHour(Integer.parseInt(time.substring(6, 8)))
.setMinute(Integer.parseInt(time.substring(8, 10)))
.setSecond(Integer.parseInt(time.substring(10, 12)));
position.setTime(dateBuilder.getDate());
position.setLongitude(buf.readInt() * 0.00001);
position.setLatitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readUnsignedShort());
buf.readUnsignedShort();
Network network = new Network();
while (buf.readableBytes() > 4) {
int subtype = buf.readUnsignedShort();
int length = buf.readUnsignedShort() - 4;
int endIndex = buf.readerIndex() + length;
switch (subtype) {
case 0x0001:
int coolantTemperature = buf.readUnsignedByte() - 40;
if (coolantTemperature <= 215) {
position.set(Position.KEY_COOLANT_TEMP, coolantTemperature);
}
int rpm = buf.readUnsignedShort();
if (rpm <= 65535) {
position.set(Position.KEY_RPM, rpm);
}
position.set("averageSpeed", buf.readUnsignedByte());
buf.readUnsignedShort();
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
buf.readUnsignedInt();
if (buf.readerIndex() < endIndex) {
position.set("adBlueLevel", buf.readUnsignedByte() * 0.4);
}
break;
case 0x0005:
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
buf.readUnsignedInt();
break;
case 0x0009:
position.set(Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
break;
case 0x0010:
position.set(Position.KEY_ODOMETER, Double.parseDouble(
buf.readCharSequence(length, StandardCharsets.US_ASCII).toString()) * 1000);
break;
case 0x0011:
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 0.05);
break;
case 0x0014:
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() / 255.0);
position.set("timingAdvance", buf.readUnsignedByte() * 0.5);
position.set("airTemp", buf.readUnsignedByte() - 40);
position.set("airFlow", buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() / 255.0);
break;
case 0x0020:
String[] cells = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String cell : cells) {
String[] values = cell.split("@");
network.addCellTower(CellTower.from(
Integer.parseInt(values[0]), Integer.parseInt(values[1]),
Integer.parseInt(values[2], 16), Long.parseLong(values[3], 16)));
}
break;
case 0x0021:
String[] points = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String point : points) {
String[] values = point.split("@");
network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
}
break;
default:
buf.skipBytes(length);
break;
}
buf.readerIndex(endIndex);
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
sendResponse(channel, MSG_POSITION_RSP, index, null);
return position;
}
|
traccar-traccar-2749e520c9ea | private Position decodeLocation2(DeviceSession deviceSession, ByteBuf buf, int type) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
Jt600ProtocolDecoder.decodeBinaryLocation(buf, position);
position.setValid(type != MSG_LOCATION_REPORT_BLIND);
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000L);
int battery = buf.readUnsignedByte();
if (battery <= 100) {
position.set(Position.KEY_BATTERY_LEVEL, battery);
} else if (battery == 0xAA) {
position.set(Position.KEY_CHARGE, true);
}
position.setNetwork(new Network(CellTower.fromCidLac(
getConfig(), buf.readUnsignedInt(), buf.readUnsignedShort())));
int product = buf.readUnsignedByte();
int status = buf.readUnsignedShort();
int alarm = buf.readUnsignedShort();
if (product == 1 || product == 2) {
if (BitUtil.check(alarm, 0)) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
}
} else if (product == 3) {
position.set(Position.KEY_BLOCKED, BitUtil.check(status, 5));
if (BitUtil.check(alarm, 1)) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
}
if (BitUtil.check(alarm, 2)) {
position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
}
if (BitUtil.check(alarm, 3)) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
}
}
position.set(Position.KEY_STATUS, status);
return position;
}
| private Position decodeLocation2(DeviceSession deviceSession, ByteBuf buf, int type) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
Jt600ProtocolDecoder.decodeBinaryLocation(buf, position);
position.setValid(type != MSG_LOCATION_REPORT_BLIND);
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000L);
int battery = buf.readUnsignedByte();
if (battery <= 100) {
position.set(Position.KEY_BATTERY_LEVEL, battery);
} else if (battery == 0xAA) {
position.set(Position.KEY_CHARGE, true);
}
position.setNetwork(new Network(CellTower.fromCidLac(
getConfig(), buf.readUnsignedInt(), buf.readUnsignedShort())));
int product = buf.readUnsignedByte();
int status = buf.readUnsignedShort();
int alarm = buf.readUnsignedShort();
if (product == 1 || product == 2) {
if (BitUtil.check(alarm, 0)) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
}
} else if (product == 3) {
position.set(Position.KEY_BLOCKED, BitUtil.check(status, 5));
if (BitUtil.check(alarm, 1)) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
}
if (BitUtil.check(alarm, 2)) {
position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
}
if (BitUtil.check(alarm, 3)) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
}
}
position.set(Position.KEY_STATUS, status);
while (buf.readableBytes() > 2) {
int id = buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x02:
position.setAltitude(buf.readShort());
break;
case 0x0C:
position.set("gyro", ByteBufUtil.hexDump(buf.readSlice(6)));
break;
default:
buf.skipBytes(length);
break;
}
}
return position;
}
|
traccar-traccar-f92bde208800 | private void readBinaryCustomData(Position position, ByteBuf buf, String form) {
CellTower cellTower = new CellTower();
String[] keys = form.substring(1).split("%");
for (String key : keys) {
switch (key) {
case "SA":
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case "MV":
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1);
break;
case "BV":
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
break;
case "GQ":
cellTower.setSignalStrength((int) buf.readUnsignedByte());
break;
case "CE":
cellTower.setCellId(buf.readUnsignedInt());
break;
case "LC":
cellTower.setLocationAreaCode(buf.readUnsignedShort());
break;
case "CN":
int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000);
cellTower.setMobileCountryCode(combinedMobileCodes / 100);
cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
break;
case "RL":
buf.readUnsignedByte();
break;
case "PC":
position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
break;
case "AT":
position.setAltitude(buf.readUnsignedInt());
break;
case "RP":
position.set(Position.KEY_RPM, buf.readUnsignedShort());
break;
case "GS":
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
break;
case "DT":
position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
break;
case "VN":
position.set(Position.KEY_VIN, readString(buf));
break;
case "MF":
buf.readUnsignedShort();
break;
case "EL":
buf.readUnsignedByte();
break;
case "TR":
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case "ET":
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
break;
case "FL":
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case "ML":
buf.readUnsignedByte();
break;
case "FC":
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
break;
case "CI":
readString(buf);
break;
case "AV1":
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
break;
case "NC":
readString(buf);
break;
case "SM":
buf.readUnsignedShort();
break;
case "GL":
readString(buf);
break;
case "MA":
readString(buf);
break;
case "PD":
buf.readUnsignedByte();
break;
case "CD":
position.set(Position.KEY_ICCID, readString(buf));
break;
case "CM":
buf.readLong();
break;
case "GN":
buf.skipBytes(60);
break;
case "GV":
buf.skipBytes(6);
break;
case "ME":
buf.readLong();
break;
case "IA":
buf.readUnsignedByte();
break;
case "MP":
buf.readUnsignedByte();
break;
default:
break;
}
}
if (cellTower.getMobileCountryCode() != null
&& cellTower.getMobileNetworkCode() != null
&& cellTower.getCellId() != null && cellTower.getCellId() != 0
&& cellTower.getLocationAreaCode() != null) {
position.setNetwork(new Network(cellTower));
} else if (cellTower.getSignalStrength() != null) {
position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
}
}
| private void readBinaryCustomData(Position position, ByteBuf buf, String form) {
CellTower cellTower = new CellTower();
String[] keys = form.substring(1).split("%");
for (String key : keys) {
switch (key) {
case "SA":
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case "MV":
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1);
break;
case "BV":
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
break;
case "GQ":
cellTower.setSignalStrength((int) buf.readUnsignedByte());
break;
case "CE":
cellTower.setCellId(buf.readUnsignedInt());
break;
case "LC":
cellTower.setLocationAreaCode(buf.readUnsignedShort());
break;
case "CN":
int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000);
cellTower.setMobileCountryCode(combinedMobileCodes / 100);
cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
break;
case "RL":
buf.readUnsignedByte();
break;
case "PC":
position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
break;
case "AT":
position.setAltitude(buf.readUnsignedInt());
break;
case "RP":
position.set(Position.KEY_RPM, buf.readUnsignedShort());
break;
case "GS":
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
break;
case "DT":
position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
break;
case "VN":
position.set(Position.KEY_VIN, readString(buf));
break;
case "MF":
buf.readUnsignedShort();
break;
case "EL":
buf.readUnsignedByte();
break;
case "TR":
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case "ET":
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
break;
case "FL":
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case "ML":
buf.readUnsignedByte();
break;
case "FC":
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
break;
case "CI":
readString(buf);
break;
case "AV1":
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
break;
case "NC":
readString(buf);
break;
case "SM":
buf.readUnsignedShort();
break;
case "GL":
readString(buf);
break;
case "MA":
readString(buf);
break;
case "PD":
buf.readUnsignedByte();
break;
case "CD":
position.set(Position.KEY_ICCID, readString(buf));
break;
case "CM":
buf.readLong();
break;
case "GN":
buf.skipBytes(60);
break;
case "GV":
buf.skipBytes(6);
break;
case "ME":
buf.readLong();
break;
case "IA":
buf.readUnsignedByte();
break;
case "MP":
buf.readUnsignedByte();
break;
case "EO":
position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(buf.readUnsignedInt()));
break;
case "EH":
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 360000);
break;
case "ZO1":
buf.readUnsignedByte();
break;
case "ZO2":
buf.readUnsignedByte();
break;
case "ZO3":
buf.readUnsignedByte();
break;
case "ZO4":
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() * 0.4);
break;
case "ZO5":
buf.readUnsignedByte();
break;
case "ZO6":
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte() * 0.805);
break;
case "ZO7":
buf.readUnsignedByte();
break;
case "ZO8":
buf.readUnsignedByte();
break;
case "ZO9":
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() * 0.5);
break;
case "ZO10":
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.5);
break;
case "ZO11":
buf.readUnsignedByte();
break;
case "ZO12":
buf.readUnsignedByte();
break;
case "ZO13":
buf.readUnsignedByte();
break;
case "ZO14":
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte());
break;
case "ZO15":
buf.readUnsignedByte();
break;
case "ZO16":
buf.readUnsignedByte();
break;
case "ZO17":
buf.readUnsignedByte();
break;
case "ZH1":
buf.readUnsignedShort();
break;
case "ZH2":
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 16.428 / 3600);
break;
case "ZH3":
position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.25);
break;
case "ZL1":
buf.readUnsignedInt();
break;
case "ZL2":
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 161);
break;
case "ZL3":
buf.readUnsignedInt();
break;
case "ZL4":
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 5 * 36000);
break;
case "ZS1":
position.set(Position.KEY_VIN, readString(buf));
break;
case "JO1":
buf.readUnsignedByte();
break;
case "JO2":
buf.readUnsignedByte();
break;
case "JO3":
buf.readUnsignedByte();
break;
case "JO4":
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte());
break;
case "JO5":
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
break;
case "JO6":
buf.readUnsignedByte();
break;
case "JO7":
buf.readUnsignedByte();
break;
case "JO8":
buf.readUnsignedByte();
break;
case "JO9":
buf.readUnsignedByte();
break;
case "JO10":
buf.readUnsignedByte();
break;
case "JO11":
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40);
break;
case "JO12":
buf.readUnsignedByte();
break;
case "JH1":
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0);
break;
case "JH2":
position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125);
break;
case "JH3":
case "JH4":
case "JH5":
case "JH6":
case "JH7":
int index = Integer.parseInt(key.substring(2)) - 2;
position.set("axleWeight" + index, buf.readUnsignedShort() * 0.5);
break;
case "JH8":
position.set(Position.KEY_ODOMETER_SERVICE, buf.readUnsignedShort() * 5);
break;
case "JH9":
buf.readUnsignedShort();
break;
case "JH10":
buf.readUnsignedShort();
break;
case "JH11":
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.05);
break;
case "JH12":
buf.readUnsignedShort();
break;
case "JL1":
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.5);
break;
case "JL2":
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 5 * 36000);
break;
case "JL3":
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
break;
case "JL4":
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.001);
break;
case "JS1":
position.set(Position.KEY_VIN, readString(buf));
break;
case "JS2":
readString(buf);
break;
case "JS3":
position.set("driver1", readString(buf));
break;
case "JS4":
position.set("driver2", readString(buf));
break;
case "JN1":
buf.readUnsignedInt();
break;
case "JN2":
buf.readUnsignedInt();
break;
case "JN3":
buf.readUnsignedInt();
break;
case "JN4":
buf.readUnsignedInt();
break;
case "JN5":
buf.readUnsignedInt();
break;
default:
break;
}
}
if (cellTower.getMobileCountryCode() != null
&& cellTower.getMobileNetworkCode() != null
&& cellTower.getCellId() != null && cellTower.getCellId() != 0
&& cellTower.getLocationAreaCode() != null) {
position.setNetwork(new Network(cellTower));
} else if (cellTower.getSignalStrength() != null) {
position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
}
}
|
traccar-traccar-f4d10160d951 | @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte();
int flags = buf.readUnsignedByte();
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
int type = buf.readUnsignedByte();
if (BitUtil.check(flags, 4)) {
sendResponse(channel, remoteAddress, index, type, buf);
}
if (type == MSG_DATA) {
List<Position> positions = new LinkedList<>();
Set<Integer> keys = new HashSet<>();
boolean hasLocation = false;
Position position = new Position(getProtocolName());
DeviceSession deviceSession = null;
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
if (keys.contains(key)) {
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
keys.clear();
hasLocation = false;
position = new Position(getProtocolName());
}
keys.add(key);
switch (key) {
case 0x01:
deviceSession = getDeviceSession(
channel, remoteAddress, buf.readCharSequence(15, StandardCharsets.US_ASCII).toString());
position.setDeviceId(deviceSession.getDeviceId());
break;
case 0x02:
long alarm = buf.readUnsignedIntLE();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (BitUtil.check(alarm, 31)) {
position.set("bark", true);
}
break;
case 0x14:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
break;
case 0x20:
hasLocation = true;
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.setAltitude(buf.readShortLE());
int hdop = buf.readUnsignedShortLE();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x21:
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedByte();
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
position.getNetwork().addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi));
}
break;
case 0x22:
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.getNetwork().addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), rssi));
}
break;
case 0x23:
position.set("tagId", readTagId(buf));
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x24:
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
long status = buf.readUnsignedIntLE();
position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(status, 24));
position.set(Position.KEY_STATUS, status);
break;
case 0x28:
int beaconFlags = buf.readUnsignedByte();
position.set("tagId", readTagId(buf));
position.set("tagRssi", (int) buf.readByte());
position.set("tag1mRssi", (int) buf.readByte());
if (BitUtil.check(beaconFlags, 7)) {
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
}
if (BitUtil.check(beaconFlags, 6)) {
position.set("description", buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString());
}
break;
case 0x2A:
buf.readUnsignedByte();
buf.skipBytes(6);
buf.readUnsignedByte();
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x30:
buf.readUnsignedIntLE();
position.set(Position.KEY_STEPS, buf.readUnsignedIntLE());
break;
case 0x31:
int i = 1;
while (buf.readerIndex() < endIndex) {
position.set("activity" + i + "Time", buf.readUnsignedIntLE());
position.set("activity" + i, buf.readUnsignedIntLE());
i += 1;
}
break;
case 0x40:
buf.readUnsignedIntLE();
int heartRate = buf.readUnsignedByte();
if (heartRate > 1) {
position.set(Position.KEY_HEART_RATE, heartRate);
}
break;
default:
break;
}
buf.readerIndex(endIndex);
}
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
if (deviceSession != null) {
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
}
} else {
return null;
}
return positions;
}
return null;
}
| @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte();
int flags = buf.readUnsignedByte();
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
int type = buf.readUnsignedByte();
if (BitUtil.check(flags, 4)) {
sendResponse(channel, remoteAddress, index, type, buf);
}
if (type == MSG_DATA) {
List<Position> positions = new LinkedList<>();
Set<Integer> keys = new HashSet<>();
boolean hasLocation = false;
Position position = new Position(getProtocolName());
DeviceSession deviceSession = null;
while (buf.isReadable()) {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
if (keys.contains(key)) {
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
keys.clear();
hasLocation = false;
position = new Position(getProtocolName());
}
keys.add(key);
switch (key) {
case 0x01:
deviceSession = getDeviceSession(
channel, remoteAddress, buf.readCharSequence(15, StandardCharsets.US_ASCII).toString());
position.setDeviceId(deviceSession.getDeviceId());
break;
case 0x02:
long alarm = buf.readUnsignedIntLE();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (BitUtil.check(alarm, 31)) {
position.set("bark", true);
}
break;
case 0x14:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
break;
case 0x20:
hasLocation = true;
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.setAltitude(buf.readShortLE());
int hdop = buf.readUnsignedShortLE();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x21:
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedByte();
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
position.getNetwork().addCellTower(CellTower.from(
mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), rssi));
}
break;
case 0x22:
if (position.getNetwork() == null) {
position.setNetwork(new Network());
}
while (buf.readerIndex() < endIndex) {
int rssi = buf.readByte();
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.getNetwork().addWifiAccessPoint(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), rssi));
}
break;
case 0x23:
position.set("tagId", readTagId(buf));
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x24:
position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
long status = buf.readUnsignedIntLE();
position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(status, 24));
position.set(Position.KEY_STATUS, status);
break;
case 0x28:
int beaconFlags = buf.readUnsignedByte();
position.set("tagId", readTagId(buf));
position.set("tagRssi", (int) buf.readByte());
position.set("tag1mRssi", (int) buf.readByte());
if (BitUtil.check(beaconFlags, 7)) {
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
}
if (BitUtil.check(beaconFlags, 6)) {
position.set("description", buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString());
}
break;
case 0x2A:
buf.readUnsignedByte();
buf.skipBytes(6);
buf.readUnsignedByte();
position.setLatitude(buf.readIntLE() * 0.0000001);
position.setLongitude(buf.readIntLE() * 0.0000001);
position.setValid(true);
hasLocation = true;
break;
case 0x30:
buf.readUnsignedIntLE();
position.set(Position.KEY_STEPS, buf.readUnsignedIntLE());
break;
case 0x31:
int i = 1;
while (buf.readerIndex() < endIndex) {
position.set("activity" + i + "Time", buf.readUnsignedIntLE());
position.set("activity" + i, buf.readUnsignedIntLE());
i += 1;
}
break;
case 0x37:
buf.readUnsignedIntLE();
position.set("barkCount", BitUtil.to(buf.readUnsignedIntLE(), 31));
break;
case 0x40:
buf.readUnsignedIntLE();
int heartRate = buf.readUnsignedByte();
if (heartRate > 1) {
position.set(Position.KEY_HEART_RATE, heartRate);
}
break;
default:
break;
}
buf.readerIndex(endIndex);
}
if (!hasLocation) {
getLastLocation(position, null);
}
positions.add(position);
if (deviceSession != null) {
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
}
} else {
return null;
}
return positions;
}
return null;
}
|
traccar-traccar-5c26f25b3b0a | 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);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
buf.readUnsignedIntLE();
int count = buf.readUnsignedShortLE();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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;
case 0x14:
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
break;
case 0x15:
position.set(Position.KEY_INPUT, buf.readUnsignedByte());
break;
case 0x47:
int lockState = buf.readUnsignedByte();
if (lockState > 0) {
position.set(Position.KEY_LOCK, lockState == 2);
}
break;
case 0x97:
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case 0x9D:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case 0xFE69:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
break;
default:
buf.readUnsignedByte();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
case 0x08:
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
break;
case 0x09:
position.setCourse(buf.readUnsignedShortLE());
break;
case 0x0A:
position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
break;
case 0x0B:
position.setAltitude(buf.readShortLE());
break;
case 0x16:
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
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;
case 0x40:
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
break;
case 0x91:
case 0x92:
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
break;
case 0x98:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
break;
case 0x99:
position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
break;
case 0x9C:
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
break;
case 0x9F:
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
break;
case 0xC9:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
break;
default:
buf.readUnsignedShortLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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));
break;
case 0x0C:
case 0x9B:
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
break;
case 0x0D:
position.set("runtime", buf.readUnsignedIntLE());
break;
case 0x25:
position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
break;
case 0xA0:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
break;
case 0xA2:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
break;
default:
buf.readUnsignedIntLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
buf.readUnsignedByte();
position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01);
break;
case 0xFE31:
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.skipBytes(length - 2);
break;
case 0xFEA8:
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
} else {
buf.readUnsignedByte();
}
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
break;
default:
buf.skipBytes(length);
break;
}
}
positions.add(position);
}
return positions;
}
| 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);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
buf.readUnsignedIntLE();
int count = buf.readUnsignedShortLE();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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;
case 0x14:
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
break;
case 0x15:
position.set(Position.KEY_INPUT, buf.readUnsignedByte());
break;
case 0x47:
int lockState = buf.readUnsignedByte();
if (lockState > 0) {
position.set(Position.KEY_LOCK, lockState == 2);
}
break;
case 0x97:
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case 0x9D:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case 0xFE69:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
break;
default:
buf.readUnsignedByte();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
case 0x08:
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
break;
case 0x09:
position.setCourse(buf.readUnsignedShortLE());
break;
case 0x0A:
position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
break;
case 0x0B:
position.setAltitude(buf.readShortLE());
break;
case 0x16:
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
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;
case 0x40:
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
break;
case 0x91:
case 0x92:
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
break;
case 0x98:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
break;
case 0x99:
position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
break;
case 0x9C:
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
break;
case 0x9F:
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
break;
case 0xC9:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
break;
default:
buf.readUnsignedShortLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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));
break;
case 0x0C:
case 0x9B:
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
break;
case 0x0D:
position.set("runtime", buf.readUnsignedIntLE());
break;
case 0x25:
position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
break;
case 0xA0:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
break;
case 0xA2:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
break;
default:
buf.readUnsignedIntLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
buf.readUnsignedByte();
position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01);
break;
case 0xFE31:
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.skipBytes(length - 2);
break;
case 0xFEA8:
for (int k = 1; k <= 3; k++) {
if (buf.readUnsignedByte() > 0) {
String key = k == 1 ? Position.KEY_BATTERY_LEVEL : "battery" + k + "Level";
position.set(key, buf.readUnsignedByte());
} else {
buf.readUnsignedByte();
}
}
buf.readUnsignedByte();
break;
default:
buf.skipBytes(length);
break;
}
}
positions.add(position);
}
return positions;
}
|
traccar-traccar-7ce4fb9a628f | protected Object decodePosition(DeviceSession deviceSession, String content) throws Exception {
Parser parser = new Parser(PATTERN_POSITION, content);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int event = parser.nextInt();
String eventData = parser.next();
position.set(Position.KEY_EVENT, event);
if (event == 53) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
} else {
position.set(Position.KEY_ALARM, decodeAlarm(event));
}
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_HDOP, parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.setCourse(parser.nextInt());
position.setAltitude(parser.nextInt());
position.set(Position.KEY_ODOMETER, parser.nextInt());
position.setNetwork(new Network(CellTower.from(
parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt(), parser.nextInt())));
position.set(Position.KEY_STATUS, parser.nextHexInt());
int input = parser.nextHexInt();
int output = parser.nextHexInt();
position.set(Position.KEY_IGNITION, BitUtil.check(input, 1));
position.set(Position.KEY_DOOR, BitUtil.check(input, 2));
position.set(Position.KEY_INPUT, input);
position.set(Position.KEY_OUTPUT, output);
position.set(Position.KEY_POWER, parser.nextHexInt() * 0.01);
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 0.01);
if (parser.hasNext()) {
String[] adc = parser.next().split("\\|");
for (int i = 1; i < adc.length; i++) {
position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16) * 0.01);
}
}
if (parser.hasNext()) {
String[] fuels = parser.next().split("\\|");
for (String fuel : fuels) {
int index = Integer.parseInt(fuel.substring(0, 2));
int value = Integer.parseInt(fuel.substring(2), 16);
position.set("fuel" + index, value * 0.1);
}
}
if (parser.hasNext()) {
String[] temperatures = parser.next().split("\\|");
for (String temperature : temperatures) {
int index = Integer.parseInt(temperature.substring(0, 2));
int value = Integer.parseInt(temperature.substring(2), 16);
double convertedValue = BitUtil.to(value, 15);
if (BitUtil.check(value, 15)) {
convertedValue = -convertedValue;
}
position.set(Position.PREFIX_TEMP + index, convertedValue * 0.1);
}
}
if (parser.hasNextAny(9)) {
position.set(Position.KEY_RPM, parser.nextInt());
position.set(Position.KEY_ENGINE_LOAD, parser.nextInt());
position.set("airFlow", parser.nextInt());
position.set("airPressure", parser.nextInt());
if (parser.hasNext()) {
position.set("airTemp", parser.nextInt() - 40);
}
position.set(Position.KEY_THROTTLE, parser.nextInt());
if (parser.hasNext()) {
position.set(Position.KEY_COOLANT_TEMP, parser.nextInt() - 40);
}
if (parser.hasNext()) {
position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextInt() * 0.1);
}
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
}
if (parser.hasNext()) {
position.set(Position.KEY_HOURS, parser.nextInt() * 1000L);
}
return position;
}
| protected Object decodePosition(DeviceSession deviceSession, String content) throws Exception {
Parser parser = new Parser(PATTERN_POSITION, content);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int event = parser.nextInt();
String eventData = parser.next();
position.set(Position.KEY_EVENT, event);
if (event == 53) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
} else {
position.set(Position.KEY_ALARM, decodeAlarm(event));
}
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_HDOP, parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.setCourse(parser.nextInt());
position.setAltitude(parser.nextInt());
position.set(Position.KEY_ODOMETER, parser.nextLong());
position.setNetwork(new Network(CellTower.from(
parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt(), parser.nextInt())));
position.set(Position.KEY_STATUS, parser.nextHexInt());
int input = parser.nextHexInt();
int output = parser.nextHexInt();
position.set(Position.KEY_IGNITION, BitUtil.check(input, 1));
position.set(Position.KEY_DOOR, BitUtil.check(input, 2));
position.set(Position.KEY_INPUT, input);
position.set(Position.KEY_OUTPUT, output);
position.set(Position.KEY_POWER, parser.nextHexInt() * 0.01);
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 0.01);
if (parser.hasNext()) {
String[] adc = parser.next().split("\\|");
for (int i = 1; i < adc.length; i++) {
position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16) * 0.01);
}
}
if (parser.hasNext()) {
String[] fuels = parser.next().split("\\|");
for (String fuel : fuels) {
int index = Integer.parseInt(fuel.substring(0, 2));
int value = Integer.parseInt(fuel.substring(2), 16);
position.set("fuel" + index, value * 0.1);
}
}
if (parser.hasNext()) {
String[] temperatures = parser.next().split("\\|");
for (String temperature : temperatures) {
int index = Integer.parseInt(temperature.substring(0, 2));
int value = Integer.parseInt(temperature.substring(2), 16);
double convertedValue = BitUtil.to(value, 15);
if (BitUtil.check(value, 15)) {
convertedValue = -convertedValue;
}
position.set(Position.PREFIX_TEMP + index, convertedValue * 0.1);
}
}
if (parser.hasNextAny(9)) {
position.set(Position.KEY_RPM, parser.nextInt());
position.set(Position.KEY_ENGINE_LOAD, parser.nextInt());
position.set("airFlow", parser.nextInt());
position.set("airPressure", parser.nextInt());
if (parser.hasNext()) {
position.set("airTemp", parser.nextInt() - 40);
}
position.set(Position.KEY_THROTTLE, parser.nextInt());
if (parser.hasNext()) {
position.set(Position.KEY_COOLANT_TEMP, parser.nextInt() - 40);
}
if (parser.hasNext()) {
position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextInt() * 0.1);
}
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
}
if (parser.hasNext()) {
position.set(Position.KEY_HOURS, parser.nextInt() * 1000L);
}
return position;
}
|
jhy-jsoup-e52224fbfe66 | @Override
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
final boolean trimLikeBlock = parent != null && (parent.tag().isBlock() || parent.tag().formatAsBlock());
boolean trimLeading = false, trimTrailing = false;
if (normaliseWhite) {
trimLeading = (trimLikeBlock && siblingIndex == 0) || parentNode instanceof Document;
trimTrailing = trimLikeBlock && nextSibling() == null;
Node next = nextSibling();
Node prev = previousSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()))
|| (prev instanceof Element && ((Element) prev).isBlock())
;
if (couldSkip && isBlank) return;
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && isNode(prev, "br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
| @Override
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
final boolean trimLikeBlock = parent != null && (parent.tag().isBlock() || parent.tag().formatAsBlock());
boolean trimLeading = false, trimTrailing = false;
if (normaliseWhite) {
trimLeading = (trimLikeBlock && siblingIndex == 0) || parentNode instanceof Document;
trimTrailing = trimLikeBlock && nextSibling() == null;
Node next = nextSibling();
Node prev = previousSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()))
|| (prev instanceof Element && (((Element) prev).isBlock() || prev.isNode("br")))
;
if (couldSkip && isBlank) return;
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && isNode(prev, "br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
|
xtremexp-UT4X-Converter-e719841eb260 | protected String convertScaleAndToT3D(double scaleFactor) {
this.convert();
this.scale(scaleFactor);
return "Begin Map\nBegin Level\n" + toT3d() + "End Level\nEnd Map";
}
| protected String convertScaleAndToT3D(double scaleFactor) {
this.convert();
this.scale(scaleFactor);
String convT3d = toT3d();
if (convT3d == null) {
convT3d = "";
for (T3DActor repActor : this.children) {
convT3d += repActor.toT3d();
}
}
return "Begin Map\nBegin Level\n" + convT3d + "End Level\nEnd Map";
}
|
traccar-traccar-5e18cb586d34 | private Object decodeCan(Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
Position position = new Position(getProtocolName());
int index = 0;
String[] values = sentence.split(",");
index += 1;
index += 1;
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
position.setDeviceId(deviceSession.getDeviceId());
index += 1;
index += 1;
index += 1;
long reportMask = Long.parseLong(values[index++], 16);
long reportMaskExt = 0;
if (BitUtil.check(reportMask, 0)) {
position.set(Position.KEY_VIN, values[index++]);
}
if (BitUtil.check(reportMask, 1)) {
position.set(Position.KEY_IGNITION, Integer.parseInt(values[index++]) > 0);
}
if (BitUtil.check(reportMask, 2)) {
position.set(Position.KEY_OBD_ODOMETER, values[index++]);
}
if (BitUtil.check(reportMask, 3) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_USED, Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 5) && !values[index++].isEmpty()) {
position.set(Position.KEY_RPM, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 4) && !values[index++].isEmpty()) {
position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));
}
if (BitUtil.check(reportMask, 6) && !values[index++].isEmpty()) {
position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 7) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_CONSUMPTION, Double.parseDouble(values[index - 1].substring(1)));
}
if (BitUtil.check(reportMask, 8) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(values[index - 1].substring(1)));
}
if (BitUtil.check(reportMask, 9) && !values[index++].isEmpty()) {
position.set("range", Long.parseLong(values[index - 1]) * 100);
}
if (BitUtil.check(reportMask, 10) && !values[index++].isEmpty()) {
position.set(Position.KEY_THROTTLE, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 11) && !values[index++].isEmpty()) {
position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Double.parseDouble(values[index - 1])));
}
if (BitUtil.check(reportMask, 12)) {
position.set(Position.KEY_DRIVING_TIME, Double.parseDouble(values[index++]));
}
if (BitUtil.check(reportMask, 13)) {
position.set("idleHours", Double.parseDouble(values[index++]));
}
if (BitUtil.check(reportMask, 14) && !values[index++].isEmpty()) {
position.set("idleFuelConsumption", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 15) && !values[index++].isEmpty()) {
position.set(Position.KEY_AXLE_WEIGHT, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 16) && !values[index++].isEmpty()) {
position.set("tachographInfo", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 17) && !values[index++].isEmpty()) {
position.set("indicators", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 18) && !values[index++].isEmpty()) {
position.set("lights", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 19) && !values[index++].isEmpty()) {
position.set("doors", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 20) && !values[index++].isEmpty()) {
position.set("vehicleOverspeed", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 21) && !values[index++].isEmpty()) {
position.set("engineOverspeed", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 29)) {
reportMaskExt = Long.parseLong(values[index++], 16);
}
if (BitUtil.check(reportMaskExt, 0) && !values[index++].isEmpty()) {
position.set("adBlueLevel", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 1) && !values[index++].isEmpty()) {
position.set("axleWeight1", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 2) && !values[index++].isEmpty()) {
position.set("axleWeight3", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 3) && !values[index++].isEmpty()) {
position.set("axleWeight4", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 4)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 5)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 6)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 7) && !values[index++].isEmpty()) {
position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[index - 1]) * 0.001);
}
if (BitUtil.check(reportMaskExt, 8)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 9)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 10)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 11)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 12)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 13)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 14)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 15) && !values[index++].isEmpty()) {
position.set("driver1Card", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 16) && !values[index++].isEmpty()) {
position.set("driver2Card", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 17) && !values[index++].isEmpty()) {
position.set("driver1Name", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 18) && !values[index++].isEmpty()) {
position.set("driver2Name", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 19) && !values[index++].isEmpty()) {
position.set("registration", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 20)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 21)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 22)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 23)) {
index += 1;
}
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
if (BitUtil.check(reportMask, 30)) {
while (values[index].isEmpty()) {
index += 1;
}
position.setValid(Integer.parseInt(values[index++]) > 0);
if (!values[index].isEmpty()) {
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
position.setCourse(Integer.parseInt(values[index++]));
position.setAltitude(Double.parseDouble(values[index++]));
position.setLongitude(Double.parseDouble(values[index++]));
position.setLatitude(Double.parseDouble(values[index++]));
position.setTime(dateFormat.parse(values[index++]));
} else {
index += 6;
getLastLocation(position, null);
}
} else {
getLastLocation(position, null);
}
if (BitUtil.check(reportMask, 31)) {
index += 4;
index += 1;
}
if (ignoreFixTime) {
position.setTime(dateFormat.parse(values[index]));
} else {
position.setDeviceTime(dateFormat.parse(values[index]));
}
return position;
}
| private Object decodeCan(Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
Position position = new Position(getProtocolName());
int index = 0;
String[] values = sentence.split(",");
index += 1;
index += 1;
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
position.setDeviceId(deviceSession.getDeviceId());
String deviceName = values[index++];
index += 1;
index += 1;
long reportMask = Long.parseLong(values[index++], 16);
long reportMaskExt = 0;
if (BitUtil.check(reportMask, 0)) {
position.set(Position.KEY_VIN, values[index++]);
}
if (BitUtil.check(reportMask, 1)) {
position.set(Position.KEY_IGNITION, Integer.parseInt(values[index++]) > 0);
}
if (BitUtil.check(reportMask, 2)) {
position.set(Position.KEY_OBD_ODOMETER, values[index++]);
}
if (BitUtil.check(reportMask, 3) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_USED, Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 5) && !values[index++].isEmpty()) {
position.set(Position.KEY_RPM, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 4) && !values[index++].isEmpty()) {
position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));
}
if (BitUtil.check(reportMask, 6) && !values[index++].isEmpty()) {
position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 7) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_CONSUMPTION, Double.parseDouble(values[index - 1].substring(1)));
}
if (BitUtil.check(reportMask, 8) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(values[index - 1].substring(1)));
}
if (BitUtil.check(reportMask, 9) && !values[index++].isEmpty()) {
position.set("range", Long.parseLong(values[index - 1]) * 100);
}
if (BitUtil.check(reportMask, 10) && !values[index++].isEmpty()) {
position.set(Position.KEY_THROTTLE, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 11) && !values[index++].isEmpty()) {
position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Double.parseDouble(values[index - 1])));
}
if (BitUtil.check(reportMask, 12) && !values[index++].isEmpty()) {
position.set(Position.KEY_DRIVING_TIME, Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 13) && !values[index++].isEmpty()) {
position.set("idleHours", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 14) && !values[index++].isEmpty()) {
position.set("idleFuelConsumption", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 15) && !values[index++].isEmpty()) {
position.set(Position.KEY_AXLE_WEIGHT, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 16) && !values[index++].isEmpty()) {
position.set("tachographInfo", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 17) && !values[index++].isEmpty()) {
position.set("indicators", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 18) && !values[index++].isEmpty()) {
position.set("lights", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 19) && !values[index++].isEmpty()) {
position.set("doors", Integer.parseInt(values[index - 1], 16));
}
if (BitUtil.check(reportMask, 20) && !values[index++].isEmpty()) {
position.set("vehicleOverspeed", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 21) && !values[index++].isEmpty()) {
position.set("engineOverspeed", Double.parseDouble(values[index - 1]));
}
if ("GV350M".equals(deviceName)) {
if (BitUtil.check(reportMask, 22)) {
index += 1;
}
if (BitUtil.check(reportMask, 23)) {
index += 1;
}
if (BitUtil.check(reportMask, 24)) {
index += 1;
}
}
if (BitUtil.check(reportMask, 29) && !values[index++].isEmpty()) {
reportMaskExt = Long.parseLong(values[index - 1], 16);
}
if (BitUtil.check(reportMaskExt, 0) && !values[index++].isEmpty()) {
position.set("adBlueLevel", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 1) && !values[index++].isEmpty()) {
position.set("axleWeight1", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 2) && !values[index++].isEmpty()) {
position.set("axleWeight3", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 3) && !values[index++].isEmpty()) {
position.set("axleWeight4", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMaskExt, 4)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 5)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 6)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 7) && !values[index++].isEmpty()) {
position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[index - 1]) * 0.001);
}
if (BitUtil.check(reportMaskExt, 8)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 9)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 10)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 11)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 12)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 13)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 14)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 15) && !values[index++].isEmpty()) {
position.set("driver1Card", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 16) && !values[index++].isEmpty()) {
position.set("driver2Card", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 17) && !values[index++].isEmpty()) {
position.set("driver1Name", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 18) && !values[index++].isEmpty()) {
position.set("driver2Name", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 19) && !values[index++].isEmpty()) {
position.set("registration", values[index - 1]);
}
if (BitUtil.check(reportMaskExt, 20)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 21)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 22)) {
index += 1;
}
if (BitUtil.check(reportMaskExt, 23)) {
index += 1;
}
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
if (BitUtil.check(reportMask, 30)) {
while (values[index].isEmpty()) {
index += 1;
}
position.setValid(Integer.parseInt(values[index++]) > 0);
if (!values[index].isEmpty()) {
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
position.setCourse(Integer.parseInt(values[index++]));
position.setAltitude(Double.parseDouble(values[index++]));
position.setLongitude(Double.parseDouble(values[index++]));
position.setLatitude(Double.parseDouble(values[index++]));
position.setTime(dateFormat.parse(values[index++]));
} else {
index += 6;
getLastLocation(position, null);
}
} else {
getLastLocation(position, null);
}
if (BitUtil.check(reportMask, 31)) {
index += 4;
index += 1;
}
if (ignoreFixTime) {
position.setTime(dateFormat.parse(values[index]));
} else {
position.setDeviceTime(dateFormat.parse(values[index]));
}
return position;
}
|
traccar-traccar-9a1cbeb7b754 | 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);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
buf.readUnsignedIntLE();
int count = buf.readUnsignedShortLE();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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;
case 0x14:
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
break;
case 0x15:
position.set(Position.KEY_INPUT, buf.readUnsignedByte());
break;
case 0x47:
int lockState = buf.readUnsignedByte();
if (lockState > 0) {
position.set(Position.KEY_LOCK, lockState == 2);
}
break;
case 0x97:
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case 0x9D:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case 0xFE69:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
break;
default:
buf.readUnsignedByte();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
case 0x08:
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
break;
case 0x09:
position.setCourse(buf.readUnsignedShortLE());
break;
case 0x0A:
position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
break;
case 0x0B:
position.setAltitude(buf.readShortLE());
break;
case 0x16:
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
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;
case 0x40:
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
break;
case 0x91:
case 0x92:
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
break;
case 0x98:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
break;
case 0x99:
position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
break;
case 0x9C:
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
break;
case 0x9F:
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
break;
case 0xC9:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
break;
default:
buf.readUnsignedShortLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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));
break;
case 0x0C:
case 0x9B:
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
break;
case 0x0D:
position.set("runtime", buf.readUnsignedIntLE());
break;
case 0x25:
position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
break;
case 0xA0:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
break;
case 0xA2:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
break;
default:
buf.readUnsignedIntLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
buf.readUnsignedByte();
position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01);
break;
case 0xFE31:
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.skipBytes(length - 2);
break;
case 0xFEA8:
buf.readUnsignedByte();
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
buf.readUnsignedByte();
break;
default:
buf.skipBytes(length);
break;
}
}
positions.add(position);
}
return positions;
}
| 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);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
buf.readUnsignedIntLE();
int count = buf.readUnsignedShortLE();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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;
case 0x14:
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
break;
case 0x15:
position.set(Position.KEY_INPUT, buf.readUnsignedByte());
break;
case 0x47:
int lockState = buf.readUnsignedByte();
if (lockState > 0) {
position.set(Position.KEY_LOCK, lockState == 2);
}
break;
case 0x97:
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case 0x9D:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case 0xFE69:
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
break;
default:
buf.readUnsignedByte();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
case 0x08:
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
break;
case 0x09:
position.setCourse(buf.readUnsignedShortLE());
break;
case 0x0A:
position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
break;
case 0x0B:
position.setAltitude(buf.readShortLE());
break;
case 0x16:
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
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;
case 0x40:
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
break;
case 0x91:
case 0x92:
position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
break;
case 0x98:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
break;
case 0x99:
position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
break;
case 0x9C:
position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
break;
case 0x9F:
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
break;
case 0xC9:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
break;
default:
buf.readUnsignedShortLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : 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));
break;
case 0x0C:
case 0x9B:
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
break;
case 0x0D:
position.set("runtime", buf.readUnsignedIntLE());
break;
case 0x25:
position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
break;
case 0xA0:
position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
break;
case 0xA2:
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
break;
default:
buf.readUnsignedIntLE();
break;
}
}
paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
buf.readUnsignedByte();
position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01);
break;
case 0xFE31:
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.skipBytes(length - 2);
break;
case 0xFEA8:
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
} else {
buf.readUnsignedByte();
}
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte();
break;
default:
buf.skipBytes(length);
break;
}
}
positions.add(position);
}
return positions;
}
|
TheAlgorithms-Java-e5c7a08874a6 | public static int postfixEvaluate(final String exp) {
Stack<Integer> s = new Stack<Integer>();
Scanner tokens = new Scanner(exp);
while (tokens.hasNext()) {
if (tokens.hasNextInt()) {
s.push(tokens.nextInt());
} else {
int num2 = s.pop();
int num1 = s.pop();
String op = tokens.next();
switch (op) {
case "+" -> s.push(num1 + num2);
case "-" -> s.push(num1 - num2);
case "*" -> s.push(num1 * num2);
case "/" -> s.push(num1 / num2);
default -> throw new IllegalArgumentException("exp contains an unknown operation.");
}
}
}
tokens.close();
if (s.size() != 1) {
throw new IllegalArgumentException("exp is not a proper postfix expression.");
}
return s.pop();
}
| public static int postfixEvaluate(final String exp) {
Stack<Integer> s = new Stack<Integer>();
Scanner tokens = new Scanner(exp);
while (tokens.hasNext()) {
if (tokens.hasNextInt()) {
s.push(tokens.nextInt());
} else {
if (s.size() < 2) {
throw new IllegalArgumentException("exp is not a proper postfix expression (too few arguments).");
}
int num2 = s.pop();
int num1 = s.pop();
String op = tokens.next();
switch (op) {
case "+" -> s.push(num1 + num2);
case "-" -> s.push(num1 - num2);
case "*" -> s.push(num1 * num2);
case "/" -> s.push(num1 / num2);
default -> throw new IllegalArgumentException("exp contains an unknown operation.");
}
}
}
tokens.close();
if (s.size() != 1) {
throw new IllegalArgumentException("exp is not a proper postfix expression.");
}
return s.pop();
}
|
traccar-traccar-a9c311855a49 | @Override
protected Object decode(DeviceSession deviceSession, MqttPublishMessage message) throws Exception {
JsonObject json;
try (ByteBufferInputStream inputStream = new ByteBufferInputStream(message.payload().nioBuffer())) {
json = Json.createReader(inputStream).readObject();
}
String type = json.getString("rpt");
switch (type) {
case "hf":
case "loc":
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS'Z'");
position.setTime(dateFormat.parse(json.getString("ts")));
JsonObject location = json.getJsonObject("location");
position.setLatitude(location.getJsonNumber("lat").doubleValue());
position.setLongitude(location.getJsonNumber("lon").doubleValue());
position.setCourse(json.getInt("bear"));
position.setSpeed(UnitsConverter.knotsFromCps(json.getInt("spd")));
position.set(Position.KEY_IGNITION, json.getString("ign").equals("on"));
return position;
default:
return null;
}
}
| @Override
protected Object decode(DeviceSession deviceSession, MqttPublishMessage message) throws Exception {
JsonObject json;
try (ByteBufferInputStream inputStream = new ByteBufferInputStream(message.payload().nioBuffer())) {
json = Json.createReader(inputStream).readObject();
}
String type = json.getString("rpt");
switch (type) {
case "hf":
case "loc":
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
position.setTime(dateFormat.parse(json.getString("ts")));
JsonObject location = json.getJsonObject("location");
position.setLatitude(location.getJsonNumber("lat").doubleValue());
position.setLongitude(location.getJsonNumber("lon").doubleValue());
position.setCourse(json.getInt("bear"));
position.setSpeed(UnitsConverter.knotsFromCps(json.getInt("spd")));
position.set(Position.KEY_IGNITION, json.getString("ign").equals("on"));
return position;
default:
return null;
}
}
|
jhy-jsoup-45ed00232722 | static URL encodeUrl(URL u) {
u = punyUrl(u);
try {
String urlS = u.toExternalForm();
urlS = urlS.replace(" ", "%20");
final URI uri = new URI(urlS);
return new URL(uri.toASCIIString());
} catch (URISyntaxException | MalformedURLException e) {
return u;
}
}
| static URL encodeUrl(URL u) {
u = punyUrl(u);
try {
URI uri = new URI(u.getProtocol(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(), u.getRef());
return uri.toURL();
} catch (URISyntaxException | MalformedURLException e) {
return u;
}
}
|
traccar-traccar-ed3950fbdccf | @Override
protected Object encodeCommand(Command command) {
ByteBuf content = Unpooled.buffer();
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, content);
case Command.TYPE_ENGINE_STOP:
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT, content);
case Command.TYPE_ENGINE_RESUME:
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT, content);
case Command.TYPE_SET_SPEED_LIMIT:
content.writeByte(command.getInteger(Command.KEY_DATA));
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_SPEED_LIMIT, content);
case Command.TYPE_SET_ODOMETER:
content.writeShort(command.getInteger(Command.KEY_DATA));
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_ODOMETER, content);
case Command.TYPE_POSITION_PERIODIC:
String[] data = command.getString(Command.KEY_FREQUENCY).split(";");
content.writeShort(Integer.valueOf(data[0]));
content.writeShort(Integer.valueOf(data[1]));
content.writeShort(Integer.valueOf(data[2]));
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content);
default:
return null;
}
}
| @Override
protected Object encodeCommand(Command command) {
ByteBuf content = Unpooled.buffer();
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, content);
case Command.TYPE_ENGINE_STOP:
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT, content);
case Command.TYPE_ENGINE_RESUME:
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT, content);
case Command.TYPE_SET_SPEED_LIMIT:
content.writeByte(command.getInteger(Command.KEY_DATA));
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_SPEED_LIMIT, content);
case Command.TYPE_SET_ODOMETER:
content.writeShort(command.getInteger(Command.KEY_DATA));
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_ODOMETER, content);
case Command.TYPE_POSITION_PERIODIC:
String[] data = command.getString(Command.KEY_FREQUENCY).split(";");
content.writeShort(Integer.valueOf(data[0]));
content.writeShort(Integer.valueOf(data[1]));
content.writeByte(Integer.valueOf(data[2]));
return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content);
default:
return null;
}
}
|
fusesource-jansi-58260c6ce08c | public static Appendable render(final String input, Appendable target) throws IOException {
int i = 0;
int j, k;
while (true) {
j = input.indexOf(BEGIN_TOKEN, i);
if (j == -1) {
if (i == 0) {
target.append(input);
return target;
}
target.append(input.substring(i));
return target;
}
target.append(input.substring(i, j));
k = input.indexOf(END_TOKEN, j);
if (k == -1) {
target.append(input);
return target;
}
j += BEGIN_TOKEN_LEN;
String spec = input.substring(j, k);
String[] items = spec.split(CODE_TEXT_SEPARATOR, 2);
if (items.length == 1) {
target.append(input);
return target;
}
String replacement = render(items[1], items[0].split(CODE_LIST_SEPARATOR));
target.append(replacement);
i = k + END_TOKEN_LEN;
}
}
| public static Appendable render(final String input, Appendable target) throws IOException {
int i = 0;
int j, k;
while (true) {
j = input.indexOf(BEGIN_TOKEN, i);
if (j == -1) {
if (i == 0) {
target.append(input);
return target;
}
target.append(input.substring(i));
return target;
}
target.append(input.substring(i, j));
k = input.indexOf(END_TOKEN, j);
if (k == -1) {
target.append(input);
return target;
}
j += BEGIN_TOKEN_LEN;
if (k < j) {
throw new IllegalArgumentException("Invalid input string found.");
}
String spec = input.substring(j, k);
String[] items = spec.split(CODE_TEXT_SEPARATOR, 2);
if (items.length == 1) {
target.append(input);
return target;
}
String replacement = render(items[1], items[0].split(CODE_LIST_SEPARATOR));
target.append(replacement);
i = k + END_TOKEN_LEN;
}
}
|
traccar-traccar-782fd787d14b | private Position decode04(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws ParseException {
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
String id = String.format("%08d%07d", buf.readUnsignedIntLE(), buf.readUnsignedIntLE());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
position.setDeviceTime(new Date(buf.readUnsignedIntLE() * 1000));
while (buf.isReadable()) {
int type = buf.readUnsignedByte();
switch (type) {
case 0:
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
buf.readUnsignedIntLE();
int status = buf.readUnsignedShortLE();
position.set(Position.KEY_IGNITION, BitUtil.check(status, 5));
position.set(Position.KEY_STATUS, status);
position.setValid(true);
position.setLatitude(buf.readInt() * 0.00001);
position.setLongitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_GPS, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShortLE());
position.set("maxAcceleration", buf.readUnsignedShortLE() * 0.001);
position.set("maxDeceleration", buf.readUnsignedShortLE() * 0.001);
buf.readUnsignedShortLE();
buf.readUnsignedIntLE();
position.setFixTime(new Date(buf.readUnsignedIntLE() * 1000));
buf.readUnsignedByte();
break;
case 1:
buf.skipBytes(buf.readUnsignedShortLE());
break;
case 4:
buf.skipBytes(53);
break;
case 20:
buf.skipBytes(32);
break;
case 22:
buf.readUnsignedByte();
buf.skipBytes(buf.readUnsignedShortLE());
break;
case 30:
buf.skipBytes(79);
break;
case 40:
buf.skipBytes(40);
break;
case 50:
buf.skipBytes(buf.readUnsignedShortLE());
break;
case 255:
buf.skipBytes(4);
break;
default:
throw new IllegalArgumentException(String.format("Unknown type %d", type));
}
}
return position.getValid() ? position : null;
}
| private Position decode04(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws ParseException {
buf.readUnsignedShortLE();
buf.readUnsignedShortLE();
int index = buf.readUnsignedShortLE();
String id = String.format("%08d%07d", buf.readUnsignedIntLE(), buf.readUnsignedIntLE());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
position.setDeviceTime(new Date(buf.readUnsignedIntLE() * 1000));
while (buf.isReadable()) {
int type = buf.readUnsignedByte();
switch (type) {
case 0:
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
buf.readUnsignedIntLE();
int status = buf.readUnsignedShortLE();
position.set(Position.KEY_IGNITION, BitUtil.check(status, 5));
position.set(Position.KEY_STATUS, status);
position.setValid(true);
position.setLatitude(buf.readIntLE() * 0.00001);
position.setLongitude(buf.readIntLE() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
position.setCourse(buf.readUnsignedShortLE());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_GPS, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShortLE());
position.set("maxAcceleration", buf.readUnsignedShortLE() * 0.001);
position.set("maxDeceleration", buf.readUnsignedShortLE() * 0.001);
buf.readUnsignedShortLE();
buf.readUnsignedIntLE();
position.setFixTime(new Date(buf.readUnsignedIntLE() * 1000));
buf.readUnsignedByte();
break;
case 1:
buf.skipBytes(buf.readUnsignedShortLE() - 3);
break;
case 4:
buf.skipBytes(53);
break;
case 20:
buf.skipBytes(32);
break;
case 22:
buf.readUnsignedByte();
buf.skipBytes(buf.readUnsignedShortLE());
break;
case 30:
buf.skipBytes(79);
break;
case 40:
buf.skipBytes(40);
break;
case 50:
buf.skipBytes(buf.readUnsignedShortLE() - 3);
break;
case 255:
buf.skipBytes(4);
break;
default:
throw new IllegalArgumentException(String.format("Unknown type %d", type));
}
}
return position.getValid() ? position : null;
}
|
jhy-jsoup-f2913bd731f1 | void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
final boolean trimLikeBlock = parent != null && (parent.tag().isBlock() || parent.tag().formatAsBlock());
boolean trimLeading = false, trimTrailing = false;
if (normaliseWhite) {
trimLeading = (trimLikeBlock && siblingIndex == 0) || parentNode instanceof Document;
trimTrailing = trimLikeBlock && nextSibling() == null;
Node next = nextSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()));
if (couldSkip && isBlank) return;
Node prev = previousSibling();
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && prev instanceof Element && ((Element) prev).normalName().equals("br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
| void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
final boolean prettyPrint = out.prettyPrint();
final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null;
final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
final boolean trimLikeBlock = parent != null && (parent.tag().isBlock() || parent.tag().formatAsBlock());
boolean trimLeading = false, trimTrailing = false;
if (normaliseWhite) {
trimLeading = (trimLikeBlock && siblingIndex == 0) || parentNode instanceof Document;
trimTrailing = trimLikeBlock && nextSibling() == null;
Node next = nextSibling();
Node prev = previousSibling();
boolean isBlank = isBlank();
boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out))
|| (next instanceof TextNode && (((TextNode) next).isBlank()))
|| (prev instanceof Element && ((Element) prev).isBlock())
;
if (couldSkip && isBlank) return;
if (
(siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) ||
(out.outline() && siblingNodes().size() > 0 && !isBlank) ||
(siblingIndex > 0 && prev instanceof Element && ((Element) prev).normalName().equals("br"))
)
indent(accum, depth, out);
}
Entities.escape(accum, coreValue(), out, false, normaliseWhite, trimLeading, trimTrailing);
}
|
crawler-commons-crawler-commons-2c2cb3bf7a95 | private SimpleRobotRules parseContent(String url, byte[] content, String contentType, Collection<String> robotNames, boolean exactUserAgentMatching) {
if ((content == null) || (content.length == 0)) {
return new SimpleRobotRules(RobotRulesMode.ALLOW_ALL);
}
int bytesLen = content.length;
int offset = 0;
Charset encoding = StandardCharsets.US_ASCII;
if ((bytesLen >= 3) && (content[0] == (byte) 0xEF) && (content[1] == (byte) 0xBB) && (content[2] == (byte) 0xBF)) {
offset = 3;
bytesLen -= 3;
encoding = StandardCharsets.UTF_8;
}
else if ((bytesLen >= 2) && (content[0] == (byte) 0xFF) && (content[1] == (byte) 0xFE)) {
offset = 2;
bytesLen -= 2;
encoding = StandardCharsets.UTF_16LE;
}
else if ((bytesLen >= 2) && (content[0] == (byte) 0xFE) && (content[1] == (byte) 0xFF)) {
offset = 2;
bytesLen -= 2;
encoding = StandardCharsets.UTF_16BE;
}
String contentAsStr;
contentAsStr = new String(content, offset, bytesLen, encoding);
boolean isHtmlType = ((contentType != null) && contentType.toLowerCase(Locale.ROOT).startsWith("text/html"));
boolean hasHTML = false;
if (isHtmlType || SIMPLE_HTML_PATTERN.matcher(contentAsStr).find()) {
if (!USER_AGENT_PATTERN.matcher(contentAsStr).find()) {
LOGGER.trace("Found non-robots.txt HTML file: " + url);
return new SimpleRobotRules(RobotRulesMode.ALLOW_ALL);
} else {
if (isHtmlType) {
LOGGER.debug("HTML content type returned for robots.txt file: " + url);
} else {
LOGGER.debug("Found HTML in robots.txt file: " + url);
}
hasHTML = true;
}
}
StringTokenizer lineParser = new StringTokenizer(contentAsStr, "\n\r\u0085\u2028\u2029");
ParseState parseState = new ParseState(url, robotNames);
while (lineParser.hasMoreTokens()) {
String line = lineParser.nextToken();
if (hasHTML) {
line = line.replaceAll("<[^>]+>", "");
}
int hashPos = line.indexOf("#");
if (hashPos >= 0) {
line = line.substring(0, hashPos);
}
line = line.trim();
if (line.length() == 0) {
continue;
}
RobotToken token = tokenize(line);
switch (token.getDirective()) {
case USER_AGENT:
handleUserAgent(parseState, token);
break;
case DISALLOW:
parseState.setFinishedAgentFields(true);
handleDisallow(parseState, token);
break;
case ALLOW:
parseState.setFinishedAgentFields(true);
handleAllow(parseState, token);
break;
case CRAWL_DELAY:
parseState.setFinishedAgentFields(true);
handleCrawlDelay(parseState, token);
break;
case SITEMAP:
parseState.setFinishedAgentFields(true);
handleSitemap(parseState, token);
break;
case HTTP:
parseState.setFinishedAgentFields(true);
handleHttp(parseState, token);
break;
case UNKNOWN:
reportWarning(parseState, "Unknown directive in robots.txt file: {}", line);
parseState.setFinishedAgentFields(true);
break;
case MISSING:
reportWarning(parseState, "Unknown line in robots.txt file (size {}): {}", content.length, line);
parseState.setFinishedAgentFields(true);
break;
default:
break;
}
}
this._numWarningsDuringLastParse.set(parseState._numWarnings);
SimpleRobotRules result = parseState.getRobotRules();
if (result.getCrawlDelay() > _maxCrawlDelay) {
LOGGER.debug("Crawl delay exceeds max value - so disallowing all URLs: {}", url);
return new SimpleRobotRules(RobotRulesMode.ALLOW_NONE);
} else {
result.sortRules();
return result;
}
}
| private SimpleRobotRules parseContent(String url, byte[] content, String contentType, Collection<String> robotNames, boolean exactUserAgentMatching) {
if ((content == null) || (content.length == 0)) {
return new SimpleRobotRules(RobotRulesMode.ALLOW_ALL);
}
int bytesLen = content.length;
int offset = 0;
Charset encoding = StandardCharsets.UTF_8;
if ((bytesLen >= 3) && (content[0] == (byte) 0xEF) && (content[1] == (byte) 0xBB) && (content[2] == (byte) 0xBF)) {
offset = 3;
bytesLen -= 3;
encoding = StandardCharsets.UTF_8;
}
else if ((bytesLen >= 2) && (content[0] == (byte) 0xFF) && (content[1] == (byte) 0xFE)) {
offset = 2;
bytesLen -= 2;
encoding = StandardCharsets.UTF_16LE;
}
else if ((bytesLen >= 2) && (content[0] == (byte) 0xFE) && (content[1] == (byte) 0xFF)) {
offset = 2;
bytesLen -= 2;
encoding = StandardCharsets.UTF_16BE;
}
String contentAsStr;
contentAsStr = new String(content, offset, bytesLen, encoding);
boolean isHtmlType = ((contentType != null) && contentType.toLowerCase(Locale.ROOT).startsWith("text/html"));
boolean hasHTML = false;
if (isHtmlType || SIMPLE_HTML_PATTERN.matcher(contentAsStr).find()) {
if (!USER_AGENT_PATTERN.matcher(contentAsStr).find()) {
LOGGER.trace("Found non-robots.txt HTML file: " + url);
return new SimpleRobotRules(RobotRulesMode.ALLOW_ALL);
} else {
if (isHtmlType) {
LOGGER.debug("HTML content type returned for robots.txt file: " + url);
} else {
LOGGER.debug("Found HTML in robots.txt file: " + url);
}
hasHTML = true;
}
}
StringTokenizer lineParser = new StringTokenizer(contentAsStr, "\n\r\u0085\u2028\u2029");
ParseState parseState = new ParseState(url, robotNames);
while (lineParser.hasMoreTokens()) {
String line = lineParser.nextToken();
if (hasHTML) {
line = line.replaceAll("<[^>]+>", "");
}
int hashPos = line.indexOf("#");
if (hashPos >= 0) {
line = line.substring(0, hashPos);
}
line = line.trim();
if (line.length() == 0) {
continue;
}
RobotToken token = tokenize(line);
switch (token.getDirective()) {
case USER_AGENT:
handleUserAgent(parseState, token);
break;
case DISALLOW:
parseState.setFinishedAgentFields(true);
handleDisallow(parseState, token);
break;
case ALLOW:
parseState.setFinishedAgentFields(true);
handleAllow(parseState, token);
break;
case CRAWL_DELAY:
parseState.setFinishedAgentFields(true);
handleCrawlDelay(parseState, token);
break;
case SITEMAP:
parseState.setFinishedAgentFields(true);
handleSitemap(parseState, token);
break;
case HTTP:
parseState.setFinishedAgentFields(true);
handleHttp(parseState, token);
break;
case UNKNOWN:
reportWarning(parseState, "Unknown directive in robots.txt file: {}", line);
parseState.setFinishedAgentFields(true);
break;
case MISSING:
reportWarning(parseState, "Unknown line in robots.txt file (size {}): {}", content.length, line);
parseState.setFinishedAgentFields(true);
break;
default:
break;
}
}
this._numWarningsDuringLastParse.set(parseState._numWarnings);
SimpleRobotRules result = parseState.getRobotRules();
if (result.getCrawlDelay() > _maxCrawlDelay) {
LOGGER.debug("Crawl delay exceeds max value - so disallowing all URLs: {}", url);
return new SimpleRobotRules(RobotRulesMode.ALLOW_NONE);
} else {
result.sortRules();
return result;
}
}
|
vmzakharov-dataframe-ec-12af99192d24 | @Override
public String asStringLiteral()
{
return '"' + this.value + '"';
}
| @Override
public String asStringLiteral()
{
return this.value.indexOf('\"') == -1 ? '"' + this.value + '"' : '\'' + this.value + '\'';
}
|
traccar-traccar-230f629c3dce | @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedShort();
String imei = String.format("%015d", buf.readLong());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
int type = buf.readUnsignedByte();
if (type == MSG_RECORDS || type == MSG_EXTENDED_RECORDS) {
List<Position> positions = new LinkedList<>();
buf.readUnsignedByte();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
buf.readUnsignedByte();
if (type == MSG_EXTENDED_RECORDS) {
int recordExtension = buf.readUnsignedByte();
int mergeRecordCount = BitUtil.from(recordExtension, 4);
int currentRecord = BitUtil.to(recordExtension, 4);
if (currentRecord > 0 && currentRecord <= mergeRecordCount) {
position = positions.remove(positions.size() - 1);
}
}
buf.readUnsignedByte();
position.setValid(true);
position.setLongitude(buf.readInt() / 10000000.0);
position.setLatitude(buf.readInt() / 10000000.0);
position.setAltitude(buf.readUnsignedShort() / 10.0);
position.setCourse(buf.readUnsignedShort() / 100.0);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.set(Position.KEY_HDOP, buf.readUnsignedByte() / 10.0);
if (type == MSG_EXTENDED_RECORDS) {
position.set(Position.KEY_EVENT, buf.readUnsignedShort());
} else {
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
}
int valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 1);
}
valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 2);
}
valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 4);
}
valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 8);
}
decodeDriver(position, Position.PREFIX_IO + 126, Position.PREFIX_IO + 127);
decodeDriver(position, Position.PREFIX_IO + 155, Position.PREFIX_IO + 156);
Long tagIdPart1 = (Long) position.getAttributes().remove(Position.PREFIX_IO + 760);
Long tagIdPart2 = (Long) position.getAttributes().remove(Position.PREFIX_IO + 761);
if (tagIdPart1 != null && tagIdPart2 != null) {
position.set("tagId", Long.toHexString(tagIdPart1) + Long.toHexString(tagIdPart2));
}
positions.add(position);
}
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(
Unpooled.wrappedBuffer(DataConverter.parseHex("0002640113bc")), remoteAddress));
}
return positions;
} else if (type == MSG_DTCS) {
List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte();
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.setValid(true);
position.setLongitude(buf.readInt() / 10000000.0);
position.setLatitude(buf.readInt() / 10000000.0);
if (buf.readUnsignedByte() == 2) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_DTCS, buf.readSlice(5).toString(StandardCharsets.US_ASCII));
positions.add(position);
}
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(
Unpooled.wrappedBuffer(DataConverter.parseHex("00026d01c4a4")), remoteAddress));
}
return positions;
} else if (type == MSG_FILES) {
int subtype = buf.readUnsignedByte();
int source = buf.readUnsignedByte();
if (subtype == 2) {
ByteBuf filename = buf.readSlice(8);
int total = buf.readUnsignedShort();
int current = buf.readUnsignedShort();
if (photo == null) {
photo = Unpooled.buffer();
}
photo.writeBytes(buf.readSlice(buf.readableBytes() - 2));
if (current < total - 1) {
ByteBuf content = Unpooled.buffer();
content.writeByte(subtype);
content.writeByte(source);
content.writeBytes(filename);
content.writeShort(current + 1);
ByteBuf response = RuptelaProtocolEncoder.encodeContent(type, content);
content.release();
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
} else {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_IMAGE, writeMediaFile(imei, photo, "jpg"));
photo.release();
photo = null;
return position;
}
}
return null;
} else if (type == MSG_IDENTIFICATION) {
ByteBuf content = Unpooled.buffer();
content.writeByte(1);
ByteBuf response = RuptelaProtocolEncoder.encodeContent(type, content);
content.release();
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
return null;
} else {
return decodeCommandResponse(deviceSession, type, buf);
}
}
| @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedShort();
String imei = String.format("%015d", buf.readLong());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
int type = buf.readUnsignedByte();
if (type == MSG_RECORDS || type == MSG_EXTENDED_RECORDS) {
List<Position> positions = new LinkedList<>();
buf.readUnsignedByte();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
buf.readUnsignedByte();
if (type == MSG_EXTENDED_RECORDS) {
int recordExtension = buf.readUnsignedByte();
int mergeRecordCount = BitUtil.from(recordExtension, 4);
int currentRecord = BitUtil.to(recordExtension, 4);
if (currentRecord > 0 && currentRecord <= mergeRecordCount) {
position = positions.remove(positions.size() - 1);
}
}
buf.readUnsignedByte();
int longitude = buf.readInt();
int latitude = buf.readInt();
if (longitude > Integer.MIN_VALUE && latitude > Integer.MIN_VALUE) {
position.setValid(true);
position.setLongitude(longitude / 10000000.0);
position.setLatitude(latitude / 10000000.0);
position.setAltitude(buf.readUnsignedShort() / 10.0);
position.setCourse(buf.readUnsignedShort() / 100.0);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.set(Position.KEY_HDOP, buf.readUnsignedByte() / 10.0);
} else {
buf.skipBytes(8);
getLastLocation(position, null);
}
if (type == MSG_EXTENDED_RECORDS) {
position.set(Position.KEY_EVENT, buf.readUnsignedShort());
} else {
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
}
int valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 1);
}
valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 2);
}
valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 4);
}
valueCount = buf.readUnsignedByte();
for (int j = 0; j < valueCount; j++) {
int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
decodeParameter(position, id, buf, 8);
}
decodeDriver(position, Position.PREFIX_IO + 126, Position.PREFIX_IO + 127);
decodeDriver(position, Position.PREFIX_IO + 155, Position.PREFIX_IO + 156);
Long tagIdPart1 = (Long) position.getAttributes().remove(Position.PREFIX_IO + 760);
Long tagIdPart2 = (Long) position.getAttributes().remove(Position.PREFIX_IO + 761);
if (tagIdPart1 != null && tagIdPart2 != null) {
position.set("tagId", Long.toHexString(tagIdPart1) + Long.toHexString(tagIdPart2));
}
positions.add(position);
}
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(
Unpooled.wrappedBuffer(DataConverter.parseHex("0002640113bc")), remoteAddress));
}
return positions;
} else if (type == MSG_DTCS) {
List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte();
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.setValid(true);
position.setLongitude(buf.readInt() / 10000000.0);
position.setLatitude(buf.readInt() / 10000000.0);
if (buf.readUnsignedByte() == 2) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_DTCS, buf.readSlice(5).toString(StandardCharsets.US_ASCII));
positions.add(position);
}
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(
Unpooled.wrappedBuffer(DataConverter.parseHex("00026d01c4a4")), remoteAddress));
}
return positions;
} else if (type == MSG_FILES) {
int subtype = buf.readUnsignedByte();
int source = buf.readUnsignedByte();
if (subtype == 2) {
ByteBuf filename = buf.readSlice(8);
int total = buf.readUnsignedShort();
int current = buf.readUnsignedShort();
if (photo == null) {
photo = Unpooled.buffer();
}
photo.writeBytes(buf.readSlice(buf.readableBytes() - 2));
if (current < total - 1) {
ByteBuf content = Unpooled.buffer();
content.writeByte(subtype);
content.writeByte(source);
content.writeBytes(filename);
content.writeShort(current + 1);
ByteBuf response = RuptelaProtocolEncoder.encodeContent(type, content);
content.release();
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
} else {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_IMAGE, writeMediaFile(imei, photo, "jpg"));
photo.release();
photo = null;
return position;
}
}
return null;
} else if (type == MSG_IDENTIFICATION) {
ByteBuf content = Unpooled.buffer();
content.writeByte(1);
ByteBuf response = RuptelaProtocolEncoder.encodeContent(type, content);
content.release();
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
return null;
} else {
return decodeCommandResponse(deviceSession, type, buf);
}
}
|
traccar-traccar-3642b9520863 | private Position decodePosition(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int index) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 15));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
int event = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString();
DateBuilder dateBuilder = new DateBuilder()
.setYear(Integer.parseInt(time.substring(0, 2)))
.setMonth(Integer.parseInt(time.substring(2, 4)))
.setDay(Integer.parseInt(time.substring(4, 6)))
.setHour(Integer.parseInt(time.substring(6, 8)))
.setMinute(Integer.parseInt(time.substring(8, 10)))
.setSecond(Integer.parseInt(time.substring(10, 12)));
position.setTime(dateBuilder.getDate());
position.setLongitude(buf.readInt() * 0.00001);
position.setLatitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
Network network = new Network();
while (buf.readableBytes() > 4) {
int subtype = buf.readUnsignedShort();
int length = buf.readUnsignedShort() - 4;
int endIndex = buf.readerIndex() + length;
switch (subtype) {
case 0x0001:
int coolantTemperature = buf.readUnsignedByte() - 40;
if (coolantTemperature <= 215) {
position.set(Position.KEY_COOLANT_TEMP, coolantTemperature);
}
int rpm = buf.readUnsignedShort();
if (rpm <= 65535) {
position.set(Position.KEY_RPM, rpm);
}
position.set("averageSpeed", buf.readUnsignedByte());
buf.readUnsignedShort();
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
buf.readUnsignedInt();
if (buf.readerIndex() < endIndex) {
position.set("adBlueLevel", buf.readUnsignedByte() * 0.4);
}
break;
case 0x0005:
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
buf.readUnsignedInt();
break;
case 0x0009:
position.set(
Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
break;
case 0x0011:
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 0.05);
break;
case 0x0014:
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() / 255.0);
position.set("timingAdvance", buf.readUnsignedByte() * 0.5);
position.set("airTemp", buf.readUnsignedByte() - 40);
position.set("airFlow", buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() / 255.0);
break;
case 0x0020:
String[] cells = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String cell : cells) {
String[] values = cell.split("@");
network.addCellTower(CellTower.from(
Integer.parseInt(values[0]), Integer.parseInt(values[1]),
Integer.parseInt(values[2], 16), Integer.parseInt(values[3], 16)));
}
break;
case 0x0021:
String[] points = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String point : points) {
String[] values = point.split("@");
network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
}
break;
default:
buf.skipBytes(length);
break;
}
buf.readerIndex(endIndex);
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
sendResponse(channel, MSG_POSITION_RSP, index, null);
return position;
}
| private Position decodePosition(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int index) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 15));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
int event = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString();
DateBuilder dateBuilder = new DateBuilder()
.setYear(Integer.parseInt(time.substring(0, 2)))
.setMonth(Integer.parseInt(time.substring(2, 4)))
.setDay(Integer.parseInt(time.substring(4, 6)))
.setHour(Integer.parseInt(time.substring(6, 8)))
.setMinute(Integer.parseInt(time.substring(8, 10)))
.setSecond(Integer.parseInt(time.substring(10, 12)));
position.setTime(dateBuilder.getDate());
position.setLongitude(buf.readInt() * 0.00001);
position.setLatitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
Network network = new Network();
while (buf.readableBytes() > 4) {
int subtype = buf.readUnsignedShort();
int length = buf.readUnsignedShort() - 4;
int endIndex = buf.readerIndex() + length;
switch (subtype) {
case 0x0001:
int coolantTemperature = buf.readUnsignedByte() - 40;
if (coolantTemperature <= 215) {
position.set(Position.KEY_COOLANT_TEMP, coolantTemperature);
}
int rpm = buf.readUnsignedShort();
if (rpm <= 65535) {
position.set(Position.KEY_RPM, rpm);
}
position.set("averageSpeed", buf.readUnsignedByte());
buf.readUnsignedShort();
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
buf.readUnsignedInt();
if (buf.readerIndex() < endIndex) {
position.set("adBlueLevel", buf.readUnsignedByte() * 0.4);
}
break;
case 0x0005:
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
buf.readUnsignedInt();
break;
case 0x0009:
position.set(
Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
break;
case 0x0011:
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 0.05);
break;
case 0x0014:
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() / 255.0);
position.set("timingAdvance", buf.readUnsignedByte() * 0.5);
position.set("airTemp", buf.readUnsignedByte() - 40);
position.set("airFlow", buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() / 255.0);
break;
case 0x0020:
String[] cells = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String cell : cells) {
String[] values = cell.split("@");
network.addCellTower(CellTower.from(
Integer.parseInt(values[0]), Integer.parseInt(values[1]),
Integer.parseInt(values[2], 16), Long.parseLong(values[3], 16)));
}
break;
case 0x0021:
String[] points = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String point : points) {
String[] values = point.split("@");
network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
}
break;
default:
buf.skipBytes(length);
break;
}
buf.readerIndex(endIndex);
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
sendResponse(channel, MSG_POSITION_RSP, index, null);
return position;
}
|
traccar-traccar-3dad196b882c | private Position decodePosition(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int index) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 15));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
int event = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString();
DateBuilder dateBuilder = new DateBuilder()
.setYear(Integer.parseInt(time.substring(0, 2)))
.setMonth(Integer.parseInt(time.substring(2, 4)))
.setDay(Integer.parseInt(time.substring(4, 6)))
.setHour(Integer.parseInt(time.substring(6, 8)))
.setMinute(Integer.parseInt(time.substring(8, 10)))
.setSecond(Integer.parseInt(time.substring(10, 12)));
position.setTime(dateBuilder.getDate());
position.setLongitude(buf.readInt() * 0.00001);
position.setLatitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
Network network = new Network();
while (buf.readableBytes() > 4) {
int subtype = buf.readUnsignedShort();
int length = buf.readUnsignedShort() - 4;
switch (subtype) {
case 0x0001:
int coolantTemperature = buf.readUnsignedByte() - 40;
if (coolantTemperature <= 215) {
position.set(Position.KEY_COOLANT_TEMP, coolantTemperature);
}
int rpm = buf.readUnsignedShort();
if (rpm <= 65535) {
position.set(Position.KEY_RPM, rpm);
}
position.set("averageSpeed", buf.readUnsignedByte());
buf.readUnsignedShort();
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
buf.readUnsignedInt();
break;
case 0x0005:
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
buf.readUnsignedInt();
break;
case 0x0009:
position.set(
Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
break;
case 0x0011:
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 0.05);
break;
case 0x0014:
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() / 255.0);
position.set("timingAdvance", buf.readUnsignedByte() * 0.5);
position.set("airTemp", buf.readUnsignedByte() - 40);
position.set("airFlow", buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() / 255.0);
break;
case 0x0020:
String[] cells = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String cell : cells) {
String[] values = cell.split("@");
network.addCellTower(CellTower.from(
Integer.parseInt(values[0]), Integer.parseInt(values[1]),
Integer.parseInt(values[2], 16), Integer.parseInt(values[3], 16)));
}
break;
case 0x0021:
String[] points = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String point : points) {
String[] values = point.split("@");
network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
}
break;
default:
buf.skipBytes(length);
break;
}
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
sendResponse(channel, MSG_POSITION_RSP, index, null);
return position;
}
| private Position decodePosition(
Channel channel, SocketAddress remoteAddress, ByteBuf buf, int index) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 15));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
int event = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString();
DateBuilder dateBuilder = new DateBuilder()
.setYear(Integer.parseInt(time.substring(0, 2)))
.setMonth(Integer.parseInt(time.substring(2, 4)))
.setDay(Integer.parseInt(time.substring(4, 6)))
.setHour(Integer.parseInt(time.substring(6, 8)))
.setMinute(Integer.parseInt(time.substring(8, 10)))
.setSecond(Integer.parseInt(time.substring(10, 12)));
position.setTime(dateBuilder.getDate());
position.setLongitude(buf.readInt() * 0.00001);
position.setLatitude(buf.readInt() * 0.00001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
Network network = new Network();
while (buf.readableBytes() > 4) {
int subtype = buf.readUnsignedShort();
int length = buf.readUnsignedShort() - 4;
int endIndex = buf.readerIndex() + length;
switch (subtype) {
case 0x0001:
int coolantTemperature = buf.readUnsignedByte() - 40;
if (coolantTemperature <= 215) {
position.set(Position.KEY_COOLANT_TEMP, coolantTemperature);
}
int rpm = buf.readUnsignedShort();
if (rpm <= 65535) {
position.set(Position.KEY_RPM, rpm);
}
position.set("averageSpeed", buf.readUnsignedByte());
buf.readUnsignedShort();
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
buf.readUnsignedInt();
if (buf.readerIndex() < endIndex) {
position.set("adBlueLevel", buf.readUnsignedByte() * 0.4);
}
break;
case 0x0005:
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
buf.readUnsignedInt();
break;
case 0x0009:
position.set(
Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
break;
case 0x0011:
position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 0.05);
break;
case 0x0014:
position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() / 255.0);
position.set("timingAdvance", buf.readUnsignedByte() * 0.5);
position.set("airTemp", buf.readUnsignedByte() - 40);
position.set("airFlow", buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() / 255.0);
break;
case 0x0020:
String[] cells = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String cell : cells) {
String[] values = cell.split("@");
network.addCellTower(CellTower.from(
Integer.parseInt(values[0]), Integer.parseInt(values[1]),
Integer.parseInt(values[2], 16), Integer.parseInt(values[3], 16)));
}
break;
case 0x0021:
String[] points = buf.readCharSequence(
length, StandardCharsets.US_ASCII).toString().split("\\+");
for (String point : points) {
String[] values = point.split("@");
network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
}
break;
default:
buf.skipBytes(length);
break;
}
buf.readerIndex(endIndex);
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
sendResponse(channel, MSG_POSITION_RSP, index, null);
return position;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.