From 51f22a533b0e511bd97da6d46a676ac15a47884d Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 13 Jul 2016 17:37:31 +0500 Subject: Added possibility to forward all events via POST request. --- src/org/traccar/database/NotificationManager.java | 7 +++ .../traccar/notification/NotificationForward.java | 71 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/org/traccar/notification/NotificationForward.java (limited to 'src') diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index e618d7ed3..90edce43e 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -31,6 +31,7 @@ import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Notification; import org.traccar.model.Position; +import org.traccar.notification.NotificationForward; import org.traccar.notification.NotificationMail; public class NotificationManager { @@ -41,8 +42,11 @@ public class NotificationManager { private final ReadWriteLock notificationsLock = new ReentrantReadWriteLock(); + private final boolean forward; + public NotificationManager(DataManager dataManager) { this.dataManager = dataManager; + forward = Context.getConfig().getBoolean("event.forward.enable"); refresh(); } @@ -68,6 +72,9 @@ public class NotificationManager { } } } + if (forward) { + NotificationForward.forwardEvent(event, position); + } } public void updateEvents(Collection events, Position position) { diff --git a/src/org/traccar/notification/NotificationForward.java b/src/org/traccar/notification/NotificationForward.java new file mode 100644 index 000000000..32f8a1ffc --- /dev/null +++ b/src/org/traccar/notification/NotificationForward.java @@ -0,0 +1,71 @@ +package org.traccar.notification; + +import java.nio.charset.StandardCharsets; + +import javax.json.Json; +import javax.json.JsonObjectBuilder; + +import org.traccar.Context; +import org.traccar.model.Device; +import org.traccar.model.Event; +import org.traccar.model.Geofence; +import org.traccar.model.Position; +import org.traccar.web.JsonConverter; + +import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; + +public final class NotificationForward { + + private NotificationForward() { + } + + private static final String USER_AGENT = "Traccar Server"; + + private static final String KEY_POSITION = "position"; + private static final String KEY_EVENT = "event"; + private static final String KEY_GEOFENCE = "geofence"; + private static final String KEY_DEVICE = "device"; + + public static void forwardEvent(Event event, Position position) { + String url = Context.getConfig().getString("event.forward.url", "http://localhost/"); + String header = Context.getConfig().getString("event.forward.header", ""); + + BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url); + + requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8"); + requestBuilder.addHeader("User-Agent", USER_AGENT); + if (!header.equals("")) { + String[] headerLines = header.split("\\r?\\n"); + for (String headerLine: headerLines) { + String[] splitedLine = headerLine.split(":", 2); + if (splitedLine.length == 2) { + requestBuilder.addHeader(splitedLine[0].trim(), splitedLine[1].trim()); + } + } + } + + requestBuilder.setBody(preparePayload(event, position)); + requestBuilder.execute(); + } + + private static byte[] preparePayload(Event event, Position position) { + JsonObjectBuilder json = Json.createObjectBuilder(); + json.add(KEY_EVENT, JsonConverter.objectToJson(event)); + if (position != null) { + json.add(KEY_POSITION, JsonConverter.objectToJson(position)); + } + if (event.getDeviceId() != 0) { + Device device = Context.getIdentityManager().getDeviceById(event.getDeviceId()); + if (device != null) { + json.add(KEY_DEVICE, JsonConverter.objectToJson(device)); + } + } + if (event.getGeofenceId() != 0) { + Geofence geofence = Context.getGeofenceManager().getGeofence(event.getGeofenceId()); + if (geofence != null) { + json.add(KEY_GEOFENCE, JsonConverter.objectToJson(geofence)); + } + } + return json.build().toString().getBytes(StandardCharsets.UTF_8); + } +} -- cgit v1.2.3 From 8bf78f0d21c16c0538b60c05a5f6934a890de1a8 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 13 Jul 2016 18:44:46 +0500 Subject: Reduce locks of devices --- src/org/traccar/database/DataManager.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index b3f24383f..0dc3c5c52 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -401,9 +401,11 @@ public class DataManager implements IdentityManager { QueryBuilder.create(dataSource, getQuery("database.updateDeviceStatus")) .setObject(device) .executeUpdate(); - Device cachedDevice = getDeviceById(device.getId()); - cachedDevice.setStatus(device.getStatus()); - cachedDevice.setMotion(device.getMotion()); + if (devicesById.containsKey(device.getId())) { + Device cachedDevice = devicesById.get(device.getId()); + cachedDevice.setStatus(device.getStatus()); + cachedDevice.setMotion(device.getMotion()); + } } public void removeDevice(long deviceId) throws SQLException { @@ -512,8 +514,10 @@ public class DataManager implements IdentityManager { .setDate("now", new Date()) .setObject(position) .executeUpdate(); - Device device = getDeviceById(position.getDeviceId()); - device.setPositionId(position.getId()); + if (devicesById.containsKey(position.getDeviceId())) { + Device cachedDevice = devicesById.get(position.getDeviceId()); + cachedDevice.setPositionId(position.getId()); + } } public Collection getLatestPositions() throws SQLException { -- cgit v1.2.3 From 1593a9dee20ee7355f9f5feb6d121a5ad69a283f Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 13 Jul 2016 19:04:38 +0500 Subject: Renamed to EventForwarder and moved to Context --- src/org/traccar/notification/EventForwarder.java | 71 ++++++++++++++++++++++ .../traccar/notification/NotificationForward.java | 71 ---------------------- 2 files changed, 71 insertions(+), 71 deletions(-) create mode 100644 src/org/traccar/notification/EventForwarder.java delete mode 100644 src/org/traccar/notification/NotificationForward.java (limited to 'src') diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java new file mode 100644 index 000000000..32f8a1ffc --- /dev/null +++ b/src/org/traccar/notification/EventForwarder.java @@ -0,0 +1,71 @@ +package org.traccar.notification; + +import java.nio.charset.StandardCharsets; + +import javax.json.Json; +import javax.json.JsonObjectBuilder; + +import org.traccar.Context; +import org.traccar.model.Device; +import org.traccar.model.Event; +import org.traccar.model.Geofence; +import org.traccar.model.Position; +import org.traccar.web.JsonConverter; + +import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; + +public final class NotificationForward { + + private NotificationForward() { + } + + private static final String USER_AGENT = "Traccar Server"; + + private static final String KEY_POSITION = "position"; + private static final String KEY_EVENT = "event"; + private static final String KEY_GEOFENCE = "geofence"; + private static final String KEY_DEVICE = "device"; + + public static void forwardEvent(Event event, Position position) { + String url = Context.getConfig().getString("event.forward.url", "http://localhost/"); + String header = Context.getConfig().getString("event.forward.header", ""); + + BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url); + + requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8"); + requestBuilder.addHeader("User-Agent", USER_AGENT); + if (!header.equals("")) { + String[] headerLines = header.split("\\r?\\n"); + for (String headerLine: headerLines) { + String[] splitedLine = headerLine.split(":", 2); + if (splitedLine.length == 2) { + requestBuilder.addHeader(splitedLine[0].trim(), splitedLine[1].trim()); + } + } + } + + requestBuilder.setBody(preparePayload(event, position)); + requestBuilder.execute(); + } + + private static byte[] preparePayload(Event event, Position position) { + JsonObjectBuilder json = Json.createObjectBuilder(); + json.add(KEY_EVENT, JsonConverter.objectToJson(event)); + if (position != null) { + json.add(KEY_POSITION, JsonConverter.objectToJson(position)); + } + if (event.getDeviceId() != 0) { + Device device = Context.getIdentityManager().getDeviceById(event.getDeviceId()); + if (device != null) { + json.add(KEY_DEVICE, JsonConverter.objectToJson(device)); + } + } + if (event.getGeofenceId() != 0) { + Geofence geofence = Context.getGeofenceManager().getGeofence(event.getGeofenceId()); + if (geofence != null) { + json.add(KEY_GEOFENCE, JsonConverter.objectToJson(geofence)); + } + } + return json.build().toString().getBytes(StandardCharsets.UTF_8); + } +} diff --git a/src/org/traccar/notification/NotificationForward.java b/src/org/traccar/notification/NotificationForward.java deleted file mode 100644 index 32f8a1ffc..000000000 --- a/src/org/traccar/notification/NotificationForward.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.traccar.notification; - -import java.nio.charset.StandardCharsets; - -import javax.json.Json; -import javax.json.JsonObjectBuilder; - -import org.traccar.Context; -import org.traccar.model.Device; -import org.traccar.model.Event; -import org.traccar.model.Geofence; -import org.traccar.model.Position; -import org.traccar.web.JsonConverter; - -import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; - -public final class NotificationForward { - - private NotificationForward() { - } - - private static final String USER_AGENT = "Traccar Server"; - - private static final String KEY_POSITION = "position"; - private static final String KEY_EVENT = "event"; - private static final String KEY_GEOFENCE = "geofence"; - private static final String KEY_DEVICE = "device"; - - public static void forwardEvent(Event event, Position position) { - String url = Context.getConfig().getString("event.forward.url", "http://localhost/"); - String header = Context.getConfig().getString("event.forward.header", ""); - - BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url); - - requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8"); - requestBuilder.addHeader("User-Agent", USER_AGENT); - if (!header.equals("")) { - String[] headerLines = header.split("\\r?\\n"); - for (String headerLine: headerLines) { - String[] splitedLine = headerLine.split(":", 2); - if (splitedLine.length == 2) { - requestBuilder.addHeader(splitedLine[0].trim(), splitedLine[1].trim()); - } - } - } - - requestBuilder.setBody(preparePayload(event, position)); - requestBuilder.execute(); - } - - private static byte[] preparePayload(Event event, Position position) { - JsonObjectBuilder json = Json.createObjectBuilder(); - json.add(KEY_EVENT, JsonConverter.objectToJson(event)); - if (position != null) { - json.add(KEY_POSITION, JsonConverter.objectToJson(position)); - } - if (event.getDeviceId() != 0) { - Device device = Context.getIdentityManager().getDeviceById(event.getDeviceId()); - if (device != null) { - json.add(KEY_DEVICE, JsonConverter.objectToJson(device)); - } - } - if (event.getGeofenceId() != 0) { - Geofence geofence = Context.getGeofenceManager().getGeofence(event.getGeofenceId()); - if (geofence != null) { - json.add(KEY_GEOFENCE, JsonConverter.objectToJson(geofence)); - } - } - return json.build().toString().getBytes(StandardCharsets.UTF_8); - } -} -- cgit v1.2.3 From 3502e07f0aee825f8599526428dd1962d81f9933 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 13 Jul 2016 19:11:36 +0500 Subject: Renamed to EventForwarder and moved to Context --- src/org/traccar/Context.java | 11 +++++++++++ src/org/traccar/database/NotificationManager.java | 8 ++------ src/org/traccar/notification/EventForwarder.java | 16 ++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index ebe700221..0bb18b675 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -35,6 +35,7 @@ import org.traccar.helper.Log; import org.traccar.location.LocationProvider; import org.traccar.location.MozillaLocationProvider; import org.traccar.location.OpenCellIdLocationProvider; +import org.traccar.notification.EventForwarder; import org.traccar.web.WebServer; public final class Context { @@ -120,6 +121,12 @@ public final class Context { return ASYNC_HTTP_CLIENT; } + private static EventForwarder eventForwarder; + + public static EventForwarder getEventForvarder() { + return eventForwarder; + } + public static void init(String[] arguments) throws Exception { config = new Config(); @@ -210,6 +217,10 @@ public final class Context { serverManager = new ServerManager(); + if (config.getBoolean("event.forward.enable")) { + eventForwarder = new EventForwarder(); + } + } public static void init(IdentityManager testIdentityManager) { diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 90edce43e..911c5d2dc 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -31,7 +31,6 @@ import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Notification; import org.traccar.model.Position; -import org.traccar.notification.NotificationForward; import org.traccar.notification.NotificationMail; public class NotificationManager { @@ -42,11 +41,8 @@ public class NotificationManager { private final ReadWriteLock notificationsLock = new ReentrantReadWriteLock(); - private final boolean forward; - public NotificationManager(DataManager dataManager) { this.dataManager = dataManager; - forward = Context.getConfig().getBoolean("event.forward.enable"); refresh(); } @@ -72,8 +68,8 @@ public class NotificationManager { } } } - if (forward) { - NotificationForward.forwardEvent(event, position); + if (Context.getEventForvarder() != null) { + Context.getEventForvarder().forwardEvent(event, position); } } diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java index 32f8a1ffc..096026541 100644 --- a/src/org/traccar/notification/EventForwarder.java +++ b/src/org/traccar/notification/EventForwarder.java @@ -14,9 +14,14 @@ import org.traccar.web.JsonConverter; import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; -public final class NotificationForward { +public final class EventForwarder { - private NotificationForward() { + private String url; + private String header; + + public EventForwarder() { + url = Context.getConfig().getString("event.forward.url", "http://localhost/"); + header = Context.getConfig().getString("event.forward.header", ""); } private static final String USER_AGENT = "Traccar Server"; @@ -26,9 +31,8 @@ public final class NotificationForward { private static final String KEY_GEOFENCE = "geofence"; private static final String KEY_DEVICE = "device"; - public static void forwardEvent(Event event, Position position) { - String url = Context.getConfig().getString("event.forward.url", "http://localhost/"); - String header = Context.getConfig().getString("event.forward.header", ""); + public void forwardEvent(Event event, Position position) { + BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url); @@ -48,7 +52,7 @@ public final class NotificationForward { requestBuilder.execute(); } - private static byte[] preparePayload(Event event, Position position) { + private byte[] preparePayload(Event event, Position position) { JsonObjectBuilder json = Json.createObjectBuilder(); json.add(KEY_EVENT, JsonConverter.objectToJson(event)); if (position != null) { -- cgit v1.2.3 From 7ce8c4ecf82828920926f81f55cbc4fb833ef259 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 13 Jul 2016 20:36:16 +0500 Subject: Removed unnecessary geofences refresh while user manipulation --- src/org/traccar/api/resource/UserResource.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src') diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java index cfe338b56..da72c7f47 100644 --- a/src/org/traccar/api/resource/UserResource.java +++ b/src/org/traccar/api/resource/UserResource.java @@ -52,9 +52,6 @@ public class UserResource extends BaseResource { } Context.getDataManager().addUser(entity); Context.getPermissionsManager().refresh(); - if (Context.getGeofenceManager() != null) { - Context.getGeofenceManager().refresh(); - } if (Context.getNotificationManager() != null) { Context.getNotificationManager().refresh(); } @@ -71,9 +68,6 @@ public class UserResource extends BaseResource { } Context.getDataManager().updateUser(entity); Context.getPermissionsManager().refresh(); - if (Context.getGeofenceManager() != null) { - Context.getGeofenceManager().refresh(); - } if (Context.getNotificationManager() != null) { Context.getNotificationManager().refresh(); } @@ -87,7 +81,7 @@ public class UserResource extends BaseResource { Context.getDataManager().removeUser(id); Context.getPermissionsManager().refresh(); if (Context.getGeofenceManager() != null) { - Context.getGeofenceManager().refresh(); + Context.getGeofenceManager().refreshUserGeofences(); } if (Context.getNotificationManager() != null) { Context.getNotificationManager().refresh(); -- cgit v1.2.3 From 6dfd599ef69fac9ea0851e3c07873c6368231610 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 14 Jul 2016 16:42:27 +1200 Subject: Support new eelink protocol messages --- .../traccar/protocol/EelinkProtocolDecoder.java | 129 ++++++++++++++++----- .../protocol/EelinkProtocolDecoderTest.java | 9 ++ 2 files changed, 108 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 09cf1808f..e9de73dd5 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ 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.helper.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -41,6 +42,16 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_INTERACTIVE = 0x80; public static final int MSG_DATA = 0x81; + public static final int MSG_NORMAL = 0x12; + public static final int MSG_WARNING = 0x14; + public static final int MSG_REPORT = 0x15; + public static final int MSG_COMMAND = 0x16; + public static final int MSG_OBD_DATA = 0x17; + public static final int MSG_OBD_BODY = 0x18; + public static final int MSG_OBD_CODE = 0x19; + public static final int MSG_CAMERA_INFO = 0x1E; + public static final int MSG_CAMERA_DATA = 0x1F; + private void sendResponse(Channel channel, int type, int index) { if (channel != null) { ChannelBuffer response = ChannelBuffers.buffer(7); @@ -52,57 +63,115 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } } - @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + private Position decodeOld(ChannelBuffer buf, int type, int index) { - ChannelBuffer buf = (ChannelBuffer) msg; + Position position = new Position(); + position.setDeviceId(getDeviceId()); + position.setProtocol(getProtocolName()); - buf.skipBytes(2); // header - int type = buf.readUnsignedByte(); - buf.readShort(); // length - int index = buf.readUnsignedShort(); + position.set(Position.KEY_INDEX, index); - if (type != MSG_GPS && type != MSG_DATA) { - sendResponse(channel, type, index); + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + position.setLatitude(buf.readInt() / 1800000.0); + position.setLongitude(buf.readInt() / 1800000.0); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + position.setCourse(buf.readUnsignedShort()); + + position.set(Position.KEY_MCC, buf.readUnsignedShort()); + position.set(Position.KEY_MNC, buf.readUnsignedShort()); + position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.set(Position.KEY_CID, buf.readUnsignedMedium()); + + position.setValid((buf.readUnsignedByte() & 0x01) != 0); + + if (type == MSG_ALARM) { + position.set(Position.KEY_ALARM, buf.readUnsignedByte()); } - if (type == MSG_LOGIN) { + if (type == MSG_STATE) { + position.set(Position.KEY_STATUS, buf.readUnsignedByte()); + } - identify(ChannelBuffers.hexDump(buf.readBytes(8)).substring(1), channel, remoteAddress); + return position; + } + + private Position decodeNew(ChannelBuffer buf, int type, int index) { + + Position position = new Position(); + position.setDeviceId(getDeviceId()); + position.setProtocol(getProtocolName()); - } else if (hasDeviceId() - && (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS)) { + position.set(Position.KEY_INDEX, index); - Position position = new Position(); - position.setDeviceId(getDeviceId()); + position.setTime(new Date(buf.readUnsignedInt() * 1000)); - position.setProtocol(getProtocolName()); - position.set(Position.KEY_INDEX, index); + int flags = buf.readUnsignedByte(); - position.setTime(new Date(buf.readUnsignedInt() * 1000)); + if (BitUtil.check(flags, 0)) { position.setLatitude(buf.readInt() / 1800000.0); position.setLongitude(buf.readInt() / 1800000.0); - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + position.setAltitude(buf.readShort()); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); position.setCourse(buf.readUnsignedShort()); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + } + if (BitUtil.check(flags, 1)) { position.set(Position.KEY_MCC, buf.readUnsignedShort()); position.set(Position.KEY_MNC, buf.readUnsignedShort()); position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedMedium()); + position.set(Position.KEY_CID, buf.readUnsignedInt()); + position.set(Position.KEY_GSM, buf.readUnsignedByte()); + } - position.setValid((buf.readUnsignedByte() & 0x01) != 0); + if (BitUtil.check(flags, 2)) { + buf.skipBytes(7); // bsid1 + } - if (type == MSG_ALARM) { - position.set(Position.KEY_ALARM, buf.readUnsignedByte()); - } + if (BitUtil.check(flags, 3)) { + buf.skipBytes(7); // bsid2 + } - if (type == MSG_STATE) { - position.set(Position.KEY_STATUS, buf.readUnsignedByte()); - } + if (BitUtil.check(flags, 4)) { + buf.skipBytes(7); // bss0 + } + + if (BitUtil.check(flags, 5)) { + buf.skipBytes(7); // bss1 + } + + if (BitUtil.check(flags, 6)) { + buf.skipBytes(7); // bss2 + } + + return position; + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; - return position; + buf.skipBytes(2); // header + int type = buf.readUnsignedByte(); + buf.readShort(); // length + int index = buf.readUnsignedShort(); + if (type != MSG_GPS && type != MSG_DATA) { + sendResponse(channel, type, index); + } + + if (type == MSG_LOGIN) { + + identify(ChannelBuffers.hexDump(buf.readBytes(8)).substring(1), channel, remoteAddress); + + } else if (hasDeviceId()) { + if (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS) { + return decodeOld(buf, type, index); + } else if (type >= MSG_NORMAL && type <= MSG_OBD_CODE) { + return decodeNew(buf, type, index); + } } return null; diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index d7a6c5e86..925e90dd6 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -10,6 +10,15 @@ public class EelinkProtocolDecoderTest extends ProtocolTest { EelinkProtocolDecoder decoder = new EelinkProtocolDecoder(new EelinkProtocol()); + verifyNothing(decoder, binary( + "676701000c007b03525440717505180104")); + + verifyPosition(decoder, binary( + "676712003400505784cc0b130246479b07d05a06001800000000070195039f046100002cc52e6466b391604a4900890e7c00000000000006ca")); + + verifyPosition(decoder, binary( + "676714002b00515784cc24130246479b07d05a06001800010000060195039f046100002cc52f6466b391604a49020089")); + verifyNothing(decoder, binary( "676701000c002603541880486128290120")); -- cgit v1.2.3