diff options
-rw-r--r-- | src/org/traccar/protocol/Xrb28ProtocolDecoder.java | 61 | ||||
-rw-r--r-- | test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java | 8 |
2 files changed, 62 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/Xrb28ProtocolDecoder.java b/src/org/traccar/protocol/Xrb28ProtocolDecoder.java index 527fa4254..938394d6b 100644 --- a/src/org/traccar/protocol/Xrb28ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xrb28ProtocolDecoder.java @@ -88,16 +88,71 @@ public class Xrb28ProtocolDecoder extends BaseProtocolDecoder { } } - if (type.matches("R0|L0|L1|S4|S5|S6|S7|V0|G0|K0|I0|M0")) { + if (!type.startsWith("D")) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); getLastLocation(position, null); - position.set(Position.KEY_RESULT, sentence.substring(25, sentence.length() - 1)); + String payload = sentence.substring(25, sentence.length() - 1); + + int index = 0; + String[] values = payload.substring(3).split(","); + + switch (type) { + case "Q0": + position.set(Position.KEY_BATTERY, Integer.parseInt(values[index++]) * 0.01); + position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[index++])); + position.set(Position.KEY_RSSI, Integer.parseInt(values[index++])); + break; + case "H0": + position.set(Position.KEY_BLOCKED, Integer.parseInt(values[index++]) > 0); + position.set(Position.KEY_BATTERY, Integer.parseInt(values[index++]) * 0.01); + position.set(Position.KEY_RSSI, Integer.parseInt(values[index++])); + position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[index++])); + break; + case "W0": + switch (Integer.parseInt(values[index++])) { + case 1: + position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); + break; + case 2: + position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN); + break; + case 3: + position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + break; + default: + break; + } + break; + case "E0": + position.set(Position.KEY_ALARM, Position.ALARM_FAULT); + position.set("error", Integer.parseInt(values[index++])); + break; + case "S1": + position.set(Position.KEY_EVENT, Integer.parseInt(values[index++])); + break; + case "R0": + case "L0": + case "L1": + case "S4": + case "S5": + case "S6": + case "S7": + case "V0": + case "G0": + case "K0": + case "I0": + case "M0": + position.set(Position.KEY_RESULT, payload); + break; + default: + break; + } - return position; + return !position.getAttributes().isEmpty() ? position : null; } else { diff --git a/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java b/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java index cef1f38f9..0f15f31b4 100644 --- a/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java @@ -10,15 +10,15 @@ public class Xrb28ProtocolDecoderTest extends ProtocolTest { Xrb28ProtocolDecoder decoder = new Xrb28ProtocolDecoder(null); + verifyAttributes(decoder, text( + "*SCOR,OM,123456789123456,Q0,412,80,28#")); + verifyPosition(decoder, text( "*SCOR,OM,867584030387299,D0,0,012102.00,A,0608.00062,S,10659.70331,E,12,0.69,151118,30.3,M,A#")); - verifyNull(decoder, text( + verifyAttributes(decoder, text( "*SCOR,OM,863158022988725,H0,0,412,28,80,0#")); - verifyNull(decoder, text( - "*HBCR,OM,123456789123456,Q0,412,80#")); - verifyAttributes(decoder, text( "*HBCR,OM,123456789123456,R0,0,55,1234,1497689816#")); |