diff --git "a/train.csv" "b/train.csv" new file mode 100644--- /dev/null +++ "b/train.csv" @@ -0,0 +1,18408 @@ +bug_id,func_before,func_after +aws-aws-secretsmanager-jdbc-d25e52d637cf," @Override + public String constructUrlFromEndpointPortDatabase(String endpoint, String port, String dbname) { + String url = ""jdbc:postgresql://"" + endpoint; + if (!StringUtils.isNullOrEmpty(port)) { + url += "":"" + port; + } + if (!StringUtils.isNullOrEmpty(dbname)) { + url += ""/"" + dbname; + } + return url; + } +"," @Override + public String constructUrlFromEndpointPortDatabase(String endpoint, String port, String dbname) { + String url = ""jdbc:postgresql://"" + endpoint; + if (!StringUtils.isNullOrEmpty(port)) { + url += "":"" + port; + } + url += ""/""; + if (!StringUtils.isNullOrEmpty(dbname)) { + url += dbname; + } + return url; + } +" +jitterted-ensembler-14a39138787f," public void acceptedBy(MemberId memberId) { + requireNotCompleted(); + requireNotCanceled(); + requireHasSpace(); + membersWhoAccepted.add(memberId); + membersWhoDeclined.remove(memberId); + } +"," public void acceptedBy(MemberId memberId) { + requireNotCompleted(); + requireNotCanceled(); + requireHasSpace(); + membersWhoAccepted.add(memberId); + membersWhoDeclined.remove(memberId); + membersAsSpectators.remove(memberId); + } +" +dmak-jaxb-xew-plugin-f48935133d6a," private void moveClassLevelUp(Outline outline, JDefinedClass clazz) { + JDefinedClass parent = (JDefinedClass) clazz.parentContainer(); + JClassContainer grandParent = parent.parentContainer(); + Map classes; + if (grandParent.isClass()) { + JDefinedClass grandParentClass = (JDefinedClass) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to class "" + grandParentClass.fullName()); + classes = getPrivateField(grandParentClass, ""classes""); + } + else { + JPackage grandParentPackage = (JPackage) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to package "" + grandParentPackage.name()); + classes = getPrivateField(grandParentPackage, ""classes""); + setPrivateField(clazz.mods(), ""mods"", Integer.valueOf(clazz.mods().getValue() & ~JMod.STATIC)); + for (ClassOutline classOutline : outline.getClasses()) { + if (classOutline.implClass == clazz) { + XSComponent sc = classOutline.target.getSchemaComponent(); + assert (sc instanceof XSDeclaration && ((XSDeclaration) sc).isLocal()); + setPrivateField(sc, ""anonymous"", Boolean.FALSE); + break; + } + } + } + if (classes.containsKey(clazz.name())) { + writeSummary(""\tRenaming class "" + clazz.fullName() + "" to class "" + parent.name() + clazz.name()); + setPrivateField(clazz, ""name"", parent.name() + clazz.name()); + } + classes.put(clazz.name(), clazz); + setPrivateField(clazz, ""outer"", grandParent); + } +"," private void moveClassLevelUp(Outline outline, JDefinedClass clazz) { + JDefinedClass parent = (JDefinedClass) clazz.parentContainer(); + JClassContainer grandParent = parent.parentContainer(); + Map classes; + if (grandParent.isClass()) { + JDefinedClass grandParentClass = (JDefinedClass) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to class "" + grandParentClass.fullName()); + classes = getPrivateField(grandParentClass, ""classes""); + } + else { + JPackage grandParentPackage = (JPackage) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to package "" + grandParentPackage.name()); + classes = getPrivateField(grandParentPackage, ""classes""); + setPrivateField(clazz.mods(), ""mods"", Integer.valueOf(clazz.mods().getValue() & ~JMod.STATIC)); + for (ClassOutline classOutline : outline.getClasses()) { + if (classOutline.implClass == clazz) { + XSComponent sc = classOutline.target.getSchemaComponent(); + assert (sc instanceof XSDeclaration && ((XSDeclaration) sc).isLocal()); + setPrivateField(sc, ""anonymous"", Boolean.FALSE); + break; + } + } + } + if (classes.containsKey(clazz.name()) || classes.containsKey(clazz.name().toUpperCase())) { + String newName = parent.name() + clazz.name(); + writeSummary(""\tRenaming class "" + clazz.fullName() + "" to class "" + newName); + setPrivateField(clazz, ""name"", newName); + } + boolean allClassNamesInUpperCase = classes.keySet().stream().allMatch(key -> key.equals(key.toUpperCase())); + classes.put(allClassNamesInUpperCase ? clazz.name().toUpperCase() : clazz.name(), clazz); + setPrivateField(clazz, ""outer"", grandParent); + } +" +jhy-jsoup-5f20fcc2f728," public Safelist addTags(String... tags) { + Validate.notNull(tags); + for (String tagName : tags) { + Validate.notEmpty(tagName); + tagNames.add(TagName.valueOf(tagName)); + } + return this; + } +"," public Safelist addTags(String... tags) { + Validate.notNull(tags); + for (String tagName : tags) { + Validate.notEmpty(tagName); + Validate.isFalse(tagName.equalsIgnoreCase(""noscript""), + ""noscript is unsupported in Safelists, due to incompatibilities between parsers with and without script-mode enabled""); + tagNames.add(TagName.valueOf(tagName)); + } + return this; + } +" +crowdin-crowdin-api-client-java-f0f22b2b56d7," public JacksonJsonTransformer() { + ObjectMapper cleanObjectMapper = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + SimpleModule enumModule = new SimpleModule() + .addDeserializer(Enum.class, new EnumDeserializer()); + SimpleModule module = new SimpleModule() + .addSerializer(Enum.class, new EnumSerializer()) + .addDeserializer(Enum.class, new EnumDeserializer()) + .addDeserializer(CrowdinApiException.class, new CrowdinApiExceptionDeserializer(cleanObjectMapper)) + .addDeserializer(Project.class, new ProjectDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule))) + .addDeserializer(FileInfo.class, new FileInfoDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule) + .registerModule(new SimpleModule() + .addDeserializer(ImportOptions.class, new FileImportOptionsDeserializer(cleanObjectMapper)) + .addDeserializer(ExportOptions.class, new FileExportOptionsDeserializer(cleanObjectMapper))))) + .addDeserializer(LanguageTranslations.class, new LanguageTranslationsDeserializer(cleanObjectMapper)); + this.objectMapper = cleanObjectMapper.copy() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .setDateFormat(new SimpleDateFormat(""yyyy-MM-dd'T'HH:mm:ss+hh:mm"")) + .registerModule(module) + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + this.errorObjectMapper = cleanObjectMapper; + } +"," public JacksonJsonTransformer() { + ObjectMapper cleanObjectMapper = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + SimpleModule enumModule = new SimpleModule() + .addDeserializer(Enum.class, new EnumDeserializer()); + SimpleModule module = new SimpleModule() + .addSerializer(Enum.class, new EnumSerializer()) + .addDeserializer(Enum.class, new EnumDeserializer()) + .addDeserializer(CrowdinApiException.class, new CrowdinApiExceptionDeserializer(cleanObjectMapper)) + .addDeserializer(Project.class, new ProjectDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule))) + .addDeserializer(FileInfo.class, new FileInfoDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule) + .registerModule(new SimpleModule() + .addDeserializer(ImportOptions.class, new FileImportOptionsDeserializer(cleanObjectMapper)) + .addDeserializer(ExportOptions.class, new FileExportOptionsDeserializer(cleanObjectMapper))))) + .addDeserializer(LanguageTranslations.class, new LanguageTranslationsDeserializer(cleanObjectMapper)); + this.objectMapper = cleanObjectMapper.copy() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .setDateFormat(new SimpleDateFormat(""yyyy-MM-dd'T'HH:mm:ssXXX"")) + .registerModule(module) + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + this.errorObjectMapper = cleanObjectMapper; + } +" +stellar-java-stellar-sdk-1461c2fc5b89," public boolean isSorobanTransaction() { + if (mOperations.length != 1) { + return false; + } + Operation op = mOperations[0]; + return op instanceof InvokeHostFunctionOperation + || op instanceof BumpSequenceOperation + || op instanceof RestoreFootprintOperation; + } +"," public boolean isSorobanTransaction() { + if (mOperations.length != 1) { + return false; + } + Operation op = mOperations[0]; + return op instanceof InvokeHostFunctionOperation + || op instanceof BumpFootprintExpirationOperation + || op instanceof RestoreFootprintOperation; + } +" +traccar-traccar-65f54c200cf0," private void decodeLocation(Position position, ByteBuf buf, int codec, String model) { + int globalMask = 0x0f; + if (codec == CODEC_GH3000) { + long time = buf.readUnsignedInt() & 0x3fffffff; + time += 1167609600; + globalMask = buf.readUnsignedByte(); + if (BitUtil.check(globalMask, 0)) { + position.setTime(new Date(time * 1000)); + int locationMask = buf.readUnsignedByte(); + if (BitUtil.check(locationMask, 0)) { + position.setLatitude(buf.readFloat()); + position.setLongitude(buf.readFloat()); + } + if (BitUtil.check(locationMask, 1)) { + position.setAltitude(buf.readUnsignedShort()); + } + if (BitUtil.check(locationMask, 2)) { + position.setCourse(buf.readUnsignedByte() * 360.0 / 256); + } + if (BitUtil.check(locationMask, 3)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + if (BitUtil.check(locationMask, 4)) { + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 5)) { + CellTower cellTower = CellTower.fromLacCid( + getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort()); + if (BitUtil.check(locationMask, 6)) { + cellTower.setSignalStrength((int) buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + cellTower.setOperator(buf.readUnsignedInt()); + } + position.setNetwork(new Network(cellTower)); + } else { + if (BitUtil.check(locationMask, 6)) { + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + position.set(Position.KEY_OPERATOR, buf.readUnsignedInt()); + } + } + } else { + getLastLocation(position, new Date(time * 1000)); + } + } else { + position.setTime(new Date(buf.readLong())); + position.set(""priority"", buf.readUnsignedByte()); + position.setLongitude(buf.readInt() / 10000000.0); + position.setLatitude(buf.readInt() / 10000000.0); + position.setAltitude(buf.readShort()); + position.setCourse(buf.readUnsignedShort()); + int satellites = buf.readUnsignedByte(); + position.set(Position.KEY_SATELLITES, satellites); + position.setValid(satellites != 0); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); + position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16)); + if (codec == CODEC_16) { + buf.readUnsignedByte(); + } + readExtByte(buf, codec, CODEC_8_EXT); + } + if (BitUtil.check(globalMask, 1)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec, model); + } + } + if (BitUtil.check(globalMask, 2)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec, model); + } + } + if (BitUtil.check(globalMask, 3)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec, model); + } + } + if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8, codec, model); + } + } + if (extended) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16); + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16))); + } + } + if (codec == CODEC_8_EXT) { + int cnt = buf.readUnsignedShort(); + for (int j = 0; j < cnt; j++) { + int id = buf.readUnsignedShort(); + int length = buf.readUnsignedShort(); + if (id == 256) { + position.set(Position.KEY_VIN, + buf.readSlice(length).toString(StandardCharsets.US_ASCII)); + } else if (id == 281) { + position.set(Position.KEY_DTCS, + buf.readSlice(length).toString(StandardCharsets.US_ASCII).replace(',', ' ')); + } else if (id == 385) { + ByteBuf data = buf.readSlice(length); + data.readUnsignedByte(); + int index = 1; + while (data.isReadable()) { + int flags = data.readUnsignedByte(); + if (BitUtil.from(flags, 4) > 0) { + position.set(""beacon"" + index + ""Uuid"", ByteBufUtil.hexDump(data.readSlice(16))); + position.set(""beacon"" + index + ""Major"", data.readUnsignedShort()); + position.set(""beacon"" + index + ""Minor"", data.readUnsignedShort()); + } else { + position.set(""beacon"" + index + ""Namespace"", ByteBufUtil.hexDump(data.readSlice(10))); + position.set(""beacon"" + index + ""Instance"", ByteBufUtil.hexDump(data.readSlice(6))); + } + position.set(""beacon"" + index + ""Rssi"", (int) data.readByte()); + if (BitUtil.check(flags, 1)) { + position.set(""beacon"" + index + ""Battery"", data.readUnsignedShort() * 0.01); + } + if (BitUtil.check(flags, 2)) { + position.set(""beacon"" + index + ""Temp"", data.readUnsignedShort()); + } + index += 1; + } + } else { + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length))); + } + } + } + decodeNetwork(position, model); + } +"," private void decodeLocation(Position position, ByteBuf buf, int codec, String model) { + int globalMask = 0x0f; + if (codec == CODEC_GH3000) { + long time = buf.readUnsignedInt() & 0x3fffffff; + time += 1167609600; + globalMask = buf.readUnsignedByte(); + if (BitUtil.check(globalMask, 0)) { + position.setTime(new Date(time * 1000)); + int locationMask = buf.readUnsignedByte(); + if (BitUtil.check(locationMask, 0)) { + position.setLatitude(buf.readFloat()); + position.setLongitude(buf.readFloat()); + } + if (BitUtil.check(locationMask, 1)) { + position.setAltitude(buf.readUnsignedShort()); + } + if (BitUtil.check(locationMask, 2)) { + position.setCourse(buf.readUnsignedByte() * 360.0 / 256); + } + if (BitUtil.check(locationMask, 3)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + if (BitUtil.check(locationMask, 4)) { + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 5)) { + CellTower cellTower = CellTower.fromLacCid( + getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort()); + if (BitUtil.check(locationMask, 6)) { + cellTower.setSignalStrength((int) buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + cellTower.setOperator(buf.readUnsignedInt()); + } + position.setNetwork(new Network(cellTower)); + } else { + if (BitUtil.check(locationMask, 6)) { + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + position.set(Position.KEY_OPERATOR, buf.readUnsignedInt()); + } + } + } else { + getLastLocation(position, new Date(time * 1000)); + } + } else { + position.setTime(new Date(buf.readLong())); + position.set(""priority"", buf.readUnsignedByte()); + position.setLongitude(buf.readInt() / 10000000.0); + position.setLatitude(buf.readInt() / 10000000.0); + position.setAltitude(buf.readShort()); + position.setCourse(buf.readUnsignedShort()); + int satellites = buf.readUnsignedByte(); + position.set(Position.KEY_SATELLITES, satellites); + position.setValid(satellites != 0); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); + position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16)); + if (codec == CODEC_16) { + buf.readUnsignedByte(); + } + readExtByte(buf, codec, CODEC_8_EXT); + } + if (BitUtil.check(globalMask, 1)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec, model); + } + } + if (BitUtil.check(globalMask, 2)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec, model); + } + } + if (BitUtil.check(globalMask, 3)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec, model); + } + } + if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8, codec, model); + } + } + if (extended) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16); + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16))); + } + } + if (codec == CODEC_8_EXT) { + int cnt = buf.readUnsignedShort(); + for (int j = 0; j < cnt; j++) { + int id = buf.readUnsignedShort(); + int length = buf.readUnsignedShort(); + if (id == 256) { + position.set(Position.KEY_VIN, + buf.readSlice(length).toString(StandardCharsets.US_ASCII)); + } else if (id == 281) { + position.set(Position.KEY_DTCS, + buf.readSlice(length).toString(StandardCharsets.US_ASCII).replace(',', ' ')); + } else if (id == 385) { + ByteBuf data = buf.readSlice(length); + data.readUnsignedByte(); + int index = 1; + while (data.isReadable()) { + int flags = data.readUnsignedByte(); + if (BitUtil.from(flags, 4) > 0) { + position.set(""beacon"" + index + ""Uuid"", ByteBufUtil.hexDump(data.readSlice(16))); + position.set(""beacon"" + index + ""Major"", data.readUnsignedShort()); + position.set(""beacon"" + index + ""Minor"", data.readUnsignedShort()); + } else { + position.set(""beacon"" + index + ""Namespace"", ByteBufUtil.hexDump(data.readSlice(10))); + position.set(""beacon"" + index + ""Instance"", ByteBufUtil.hexDump(data.readSlice(6))); + } + position.set(""beacon"" + index + ""Rssi"", (int) data.readByte()); + if (BitUtil.check(flags, 1)) { + position.set(""beacon"" + index + ""Battery"", data.readUnsignedShort() * 0.01); + } + if (BitUtil.check(flags, 2)) { + position.set(""beacon"" + index + ""Temp"", data.readUnsignedShort()); + } + index += 1; + } + } else if (id == 10829 || id == 10831) { + ByteBuf data = buf.readSlice(length); + data.readUnsignedByte(); + for (int i = 1; data.isReadable(); i++) { + ByteBuf beacon = data.readSlice(data.readUnsignedByte()); + while (beacon.isReadable()) { + int parameterId = beacon.readUnsignedByte(); + int parameterLength = beacon.readUnsignedByte(); + switch (parameterId) { + case 0: + position.set(""tag"" + i + ""Rssi"", (int) beacon.readByte()); + break; + case 1: + String beaconId = ByteBufUtil.hexDump(beacon.readSlice(parameterLength)); + position.set(""tag"" + i + ""Id"", beaconId); + break; + case 13: + position.set(""tag"" + i + ""LowBattery"", beacon.readUnsignedByte()); + break; + case 14: + position.set(""tag"" + i + ""Battery"", beacon.readUnsignedShort()); + break; + default: + beacon.skipBytes(parameterLength); + break; + } + } + } + } else { + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length))); + } + } + } + decodeNetwork(position, model); + } +" +mthmulders-mcs-eff905bef8d8," private void printRow(final Help.TextTable table, final SearchResponse.Response.Doc doc) { + var lastUpdated = DATE_TIME_FORMATTER.format( + Instant.ofEpochMilli(doc.timestamp()).atZone(ZoneId.systemDefault()) + ); + table.addRowValues(doc.id(), lastUpdated); + } +"," private void printRow(final Help.TextTable table, final SearchResponse.Response.Doc doc) { + var lastUpdated = DATE_TIME_FORMATTER.format( + Instant.ofEpochMilli(doc.timestamp()).atZone(ZoneId.systemDefault()) + ); + table.addRowValues(doc.id() + "":"" + doc.latestVersion(), lastUpdated); + } +" +traccar-traccar-fdbd269b9b99," private Object decodePosition( + Channel channel, SocketAddress remoteAddress, String sentence, String id) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + if (deviceSession == null) { + return null; + } + List positions = new LinkedList<>(); + Position position = null; + DateBuilder dateBuilder = null; + for (String pair : sentence.split("","")) { + String[] data = pair.split(""[=:]""); + int key; + try { + key = Integer.parseInt(data[0], 16); + } catch (NumberFormatException e) { + continue; + } + String value = data[1]; + if (key == 0x0) { + if (position != null) { + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + dateBuilder = new DateBuilder(new Date()); + } else if (position != null) { + switch (key) { + case 0x11: + value = (""000000"" + value).substring(value.length()); + dateBuilder.setDateReverse( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4))); + break; + case 0x10: + value = (""00000000"" + value).substring(value.length()); + dateBuilder.setTime( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4, 6)), + Integer.parseInt(value.substring(6)) * 10); + break; + case 0xA: + position.setValid(true); + position.setLatitude(Double.parseDouble(value)); + break; + case 0xB: + position.setValid(true); + position.setLongitude(Double.parseDouble(value)); + break; + case 0xC: + position.setAltitude(Double.parseDouble(value)); + break; + case 0xD: + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value))); + break; + case 0xE: + position.setCourse(Integer.parseInt(value)); + break; + case 0xF: + position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + break; + case 0x12: + position.set(Position.KEY_HDOP, Integer.parseInt(value)); + break; + case 0x20: + position.set(Position.KEY_ACCELERATION, value); + break; + case 0x24: + position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01); + break; + case 0x81: + position.set(Position.KEY_RSSI, Integer.parseInt(value)); + break; + case 0x82: + position.set(Position.KEY_DEVICE_TEMP, Integer.parseInt(value) * 0.1); + break; + case 0x104: + position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value)); + break; + case 0x105: + position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value)); + break; + case 0x10c: + position.set(Position.KEY_RPM, Integer.parseInt(value)); + break; + case 0x10d: + position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(value))); + break; + case 0x111: + position.set(Position.KEY_THROTTLE, Integer.parseInt(value)); + break; + default: + position.set(Position.PREFIX_IO + key, value); + break; + } + } + } + if (position != null) { + if (!position.getValid()) { + getLastLocation(position, null); + } + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + return positions.isEmpty() ? null : positions; + } +"," private Object decodePosition( + Channel channel, SocketAddress remoteAddress, String sentence, String id) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + if (deviceSession == null) { + return null; + } + List positions = new LinkedList<>(); + Position position = null; + DateBuilder dateBuilder = null; + for (String pair : sentence.split("","")) { + String[] data = pair.split(""[=:]""); + int key; + try { + key = Integer.parseInt(data[0], 16); + } catch (NumberFormatException e) { + continue; + } + String value = data[1]; + if (key == 0x0) { + if (position != null) { + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + dateBuilder = new DateBuilder(new Date()); + } else if (position != null) { + switch (key) { + case 0x11: + value = (""000000"" + value).substring(value.length()); + dateBuilder.setDateReverse( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4))); + break; + case 0x10: + value = (""00000000"" + value).substring(value.length()); + dateBuilder.setTime( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4, 6)), + Integer.parseInt(value.substring(6)) * 10); + break; + case 0xA: + position.setValid(true); + position.setLatitude(Double.parseDouble(value)); + break; + case 0xB: + position.setValid(true); + position.setLongitude(Double.parseDouble(value)); + break; + case 0xC: + position.setAltitude(Double.parseDouble(value)); + break; + case 0xD: + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value))); + break; + case 0xE: + position.setCourse(Integer.parseInt(value)); + break; + case 0xF: + position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + break; + case 0x12: + position.set(Position.KEY_HDOP, Integer.parseInt(value)); + break; + case 0x20: + position.set(Position.KEY_ACCELERATION, value); + break; + case 0x24: + position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01); + break; + case 0x81: + position.set(Position.KEY_RSSI, Integer.parseInt(value)); + break; + case 0x82: + position.set(Position.KEY_DEVICE_TEMP, Double.parseDouble(value) * 0.1); + break; + case 0x104: + position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value)); + break; + case 0x105: + position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value)); + break; + case 0x10c: + position.set(Position.KEY_RPM, Integer.parseInt(value)); + break; + case 0x10d: + position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(value))); + break; + case 0x111: + position.set(Position.KEY_THROTTLE, Integer.parseInt(value)); + break; + default: + position.set(Position.PREFIX_IO + key, value); + break; + } + } + } + if (position != null) { + if (!position.getValid()) { + getLastLocation(position, null); + } + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + return positions.isEmpty() ? null : positions; + } +" +traccar-traccar-8b4d3ee0b964," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; + if (sentence.startsWith(""!1,"")) { + int index = sentence.indexOf(',', 3); + if (index < 0) { + index = sentence.length(); + } + getDeviceSession(channel, remoteAddress, sentence.substring(3, index)); + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null || !sentence.matches(""![35A-D],.*"")) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + String type = sentence.substring(1, 2); + position.set(Position.KEY_TYPE, type); + if (type.equals(""3"")) { + getLastLocation(position, null); + position.set(Position.KEY_RESULT, sentence.substring(3)); + return position; + } else if (type.equals(""5"")) { + String[] values = sentence.split("",""); + getLastLocation(position, null); + position.set(Position.KEY_RSSI, Integer.parseInt(values[1])); + if (values.length >= 4) { + position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[3])); + } + return position; + } else if (type.equals(""B"") || type.equals(""D"")) { + Parser parser = new Parser(PATTERN_BD, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0)); + position.set(Position.KEY_HDOP, parser.nextDouble(0)); + return position; + } else if (type.equals(""C"")) { + Parser parser = new Parser(PATTERN_C, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + return position; + } else if (type.equals(""A"")) { + Parser parser = new Parser(PATTERN_A, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + return position; + } + return null; + } +"," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; + if (sentence.startsWith(""!1,"")) { + int index = sentence.indexOf(',', 3); + if (index < 0) { + index = sentence.length(); + } + getDeviceSession(channel, remoteAddress, sentence.substring(3, index)); + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null || !sentence.matches(""![345A-D],.*"")) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + String type = sentence.substring(1, 2); + position.set(Position.KEY_TYPE, type); + if (type.equals(""3"")) { + getLastLocation(position, null); + position.set(Position.KEY_RESULT, sentence.substring(3)); + return position; + } else if (type.equals(""4"")) { + String[] values = sentence.split("",""); + getLastLocation(position, null); + for (int i = 1; i <= 3; i++) { + if (!values[i + 1].isEmpty()) { + position.set(""phone"" + i, values[i + 1]); + } + } + return position; + } else if (type.equals(""5"")) { + String[] values = sentence.split("",""); + getLastLocation(position, null); + position.set(Position.KEY_RSSI, Integer.parseInt(values[1])); + if (values.length >= 4) { + position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[3])); + } + return position; + } else if (type.equals(""B"") || type.equals(""D"")) { + Parser parser = new Parser(PATTERN_BD, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0)); + position.set(Position.KEY_HDOP, parser.nextDouble(0)); + return position; + } else if (type.equals(""C"")) { + Parser parser = new Parser(PATTERN_C, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + return position; + } else if (type.equals(""A"")) { + Parser parser = new Parser(PATTERN_A, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + return position; + } + return null; + } +" +traccar-traccar-e73f36db83b9," private Object decodeEri(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_ERI, sentence); + if (!parser.matches()) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + long mask = parser.nextHexLong(); + LinkedList positions = new LinkedList<>(); + Integer power = parser.nextInt(); + Parser itemParser = new Parser(PATTERN_LOCATION, parser.next()); + while (itemParser.find()) { + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + decodeLocation(position, itemParser); + positions.add(position); + } + Position position = positions.getLast(); + skipLocation(parser); + if (power != null) { + position.set(Position.KEY_POWER, power * 0.001); + } + if (parser.hasNextAny(12)) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + position.set(Position.KEY_HOURS, parseHours(parser.next())); + position.set(Position.PREFIX_ADC + 1, parser.next()); + position.set(Position.PREFIX_ADC + 2, parser.next()); + position.set(Position.PREFIX_ADC + 3, parser.next()); + if (parser.hasNext(2)) { + position.set(Position.KEY_INPUT, parser.nextHexInt()); + position.set(Position.KEY_OUTPUT, parser.nextHexInt()); + } + if (parser.hasNext(4)) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + decodeStatus(position, parser); + } + int index = 0; + String[] data = parser.next().split("",""); + index += 1; + if (BitUtil.check(mask, 0)) { + index += 1; + } + if (BitUtil.check(mask, 1)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + index += 1; + if (!data[index++].isEmpty()) { + position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625); + } + } + } + if (BitUtil.check(mask, 2)) { + index += 1; + } + if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + if (BitUtil.check(mask, 3)) { + position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++])); + } + if (BitUtil.check(mask, 4)) { + index += 1; + } + } + } + } + if (parser.hasNext()) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + } + decodeDeviceTime(position, parser); + if (ignoreFixTime) { + positions.clear(); + positions.add(position); + } + return positions; + } +"," private Object decodeEri(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_ERI, sentence); + if (!parser.matches()) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + long mask = parser.nextHexLong(); + LinkedList positions = new LinkedList<>(); + Integer power = parser.nextInt(); + Parser itemParser = new Parser(PATTERN_LOCATION, parser.next()); + while (itemParser.find()) { + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + decodeLocation(position, itemParser); + positions.add(position); + } + Position position = positions.getLast(); + skipLocation(parser); + if (power != null) { + position.set(Position.KEY_POWER, power * 0.001); + } + if (parser.hasNextAny(12)) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + position.set(Position.KEY_HOURS, parseHours(parser.next())); + position.set(Position.PREFIX_ADC + 1, parser.next()); + position.set(Position.PREFIX_ADC + 2, parser.next()); + position.set(Position.PREFIX_ADC + 3, parser.next()); + if (parser.hasNext(2)) { + position.set(Position.KEY_INPUT, parser.nextHexInt()); + position.set(Position.KEY_OUTPUT, parser.nextHexInt()); + } + if (parser.hasNext(4)) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + decodeStatus(position, parser); + } + int index = 0; + String[] data = parser.next().split("",""); + index += 1; + if (BitUtil.check(mask, 0)) { + position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(data[index++], 16)); + } + if (BitUtil.check(mask, 1)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + index += 1; + if (!data[index++].isEmpty()) { + position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625); + } + } + } + if (BitUtil.check(mask, 2)) { + index += 1; + } + if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + if (BitUtil.check(mask, 3)) { + position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++])); + } + if (BitUtil.check(mask, 4)) { + index += 1; + } + } + } + } + if (parser.hasNext()) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + } + decodeDeviceTime(position, parser); + if (ignoreFixTime) { + positions.clear(); + positions.add(position); + } + return positions; + } +" +AuthMe-ConfigMe-aa91a6b315ec," public void setComment(@NotNull String path, @NotNull String... commentLines) { + comments.put(path, Collections.unmodifiableList(Arrays.asList(commentLines))); + } +"," public void setComment(@NotNull String path, @NotNull String... commentLines) { + List replaced = comments.put(path, Collections.unmodifiableList(Arrays.asList(commentLines))); + if (replaced != null) { + throw new IllegalStateException(""Comment lines already exists for the path '"" + path + ""'""); + } + } +" +traccar-traccar-8de9a36abef8," private void decodeFragment(Position position, String fragment) { + int dataIndex = fragment.indexOf(':'); + int index = 0; + String[] values; + if (fragment.length() == dataIndex + 1) { + values = new String[0]; + } else { + values = fragment.substring(dataIndex + 1).split("";""); + } + switch (fragment.substring(0, dataIndex)) { + case ""GPS"": + position.setValid(values[index++].equals(""A"")); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setLatitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'S') { + position.setLatitude(-position.getLatitude()); + } + position.setLongitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'W') { + position.setLongitude(-position.getLongitude()); + } + if (!values[index++].isEmpty()) { + position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1]))); + } + position.setCourse(Integer.parseInt(values[index++])); + if (index < values.length) { + position.setAltitude(Integer.parseInt(values[index++])); + } + if (index < values.length) { + position.set(Position.KEY_HDOP, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.KEY_VDOP, Double.parseDouble(values[index++])); + } + break; + case ""GSM"": + index += 1; + index += 1; + position.setNetwork(new Network(CellTower.from( + Integer.parseInt(values[index++]), Integer.parseInt(values[index++]), + Integer.parseInt(values[index++], 16), Integer.parseInt(values[index++], 16), + Integer.parseInt(values[index++])))); + break; + case ""COT"": + if (index < values.length) { + position.set(Position.KEY_ODOMETER, Long.parseLong(values[index++])); + } + if (index < values.length) { + String[] hours = values[index].split(""-""); + position.set(Position.KEY_HOURS, (Integer.parseInt(hours[0]) * 3600 + + (hours.length > 1 ? Integer.parseInt(hours[1]) * 60 : 0) + + (hours.length > 2 ? Integer.parseInt(hours[2]) : 0)) * 1000); + } + break; + case ""ADC"": + position.set(Position.KEY_POWER, Double.parseDouble(values[index++])); + if (index < values.length) { + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++])); + } + break; + case ""DTT"": + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16)); + if (!values[index++].isEmpty()) { + int io = Integer.parseInt(values[index - 1], 16); + position.set(Position.KEY_IGNITION, BitUtil.check(io, 0)); + position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1)); + position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2)); + position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3)); + position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4)); + position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5)); + position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6)); + position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7)); + } + position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]); + position.set(""eventStatus"", values[index++]); + if (index < values.length) { + position.set(""packetType"", values[index++]); + } + break; + case ""ETD"": + position.set(""eventData"", values[index++]); + break; + case ""OBD"": + position.set(""obd"", values[index++]); + break; + case ""TAG"": + position.set(""tagData"", values[index++]); + break; + case ""IWD"": + while (index < values.length) { + int sensorIndex = Integer.parseInt(values[index++]); + int dataType = Integer.parseInt(values[index++]); + if (dataType == 0) { + position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index++]); + } else if (dataType == 1) { + index += 1; + position.set(Position.PREFIX_TEMP + sensorIndex, Double.parseDouble(values[index++])); + } + } + break; + default: + break; + } + } +"," private void decodeFragment(Position position, String fragment) { + int dataIndex = fragment.indexOf(':'); + int index = 0; + String[] values; + if (fragment.length() == dataIndex + 1) { + values = new String[0]; + } else { + values = fragment.substring(dataIndex + 1).split("";""); + } + switch (fragment.substring(0, dataIndex)) { + case ""GPS"": + position.setValid(values[index++].equals(""A"")); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setLatitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'S') { + position.setLatitude(-position.getLatitude()); + } + position.setLongitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'W') { + position.setLongitude(-position.getLongitude()); + } + if (!values[index++].isEmpty()) { + position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1]))); + } + position.setCourse(Integer.parseInt(values[index++])); + if (index < values.length && !values[index++].isEmpty()) { + position.setAltitude(Integer.parseInt(values[index - 1])); + } + if (index < values.length && !values[index++].isEmpty()) { + position.set(Position.KEY_HDOP, Double.parseDouble(values[index - 1])); + } + if (index < values.length && !values[index++].isEmpty()) { + position.set(Position.KEY_VDOP, Double.parseDouble(values[index - 1])); + } + break; + case ""GSM"": + index += 1; + index += 1; + position.setNetwork(new Network(CellTower.from( + Integer.parseInt(values[index++]), Integer.parseInt(values[index++]), + Integer.parseInt(values[index++], 16), Integer.parseInt(values[index++], 16), + Integer.parseInt(values[index++])))); + break; + case ""COT"": + if (index < values.length) { + position.set(Position.KEY_ODOMETER, Long.parseLong(values[index++])); + } + if (index < values.length) { + String[] hours = values[index].split(""-""); + position.set(Position.KEY_HOURS, (Integer.parseInt(hours[0]) * 3600 + + (hours.length > 1 ? Integer.parseInt(hours[1]) * 60 : 0) + + (hours.length > 2 ? Integer.parseInt(hours[2]) : 0)) * 1000); + } + break; + case ""ADC"": + position.set(Position.KEY_POWER, Double.parseDouble(values[index++])); + if (index < values.length) { + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++])); + } + break; + case ""DTT"": + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16)); + if (!values[index++].isEmpty()) { + int io = Integer.parseInt(values[index - 1], 16); + position.set(Position.KEY_IGNITION, BitUtil.check(io, 0)); + position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1)); + position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2)); + position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3)); + position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4)); + position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5)); + position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6)); + position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7)); + } + position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]); + position.set(""eventStatus"", values[index++]); + if (index < values.length) { + position.set(""packetType"", values[index++]); + } + break; + case ""ETD"": + position.set(""eventData"", values[index++]); + break; + case ""OBD"": + position.set(""obd"", values[index++]); + break; + case ""TAG"": + position.set(""tagData"", values[index++]); + break; + case ""IWD"": + while (index < values.length) { + int sensorIndex = Integer.parseInt(values[index++]); + int dataType = Integer.parseInt(values[index++]); + if (dataType == 0) { + position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index++]); + } else if (dataType == 1) { + index += 1; + position.set(Position.PREFIX_TEMP + sensorIndex, Double.parseDouble(values[index++])); + } + } + break; + default: + break; + } + } +" +traccar-traccar-392f00082faf," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 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; + default: + buf.skipBytes(length); + break; + } + } + positions.add(position); + } + return positions; + } +"," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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; + default: + buf.skipBytes(length); + break; + } + } + positions.add(position); + } + return positions; + } +" +cloudsimplus-cloudsimplus-61c8b942d1ec," public HostAbstract(final List peList, final boolean activate) { + this(defaultBwCapacity, defaultStorageCapacity, new HarddriveStorage(defaultRamCapacity), peList, activate); + } +"," public HostAbstract(final List peList, final boolean activate) { + this(defaultRamCapacity, defaultBwCapacity, new HarddriveStorage(defaultStorageCapacity), peList, activate); + } +" +traccar-traccar-3771dd156efb," private Position decodePosition(DeviceSession deviceSession, String data) { + Parser parser = new Parser(PATTERN_POSITION, data); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + position.setValid(parser.next().equals(""A"")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.setCourse(parser.nextDouble(0)); + position.setAltitude(parser.nextDouble(0)); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_RSSI, parser.nextInt(0)); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_STEPS, parser.nextInt(0)); + int status = parser.nextHexInt(0); + position.set(Position.KEY_ALARM, decodeAlarm(status)); + if (BitUtil.check(status, 4)) { + position.set(Position.KEY_MOTION, true); + } + String[] values = parser.next().split("",""); + int index = 0; + Network network = new Network(); + int cellCount = Integer.parseInt(values[index++]); + if (cellCount > 0) { + index += 1; + int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + for (int i = 0; i < cellCount; i++) { + int lac = Integer.parseInt(values[index++]); + int cid = Integer.parseInt(values[index++]); + String rssi = values[index++]; + if (!rssi.isEmpty()) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); + } else { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } + } + } + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); + for (int i = 0; i < wifiCount; i++) { + index += 1; + String macAddress = values[index++]; + String rssi = values[index++]; + if (!macAddress.isEmpty() && !macAddress.equals(""0"") && !rssi.isEmpty()) { + network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + } + } + } + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } + return position; + } +"," private Position decodePosition(DeviceSession deviceSession, String data) { + Parser parser = new Parser(PATTERN_POSITION, data); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + position.setValid(parser.next().equals(""A"")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.setCourse(parser.nextDouble(0)); + position.setAltitude(parser.nextDouble(0)); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_RSSI, parser.nextInt(0)); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_STEPS, parser.nextInt(0)); + int status = parser.nextHexInt(0); + position.set(Position.KEY_ALARM, decodeAlarm(status)); + if (BitUtil.check(status, 4)) { + position.set(Position.KEY_MOTION, true); + } + String[] values = parser.next().split("",""); + int index = 0; + if (values.length < 4 || !values[index + 3].startsWith(""F"")) { + Network network = new Network(); + int cellCount = Integer.parseInt(values[index++]); + if (cellCount > 0) { + index += 1; + int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + for (int i = 0; i < cellCount; i++) { + int lac = Integer.parseInt(values[index++]); + int cid = Integer.parseInt(values[index++]); + String rssi = values[index++]; + if (!rssi.isEmpty()) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); + } else { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } + } + } + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); + for (int i = 0; i < wifiCount; i++) { + index += 1; + String macAddress = values[index++]; + String rssi = values[index++]; + if (!macAddress.isEmpty() && !macAddress.equals(""0"") && !rssi.isEmpty()) { + network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + } + } + } + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } + } + return position; + } +" +traccar-traccar-dfc546a26f5b," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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; + default: + buf.skipBytes(length); + break; + } + } + positions.add(position); + } + return positions; + } +"," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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; + } +" +traccar-traccar-3331593759a2," 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; + 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; + } + } + decodeCoordinates(position, buf); + position.setTime(time); + break; + case 0x03: + count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + int id = buf.readUnsignedShort(); + 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); + } + 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; + } +"," 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; + 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; + } + } + 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); + } + 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; + } +" +semver4j-semver4j-10102b374298," @Override + public String toString() { + return rangesList.stream() + .map(RangesList::formatRanges) + .collect(joining(OR_JOINER)); + } +"," @Override + public String toString() { + return rangesList.stream() + .map(RangesList::formatRanges) + .collect(joining(OR_JOINER)) + .replaceAll(""^\\(([^()]+)\\)$"", ""$1""); + } +" +nikoo28-java-solutions-8d81307ea165," public int[] calculateSpans(int[] prices) { + int[] spans = new int[prices.length]; + spans[0] = 1; + Stack indexStack = new Stack<>(); + indexStack.push(0); + for (int i = 1; i < prices.length; i++) { + while (!indexStack.isEmpty() + && prices[indexStack.peek()] <= prices[i]) + indexStack.pop(); + if (indexStack.isEmpty()) + spans[i] = i + 1; + else + spans[i] = i - indexStack.peek(); + indexStack.push(i); + } + return spans; + } +"," public int[] calculateSpans(int[] prices) { + int[] spans = new int[prices.length]; + spans[0] = 1; + Stack indexStack = new Stack<>(); + indexStack.push(0); + for (int i = 1; i < prices.length; i++) { + while (!indexStack.isEmpty() + && prices[indexStack.peek()] < prices[i]) + indexStack.pop(); + if (indexStack.isEmpty()) + spans[i] = i + 1; + else + spans[i] = i - indexStack.peek(); + indexStack.push(i); + } + return spans; + } +" +traccar-traccar-5a1a8d9192ee," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + String imei = buf.readCharSequence(15, StandardCharsets.US_ASCII).toString(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + List parameters = getParameters(deviceSession.getDeviceId()); + for (int parameter : parameters) { + switch (parameter) { + case 0x01: + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + break; + case 0x02: + position.setLatitude(buf.readIntLE() / 1000000.0); + break; + case 0x03: + position.setLongitude(buf.readIntLE() / 1000000.0); + break; + case 0x04: + position.setTime(new Date((buf.readUnsignedIntLE() + 946713600) * 1000)); + 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 0x08: + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); + break; + case 0x09: + position.setCourse(buf.readUnsignedShortLE()); + break; + case 0x0A: + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + break; + case 0x0B: + position.setAltitude(buf.readShortLE()); + break; + case 0x0C: + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + break; + case 0x0D: + position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000); + break; + case 0x14: + position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); + break; + case 0x15: + position.set(Position.KEY_INPUT, buf.readUnsignedByte()); + 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 0x1B: + buf.readUnsignedByte(); + break; + default: + break; + } + } + return position; + } +"," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + String imei = buf.readCharSequence(15, StandardCharsets.US_ASCII).toString(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + List parameters = getParameters(deviceSession.getDeviceId()); + for (int parameter : parameters) { + switch (parameter) { + case 0x01: + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + break; + case 0x02: + position.setLatitude(buf.readIntLE() / 1000000.0); + break; + case 0x03: + position.setLongitude(buf.readIntLE() / 1000000.0); + break; + case 0x04: + position.setTime(new Date((buf.readUnsignedIntLE() + 946684800) * 1000)); + 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 0x08: + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); + break; + case 0x09: + position.setCourse(buf.readUnsignedShortLE()); + break; + case 0x0A: + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + break; + case 0x0B: + position.setAltitude(buf.readShortLE()); + break; + case 0x0C: + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + break; + case 0x0D: + position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000); + break; + case 0x14: + position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); + break; + case 0x15: + position.set(Position.KEY_INPUT, buf.readUnsignedByte()); + 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 0x1B: + buf.readUnsignedByte(); + break; + default: + break; + } + } + return position; + } +" +jitterted-ensembler-0963194c9ebc," public static ParticipantAction from(MemberStatus memberStatus, boolean disabled) { + return switch (memberStatus) { + case UNKNOWN, DECLINED -> new ParticipantAction( + ""/member/accept"", + ""Participate in Rotation ⌨"", + disabled); + case PARTICIPANT -> new ParticipantAction( + ""/member/decline"", + ""Leave Rotation 👋"", + false); + case SPECTATOR -> new ParticipantAction( + ""/member/accept"", + ""Switch to Participant 👋"", + disabled); + }; + } +"," public static ParticipantAction from(MemberStatus memberStatus, boolean disabled) { + return switch (memberStatus) { + case UNKNOWN, DECLINED -> new ParticipantAction( + ""/member/accept"", + ""Participate in Rotation ⌨"", + disabled); + case PARTICIPANT -> new ParticipantAction( + ""/member/decline"", + ""Leave Rotation 👋"", + false); + case SPECTATOR -> new ParticipantAction( + ""/member/accept"", + ""Switch to Participant ⌨"", + disabled); + }; + } +" +jitterted-ensembler-0e512e5b3677," public static EnsembleSummaryView toView(Ensemble ensemble, MemberId memberId, MemberService memberService) { + List participantViews = transform(memberService, ensemble.acceptedMembers()); + return new EnsembleSummaryView(ensemble.getId().id(), + ensemble.name(), + DateTimeFormatting.formatAsDateTimeForCommonIso8601(ensemble.startDateTime()), + ensemble.acceptedCount(), + participantViews, + participantViews, + memberStatusToViewString(ensemble, memberId), + ensemble.meetingLink().toString(), + new GoogleCalendarLinkCreator().createFor(ensemble), + ensemble.recordingLink().toString() + ); + } +"," public static EnsembleSummaryView toView(Ensemble ensemble, MemberId memberId, MemberService memberService) { + List participantViews = transform(memberService, ensemble.acceptedMembers()); + List spectatorViews = transform(memberService, ensemble.spectators()); + return new EnsembleSummaryView(ensemble.getId().id(), + ensemble.name(), + DateTimeFormatting.formatAsDateTimeForCommonIso8601(ensemble.startDateTime()), + ensemble.acceptedCount(), + participantViews, + spectatorViews, + memberStatusToViewString(ensemble, memberId), + ensemble.meetingLink().toString(), + new GoogleCalendarLinkCreator().createFor(ensemble), + ensemble.recordingLink().toString() + ); + } +" +jitterted-ensembler-60ec3bf0273b," public void joinAsSpectator(MemberId memberId) { + membersAsSpectators.add(memberId); + membersWhoAccepted.remove(memberId); + } +"," public void joinAsSpectator(MemberId memberId) { + membersAsSpectators.add(memberId); + membersWhoAccepted.remove(memberId); + membersWhoDeclined.remove(memberId); + } +" +traccar-traccar-ee3cbd4aba2e," 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; + } +"," 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: + int x = buf.readUnsignedShort(); + if (x > 0x8000) { + x -= 0x10000; + } + int y = buf.readUnsignedShort(); + if (y > 0x8000) { + y -= 0x10000; + } + int z = buf.readUnsignedShort(); + if (z > 0x8000) { + z -= 0x10000; + } + position.set(""tilt"", String.format(""[%d,%d,%d]"", x, y, z)); + break; + default: + buf.skipBytes(length); + break; + } + } + return position; + } +" +fishercoder1534-Leetcode-2110c6b023b7," public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null || p == root || q == root) { + return root; + } + if ((root.val - p.val) * (root.val - q.val) > 0) { + if (root.val - p.val > 0) { + return lowestCommonAncestor(root.left, p, q); + } + return lowestCommonAncestor(root.right, p, q); + } + return root; + } +"," public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null || p == root || q == root) { + return root; + } + if (root.val > p.val && root.val > q.val) { + return lowestCommonAncestor(root.left, p, q); + } else if (root.val < p.val && root.val < q.val) { + return lowestCommonAncestor(root.right, p, q); + } + return root; + } +" +jhy-jsoup-8e2b86839b27," private boolean isFormatAsBlock(Document.OutputSettings out) { + return tag.formatAsBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline(); + } +"," private boolean isFormatAsBlock(Document.OutputSettings out) { + return tag.isBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline(); + } +" +traccar-traccar-cadcd2676adb," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.skipBytes(2); + int type = buf.readUnsignedByte(); + buf.readUnsignedShort(); + if (type == MSG_LOGIN || type == MSG_ADMIN_NUMBER || type == MSG_SEND_TEXT + || type == MSG_SMS_ALARM_SWITCH || type == MSG_POSITION_REUPLOAD) { + ByteBuf response = Unpooled.buffer(); + response.writeByte(0x29); + response.writeByte(0x29); + response.writeByte(MSG_CONFIRMATION); + response.writeShort(5); + response.writeByte(buf.getByte(buf.writerIndex() - 2)); + response.writeByte(type); + response.writeByte(buf.writerIndex() > 9 ? buf.getByte(9) : 0); + response.writeByte(Checksum.xor(response.nioBuffer())); + response.writeByte(0x0D); + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + } + if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD + || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) { + Position position = new Position(getProtocolName()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readIdentifiers(buf)); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + DateBuilder dateBuilder = new DateBuilder() + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); + position.setTime(dateBuilder.getDate()); + position.setLatitude(BcdUtil.readCoordinate(buf)); + position.setLongitude(BcdUtil.readCoordinate(buf)); + position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4))); + position.setCourse(BcdUtil.readInteger(buf, 4)); + position.setValid((buf.readUnsignedByte() & 0x80) != 0); + if (type != MSG_ALARM) { + int odometer = buf.readUnsignedMedium(); + if (BitUtil.to(odometer, 16) > 0) { + position.set(Position.KEY_ODOMETER, odometer); + } else if (odometer > 0) { + position.set(Position.KEY_FUEL_LEVEL, BitUtil.from(odometer, 16)); + } + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + position.set(Position.KEY_RESULT, String.valueOf(buf.readUnsignedByte())); + if (type == MSG_PERIPHERAL) { + buf.readUnsignedShort(); + int dataType = buf.readUnsignedByte(); + buf.readUnsignedByte(); + switch (dataType) { + case 0x01: + position.set(Position.KEY_FUEL_LEVEL, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x02: + position.set(Position.PREFIX_TEMP + 1, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x18: + for (int i = 1; i <= 4; i++) { + double value = buf.readUnsignedShort(); + if (value > 0x0000 && value < 0xFFFF) { + position.set(""fuel"" + i, value / 0xFFFE); + } + } + break; + case 0x23: + Network network = new Network(); + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + network.addCellTower(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), + buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte())); + } + if (count > 0) { + position.setNetwork(network); + } + break; + default: + break; + } + } + } else { + buf.readUnsignedByte(); + buf.readUnsignedByte(); + byte[] alarmStatus = new byte[8]; + buf.readBytes(alarmStatus); + decodeAlarmStatus(position, alarmStatus); + } + return position; + } + return null; + } +"," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.skipBytes(2); + int type = buf.readUnsignedByte(); + buf.readUnsignedShort(); + if (type == MSG_LOGIN || type == MSG_ADMIN_NUMBER || type == MSG_SEND_TEXT + || type == MSG_SMS_ALARM_SWITCH || type == MSG_POSITION_REUPLOAD) { + ByteBuf response = Unpooled.buffer(); + response.writeByte(0x29); + response.writeByte(0x29); + response.writeByte(MSG_CONFIRMATION); + response.writeShort(5); + response.writeByte(buf.getByte(buf.writerIndex() - 2)); + response.writeByte(type); + response.writeByte(buf.writerIndex() > 9 ? buf.getByte(9) : 0); + response.writeByte(Checksum.xor(response.nioBuffer())); + response.writeByte(0x0D); + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + } + if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD + || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) { + Position position = new Position(getProtocolName()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readIdentifiers(buf)); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + DateBuilder dateBuilder = new DateBuilder() + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); + position.setTime(dateBuilder.getDate()); + position.setLatitude(BcdUtil.readCoordinate(buf)); + position.setLongitude(BcdUtil.readCoordinate(buf)); + position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4))); + position.setCourse(BcdUtil.readInteger(buf, 4)); + position.setValid((buf.readUnsignedByte() & 0x80) != 0); + if (type != MSG_ALARM) { + int odometer = buf.readUnsignedMedium(); + if (BitUtil.to(odometer, 16) > 0) { + position.set(Position.KEY_ODOMETER, odometer); + } else if (odometer > 0) { + position.set(Position.KEY_FUEL_LEVEL, BitUtil.from(odometer, 16)); + } + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + position.set(Position.KEY_RESULT, String.valueOf(buf.readUnsignedByte())); + if (type == MSG_PERIPHERAL) { + buf.readUnsignedShort(); + int dataType = buf.readUnsignedByte(); + buf.readUnsignedByte(); + switch (dataType) { + case 0x01: + position.set(Position.KEY_FUEL_LEVEL, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x02: + position.set(Position.PREFIX_TEMP + 1, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x18: + for (int i = 1; i <= 4; i++) { + double value = buf.readUnsignedShort(); + if (value > 0x0000 && value < 0xFFFF) { + position.set(""fuel"" + i, value / 0xFFFE); + } + } + break; + case 0x20: + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + break; + case 0x23: + Network network = new Network(); + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + network.addCellTower(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), + buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte())); + } + if (count > 0) { + position.setNetwork(network); + } + break; + default: + break; + } + } + } else { + buf.readUnsignedByte(); + buf.readUnsignedByte(); + byte[] alarmStatus = new byte[8]; + buf.readBytes(alarmStatus); + decodeAlarmStatus(position, alarmStatus); + } + return position; + } + return null; + } +" +traccar-traccar-1a1126d2d392," private Position decode4( + Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { + int index = 0; + String type = values[index++].substring(5); + if (!type.equals(""STT"") && !type.equals(""ALT"")) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]); + if (deviceSession == null) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_TYPE, type); + position.set(Position.KEY_VERSION_FW, values[index++]); + index += 1; + Network network = new Network(); + for (int i = 0; i < 7; i++) { + int cid = Integer.parseInt(values[index++]); + int mcc = Integer.parseInt(values[index++]); + int mnc = Integer.parseInt(values[index++]); + int lac, rssi; + if (i == 0) { + rssi = Integer.parseInt(values[index++]); + lac = Integer.parseInt(values[index++]); + } else { + lac = Integer.parseInt(values[index++]); + rssi = Integer.parseInt(values[index++]); + } + index += 1; + if (cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi)); + } + } + position.setNetwork(network); + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + position.set(Position.KEY_ARCHIVE, values[index++].equals(""0"") ? true : null); + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++])); + if (values[index].length() == 3) { + index += 1; + } + DateFormat dateFormat = new SimpleDateFormat(""yyyyMMddHH:mm:ss""); + dateFormat.setTimeZone(TimeZone.getTimeZone(""UTC"")); + position.setTime(dateFormat.parse(values[index++] + values[index++])); + position.setLatitude(Double.parseDouble(values[index++])); + position.setLongitude(Double.parseDouble(values[index++])); + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); + position.setCourse(Double.parseDouble(values[index++])); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setValid(values[index++].equals(""1"")); + return position; + } +"," private Position decode4( + Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { + int index = 0; + String type = values[index++].substring(5); + if (!type.equals(""STT"") && !type.equals(""ALT"")) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]); + if (deviceSession == null) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_TYPE, type); + position.set(Position.KEY_VERSION_FW, values[index++]); + index += 1; + Network network = new Network(); + for (int i = 0; i < 7; i++) { + int cid = Integer.parseInt(values[index++]); + int mcc = Integer.parseInt(values[index++]); + int mnc = Integer.parseInt(values[index++]); + int lac, rssi; + if (i == 0) { + rssi = Integer.parseInt(values[index++]); + lac = Integer.parseInt(values[index++]); + } else { + lac = Integer.parseInt(values[index++]); + rssi = Integer.parseInt(values[index++]); + } + index += 1; + if (cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi)); + } + } + position.setNetwork(network); + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + position.set(Position.KEY_ARCHIVE, values[index++].equals(""0"") ? true : null); + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++])); + if (values[index].length() == 3) { + index += 1; + } + if (values[index].isEmpty()) { + getLastLocation(position, null); + } else { + DateFormat dateFormat = new SimpleDateFormat(""yyyyMMddHH:mm:ss""); + dateFormat.setTimeZone(TimeZone.getTimeZone(""UTC"")); + position.setTime(dateFormat.parse(values[index++] + values[index++])); + position.setLatitude(Double.parseDouble(values[index++])); + position.setLongitude(Double.parseDouble(values[index++])); + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); + position.setCourse(Double.parseDouble(values[index++])); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setValid(values[index++].equals(""1"")); + } + return position; + } +" +jhy-jsoup-a349582236a7," private boolean isInlineable(Document.OutputSettings out) { + return tag().isInline() + && (parent() == null || parent().isBlock()) + && previousSibling() != null + && !out.outline(); + } +"," private boolean isInlineable(Document.OutputSettings out) { + if (!tag.isInline()) + return false; + final Node prev = previousSibling(); + boolean isFirst = siblingIndex == 0; + if (siblingIndex == 1 && prev instanceof TextNode && (((TextNode) prev).isBlank())) + isFirst = true; + return (parent() == null || parent().isBlock()) + && !isFirst + && !out.outline(); + } +" +jhy-jsoup-2a4a9cf83dea," @Override + public boolean matches(Element root, Element element) { + for (int i = evaluators.size() -1; i >= 0; --i) { + if (element == null) + return false; + Evaluator eval = evaluators.get(i); + if (!eval.matches(root, element)) + return false; + element = element.parent(); + } + return true; + } +"," @Override + public boolean matches(Element root, Element element) { + if (element == root) + return false; + for (int i = evaluators.size() -1; i >= 0; --i) { + if (element == null) + return false; + Evaluator eval = evaluators.get(i); + if (!eval.matches(root, element)) + return false; + element = element.parent(); + } + return true; + } +" +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 parseData( + Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) { + List 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 parseData( + Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) { + List 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 arguments) + { + final Map> 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 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 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> 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 arguments) + { + final Map> 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 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 argValues = valuesByArg.computeIfAbsent(arg, k -> new ArrayList<>()); + if (!argValues.isEmpty() && !arg.isAllowMultipleValues()) + { + break; + } + SimpleArgumentProcessor.addValue(arg, argument.value, argValues); + arguments.pollFirst(); + } + final Map> 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 registerCallContext( + final ActorRef callContextProvider, + final String callContext, + final AriCommand ariCommand) { + if (!ariCommand.extractCommandType().isCreationCommand()) { + return Try.success(Done.done()); + } + final Option 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 registerCallContext( + final ActorRef callContextProvider, + final String callContext, + final AriCommand ariCommand) { + if (!(ariCommand.extractCommandType().isCreationCommand() + && ""POST"".equals(ariCommand.getMethod()))) { + return Try.success(Done.done()); + } + final Option 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 s = new Stack(); + 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 s = new Stack(); + 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; + } + } +" +aws-aws-secretsmanager-jdbc-d25e52d637cf," @Override + public String constructUrlFromEndpointPortDatabase(String endpoint, String port, String dbname) { + String url = ""jdbc:postgresql://"" + endpoint; + if (!StringUtils.isNullOrEmpty(port)) { + url += "":"" + port; + } + if (!StringUtils.isNullOrEmpty(dbname)) { + url += ""/"" + dbname; + } + return url; + } +"," @Override + public String constructUrlFromEndpointPortDatabase(String endpoint, String port, String dbname) { + String url = ""jdbc:postgresql://"" + endpoint; + if (!StringUtils.isNullOrEmpty(port)) { + url += "":"" + port; + } + url += ""/""; + if (!StringUtils.isNullOrEmpty(dbname)) { + url += dbname; + } + return url; + } +" +jitterted-ensembler-14a39138787f," public void acceptedBy(MemberId memberId) { + requireNotCompleted(); + requireNotCanceled(); + requireHasSpace(); + membersWhoAccepted.add(memberId); + membersWhoDeclined.remove(memberId); + } +"," public void acceptedBy(MemberId memberId) { + requireNotCompleted(); + requireNotCanceled(); + requireHasSpace(); + membersWhoAccepted.add(memberId); + membersWhoDeclined.remove(memberId); + membersAsSpectators.remove(memberId); + } +" +dmak-jaxb-xew-plugin-f48935133d6a," private void moveClassLevelUp(Outline outline, JDefinedClass clazz) { + JDefinedClass parent = (JDefinedClass) clazz.parentContainer(); + JClassContainer grandParent = parent.parentContainer(); + Map classes; + if (grandParent.isClass()) { + JDefinedClass grandParentClass = (JDefinedClass) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to class "" + grandParentClass.fullName()); + classes = getPrivateField(grandParentClass, ""classes""); + } + else { + JPackage grandParentPackage = (JPackage) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to package "" + grandParentPackage.name()); + classes = getPrivateField(grandParentPackage, ""classes""); + setPrivateField(clazz.mods(), ""mods"", Integer.valueOf(clazz.mods().getValue() & ~JMod.STATIC)); + for (ClassOutline classOutline : outline.getClasses()) { + if (classOutline.implClass == clazz) { + XSComponent sc = classOutline.target.getSchemaComponent(); + assert (sc instanceof XSDeclaration && ((XSDeclaration) sc).isLocal()); + setPrivateField(sc, ""anonymous"", Boolean.FALSE); + break; + } + } + } + if (classes.containsKey(clazz.name())) { + writeSummary(""\tRenaming class "" + clazz.fullName() + "" to class "" + parent.name() + clazz.name()); + setPrivateField(clazz, ""name"", parent.name() + clazz.name()); + } + classes.put(clazz.name(), clazz); + setPrivateField(clazz, ""outer"", grandParent); + } +"," private void moveClassLevelUp(Outline outline, JDefinedClass clazz) { + JDefinedClass parent = (JDefinedClass) clazz.parentContainer(); + JClassContainer grandParent = parent.parentContainer(); + Map classes; + if (grandParent.isClass()) { + JDefinedClass grandParentClass = (JDefinedClass) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to class "" + grandParentClass.fullName()); + classes = getPrivateField(grandParentClass, ""classes""); + } + else { + JPackage grandParentPackage = (JPackage) grandParent; + writeSummary(""\tMoving inner class "" + clazz.fullName() + "" to package "" + grandParentPackage.name()); + classes = getPrivateField(grandParentPackage, ""classes""); + setPrivateField(clazz.mods(), ""mods"", Integer.valueOf(clazz.mods().getValue() & ~JMod.STATIC)); + for (ClassOutline classOutline : outline.getClasses()) { + if (classOutline.implClass == clazz) { + XSComponent sc = classOutline.target.getSchemaComponent(); + assert (sc instanceof XSDeclaration && ((XSDeclaration) sc).isLocal()); + setPrivateField(sc, ""anonymous"", Boolean.FALSE); + break; + } + } + } + if (classes.containsKey(clazz.name()) || classes.containsKey(clazz.name().toUpperCase())) { + String newName = parent.name() + clazz.name(); + writeSummary(""\tRenaming class "" + clazz.fullName() + "" to class "" + newName); + setPrivateField(clazz, ""name"", newName); + } + boolean allClassNamesInUpperCase = classes.keySet().stream().allMatch(key -> key.equals(key.toUpperCase())); + classes.put(allClassNamesInUpperCase ? clazz.name().toUpperCase() : clazz.name(), clazz); + setPrivateField(clazz, ""outer"", grandParent); + } +" +jhy-jsoup-5f20fcc2f728," public Safelist addTags(String... tags) { + Validate.notNull(tags); + for (String tagName : tags) { + Validate.notEmpty(tagName); + tagNames.add(TagName.valueOf(tagName)); + } + return this; + } +"," public Safelist addTags(String... tags) { + Validate.notNull(tags); + for (String tagName : tags) { + Validate.notEmpty(tagName); + Validate.isFalse(tagName.equalsIgnoreCase(""noscript""), + ""noscript is unsupported in Safelists, due to incompatibilities between parsers with and without script-mode enabled""); + tagNames.add(TagName.valueOf(tagName)); + } + return this; + } +" +crowdin-crowdin-api-client-java-f0f22b2b56d7," public JacksonJsonTransformer() { + ObjectMapper cleanObjectMapper = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + SimpleModule enumModule = new SimpleModule() + .addDeserializer(Enum.class, new EnumDeserializer()); + SimpleModule module = new SimpleModule() + .addSerializer(Enum.class, new EnumSerializer()) + .addDeserializer(Enum.class, new EnumDeserializer()) + .addDeserializer(CrowdinApiException.class, new CrowdinApiExceptionDeserializer(cleanObjectMapper)) + .addDeserializer(Project.class, new ProjectDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule))) + .addDeserializer(FileInfo.class, new FileInfoDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule) + .registerModule(new SimpleModule() + .addDeserializer(ImportOptions.class, new FileImportOptionsDeserializer(cleanObjectMapper)) + .addDeserializer(ExportOptions.class, new FileExportOptionsDeserializer(cleanObjectMapper))))) + .addDeserializer(LanguageTranslations.class, new LanguageTranslationsDeserializer(cleanObjectMapper)); + this.objectMapper = cleanObjectMapper.copy() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .setDateFormat(new SimpleDateFormat(""yyyy-MM-dd'T'HH:mm:ss+hh:mm"")) + .registerModule(module) + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + this.errorObjectMapper = cleanObjectMapper; + } +"," public JacksonJsonTransformer() { + ObjectMapper cleanObjectMapper = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + SimpleModule enumModule = new SimpleModule() + .addDeserializer(Enum.class, new EnumDeserializer()); + SimpleModule module = new SimpleModule() + .addSerializer(Enum.class, new EnumSerializer()) + .addDeserializer(Enum.class, new EnumDeserializer()) + .addDeserializer(CrowdinApiException.class, new CrowdinApiExceptionDeserializer(cleanObjectMapper)) + .addDeserializer(Project.class, new ProjectDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule))) + .addDeserializer(FileInfo.class, new FileInfoDeserializer(cleanObjectMapper.copy() + .registerModule(enumModule) + .registerModule(new SimpleModule() + .addDeserializer(ImportOptions.class, new FileImportOptionsDeserializer(cleanObjectMapper)) + .addDeserializer(ExportOptions.class, new FileExportOptionsDeserializer(cleanObjectMapper))))) + .addDeserializer(LanguageTranslations.class, new LanguageTranslationsDeserializer(cleanObjectMapper)); + this.objectMapper = cleanObjectMapper.copy() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .setDateFormat(new SimpleDateFormat(""yyyy-MM-dd'T'HH:mm:ssXXX"")) + .registerModule(module) + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + this.errorObjectMapper = cleanObjectMapper; + } +" +stellar-java-stellar-sdk-1461c2fc5b89," public boolean isSorobanTransaction() { + if (mOperations.length != 1) { + return false; + } + Operation op = mOperations[0]; + return op instanceof InvokeHostFunctionOperation + || op instanceof BumpSequenceOperation + || op instanceof RestoreFootprintOperation; + } +"," public boolean isSorobanTransaction() { + if (mOperations.length != 1) { + return false; + } + Operation op = mOperations[0]; + return op instanceof InvokeHostFunctionOperation + || op instanceof BumpFootprintExpirationOperation + || op instanceof RestoreFootprintOperation; + } +" +traccar-traccar-65f54c200cf0," private void decodeLocation(Position position, ByteBuf buf, int codec, String model) { + int globalMask = 0x0f; + if (codec == CODEC_GH3000) { + long time = buf.readUnsignedInt() & 0x3fffffff; + time += 1167609600; + globalMask = buf.readUnsignedByte(); + if (BitUtil.check(globalMask, 0)) { + position.setTime(new Date(time * 1000)); + int locationMask = buf.readUnsignedByte(); + if (BitUtil.check(locationMask, 0)) { + position.setLatitude(buf.readFloat()); + position.setLongitude(buf.readFloat()); + } + if (BitUtil.check(locationMask, 1)) { + position.setAltitude(buf.readUnsignedShort()); + } + if (BitUtil.check(locationMask, 2)) { + position.setCourse(buf.readUnsignedByte() * 360.0 / 256); + } + if (BitUtil.check(locationMask, 3)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + if (BitUtil.check(locationMask, 4)) { + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 5)) { + CellTower cellTower = CellTower.fromLacCid( + getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort()); + if (BitUtil.check(locationMask, 6)) { + cellTower.setSignalStrength((int) buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + cellTower.setOperator(buf.readUnsignedInt()); + } + position.setNetwork(new Network(cellTower)); + } else { + if (BitUtil.check(locationMask, 6)) { + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + position.set(Position.KEY_OPERATOR, buf.readUnsignedInt()); + } + } + } else { + getLastLocation(position, new Date(time * 1000)); + } + } else { + position.setTime(new Date(buf.readLong())); + position.set(""priority"", buf.readUnsignedByte()); + position.setLongitude(buf.readInt() / 10000000.0); + position.setLatitude(buf.readInt() / 10000000.0); + position.setAltitude(buf.readShort()); + position.setCourse(buf.readUnsignedShort()); + int satellites = buf.readUnsignedByte(); + position.set(Position.KEY_SATELLITES, satellites); + position.setValid(satellites != 0); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); + position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16)); + if (codec == CODEC_16) { + buf.readUnsignedByte(); + } + readExtByte(buf, codec, CODEC_8_EXT); + } + if (BitUtil.check(globalMask, 1)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec, model); + } + } + if (BitUtil.check(globalMask, 2)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec, model); + } + } + if (BitUtil.check(globalMask, 3)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec, model); + } + } + if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8, codec, model); + } + } + if (extended) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16); + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16))); + } + } + if (codec == CODEC_8_EXT) { + int cnt = buf.readUnsignedShort(); + for (int j = 0; j < cnt; j++) { + int id = buf.readUnsignedShort(); + int length = buf.readUnsignedShort(); + if (id == 256) { + position.set(Position.KEY_VIN, + buf.readSlice(length).toString(StandardCharsets.US_ASCII)); + } else if (id == 281) { + position.set(Position.KEY_DTCS, + buf.readSlice(length).toString(StandardCharsets.US_ASCII).replace(',', ' ')); + } else if (id == 385) { + ByteBuf data = buf.readSlice(length); + data.readUnsignedByte(); + int index = 1; + while (data.isReadable()) { + int flags = data.readUnsignedByte(); + if (BitUtil.from(flags, 4) > 0) { + position.set(""beacon"" + index + ""Uuid"", ByteBufUtil.hexDump(data.readSlice(16))); + position.set(""beacon"" + index + ""Major"", data.readUnsignedShort()); + position.set(""beacon"" + index + ""Minor"", data.readUnsignedShort()); + } else { + position.set(""beacon"" + index + ""Namespace"", ByteBufUtil.hexDump(data.readSlice(10))); + position.set(""beacon"" + index + ""Instance"", ByteBufUtil.hexDump(data.readSlice(6))); + } + position.set(""beacon"" + index + ""Rssi"", (int) data.readByte()); + if (BitUtil.check(flags, 1)) { + position.set(""beacon"" + index + ""Battery"", data.readUnsignedShort() * 0.01); + } + if (BitUtil.check(flags, 2)) { + position.set(""beacon"" + index + ""Temp"", data.readUnsignedShort()); + } + index += 1; + } + } else { + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length))); + } + } + } + decodeNetwork(position, model); + } +"," private void decodeLocation(Position position, ByteBuf buf, int codec, String model) { + int globalMask = 0x0f; + if (codec == CODEC_GH3000) { + long time = buf.readUnsignedInt() & 0x3fffffff; + time += 1167609600; + globalMask = buf.readUnsignedByte(); + if (BitUtil.check(globalMask, 0)) { + position.setTime(new Date(time * 1000)); + int locationMask = buf.readUnsignedByte(); + if (BitUtil.check(locationMask, 0)) { + position.setLatitude(buf.readFloat()); + position.setLongitude(buf.readFloat()); + } + if (BitUtil.check(locationMask, 1)) { + position.setAltitude(buf.readUnsignedShort()); + } + if (BitUtil.check(locationMask, 2)) { + position.setCourse(buf.readUnsignedByte() * 360.0 / 256); + } + if (BitUtil.check(locationMask, 3)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + if (BitUtil.check(locationMask, 4)) { + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 5)) { + CellTower cellTower = CellTower.fromLacCid( + getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort()); + if (BitUtil.check(locationMask, 6)) { + cellTower.setSignalStrength((int) buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + cellTower.setOperator(buf.readUnsignedInt()); + } + position.setNetwork(new Network(cellTower)); + } else { + if (BitUtil.check(locationMask, 6)) { + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + } + if (BitUtil.check(locationMask, 7)) { + position.set(Position.KEY_OPERATOR, buf.readUnsignedInt()); + } + } + } else { + getLastLocation(position, new Date(time * 1000)); + } + } else { + position.setTime(new Date(buf.readLong())); + position.set(""priority"", buf.readUnsignedByte()); + position.setLongitude(buf.readInt() / 10000000.0); + position.setLatitude(buf.readInt() / 10000000.0); + position.setAltitude(buf.readShort()); + position.setCourse(buf.readUnsignedShort()); + int satellites = buf.readUnsignedByte(); + position.set(Position.KEY_SATELLITES, satellites); + position.setValid(satellites != 0); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); + position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16)); + if (codec == CODEC_16) { + buf.readUnsignedByte(); + } + readExtByte(buf, codec, CODEC_8_EXT); + } + if (BitUtil.check(globalMask, 1)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec, model); + } + } + if (BitUtil.check(globalMask, 2)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec, model); + } + } + if (BitUtil.check(globalMask, 3)) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec, model); + } + } + if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8, codec, model); + } + } + if (extended) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); + for (int j = 0; j < cnt; j++) { + int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16); + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16))); + } + } + if (codec == CODEC_8_EXT) { + int cnt = buf.readUnsignedShort(); + for (int j = 0; j < cnt; j++) { + int id = buf.readUnsignedShort(); + int length = buf.readUnsignedShort(); + if (id == 256) { + position.set(Position.KEY_VIN, + buf.readSlice(length).toString(StandardCharsets.US_ASCII)); + } else if (id == 281) { + position.set(Position.KEY_DTCS, + buf.readSlice(length).toString(StandardCharsets.US_ASCII).replace(',', ' ')); + } else if (id == 385) { + ByteBuf data = buf.readSlice(length); + data.readUnsignedByte(); + int index = 1; + while (data.isReadable()) { + int flags = data.readUnsignedByte(); + if (BitUtil.from(flags, 4) > 0) { + position.set(""beacon"" + index + ""Uuid"", ByteBufUtil.hexDump(data.readSlice(16))); + position.set(""beacon"" + index + ""Major"", data.readUnsignedShort()); + position.set(""beacon"" + index + ""Minor"", data.readUnsignedShort()); + } else { + position.set(""beacon"" + index + ""Namespace"", ByteBufUtil.hexDump(data.readSlice(10))); + position.set(""beacon"" + index + ""Instance"", ByteBufUtil.hexDump(data.readSlice(6))); + } + position.set(""beacon"" + index + ""Rssi"", (int) data.readByte()); + if (BitUtil.check(flags, 1)) { + position.set(""beacon"" + index + ""Battery"", data.readUnsignedShort() * 0.01); + } + if (BitUtil.check(flags, 2)) { + position.set(""beacon"" + index + ""Temp"", data.readUnsignedShort()); + } + index += 1; + } + } else if (id == 10829 || id == 10831) { + ByteBuf data = buf.readSlice(length); + data.readUnsignedByte(); + for (int i = 1; data.isReadable(); i++) { + ByteBuf beacon = data.readSlice(data.readUnsignedByte()); + while (beacon.isReadable()) { + int parameterId = beacon.readUnsignedByte(); + int parameterLength = beacon.readUnsignedByte(); + switch (parameterId) { + case 0: + position.set(""tag"" + i + ""Rssi"", (int) beacon.readByte()); + break; + case 1: + String beaconId = ByteBufUtil.hexDump(beacon.readSlice(parameterLength)); + position.set(""tag"" + i + ""Id"", beaconId); + break; + case 13: + position.set(""tag"" + i + ""LowBattery"", beacon.readUnsignedByte()); + break; + case 14: + position.set(""tag"" + i + ""Battery"", beacon.readUnsignedShort()); + break; + default: + beacon.skipBytes(parameterLength); + break; + } + } + } + } else { + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length))); + } + } + } + decodeNetwork(position, model); + } +" +mthmulders-mcs-eff905bef8d8," private void printRow(final Help.TextTable table, final SearchResponse.Response.Doc doc) { + var lastUpdated = DATE_TIME_FORMATTER.format( + Instant.ofEpochMilli(doc.timestamp()).atZone(ZoneId.systemDefault()) + ); + table.addRowValues(doc.id(), lastUpdated); + } +"," private void printRow(final Help.TextTable table, final SearchResponse.Response.Doc doc) { + var lastUpdated = DATE_TIME_FORMATTER.format( + Instant.ofEpochMilli(doc.timestamp()).atZone(ZoneId.systemDefault()) + ); + table.addRowValues(doc.id() + "":"" + doc.latestVersion(), lastUpdated); + } +" +traccar-traccar-fdbd269b9b99," private Object decodePosition( + Channel channel, SocketAddress remoteAddress, String sentence, String id) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + if (deviceSession == null) { + return null; + } + List positions = new LinkedList<>(); + Position position = null; + DateBuilder dateBuilder = null; + for (String pair : sentence.split("","")) { + String[] data = pair.split(""[=:]""); + int key; + try { + key = Integer.parseInt(data[0], 16); + } catch (NumberFormatException e) { + continue; + } + String value = data[1]; + if (key == 0x0) { + if (position != null) { + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + dateBuilder = new DateBuilder(new Date()); + } else if (position != null) { + switch (key) { + case 0x11: + value = (""000000"" + value).substring(value.length()); + dateBuilder.setDateReverse( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4))); + break; + case 0x10: + value = (""00000000"" + value).substring(value.length()); + dateBuilder.setTime( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4, 6)), + Integer.parseInt(value.substring(6)) * 10); + break; + case 0xA: + position.setValid(true); + position.setLatitude(Double.parseDouble(value)); + break; + case 0xB: + position.setValid(true); + position.setLongitude(Double.parseDouble(value)); + break; + case 0xC: + position.setAltitude(Double.parseDouble(value)); + break; + case 0xD: + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value))); + break; + case 0xE: + position.setCourse(Integer.parseInt(value)); + break; + case 0xF: + position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + break; + case 0x12: + position.set(Position.KEY_HDOP, Integer.parseInt(value)); + break; + case 0x20: + position.set(Position.KEY_ACCELERATION, value); + break; + case 0x24: + position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01); + break; + case 0x81: + position.set(Position.KEY_RSSI, Integer.parseInt(value)); + break; + case 0x82: + position.set(Position.KEY_DEVICE_TEMP, Integer.parseInt(value) * 0.1); + break; + case 0x104: + position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value)); + break; + case 0x105: + position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value)); + break; + case 0x10c: + position.set(Position.KEY_RPM, Integer.parseInt(value)); + break; + case 0x10d: + position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(value))); + break; + case 0x111: + position.set(Position.KEY_THROTTLE, Integer.parseInt(value)); + break; + default: + position.set(Position.PREFIX_IO + key, value); + break; + } + } + } + if (position != null) { + if (!position.getValid()) { + getLastLocation(position, null); + } + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + return positions.isEmpty() ? null : positions; + } +"," private Object decodePosition( + Channel channel, SocketAddress remoteAddress, String sentence, String id) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + if (deviceSession == null) { + return null; + } + List positions = new LinkedList<>(); + Position position = null; + DateBuilder dateBuilder = null; + for (String pair : sentence.split("","")) { + String[] data = pair.split(""[=:]""); + int key; + try { + key = Integer.parseInt(data[0], 16); + } catch (NumberFormatException e) { + continue; + } + String value = data[1]; + if (key == 0x0) { + if (position != null) { + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + dateBuilder = new DateBuilder(new Date()); + } else if (position != null) { + switch (key) { + case 0x11: + value = (""000000"" + value).substring(value.length()); + dateBuilder.setDateReverse( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4))); + break; + case 0x10: + value = (""00000000"" + value).substring(value.length()); + dateBuilder.setTime( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4, 6)), + Integer.parseInt(value.substring(6)) * 10); + break; + case 0xA: + position.setValid(true); + position.setLatitude(Double.parseDouble(value)); + break; + case 0xB: + position.setValid(true); + position.setLongitude(Double.parseDouble(value)); + break; + case 0xC: + position.setAltitude(Double.parseDouble(value)); + break; + case 0xD: + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value))); + break; + case 0xE: + position.setCourse(Integer.parseInt(value)); + break; + case 0xF: + position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + break; + case 0x12: + position.set(Position.KEY_HDOP, Integer.parseInt(value)); + break; + case 0x20: + position.set(Position.KEY_ACCELERATION, value); + break; + case 0x24: + position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01); + break; + case 0x81: + position.set(Position.KEY_RSSI, Integer.parseInt(value)); + break; + case 0x82: + position.set(Position.KEY_DEVICE_TEMP, Double.parseDouble(value) * 0.1); + break; + case 0x104: + position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value)); + break; + case 0x105: + position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value)); + break; + case 0x10c: + position.set(Position.KEY_RPM, Integer.parseInt(value)); + break; + case 0x10d: + position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(value))); + break; + case 0x111: + position.set(Position.KEY_THROTTLE, Integer.parseInt(value)); + break; + default: + position.set(Position.PREFIX_IO + key, value); + break; + } + } + } + if (position != null) { + if (!position.getValid()) { + getLastLocation(position, null); + } + position.setTime(dateBuilder.getDate()); + positions.add(position); + } + return positions.isEmpty() ? null : positions; + } +" +traccar-traccar-8b4d3ee0b964," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; + if (sentence.startsWith(""!1,"")) { + int index = sentence.indexOf(',', 3); + if (index < 0) { + index = sentence.length(); + } + getDeviceSession(channel, remoteAddress, sentence.substring(3, index)); + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null || !sentence.matches(""![35A-D],.*"")) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + String type = sentence.substring(1, 2); + position.set(Position.KEY_TYPE, type); + if (type.equals(""3"")) { + getLastLocation(position, null); + position.set(Position.KEY_RESULT, sentence.substring(3)); + return position; + } else if (type.equals(""5"")) { + String[] values = sentence.split("",""); + getLastLocation(position, null); + position.set(Position.KEY_RSSI, Integer.parseInt(values[1])); + if (values.length >= 4) { + position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[3])); + } + return position; + } else if (type.equals(""B"") || type.equals(""D"")) { + Parser parser = new Parser(PATTERN_BD, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0)); + position.set(Position.KEY_HDOP, parser.nextDouble(0)); + return position; + } else if (type.equals(""C"")) { + Parser parser = new Parser(PATTERN_C, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + return position; + } else if (type.equals(""A"")) { + Parser parser = new Parser(PATTERN_A, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + return position; + } + return null; + } +"," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; + if (sentence.startsWith(""!1,"")) { + int index = sentence.indexOf(',', 3); + if (index < 0) { + index = sentence.length(); + } + getDeviceSession(channel, remoteAddress, sentence.substring(3, index)); + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null || !sentence.matches(""![345A-D],.*"")) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + String type = sentence.substring(1, 2); + position.set(Position.KEY_TYPE, type); + if (type.equals(""3"")) { + getLastLocation(position, null); + position.set(Position.KEY_RESULT, sentence.substring(3)); + return position; + } else if (type.equals(""4"")) { + String[] values = sentence.split("",""); + getLastLocation(position, null); + for (int i = 1; i <= 3; i++) { + if (!values[i + 1].isEmpty()) { + position.set(""phone"" + i, values[i + 1]); + } + } + return position; + } else if (type.equals(""5"")) { + String[] values = sentence.split("",""); + getLastLocation(position, null); + position.set(Position.KEY_RSSI, Integer.parseInt(values[1])); + if (values.length >= 4) { + position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[3])); + } + return position; + } else if (type.equals(""B"") || type.equals(""D"")) { + Parser parser = new Parser(PATTERN_BD, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0)); + position.set(Position.KEY_HDOP, parser.nextDouble(0)); + return position; + } else if (type.equals(""C"")) { + Parser parser = new Parser(PATTERN_C, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + decodeState(position, parser); + return position; + } else if (type.equals(""A"")) { + Parser parser = new Parser(PATTERN_A, sentence); + if (!parser.matches()) { + return null; + } + decodeFix(position, parser); + return position; + } + return null; + } +" +traccar-traccar-e73f36db83b9," private Object decodeEri(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_ERI, sentence); + if (!parser.matches()) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + long mask = parser.nextHexLong(); + LinkedList positions = new LinkedList<>(); + Integer power = parser.nextInt(); + Parser itemParser = new Parser(PATTERN_LOCATION, parser.next()); + while (itemParser.find()) { + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + decodeLocation(position, itemParser); + positions.add(position); + } + Position position = positions.getLast(); + skipLocation(parser); + if (power != null) { + position.set(Position.KEY_POWER, power * 0.001); + } + if (parser.hasNextAny(12)) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + position.set(Position.KEY_HOURS, parseHours(parser.next())); + position.set(Position.PREFIX_ADC + 1, parser.next()); + position.set(Position.PREFIX_ADC + 2, parser.next()); + position.set(Position.PREFIX_ADC + 3, parser.next()); + if (parser.hasNext(2)) { + position.set(Position.KEY_INPUT, parser.nextHexInt()); + position.set(Position.KEY_OUTPUT, parser.nextHexInt()); + } + if (parser.hasNext(4)) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + decodeStatus(position, parser); + } + int index = 0; + String[] data = parser.next().split("",""); + index += 1; + if (BitUtil.check(mask, 0)) { + index += 1; + } + if (BitUtil.check(mask, 1)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + index += 1; + if (!data[index++].isEmpty()) { + position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625); + } + } + } + if (BitUtil.check(mask, 2)) { + index += 1; + } + if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + if (BitUtil.check(mask, 3)) { + position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++])); + } + if (BitUtil.check(mask, 4)) { + index += 1; + } + } + } + } + if (parser.hasNext()) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + } + decodeDeviceTime(position, parser); + if (ignoreFixTime) { + positions.clear(); + positions.add(position); + } + return positions; + } +"," private Object decodeEri(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_ERI, sentence); + if (!parser.matches()) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + long mask = parser.nextHexLong(); + LinkedList positions = new LinkedList<>(); + Integer power = parser.nextInt(); + Parser itemParser = new Parser(PATTERN_LOCATION, parser.next()); + while (itemParser.find()) { + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + decodeLocation(position, itemParser); + positions.add(position); + } + Position position = positions.getLast(); + skipLocation(parser); + if (power != null) { + position.set(Position.KEY_POWER, power * 0.001); + } + if (parser.hasNextAny(12)) { + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + position.set(Position.KEY_HOURS, parseHours(parser.next())); + position.set(Position.PREFIX_ADC + 1, parser.next()); + position.set(Position.PREFIX_ADC + 2, parser.next()); + position.set(Position.PREFIX_ADC + 3, parser.next()); + if (parser.hasNext(2)) { + position.set(Position.KEY_INPUT, parser.nextHexInt()); + position.set(Position.KEY_OUTPUT, parser.nextHexInt()); + } + if (parser.hasNext(4)) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + decodeStatus(position, parser); + } + int index = 0; + String[] data = parser.next().split("",""); + index += 1; + if (BitUtil.check(mask, 0)) { + position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(data[index++], 16)); + } + if (BitUtil.check(mask, 1)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + index += 1; + if (!data[index++].isEmpty()) { + position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625); + } + } + } + if (BitUtil.check(mask, 2)) { + index += 1; + } + if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) { + int deviceCount = Integer.parseInt(data[index++]); + for (int i = 1; i <= deviceCount; i++) { + index += 1; + if (BitUtil.check(mask, 3)) { + position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++])); + } + if (BitUtil.check(mask, 4)) { + index += 1; + } + } + } + } + if (parser.hasNext()) { + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + } + decodeDeviceTime(position, parser); + if (ignoreFixTime) { + positions.clear(); + positions.add(position); + } + return positions; + } +" +AuthMe-ConfigMe-aa91a6b315ec," public void setComment(@NotNull String path, @NotNull String... commentLines) { + comments.put(path, Collections.unmodifiableList(Arrays.asList(commentLines))); + } +"," public void setComment(@NotNull String path, @NotNull String... commentLines) { + List replaced = comments.put(path, Collections.unmodifiableList(Arrays.asList(commentLines))); + if (replaced != null) { + throw new IllegalStateException(""Comment lines already exists for the path '"" + path + ""'""); + } + } +" +traccar-traccar-8de9a36abef8," private void decodeFragment(Position position, String fragment) { + int dataIndex = fragment.indexOf(':'); + int index = 0; + String[] values; + if (fragment.length() == dataIndex + 1) { + values = new String[0]; + } else { + values = fragment.substring(dataIndex + 1).split("";""); + } + switch (fragment.substring(0, dataIndex)) { + case ""GPS"": + position.setValid(values[index++].equals(""A"")); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setLatitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'S') { + position.setLatitude(-position.getLatitude()); + } + position.setLongitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'W') { + position.setLongitude(-position.getLongitude()); + } + if (!values[index++].isEmpty()) { + position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1]))); + } + position.setCourse(Integer.parseInt(values[index++])); + if (index < values.length) { + position.setAltitude(Integer.parseInt(values[index++])); + } + if (index < values.length) { + position.set(Position.KEY_HDOP, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.KEY_VDOP, Double.parseDouble(values[index++])); + } + break; + case ""GSM"": + index += 1; + index += 1; + position.setNetwork(new Network(CellTower.from( + Integer.parseInt(values[index++]), Integer.parseInt(values[index++]), + Integer.parseInt(values[index++], 16), Integer.parseInt(values[index++], 16), + Integer.parseInt(values[index++])))); + break; + case ""COT"": + if (index < values.length) { + position.set(Position.KEY_ODOMETER, Long.parseLong(values[index++])); + } + if (index < values.length) { + String[] hours = values[index].split(""-""); + position.set(Position.KEY_HOURS, (Integer.parseInt(hours[0]) * 3600 + + (hours.length > 1 ? Integer.parseInt(hours[1]) * 60 : 0) + + (hours.length > 2 ? Integer.parseInt(hours[2]) : 0)) * 1000); + } + break; + case ""ADC"": + position.set(Position.KEY_POWER, Double.parseDouble(values[index++])); + if (index < values.length) { + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++])); + } + break; + case ""DTT"": + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16)); + if (!values[index++].isEmpty()) { + int io = Integer.parseInt(values[index - 1], 16); + position.set(Position.KEY_IGNITION, BitUtil.check(io, 0)); + position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1)); + position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2)); + position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3)); + position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4)); + position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5)); + position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6)); + position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7)); + } + position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]); + position.set(""eventStatus"", values[index++]); + if (index < values.length) { + position.set(""packetType"", values[index++]); + } + break; + case ""ETD"": + position.set(""eventData"", values[index++]); + break; + case ""OBD"": + position.set(""obd"", values[index++]); + break; + case ""TAG"": + position.set(""tagData"", values[index++]); + break; + case ""IWD"": + while (index < values.length) { + int sensorIndex = Integer.parseInt(values[index++]); + int dataType = Integer.parseInt(values[index++]); + if (dataType == 0) { + position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index++]); + } else if (dataType == 1) { + index += 1; + position.set(Position.PREFIX_TEMP + sensorIndex, Double.parseDouble(values[index++])); + } + } + break; + default: + break; + } + } +"," private void decodeFragment(Position position, String fragment) { + int dataIndex = fragment.indexOf(':'); + int index = 0; + String[] values; + if (fragment.length() == dataIndex + 1) { + values = new String[0]; + } else { + values = fragment.substring(dataIndex + 1).split("";""); + } + switch (fragment.substring(0, dataIndex)) { + case ""GPS"": + position.setValid(values[index++].equals(""A"")); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setLatitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'S') { + position.setLatitude(-position.getLatitude()); + } + position.setLongitude(Double.parseDouble(values[index].substring(1))); + if (values[index++].charAt(0) == 'W') { + position.setLongitude(-position.getLongitude()); + } + if (!values[index++].isEmpty()) { + position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1]))); + } + position.setCourse(Integer.parseInt(values[index++])); + if (index < values.length && !values[index++].isEmpty()) { + position.setAltitude(Integer.parseInt(values[index - 1])); + } + if (index < values.length && !values[index++].isEmpty()) { + position.set(Position.KEY_HDOP, Double.parseDouble(values[index - 1])); + } + if (index < values.length && !values[index++].isEmpty()) { + position.set(Position.KEY_VDOP, Double.parseDouble(values[index - 1])); + } + break; + case ""GSM"": + index += 1; + index += 1; + position.setNetwork(new Network(CellTower.from( + Integer.parseInt(values[index++]), Integer.parseInt(values[index++]), + Integer.parseInt(values[index++], 16), Integer.parseInt(values[index++], 16), + Integer.parseInt(values[index++])))); + break; + case ""COT"": + if (index < values.length) { + position.set(Position.KEY_ODOMETER, Long.parseLong(values[index++])); + } + if (index < values.length) { + String[] hours = values[index].split(""-""); + position.set(Position.KEY_HOURS, (Integer.parseInt(hours[0]) * 3600 + + (hours.length > 1 ? Integer.parseInt(hours[1]) * 60 : 0) + + (hours.length > 2 ? Integer.parseInt(hours[2]) : 0)) * 1000); + } + break; + case ""ADC"": + position.set(Position.KEY_POWER, Double.parseDouble(values[index++])); + if (index < values.length) { + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++])); + } + if (index < values.length) { + position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++])); + } + break; + case ""DTT"": + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16)); + if (!values[index++].isEmpty()) { + int io = Integer.parseInt(values[index - 1], 16); + position.set(Position.KEY_IGNITION, BitUtil.check(io, 0)); + position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1)); + position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2)); + position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3)); + position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4)); + position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5)); + position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6)); + position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7)); + } + position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]); + position.set(""eventStatus"", values[index++]); + if (index < values.length) { + position.set(""packetType"", values[index++]); + } + break; + case ""ETD"": + position.set(""eventData"", values[index++]); + break; + case ""OBD"": + position.set(""obd"", values[index++]); + break; + case ""TAG"": + position.set(""tagData"", values[index++]); + break; + case ""IWD"": + while (index < values.length) { + int sensorIndex = Integer.parseInt(values[index++]); + int dataType = Integer.parseInt(values[index++]); + if (dataType == 0) { + position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index++]); + } else if (dataType == 1) { + index += 1; + position.set(Position.PREFIX_TEMP + sensorIndex, Double.parseDouble(values[index++])); + } + } + break; + default: + break; + } + } +" +traccar-traccar-392f00082faf," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 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; + default: + buf.skipBytes(length); + break; + } + } + positions.add(position); + } + return positions; + } +"," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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; + default: + buf.skipBytes(length); + break; + } + } + positions.add(position); + } + return positions; + } +" +cloudsimplus-cloudsimplus-61c8b942d1ec," public HostAbstract(final List peList, final boolean activate) { + this(defaultBwCapacity, defaultStorageCapacity, new HarddriveStorage(defaultRamCapacity), peList, activate); + } +"," public HostAbstract(final List peList, final boolean activate) { + this(defaultRamCapacity, defaultBwCapacity, new HarddriveStorage(defaultStorageCapacity), peList, activate); + } +" +traccar-traccar-3771dd156efb," private Position decodePosition(DeviceSession deviceSession, String data) { + Parser parser = new Parser(PATTERN_POSITION, data); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + position.setValid(parser.next().equals(""A"")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.setCourse(parser.nextDouble(0)); + position.setAltitude(parser.nextDouble(0)); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_RSSI, parser.nextInt(0)); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_STEPS, parser.nextInt(0)); + int status = parser.nextHexInt(0); + position.set(Position.KEY_ALARM, decodeAlarm(status)); + if (BitUtil.check(status, 4)) { + position.set(Position.KEY_MOTION, true); + } + String[] values = parser.next().split("",""); + int index = 0; + Network network = new Network(); + int cellCount = Integer.parseInt(values[index++]); + if (cellCount > 0) { + index += 1; + int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + for (int i = 0; i < cellCount; i++) { + int lac = Integer.parseInt(values[index++]); + int cid = Integer.parseInt(values[index++]); + String rssi = values[index++]; + if (!rssi.isEmpty()) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); + } else { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } + } + } + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); + for (int i = 0; i < wifiCount; i++) { + index += 1; + String macAddress = values[index++]; + String rssi = values[index++]; + if (!macAddress.isEmpty() && !macAddress.equals(""0"") && !rssi.isEmpty()) { + network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + } + } + } + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } + return position; + } +"," private Position decodePosition(DeviceSession deviceSession, String data) { + Parser parser = new Parser(PATTERN_POSITION, data); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + position.setValid(parser.next().equals(""A"")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.setCourse(parser.nextDouble(0)); + position.setAltitude(parser.nextDouble(0)); + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_RSSI, parser.nextInt(0)); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + position.set(Position.KEY_STEPS, parser.nextInt(0)); + int status = parser.nextHexInt(0); + position.set(Position.KEY_ALARM, decodeAlarm(status)); + if (BitUtil.check(status, 4)) { + position.set(Position.KEY_MOTION, true); + } + String[] values = parser.next().split("",""); + int index = 0; + if (values.length < 4 || !values[index + 3].startsWith(""F"")) { + Network network = new Network(); + int cellCount = Integer.parseInt(values[index++]); + if (cellCount > 0) { + index += 1; + int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + for (int i = 0; i < cellCount; i++) { + int lac = Integer.parseInt(values[index++]); + int cid = Integer.parseInt(values[index++]); + String rssi = values[index++]; + if (!rssi.isEmpty()) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); + } else { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } + } + } + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); + for (int i = 0; i < wifiCount; i++) { + index += 1; + String macAddress = values[index++]; + String rssi = values[index++]; + if (!macAddress.isEmpty() && !macAddress.equals(""0"") && !rssi.isEmpty()) { + network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + } + } + } + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } + } + return position; + } +" +traccar-traccar-dfc546a26f5b," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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; + default: + buf.skipBytes(length); + break; + } + } + positions.add(position); + } + return positions; + } +"," private List decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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; + } +" +traccar-traccar-3331593759a2," 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; + 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; + } + } + decodeCoordinates(position, buf); + position.setTime(time); + break; + case 0x03: + count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + int id = buf.readUnsignedShort(); + 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); + } + 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; + } +"," 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; + 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; + } + } + 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); + } + 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; + } +" +semver4j-semver4j-10102b374298," @Override + public String toString() { + return rangesList.stream() + .map(RangesList::formatRanges) + .collect(joining(OR_JOINER)); + } +"," @Override + public String toString() { + return rangesList.stream() + .map(RangesList::formatRanges) + .collect(joining(OR_JOINER)) + .replaceAll(""^\\(([^()]+)\\)$"", ""$1""); + } +" +nikoo28-java-solutions-8d81307ea165," public int[] calculateSpans(int[] prices) { + int[] spans = new int[prices.length]; + spans[0] = 1; + Stack indexStack = new Stack<>(); + indexStack.push(0); + for (int i = 1; i < prices.length; i++) { + while (!indexStack.isEmpty() + && prices[indexStack.peek()] <= prices[i]) + indexStack.pop(); + if (indexStack.isEmpty()) + spans[i] = i + 1; + else + spans[i] = i - indexStack.peek(); + indexStack.push(i); + } + return spans; + } +"," public int[] calculateSpans(int[] prices) { + int[] spans = new int[prices.length]; + spans[0] = 1; + Stack indexStack = new Stack<>(); + indexStack.push(0); + for (int i = 1; i < prices.length; i++) { + while (!indexStack.isEmpty() + && prices[indexStack.peek()] < prices[i]) + indexStack.pop(); + if (indexStack.isEmpty()) + spans[i] = i + 1; + else + spans[i] = i - indexStack.peek(); + indexStack.push(i); + } + return spans; + } +" +traccar-traccar-5a1a8d9192ee," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + String imei = buf.readCharSequence(15, StandardCharsets.US_ASCII).toString(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + List parameters = getParameters(deviceSession.getDeviceId()); + for (int parameter : parameters) { + switch (parameter) { + case 0x01: + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + break; + case 0x02: + position.setLatitude(buf.readIntLE() / 1000000.0); + break; + case 0x03: + position.setLongitude(buf.readIntLE() / 1000000.0); + break; + case 0x04: + position.setTime(new Date((buf.readUnsignedIntLE() + 946713600) * 1000)); + 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 0x08: + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); + break; + case 0x09: + position.setCourse(buf.readUnsignedShortLE()); + break; + case 0x0A: + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + break; + case 0x0B: + position.setAltitude(buf.readShortLE()); + break; + case 0x0C: + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + break; + case 0x0D: + position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000); + break; + case 0x14: + position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); + break; + case 0x15: + position.set(Position.KEY_INPUT, buf.readUnsignedByte()); + 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 0x1B: + buf.readUnsignedByte(); + break; + default: + break; + } + } + return position; + } +"," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + String imei = buf.readCharSequence(15, StandardCharsets.US_ASCII).toString(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + buf.readUnsignedByte(); + buf.readUnsignedShort(); + buf.readUnsignedShort(); + buf.readUnsignedInt(); + buf.readUnsignedByte(); + buf.readUnsignedShort(); + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + List parameters = getParameters(deviceSession.getDeviceId()); + for (int parameter : parameters) { + switch (parameter) { + case 0x01: + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + break; + case 0x02: + position.setLatitude(buf.readIntLE() / 1000000.0); + break; + case 0x03: + position.setLongitude(buf.readIntLE() / 1000000.0); + break; + case 0x04: + position.setTime(new Date((buf.readUnsignedIntLE() + 946684800) * 1000)); + 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 0x08: + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); + break; + case 0x09: + position.setCourse(buf.readUnsignedShortLE()); + break; + case 0x0A: + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + break; + case 0x0B: + position.setAltitude(buf.readShortLE()); + break; + case 0x0C: + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + break; + case 0x0D: + position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000); + break; + case 0x14: + position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); + break; + case 0x15: + position.set(Position.KEY_INPUT, buf.readUnsignedByte()); + 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 0x1B: + buf.readUnsignedByte(); + break; + default: + break; + } + } + return position; + } +" +jitterted-ensembler-0963194c9ebc," public static ParticipantAction from(MemberStatus memberStatus, boolean disabled) { + return switch (memberStatus) { + case UNKNOWN, DECLINED -> new ParticipantAction( + ""/member/accept"", + ""Participate in Rotation ⌨"", + disabled); + case PARTICIPANT -> new ParticipantAction( + ""/member/decline"", + ""Leave Rotation 👋"", + false); + case SPECTATOR -> new ParticipantAction( + ""/member/accept"", + ""Switch to Participant 👋"", + disabled); + }; + } +"," public static ParticipantAction from(MemberStatus memberStatus, boolean disabled) { + return switch (memberStatus) { + case UNKNOWN, DECLINED -> new ParticipantAction( + ""/member/accept"", + ""Participate in Rotation ⌨"", + disabled); + case PARTICIPANT -> new ParticipantAction( + ""/member/decline"", + ""Leave Rotation 👋"", + false); + case SPECTATOR -> new ParticipantAction( + ""/member/accept"", + ""Switch to Participant ⌨"", + disabled); + }; + } +" +jitterted-ensembler-0e512e5b3677," public static EnsembleSummaryView toView(Ensemble ensemble, MemberId memberId, MemberService memberService) { + List participantViews = transform(memberService, ensemble.acceptedMembers()); + return new EnsembleSummaryView(ensemble.getId().id(), + ensemble.name(), + DateTimeFormatting.formatAsDateTimeForCommonIso8601(ensemble.startDateTime()), + ensemble.acceptedCount(), + participantViews, + participantViews, + memberStatusToViewString(ensemble, memberId), + ensemble.meetingLink().toString(), + new GoogleCalendarLinkCreator().createFor(ensemble), + ensemble.recordingLink().toString() + ); + } +"," public static EnsembleSummaryView toView(Ensemble ensemble, MemberId memberId, MemberService memberService) { + List participantViews = transform(memberService, ensemble.acceptedMembers()); + List spectatorViews = transform(memberService, ensemble.spectators()); + return new EnsembleSummaryView(ensemble.getId().id(), + ensemble.name(), + DateTimeFormatting.formatAsDateTimeForCommonIso8601(ensemble.startDateTime()), + ensemble.acceptedCount(), + participantViews, + spectatorViews, + memberStatusToViewString(ensemble, memberId), + ensemble.meetingLink().toString(), + new GoogleCalendarLinkCreator().createFor(ensemble), + ensemble.recordingLink().toString() + ); + } +" +jitterted-ensembler-60ec3bf0273b," public void joinAsSpectator(MemberId memberId) { + membersAsSpectators.add(memberId); + membersWhoAccepted.remove(memberId); + } +"," public void joinAsSpectator(MemberId memberId) { + membersAsSpectators.add(memberId); + membersWhoAccepted.remove(memberId); + membersWhoDeclined.remove(memberId); + } +" +traccar-traccar-ee3cbd4aba2e," 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; + } +"," 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: + int x = buf.readUnsignedShort(); + if (x > 0x8000) { + x -= 0x10000; + } + int y = buf.readUnsignedShort(); + if (y > 0x8000) { + y -= 0x10000; + } + int z = buf.readUnsignedShort(); + if (z > 0x8000) { + z -= 0x10000; + } + position.set(""tilt"", String.format(""[%d,%d,%d]"", x, y, z)); + break; + default: + buf.skipBytes(length); + break; + } + } + return position; + } +" +fishercoder1534-Leetcode-2110c6b023b7," public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null || p == root || q == root) { + return root; + } + if ((root.val - p.val) * (root.val - q.val) > 0) { + if (root.val - p.val > 0) { + return lowestCommonAncestor(root.left, p, q); + } + return lowestCommonAncestor(root.right, p, q); + } + return root; + } +"," public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + if (root == null || p == root || q == root) { + return root; + } + if (root.val > p.val && root.val > q.val) { + return lowestCommonAncestor(root.left, p, q); + } else if (root.val < p.val && root.val < q.val) { + return lowestCommonAncestor(root.right, p, q); + } + return root; + } +" +jhy-jsoup-8e2b86839b27," private boolean isFormatAsBlock(Document.OutputSettings out) { + return tag.formatAsBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline(); + } +"," private boolean isFormatAsBlock(Document.OutputSettings out) { + return tag.isBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline(); + } +" +traccar-traccar-cadcd2676adb," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.skipBytes(2); + int type = buf.readUnsignedByte(); + buf.readUnsignedShort(); + if (type == MSG_LOGIN || type == MSG_ADMIN_NUMBER || type == MSG_SEND_TEXT + || type == MSG_SMS_ALARM_SWITCH || type == MSG_POSITION_REUPLOAD) { + ByteBuf response = Unpooled.buffer(); + response.writeByte(0x29); + response.writeByte(0x29); + response.writeByte(MSG_CONFIRMATION); + response.writeShort(5); + response.writeByte(buf.getByte(buf.writerIndex() - 2)); + response.writeByte(type); + response.writeByte(buf.writerIndex() > 9 ? buf.getByte(9) : 0); + response.writeByte(Checksum.xor(response.nioBuffer())); + response.writeByte(0x0D); + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + } + if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD + || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) { + Position position = new Position(getProtocolName()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readIdentifiers(buf)); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + DateBuilder dateBuilder = new DateBuilder() + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); + position.setTime(dateBuilder.getDate()); + position.setLatitude(BcdUtil.readCoordinate(buf)); + position.setLongitude(BcdUtil.readCoordinate(buf)); + position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4))); + position.setCourse(BcdUtil.readInteger(buf, 4)); + position.setValid((buf.readUnsignedByte() & 0x80) != 0); + if (type != MSG_ALARM) { + int odometer = buf.readUnsignedMedium(); + if (BitUtil.to(odometer, 16) > 0) { + position.set(Position.KEY_ODOMETER, odometer); + } else if (odometer > 0) { + position.set(Position.KEY_FUEL_LEVEL, BitUtil.from(odometer, 16)); + } + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + position.set(Position.KEY_RESULT, String.valueOf(buf.readUnsignedByte())); + if (type == MSG_PERIPHERAL) { + buf.readUnsignedShort(); + int dataType = buf.readUnsignedByte(); + buf.readUnsignedByte(); + switch (dataType) { + case 0x01: + position.set(Position.KEY_FUEL_LEVEL, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x02: + position.set(Position.PREFIX_TEMP + 1, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x18: + for (int i = 1; i <= 4; i++) { + double value = buf.readUnsignedShort(); + if (value > 0x0000 && value < 0xFFFF) { + position.set(""fuel"" + i, value / 0xFFFE); + } + } + break; + case 0x23: + Network network = new Network(); + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + network.addCellTower(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), + buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte())); + } + if (count > 0) { + position.setNetwork(network); + } + break; + default: + break; + } + } + } else { + buf.readUnsignedByte(); + buf.readUnsignedByte(); + byte[] alarmStatus = new byte[8]; + buf.readBytes(alarmStatus); + decodeAlarmStatus(position, alarmStatus); + } + return position; + } + return null; + } +"," @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + buf.skipBytes(2); + int type = buf.readUnsignedByte(); + buf.readUnsignedShort(); + if (type == MSG_LOGIN || type == MSG_ADMIN_NUMBER || type == MSG_SEND_TEXT + || type == MSG_SMS_ALARM_SWITCH || type == MSG_POSITION_REUPLOAD) { + ByteBuf response = Unpooled.buffer(); + response.writeByte(0x29); + response.writeByte(0x29); + response.writeByte(MSG_CONFIRMATION); + response.writeShort(5); + response.writeByte(buf.getByte(buf.writerIndex() - 2)); + response.writeByte(type); + response.writeByte(buf.writerIndex() > 9 ? buf.getByte(9) : 0); + response.writeByte(Checksum.xor(response.nioBuffer())); + response.writeByte(0x0D); + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + } + if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD + || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) { + Position position = new Position(getProtocolName()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readIdentifiers(buf)); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + DateBuilder dateBuilder = new DateBuilder() + .setYear(BcdUtil.readInteger(buf, 2)) + .setMonth(BcdUtil.readInteger(buf, 2)) + .setDay(BcdUtil.readInteger(buf, 2)) + .setHour(BcdUtil.readInteger(buf, 2)) + .setMinute(BcdUtil.readInteger(buf, 2)) + .setSecond(BcdUtil.readInteger(buf, 2)); + position.setTime(dateBuilder.getDate()); + position.setLatitude(BcdUtil.readCoordinate(buf)); + position.setLongitude(BcdUtil.readCoordinate(buf)); + position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4))); + position.setCourse(BcdUtil.readInteger(buf, 4)); + position.setValid((buf.readUnsignedByte() & 0x80) != 0); + if (type != MSG_ALARM) { + int odometer = buf.readUnsignedMedium(); + if (BitUtil.to(odometer, 16) > 0) { + position.set(Position.KEY_ODOMETER, odometer); + } else if (odometer > 0) { + position.set(Position.KEY_FUEL_LEVEL, BitUtil.from(odometer, 16)); + } + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.readUnsignedShort(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + buf.readUnsignedByte(); + position.set(Position.KEY_RESULT, String.valueOf(buf.readUnsignedByte())); + if (type == MSG_PERIPHERAL) { + buf.readUnsignedShort(); + int dataType = buf.readUnsignedByte(); + buf.readUnsignedByte(); + switch (dataType) { + case 0x01: + position.set(Position.KEY_FUEL_LEVEL, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x02: + position.set(Position.PREFIX_TEMP + 1, + buf.readUnsignedByte() * 100 + buf.readUnsignedByte()); + break; + case 0x18: + for (int i = 1; i <= 4; i++) { + double value = buf.readUnsignedShort(); + if (value > 0x0000 && value < 0xFFFF) { + position.set(""fuel"" + i, value / 0xFFFE); + } + } + break; + case 0x20: + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + break; + case 0x23: + Network network = new Network(); + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + network.addCellTower(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), + buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte())); + } + if (count > 0) { + position.setNetwork(network); + } + break; + default: + break; + } + } + } else { + buf.readUnsignedByte(); + buf.readUnsignedByte(); + byte[] alarmStatus = new byte[8]; + buf.readBytes(alarmStatus); + decodeAlarmStatus(position, alarmStatus); + } + return position; + } + return null; + } +" +traccar-traccar-1a1126d2d392," private Position decode4( + Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { + int index = 0; + String type = values[index++].substring(5); + if (!type.equals(""STT"") && !type.equals(""ALT"")) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]); + if (deviceSession == null) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_TYPE, type); + position.set(Position.KEY_VERSION_FW, values[index++]); + index += 1; + Network network = new Network(); + for (int i = 0; i < 7; i++) { + int cid = Integer.parseInt(values[index++]); + int mcc = Integer.parseInt(values[index++]); + int mnc = Integer.parseInt(values[index++]); + int lac, rssi; + if (i == 0) { + rssi = Integer.parseInt(values[index++]); + lac = Integer.parseInt(values[index++]); + } else { + lac = Integer.parseInt(values[index++]); + rssi = Integer.parseInt(values[index++]); + } + index += 1; + if (cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi)); + } + } + position.setNetwork(network); + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + position.set(Position.KEY_ARCHIVE, values[index++].equals(""0"") ? true : null); + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++])); + if (values[index].length() == 3) { + index += 1; + } + DateFormat dateFormat = new SimpleDateFormat(""yyyyMMddHH:mm:ss""); + dateFormat.setTimeZone(TimeZone.getTimeZone(""UTC"")); + position.setTime(dateFormat.parse(values[index++] + values[index++])); + position.setLatitude(Double.parseDouble(values[index++])); + position.setLongitude(Double.parseDouble(values[index++])); + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); + position.setCourse(Double.parseDouble(values[index++])); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setValid(values[index++].equals(""1"")); + return position; + } +"," private Position decode4( + Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { + int index = 0; + String type = values[index++].substring(5); + if (!type.equals(""STT"") && !type.equals(""ALT"")) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]); + if (deviceSession == null) { + return null; + } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_TYPE, type); + position.set(Position.KEY_VERSION_FW, values[index++]); + index += 1; + Network network = new Network(); + for (int i = 0; i < 7; i++) { + int cid = Integer.parseInt(values[index++]); + int mcc = Integer.parseInt(values[index++]); + int mnc = Integer.parseInt(values[index++]); + int lac, rssi; + if (i == 0) { + rssi = Integer.parseInt(values[index++]); + lac = Integer.parseInt(values[index++]); + } else { + lac = Integer.parseInt(values[index++]); + rssi = Integer.parseInt(values[index++]); + } + index += 1; + if (cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi)); + } + } + position.setNetwork(network); + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + position.set(Position.KEY_ARCHIVE, values[index++].equals(""0"") ? true : null); + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + position.set(Position.KEY_STATUS, Integer.parseInt(values[index++])); + if (values[index].length() == 3) { + index += 1; + } + if (values[index].isEmpty()) { + getLastLocation(position, null); + } else { + DateFormat dateFormat = new SimpleDateFormat(""yyyyMMddHH:mm:ss""); + dateFormat.setTimeZone(TimeZone.getTimeZone(""UTC"")); + position.setTime(dateFormat.parse(values[index++] + values[index++])); + position.setLatitude(Double.parseDouble(values[index++])); + position.setLongitude(Double.parseDouble(values[index++])); + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); + position.setCourse(Double.parseDouble(values[index++])); + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + position.setValid(values[index++].equals(""1"")); + } + return position; + } +" +jhy-jsoup-a349582236a7," private boolean isInlineable(Document.OutputSettings out) { + return tag().isInline() + && (parent() == null || parent().isBlock()) + && previousSibling() != null + && !out.outline(); + } +"," private boolean isInlineable(Document.OutputSettings out) { + if (!tag.isInline()) + return false; + final Node prev = previousSibling(); + boolean isFirst = siblingIndex == 0; + if (siblingIndex == 1 && prev instanceof TextNode && (((TextNode) prev).isBlank())) + isFirst = true; + return (parent() == null || parent().isBlock()) + && !isFirst + && !out.outline(); + } +" +jhy-jsoup-2a4a9cf83dea," @Override + public boolean matches(Element root, Element element) { + for (int i = evaluators.size() -1; i >= 0; --i) { + if (element == null) + return false; + Evaluator eval = evaluators.get(i); + if (!eval.matches(root, element)) + return false; + element = element.parent(); + } + return true; + } +"," @Override + public boolean matches(Element root, Element element) { + if (element == root) + return false; + for (int i = evaluators.size() -1; i >= 0; --i) { + if (element == null) + return false; + Evaluator eval = evaluators.get(i); + if (!eval.matches(root, element)) + return false; + element = element.parent(); + } + return true; + } +" +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 parseData( + Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) { + List 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 parseData( + Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) { + List 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 arguments) + { + final Map> 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 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 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> 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 arguments) + { + final Map> 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 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 argValues = valuesByArg.computeIfAbsent(arg, k -> new ArrayList<>()); + if (!argValues.isEmpty() && !arg.isAllowMultipleValues()) + { + break; + } + SimpleArgumentProcessor.addValue(arg, argument.value, argValues); + arguments.pollFirst(); + } + final Map> 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 registerCallContext( + final ActorRef callContextProvider, + final String callContext, + final AriCommand ariCommand) { + if (!ariCommand.extractCommandType().isCreationCommand()) { + return Try.success(Done.done()); + } + final Option 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 registerCallContext( + final ActorRef callContextProvider, + final String callContext, + final AriCommand ariCommand) { + if (!(ariCommand.extractCommandType().isCreationCommand() + && ""POST"".equals(ariCommand.getMethod()))) { + return Try.success(Done.done()); + } + final Option 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 positions = new LinkedList<>(); + Set 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 positions = new LinkedList<>(); + Set 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + List 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 s = new Stack(); + 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 s = new Stack(); + 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 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 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 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 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 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 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; + } +"