-
Notifications
You must be signed in to change notification settings - Fork 0
/
005538a768069a1d342190a9c85d2cad14326d6d431291b45474a65315c72f3f
7 lines (7 loc) · 6.5 KB
/
005538a768069a1d342190a9c85d2cad14326d6d431291b45474a65315c72f3f
1
2
3
4
5
6
7
{
"generation": "private void decodeFragment(Position position, String fragment) {\n\n int dataIndex = fragment.indexOf(':');\n if (dataIndex == -1) {\n return; // Ensure there is a ':' character in the fragment\n }\n \n int index = 0;\n String[] values;\n if (fragment.length() == dataIndex + 1) {\n values = new String[0];\n } else {\n values = fragment.substring(dataIndex + 1).split(\";\");\n }\n\n switch (fragment.substring(0, dataIndex)) {\n case \"GPS\":\n position.setValid(index < values.length && values[index++].equals(\"A\"));\n if (index < values.length) {\n position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++]));\n }\n if (index < values.length) {\n position.setLatitude(Double.parseDouble(values[index].substring(1)));\n if (values[index++].charAt(0) == 'S') {\n position.setLatitude(-position.getLatitude());\n }\n }\n if (index < values.length) {\n position.setLongitude(Double.parseDouble(values[index].substring(1)));\n if (values[index++].charAt(0) == 'W') {\n position.setLongitude(-position.getLongitude());\n }\n }\n if (index < values.length && !values[index].isEmpty()) {\n position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index])));\n index++;\n }\n if (index < values.length) {\n position.setCourse(Integer.parseInt(values[index++]));\n }\n if (index < values.length) {\n position.setAltitude(Integer.parseInt(values[index++]));\n }\n if (index < values.length) {\n position.set(Position.KEY_HDOP, Double.parseDouble(values[index++]));\n }\n if (index < values.length) {\n position.set(Position.KEY_VDOP, Double.parseDouble(values[index++]));\n }\n break;\n case \"GSM\":\n // Assuming the lengths need to be checked here as well\n index += 1; // registration status\n index += 1; // signal strength\n if (index < values.length - 4) {\n position.setNetwork(new Network(CellTower.from(\n Integer.parseInt(values[index++]), Integer.parseInt(values[index++]),\n Integer.parseInt(values[index++], 16), Integer.parseInt(values[index++], 16),\n Integer.parseInt(values[index++]))));\n }\n break;\n case \"COT\":\n if (index < values.length) {\n position.set(Position.KEY_ODOMETER, Long.parseLong(values[index++]));\n }\n if (index < values.length) {\n String[] hours = values[index].split(\"-\");\n position.set(Position.KEY_HOURS, (Integer.parseInt(hours[0]) * 3600\n + (hours.length > 1 ? Integer.parseInt(hours[1]) * 60 : 0)\n + (hours.length > 2 ? Integer.parseInt(hours[2]) : 0)) * 1000);\n }\n break;\n case \"ADC\":\n if (index < values.length) {\n position.set(Position.KEY_POWER, Double.parseDouble(values[index++]));\n }\n if (index < values.length) {\n position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++]));\n }\n if (index < values.length) {\n position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++]));\n }\n if (index < values.length) {\n position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++]));\n }\n break;\n case \"DTT\":\n if (index < values.length) {\n position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16));\n }\n if (index < values.length && !values[index].isEmpty()) {\n int io = Integer.parseInt(values[index], 16);\n position.set(Position.KEY_IGNITION, BitUtil.check(io, 0));\n position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1));\n position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2));\n position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3));\n position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4));\n position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5));\n position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6));\n position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7));\n index++;\n }\n if (index < values.length - 1) {\n position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]);\n }\n if (index < values.length) {\n position.set(\"eventStatus\", values[index++]);\n }\n if (index < values.length) {\n position.set(\"packetType\", values[index++]);\n }\n break;\n case \"ETD\":\n if (index < values.length) {\n position.set(\"eventData\", values[index++]);\n }\n break;\n case \"OBD\":\n if (index < values.length) {\n position.set(\"obd\", values[index++]);\n }\n break;\n case \"TAG\":\n if (index < values.length) {\n position.set(\"tagData\", values[index++]);\n }\n break;\n case \"IWD\":\n while (index < values.length) {\n int sensorIndex = Integer.parseInt(values[index++]);\n int dataType = Integer.parseInt(values[index++]);\n if (dataType == 0) {\n if (index < values.length) {\n position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index++]);\n }\n } else if (dataType == 1) {\n index += 1; // temperature sensor serial number\n if (index < values.length) {\n position.set(Position.PREFIX_TEMP + sensorIndex, Double.parseDouble(values[index++]));\n }\n }\n }\n break;\n default:\n break;\n }\n}",
"exact_match": false,
"ast_match": false,
"compile": null,
"test": false
}