aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/NavisProtocolDecoder.java
diff options
context:
space:
mode:
authorninioe <ninioe@gmail.com>2016-07-19 15:20:15 +0300
committerninioe <ninioe@gmail.com>2016-07-19 15:20:15 +0300
commit20f603076210073e122c720e21a3e8999478b11a (patch)
tree668a50e6c55601c2420bf0f4b986ed0b194c2e32 /src/org/traccar/protocol/NavisProtocolDecoder.java
parente954e95547d05a34bbd36e3aa5003f4ddaf2ccd0 (diff)
parent00e2f8a3575855a8b863e245005b8f83b3314bfb (diff)
downloadtrackermap-server-20f603076210073e122c720e21a3e8999478b11a.tar.gz
trackermap-server-20f603076210073e122c720e21a3e8999478b11a.tar.bz2
trackermap-server-20f603076210073e122c720e21a3e8999478b11a.zip
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/protocol/NavisProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index fbd704355..fad24301c 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -19,9 +19,9 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Log;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -39,7 +39,6 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- // Format types
public static final int F10 = 0x01;
public static final int F20 = 0x02;
public static final int F30 = 0x03;
@@ -75,11 +74,11 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
}
}
- private ParseResult parsePosition(ChannelBuffer buf) {
+ private ParseResult parsePosition(DeviceSession deviceSession, ChannelBuffer buf) {
Position position = new Position();
position.setProtocol(getProtocolName());
- position.setDeviceId(getDeviceId());
+ position.setDeviceId(deviceSession.getDeviceId());
int format;
if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
@@ -177,8 +176,8 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
return new ParseResult(index, position);
}
- private Object processSingle(Channel channel, ChannelBuffer buf) {
- ParseResult result = parsePosition(buf);
+ private Object processSingle(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
+ ParseResult result = parsePosition(deviceSession, buf);
ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<T", StandardCharsets.US_ASCII));
@@ -192,12 +191,12 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
return result.getPosition();
}
- private Object processArray(Channel channel, ChannelBuffer buf) {
+ private Object processArray(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
- Position position = parsePosition(buf).getPosition();
+ Position position = parsePosition(deviceSession, buf).getPosition();
if (position.getFixTime() != null) {
positions.add(position);
}
@@ -217,7 +216,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
private Object processHandshake(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
buf.readByte(); // semicolon symbol
- if (identify(buf.toString(StandardCharsets.US_ASCII), channel, remoteAddress)) {
+ if (getDeviceSession(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)) != null) {
sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", StandardCharsets.US_ASCII));
}
return null;
@@ -265,16 +264,17 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
String type = buf.toString(buf.readerIndex(), 3, StandardCharsets.US_ASCII);
buf.skipBytes(type.length());
- switch (type) {
- case "*>T":
- return processSingle(channel, buf);
- case "*>A":
- return processArray(channel, buf);
- case "*>S":
- return processHandshake(channel, remoteAddress, buf);
- default:
- Log.warning(new UnsupportedOperationException(type));
- break;
+ if (type.equals("*>S")) {
+ return processHandshake(channel, remoteAddress, buf);
+ } else {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession != null) {
+ if (type.equals("*>T")) {
+ return processSingle(deviceSession, channel, buf);
+ } else if (type.equals("*>A")) {
+ return processArray(deviceSession, channel, buf);
+ }
+ }
}
return null;