aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-05-31 22:30:45 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2017-05-31 22:30:45 +1200
commitdc5f2151d9e74f525d74663d599320b8cf3d9c47 (patch)
treec1e4994d17586ff619608608aa3e29ecf77e51b5 /src/org/traccar/protocol
parent883d296cc80e11279c5fca2d3d7a737eff762479 (diff)
downloadtraccar-server-dc5f2151d9e74f525d74663d599320b8cf3d9c47.tar.gz
traccar-server-dc5f2151d9e74f525d74663d599320b8cf3d9c47.tar.bz2
traccar-server-dc5f2151d9e74f525d74663d599320b8cf3d9c47.zip
Implement image saving
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index cfd165d06..7af856a9c 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
import org.traccar.helper.Parser;
@@ -139,22 +140,25 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(4); // length
buf.skipBytes(1); // delimiter
- String content = null;
+ buf.writerIndex(buf.writerIndex() - 1); // ignore ending
+
int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
- if (contentIndex > 0) {
- content = buf.toString(contentIndex + 1, buf.writerIndex() - 2 - contentIndex, StandardCharsets.US_ASCII);
- } else {
- contentIndex = buf.writerIndex() - 1;
+ if (contentIndex < 0) {
+ contentIndex = buf.writerIndex();
}
String type = buf.readBytes(contentIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
+ if (contentIndex < buf.writerIndex()) {
+ buf.readerIndex(contentIndex + 1);
+ }
+
if (type.equals("LK")) {
sendResponse(channel, manufacturer, id, "LK");
- if (content != null) {
- String[] values = content.split(",");
+ if (buf.readable()) {
+ String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
if (values.length >= 3) {
Position position = new Position();
position.setProtocol(getProtocolName());
@@ -175,7 +179,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, manufacturer, id, "AL");
}
- Parser parser = new Parser(PATTERN_POSITION, content);
+ Parser parser = new Parser(PATTERN_POSITION, buf.toString(StandardCharsets.US_ASCII));
if (!parser.matches()) {
return null;
}
@@ -211,17 +215,32 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
} else if (type.equals("PULSE") || type.equals("heart")) {
- if (content != null) {
+ if (buf.readable()) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, new Date());
position.setValid(false);
- position.set("pulse", content);
- position.set(Position.KEY_RESULT, content);
+ String pulse = buf.toString(StandardCharsets.US_ASCII);
+ position.set("pulse", pulse);
+ position.set(Position.KEY_RESULT, pulse);
return position;
}
+ } else if (type.equals("img")) {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ int timeIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
+ buf.readerIndex(timeIndex + 12 + 2);
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(id, buf, "jpg"));
+
+ return position;
+
}
return null;