diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-07-20 18:07:10 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-07-20 18:07:10 -0700 |
commit | 1bafb567e4a2122acf06540d11f2889ca9b473ad (patch) | |
tree | 0a5862b62ffd0b5008e2bc09d10a93916ceddf3b /src | |
parent | 51fe2fc02801e9cac455a0834b4a4510a33a1739 (diff) | |
download | trackermap-server-1bafb567e4a2122acf06540d11f2889ca9b473ad.tar.gz trackermap-server-1bafb567e4a2122acf06540d11f2889ca9b473ad.tar.bz2 trackermap-server-1bafb567e4a2122acf06540d11f2889ca9b473ad.zip |
Support AY-GPS protocol
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/UproProtocolDecoder.java | 63 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java | 12 |
2 files changed, 71 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java index dc7a9200d..0e328c920 100644 --- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,6 +89,13 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(int alarm) { + if (BitUtil.check(alarm, 2)) { + return Position.ALARM_TAMPERING; + } + return null; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -160,9 +167,25 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { position.setSpeed( Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1); break; + case 'G': + position.setAltitude( + Integer.parseInt(data.readSlice(6).toString(StandardCharsets.US_ASCII)) * 0.1); + break; case 'K': position.set("statusExtended", data.toString(StandardCharsets.US_ASCII)); break; + case 'M': + position.set(Position.KEY_BATTERY_LEVEL, + Integer.parseInt(data.readSlice(3).toString(StandardCharsets.US_ASCII)) * 0.1); + break; + case 'N': + position.set(Position.KEY_RSSI, + Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII))); + break; + case 'O': + position.set(Position.KEY_SATELLITES, + Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII))); + break; case 'P': if (data.readableBytes() >= 16) { position.setNetwork(new Network(CellTower.from( @@ -196,17 +219,49 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1); break; + case 'W': + position.set(Position.KEY_ALARM, + decodeAlarm(Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)))); + break; + case 'X': + Network network = new Network(); + int mcc = 0, mnc = 0; + String[] cells = data.toString(StandardCharsets.US_ASCII).split(";"); + if (!cells[0].startsWith("(")) { + for (int i = 0; i < cells.length; i++) { + String[] values = cells[i].split(","); + int index = 0; + if (i == 0) { + mcc = Integer.parseInt(values[index++]); + mnc = Integer.parseInt(values[index++]); + } + network.addCellTower(CellTower.from( + mcc, mnc, + Integer.parseInt(values[index++]), + Integer.parseInt(values[index++]), + Integer.parseInt(values[index]))); + } + position.setNetwork(network); + } + break; + case 'Y': + position.set(Position.KEY_POWER, + Integer.parseInt(data.readSlice(5).toString(StandardCharsets.US_ASCII)) * 0.001); + break; default: break; } } - if (position.getLatitude() != 0 && position.getLongitude() != 0) { - return position; + if (position.getLatitude() == 0 || position.getLongitude() == 0) { + if (position.getAttributes().isEmpty()) { + return null; + } + getLastLocation(position, position.getDeviceTime()); } - return null; + return position; } } diff --git a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java index dbbe4591f..856e527c4 100644 --- a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java @@ -10,6 +10,18 @@ public class UproProtocolDecoderTest extends ProtocolTest { UproProtocolDecoder decoder = new UproProtocolDecoder(null); + verifyAttributes(decoder, buffer( + "*VK201867282035754650,AH&B0000000000&W00&M990&N31&Z02&b2&T0458#")); + + verifyAttributes(decoder, buffer( + "*VK201867282035455779,AH&B0000000000&W00&M940&N30&Z02&Y12922&T0268#")); + + verifyPosition(decoder, buffer( + "*VK200867282035455779,BA&A0850065052928902036605660013170719&B0000000000&W00&G000030&M850&N20&O1808&o10&Y12922&T0081#")); + + verifyAttributes(decoder, buffer( + "*VK200867282035455779,BA&X260,6,1016,13931,60;1016,13929,81;1016,14174,82;1016,13930,82&E190717103920&B0100000000&W00&G000030&M900&N23&O0000&o07&Y14014&T0015#")); + verifyPosition(decoder, buffer( "*HQ200861810538000002,BA&A0206033302618209658563620115180119&B0100000040&C6328680=&F0039&R2710&V0036&T09&K50000&N04&P0200#")); |