diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-06 21:29:27 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-06 21:29:27 -0800 |
commit | fa837208bed12dd08e1a540a2279180dec102974 (patch) | |
tree | 0a58f398569ad9f307aabd3687e96b5d1576ec5e | |
parent | 7eecff54effb04d27fdd1d67ed75a1e2dbc3c693 (diff) | |
download | trackermap-server-fa837208bed12dd08e1a540a2279180dec102974.tar.gz trackermap-server-fa837208bed12dd08e1a540a2279180dec102974.tar.bz2 trackermap-server-fa837208bed12dd08e1a540a2279180dec102974.zip |
Support Traxsit GPS1 format
-rw-r--r-- | src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java | 18 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java | 3 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java index 304f61836..bda0600cc 100644 --- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2020 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. @@ -83,7 +83,14 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder { } JsonObject json = Json.createReader(new StringReader(content)).readObject(); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, json.getString("device")); + String deviceId; + if (json.containsKey("device")) { + deviceId = json.getString("device"); + } else { + deviceId = json.getString("deviceId"); + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, deviceId); if (deviceSession == null) { sendResponse(channel, HttpResponseStatus.BAD_REQUEST); return null; @@ -99,7 +106,8 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder { } if (json.containsKey("location") - || json.containsKey("lat") && json.containsKey("lng") && !json.containsKey("data")) { + || json.containsKey("lat") && json.containsKey("lng") && !json.containsKey("data") + || json.containsKey("latitude") && json.containsKey("longitude") && !json.containsKey("data")) { JsonObject location; if (json.containsKey("location")) { @@ -109,8 +117,8 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder { } position.setValid(true); - position.setLatitude(getJsonDouble(location, "lat")); - position.setLongitude(getJsonDouble(location, "lng")); + position.setLatitude(getJsonDouble(location, location.containsKey("lat") ? "lat" : "latitude")); + position.setLongitude(getJsonDouble(location, location.containsKey("lng") ? "lng" : "longitude")); } else { diff --git a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java index 4ab343876..2bf6276b3 100644 --- a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class SigfoxProtocolDecoderTest extends ProtocolTest { SigfoxProtocolDecoder decoder = new SigfoxProtocolDecoder(null); verifyPosition(decoder, request(HttpMethod.POST, "/", + buffer("{\"deviceId\":\"3377BC\",\"snr\":\"16.46\",\"rssi\":\"-123.00\",\"station\":\"-123.00\",\"seqNum\":\"3042\",\"newPosition\":true,\"latitude\":51.9189749,\"longitude\":-8.3979322,\"positionTime\":\"1582801850\",\"moving\":false,\"magChange\":false,\"magStatus\":false,\"temperature\":-2,\"battery\":\"null\",\"batteryPercentage\":\"null\",\"lastSeen\":\"1582801850\",\"fwVersion\":\"null\",\"dlConfig\":\"null\",\"recievedPayload\":\"09495a9085f5c94c\"}"))); + + verifyPosition(decoder, request(HttpMethod.POST, "/", buffer("{ \"device\" : \"33827B\", \"data\" : \"1f03198e63807f08836402ff\", \"time\" : \"1574346702\", \"snr\" : \"8.82\", \"station\" : \"140A\", \"avgSnr\" : \"11.28\", \"lat\" : \"52.0\", \"lng\" : \"-8.0\", \"rssi\" : \"-141.00\", \"seqNumber\" : \"3662\"}"))); verifyPosition(decoder, request(HttpMethod.POST, "/", |