-
Notifications
You must be signed in to change notification settings - Fork 0
/
04c5e9638ed316f8057f01af4f0662a02d0bc7a0beeee3a0c9bfd178fd66c6fe
7 lines (7 loc) · 6.22 KB
/
04c5e9638ed316f8057f01af4f0662a02d0bc7a0beeee3a0c9bfd178fd66c6fe
1
2
3
4
5
6
7
{
"generation": " private void decodeFragment(Position position, String fragment) {\n int dataIndex = fragment.indexOf(':');\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 switch (fragment.substring(0, dataIndex)) {\n case \"GPS\":\n position.setValid(values[index++].equals(\"A\"));\n position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++]));\n position.setLatitude(Double.parseDouble(values[index].substring(1)));\n if (values[index++].charAt(0) == 'S') {\n position.setLatitude(-position.getLatitude());\n }\n position.setLongitude(Double.parseDouble(values[index].substring(1)));\n if (values[index++].charAt(0) == 'W') {\n position.setLongitude(-position.getLongitude());\n }\n if (!values[index++].isEmpty()) {\n position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));\n }\n position.setCourse(Integer.parseInt(values[index++]));\n// buggy code\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 if (index < values.length) {\n position.setAltitude(Double.parseDouble(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 }\n break;\n case \"GSM\":\n index += 1; // registration status\n index += 1; // signal strength\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 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 position.set(Position.KEY_POWER, Double.parseDouble(values[index++]));\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 position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16));\n if (!values[index++].isEmpty()) {\n int io = Integer.parseInt(values[index - 1], 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 }\n position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]);\n position.set(\"eventStatus\", values[index++]);\n if (index < values.length) {\n position.set(\"packetType\", values[index++]);\n }\n break;\n case \"ETD\":\n position.set(\"eventData\", values[index++]);\n break;\n case \"OBD\":\n position.set(\"obd\", values[index++]);\n break;\n case \"TAG\":\n position.set(\"tagData\", values[index++]);\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 position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index++]);\n } else if (dataType == 1) {\n index += 1; // temperature sensor serial number\n position.set(Position.PREFIX_TEMP + sensorIndex, Double.parseDouble(values[index++]));\n }\n }\n break;\n default:\n break;\n }\n }\n",
"exact_match": false,
"ast_match": false,
"compile": null,
"test": false
}