aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/PiligrimProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/PiligrimProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
index 9e26594f2..b05e51c68 100644
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
@@ -18,7 +18,7 @@ package org.traccar.protocol;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.net.SocketAddress;
-import java.util.Calendar;
+import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
@@ -38,7 +38,7 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
-
+
public PiligrimProtocolDecoder(PiligrimProtocol protocol) {
super(protocol);
}
@@ -61,26 +61,26 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg)
throws Exception {
-
+
HttpRequest request = (HttpRequest) msg;
String uri = request.getUri();
-
+
if (uri.startsWith("/config")) {
sendResponse(channel, "CONFIG: OK");
-
+
} else if (uri.startsWith("/addlog")) {
sendResponse(channel, "ADDLOG: OK");
-
+
} else if (uri.startsWith("/inform")) {
sendResponse(channel, "INFORM: OK");
-
+
} else if (uri.startsWith("/bingps")) {
sendResponse(channel, "BINGPS: OK");
-
+
// Identification
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
if (!identify(decoder.getParameters().get("imei").get(0), channel)) {
@@ -89,19 +89,19 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<>();
ChannelBuffer buf = request.getContent();
-
+
while (buf.readableBytes() > 2) {
buf.readUnsignedByte(); // header
int type = buf.readUnsignedByte();
buf.readUnsignedByte(); // length
-
+
if (type == MSG_GPS || type == MSG_GPS_SENSORS) {
-
+
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(getDeviceId());
-
+
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
@@ -112,34 +112,34 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.MINUTE, buf.readUnsignedByte());
time.set(Calendar.SECOND, buf.readUnsignedByte());
position.setTime(time.getTime());
-
+
// Latitude
double latitude = buf.readUnsignedByte();
latitude += buf.readUnsignedByte() / 60.0;
latitude += buf.readUnsignedByte() / 6000.0;
latitude += buf.readUnsignedByte() / 600000.0;
-
+
// Longitude
double longitude = buf.readUnsignedByte();
longitude += buf.readUnsignedByte() / 60.0;
longitude += buf.readUnsignedByte() / 6000.0;
longitude += buf.readUnsignedByte() / 600000.0;
-
+
// Hemisphere
int flags = buf.readUnsignedByte();
if ((flags & 0x01) != 0) latitude = -latitude;
if ((flags & 0x02) != 0) longitude = -longitude;
position.setLatitude(latitude);
position.setLongitude(longitude);
-
+
// Satellites
int satellites = buf.readUnsignedByte();
position.set(Event.KEY_SATELLITES, satellites);
position.setValid(satellites >= 3);
-
+
// Speed
position.setSpeed(buf.readUnsignedByte());
-
+
// Course
double course = buf.readUnsignedByte() << 1;
course += (flags >> 2) & 1;
@@ -158,18 +158,18 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
double battery = buf.readUnsignedByte();
battery += buf.readUnsignedByte() << 8;
position.set(Event.KEY_BATTERY, battery / 100);
-
+
buf.skipBytes(6);
-
+
}
positions.add(position);
-
+
} else if (type == MSG_EVENTS) {
-
+
buf.skipBytes(13);
}
}
-
+
return positions;
}