diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java | 15 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java | 11 |
2 files changed, 20 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java index de23ea170..b742d0cac 100644 --- a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java @@ -60,9 +60,9 @@ import java.util.List; public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder { - private DocumentBuilder documentBuilder; - private XPath xPath; - private XPathExpression messageExpression; + private final DocumentBuilder documentBuilder; + private final XPath xPath; + private final XPathExpression messageExpression; public GlobalstarProtocolDecoder(Protocol protocol) { super(protocol); @@ -161,17 +161,20 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder { position.setLongitude(position.getLongitude() - 360); } - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + int speed = buf.readUnsignedByte(); + position.setSpeed(UnitsConverter.knotsFromKph(speed)); position.set("batteryReplace", BitUtil.check(buf.readUnsignedByte(), 7)); - positions.add(position); + if (speed != 0xff) { + positions.add(position); + } } } sendResponse(channel, document.getFirstChild().getAttributes().getNamedItem("messageID").getNodeValue()); - return positions; + return !positions.isEmpty() ? positions : null; } } diff --git a/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java index f7bf8f514..75d30ec47 100644 --- a/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java @@ -11,6 +11,17 @@ public class GlobalstarProtocolDecoderTest extends ProtocolTest { GlobalstarProtocolDecoder decoder = new GlobalstarProtocolDecoder(null); + verifyNull(decoder, request(HttpMethod.POST, "/", buffer( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", + "<stuMessages xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://cody.glpconnect.com/XSD/StuMessage_Rev1_0_1.xsd\" timeStamp=\"16/09/2020 01:33:07 GMT\" messageID=\"567207180ae9100687cef8c81978371a\">\n", + "<stuMessage>\n", + "<esn>0-4325340</esn>\n", + "<unixTime>1600220003</unixTime>\n", + "<gps>N</gps>\n", + "<payload length=\"9\" source=\"pc\" encoding=\"hex\">0x63FFFF1BB4FFFFFFFF</payload>\n", + "</stuMessage>\n", + "</stuMessages>"))); + verifyPositions(decoder, request(HttpMethod.POST, "/", buffer( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<stuMessages xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://cody.glpconnect.com/XSD/StuMessage_Rev1_0_1.xsd\" timeStamp=\"25/03/2020 03:02:32 GMT\" messageID=\"300421a0fd2a100585bdde409d6f601a\">", |