From 867404e9d7ffc6019d8d87dedc892aef1e70aec8 Mon Sep 17 00:00:00 2001 From: seym45 Date: Thu, 10 Aug 2023 01:26:28 +0400 Subject: Add gator commands to manage engine --- src/main/java/org/traccar/protocol/GatorProtocolDecoder.java | 4 +++- src/main/java/org/traccar/protocol/GatorProtocolEncoder.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index f7da5dc75..a5ecb2169 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.helper.BcdUtil; @@ -27,6 +26,7 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; +import org.traccar.session.DeviceSession; import java.net.SocketAddress; @@ -38,6 +38,8 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_HEARTBEAT = 0x21; public static final int MSG_POSITION_REQUEST = 0x30; + public static final int MSG_RESTORES_THE_OIL_DUCT = 0x38; + public static final int MSG_CLOSE_THE_OIL_DUCT = 0x39; public static final int MSG_POSITION_DATA = 0x80; public static final int MSG_ROLLCALL_RESPONSE = 0x81; public static final int MSG_ALARM_DATA = 0x82; diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 3d38b7455..6d96c6e9a 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -69,6 +69,10 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST); + case Command.TYPE_ENGINE_STOP: + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT); + case Command.TYPE_ENGINE_RESUME: + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT); default: return null; } -- cgit v1.2.3 From 4157920142182c080dc6a4f21f19417d068fedc5 Mon Sep 17 00:00:00 2001 From: seym45 Date: Thu, 10 Aug 2023 01:46:02 +0400 Subject: Set support for engine management --- src/main/java/org/traccar/protocol/GatorProtocol.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocol.java b/src/main/java/org/traccar/protocol/GatorProtocol.java index 46862f583..096095463 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocol.java +++ b/src/main/java/org/traccar/protocol/GatorProtocol.java @@ -29,6 +29,8 @@ public class GatorProtocol extends BaseProtocol { @Inject public GatorProtocol(Config config) { setSupportedDataCommands(Command.TYPE_POSITION_SINGLE); + setSupportedDataCommands(Command.TYPE_ENGINE_RESUME); + setSupportedDataCommands(Command.TYPE_ENGINE_STOP); addServer(new TrackerServer(config, getName(), false) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) { -- cgit v1.2.3 From 860b8ba8b370f710dd5530253d8748bf6185f1fa Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 22 Aug 2023 00:27:36 +0400 Subject: Add periodic position fetching command for Gator protocol --- src/main/java/org/traccar/model/Command.java | 7 +++++-- .../java/org/traccar/protocol/GatorProtocol.java | 1 + .../org/traccar/protocol/GatorProtocolDecoder.java | 1 + .../org/traccar/protocol/GatorProtocolEncoder.java | 23 +++++++++++++++++----- 4 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/model/Command.java b/src/main/java/org/traccar/model/Command.java index 99988dd82..5b81fcfef 100644 --- a/src/main/java/org/traccar/model/Command.java +++ b/src/main/java/org/traccar/model/Command.java @@ -15,9 +15,8 @@ */ package org.traccar.model; -import org.traccar.storage.QueryIgnore; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.traccar.storage.QueryIgnore; import org.traccar.storage.StorageName; @StorageName("tc_commands") @@ -72,6 +71,10 @@ public class Command extends BaseCommand { public static final String KEY_UNIQUE_ID = "uniqueId"; public static final String KEY_FREQUENCY = "frequency"; + + public static final String KEY_ENGINE_OFF_INTERVAL = "engine_off_interval"; + public static final String KEY_ENGINE_ON_INTERVAL = "engine_on_interval"; + public static final String KEY_HEARTBEAT_INTERVAL = "heartbeat_interval"; public static final String KEY_LANGUAGE = "language"; public static final String KEY_TIMEZONE = "timezone"; public static final String KEY_DEVICE_PASSWORD = "devicePassword"; diff --git a/src/main/java/org/traccar/protocol/GatorProtocol.java b/src/main/java/org/traccar/protocol/GatorProtocol.java index 096095463..bdea0fb00 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocol.java +++ b/src/main/java/org/traccar/protocol/GatorProtocol.java @@ -31,6 +31,7 @@ public class GatorProtocol extends BaseProtocol { setSupportedDataCommands(Command.TYPE_POSITION_SINGLE); setSupportedDataCommands(Command.TYPE_ENGINE_RESUME); setSupportedDataCommands(Command.TYPE_ENGINE_STOP); + setSupportedDataCommands(Command.TYPE_POSITION_PERIODIC); addServer(new TrackerServer(config, getName(), false) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) { diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index a5ecb2169..bcd1a64b7 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -38,6 +38,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_HEARTBEAT = 0x21; public static final int MSG_POSITION_REQUEST = 0x30; + public static final int MSG_POSITION_PERIODIC = 0x30; public static final int MSG_RESTORES_THE_OIL_DUCT = 0x38; public static final int MSG_CLOSE_THE_OIL_DUCT = 0x39; public static final int MSG_POSITION_DATA = 0x80; diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 6d96c6e9a..5452d83c7 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -43,18 +43,24 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { return buf; } - private ByteBuf encodeContent(long deviceId, int type) { + private ByteBuf encodeContent(long deviceId, int type, ByteBuf content) { ByteBuf buf = Unpooled.buffer(); buf.writeByte(0x24); buf.writeByte(0x24); buf.writeByte(type); buf.writeByte(0x00); - buf.writeByte(4 + 1 + 1); // ip 4 bytes, checksum and end byte + + // ip 4 bytes, content length, checksum and end byte + buf.writeByte(4 + 1 + (content != null ? content.readableBytes() : 0) + 1); ByteBuf pseudoIPAddress = encodeId(deviceId); buf.writeBytes(pseudoIPAddress); + if (content != null) { + buf.writeBytes(content); + } + int checksum = Checksum.xor(buf.nioBuffer()); buf.writeByte(checksum); @@ -66,13 +72,20 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { + ByteBuf content = Unpooled.buffer(); + switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, content); case Command.TYPE_ENGINE_STOP: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT, content); case Command.TYPE_ENGINE_RESUME: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT, content); + case Command.TYPE_POSITION_PERIODIC: + content.writeShort(command.getInteger(Command.KEY_ENGINE_ON_INTERVAL)); + content.writeShort(command.getInteger(Command.KEY_ENGINE_OFF_INTERVAL)); + content.writeByte(command.getInteger(Command.KEY_HEARTBEAT_INTERVAL)); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content); default: return null; } -- cgit v1.2.3 From 09d4fb4a10a5362191023f5c82327d8d38ae830f Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 22 Aug 2023 01:29:10 +0400 Subject: Fix position periodic command code --- src/main/java/org/traccar/protocol/GatorProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index bcd1a64b7..c68546c00 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -38,7 +38,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_HEARTBEAT = 0x21; public static final int MSG_POSITION_REQUEST = 0x30; - public static final int MSG_POSITION_PERIODIC = 0x30; + public static final int MSG_POSITION_PERIODIC = 0x34; public static final int MSG_RESTORES_THE_OIL_DUCT = 0x38; public static final int MSG_CLOSE_THE_OIL_DUCT = 0x39; public static final int MSG_POSITION_DATA = 0x80; -- cgit v1.2.3 From 75064707c6432cc4918eab573ac3ce9d6eee1d94 Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 22 Aug 2023 02:11:40 +0400 Subject: Add command to set speed limit and odometer for Gator - Add test to verify position retrieval interval settings - Update key name MSG_POSITION_PERIODIC to MSG_SET_POSITION_REQUEST_INTERVAL --- src/main/java/org/traccar/protocol/GatorProtocol.java | 2 ++ .../java/org/traccar/protocol/GatorProtocolDecoder.java | 4 +++- .../java/org/traccar/protocol/GatorProtocolEncoder.java | 8 +++++++- .../org/traccar/protocol/GatorProtocolEncoderTest.java | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocol.java b/src/main/java/org/traccar/protocol/GatorProtocol.java index bdea0fb00..0f44fbf47 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocol.java +++ b/src/main/java/org/traccar/protocol/GatorProtocol.java @@ -32,6 +32,8 @@ public class GatorProtocol extends BaseProtocol { setSupportedDataCommands(Command.TYPE_ENGINE_RESUME); setSupportedDataCommands(Command.TYPE_ENGINE_STOP); setSupportedDataCommands(Command.TYPE_POSITION_PERIODIC); + setSupportedDataCommands(Command.TYPE_SET_SPEED_LIMIT); + setSupportedDataCommands(Command.TYPE_SET_ODOMETER); addServer(new TrackerServer(config, getName(), false) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) { diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index c68546c00..90fd5d0c6 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -38,7 +38,9 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_HEARTBEAT = 0x21; public static final int MSG_POSITION_REQUEST = 0x30; - public static final int MSG_POSITION_PERIODIC = 0x34; + public static final int MSG_SET_POSITION_REQUEST_INTERVAL = 0x34; + public static final int MSG_SET_SPEED_LIMIT = 0x3F; + public static final int MSG_SET_ODOMETER = 0x6B; public static final int MSG_RESTORES_THE_OIL_DUCT = 0x38; public static final int MSG_CLOSE_THE_OIL_DUCT = 0x39; public static final int MSG_POSITION_DATA = 0x80; diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 5452d83c7..570dd269a 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -81,11 +81,17 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT, content); case Command.TYPE_ENGINE_RESUME: return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT, content); + case Command.TYPE_SET_SPEED_LIMIT: + content.writeByte(command.getInteger(Command.KEY_DATA)); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_SPEED_LIMIT, content); + case Command.TYPE_SET_ODOMETER: + content.writeShort(command.getInteger(Command.KEY_DATA)); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_ODOMETER, content); case Command.TYPE_POSITION_PERIODIC: content.writeShort(command.getInteger(Command.KEY_ENGINE_ON_INTERVAL)); content.writeShort(command.getInteger(Command.KEY_ENGINE_OFF_INTERVAL)); content.writeByte(command.getInteger(Command.KEY_HEARTBEAT_INTERVAL)); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_POSITION_REQUEST_INTERVAL, content); default: return null; } diff --git a/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java index af6c71e37..7938ab630 100644 --- a/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java +++ b/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java @@ -20,4 +20,19 @@ public class GatorProtocolEncoderTest extends ProtocolTest { command.setType(Command.TYPE_POSITION_SINGLE); verifyCommand(encoder, command, binary("24243000062008958C070D")); } + + @Test + public void testEncodePeriodicPositionRetrievalIntervalSet() throws Exception { + var encoder = inject(new GatorProtocolEncoder(null)); + var device = encoder.getCacheManager().getObject(Device.class, 1); + when(device.getUniqueId()).thenReturn("13088005658"); + + Command command = new Command(); + command.setDeviceId(1); + command.set("heartbeat_interval", 120); + command.set("engine_off_interval", 5); + command.set("engine_on_interval", 5); + command.setType(Command.TYPE_POSITION_PERIODIC); + verifyCommand(encoder, command, binary("242434000b5800383a00050005781d0d")); + } } -- cgit v1.2.3 From 0b1b54428a6f3cc66dd1aed57de05545e4e7d30a Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 22 Aug 2023 02:30:27 +0400 Subject: Reset MSG_SET_POSITION_REQUEST_INTERVAL to MSG_POSITION_PERIODIC - As the Line is longer than 120 characters, changed the variable name to fix the issue --- src/main/java/org/traccar/protocol/GatorProtocolDecoder.java | 2 +- src/main/java/org/traccar/protocol/GatorProtocolEncoder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index 90fd5d0c6..0202ed7d0 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -38,7 +38,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_HEARTBEAT = 0x21; public static final int MSG_POSITION_REQUEST = 0x30; - public static final int MSG_SET_POSITION_REQUEST_INTERVAL = 0x34; + public static final int MSG_POSITION_PERIODIC = 0x34; public static final int MSG_SET_SPEED_LIMIT = 0x3F; public static final int MSG_SET_ODOMETER = 0x6B; public static final int MSG_RESTORES_THE_OIL_DUCT = 0x38; diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 570dd269a..d613b30c2 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -91,7 +91,7 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { content.writeShort(command.getInteger(Command.KEY_ENGINE_ON_INTERVAL)); content.writeShort(command.getInteger(Command.KEY_ENGINE_OFF_INTERVAL)); content.writeByte(command.getInteger(Command.KEY_HEARTBEAT_INTERVAL)); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_POSITION_REQUEST_INTERVAL, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content); default: return null; } -- cgit v1.2.3 From 0f38debb59b40ea9eeb89b93cdd4aeced2567f6d Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 29 Aug 2023 15:49:43 +0400 Subject: Use already existing keys to get params --- src/main/java/org/traccar/model/Command.java | 3 --- src/main/java/org/traccar/protocol/GatorProtocolEncoder.java | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/model/Command.java b/src/main/java/org/traccar/model/Command.java index 5b81fcfef..900436a01 100644 --- a/src/main/java/org/traccar/model/Command.java +++ b/src/main/java/org/traccar/model/Command.java @@ -72,9 +72,6 @@ public class Command extends BaseCommand { public static final String KEY_UNIQUE_ID = "uniqueId"; public static final String KEY_FREQUENCY = "frequency"; - public static final String KEY_ENGINE_OFF_INTERVAL = "engine_off_interval"; - public static final String KEY_ENGINE_ON_INTERVAL = "engine_on_interval"; - public static final String KEY_HEARTBEAT_INTERVAL = "heartbeat_interval"; public static final String KEY_LANGUAGE = "language"; public static final String KEY_TIMEZONE = "timezone"; public static final String KEY_DEVICE_PASSWORD = "devicePassword"; diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index d613b30c2..4a3e21d85 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -88,9 +88,10 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { content.writeShort(command.getInteger(Command.KEY_DATA)); return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_ODOMETER, content); case Command.TYPE_POSITION_PERIODIC: - content.writeShort(command.getInteger(Command.KEY_ENGINE_ON_INTERVAL)); - content.writeShort(command.getInteger(Command.KEY_ENGINE_OFF_INTERVAL)); - content.writeByte(command.getInteger(Command.KEY_HEARTBEAT_INTERVAL)); + String[] data = command.getString(Command.KEY_FREQUENCY).split(";"); + content.writeShort(Integer.valueOf(data[0])); + content.writeShort(Integer.valueOf(data[1])); + content.writeShort(Integer.valueOf(data[2])); return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content); default: return null; -- cgit v1.2.3 From ed3950fbdccfbd118ed898066fc74c93e7542ec4 Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 29 Aug 2023 16:13:47 +0400 Subject: Fix content size for encoding --- src/main/java/org/traccar/protocol/GatorProtocolEncoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 4a3e21d85..895c68af5 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -91,7 +91,7 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { String[] data = command.getString(Command.KEY_FREQUENCY).split(";"); content.writeShort(Integer.valueOf(data[0])); content.writeShort(Integer.valueOf(data[1])); - content.writeShort(Integer.valueOf(data[2])); + content.writeByte(Integer.valueOf(data[2])); return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content); default: return null; -- cgit v1.2.3 From 63ea08a14e381261568192a999f51e8c3cc3f574 Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 29 Aug 2023 17:09:18 +0400 Subject: Undo formatting changes in Command.java --- src/main/java/org/traccar/model/Command.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/model/Command.java b/src/main/java/org/traccar/model/Command.java index 900436a01..99988dd82 100644 --- a/src/main/java/org/traccar/model/Command.java +++ b/src/main/java/org/traccar/model/Command.java @@ -15,8 +15,9 @@ */ package org.traccar.model; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.traccar.storage.QueryIgnore; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.traccar.storage.StorageName; @StorageName("tc_commands") @@ -71,7 +72,6 @@ public class Command extends BaseCommand { public static final String KEY_UNIQUE_ID = "uniqueId"; public static final String KEY_FREQUENCY = "frequency"; - public static final String KEY_LANGUAGE = "language"; public static final String KEY_TIMEZONE = "timezone"; public static final String KEY_DEVICE_PASSWORD = "devicePassword"; -- cgit v1.2.3 From f6f210592413157006776ba454d29834e167688c Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 29 Aug 2023 17:29:30 +0400 Subject: - Set supported commands in one call - Remove timing interval command - Rename messages according to codebase standard --- src/main/java/org/traccar/protocol/GatorProtocol.java | 12 ++++++------ .../org/traccar/protocol/GatorProtocolDecoder.java | 9 ++++----- .../org/traccar/protocol/GatorProtocolEncoder.java | 19 ++++++------------- .../traccar/protocol/GatorProtocolEncoderTest.java | 13 ------------- 4 files changed, 16 insertions(+), 37 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocol.java b/src/main/java/org/traccar/protocol/GatorProtocol.java index 0f44fbf47..e6793875b 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocol.java +++ b/src/main/java/org/traccar/protocol/GatorProtocol.java @@ -28,12 +28,12 @@ public class GatorProtocol extends BaseProtocol { @Inject public GatorProtocol(Config config) { - setSupportedDataCommands(Command.TYPE_POSITION_SINGLE); - setSupportedDataCommands(Command.TYPE_ENGINE_RESUME); - setSupportedDataCommands(Command.TYPE_ENGINE_STOP); - setSupportedDataCommands(Command.TYPE_POSITION_PERIODIC); - setSupportedDataCommands(Command.TYPE_SET_SPEED_LIMIT); - setSupportedDataCommands(Command.TYPE_SET_ODOMETER); + setSupportedDataCommands( + Command.TYPE_POSITION_SINGLE, + Command.TYPE_ENGINE_RESUME, + Command.TYPE_ENGINE_STOP, + Command.TYPE_SET_SPEED_LIMIT, + Command.TYPE_SET_ODOMETER); addServer(new TrackerServer(config, getName(), false) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) { diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index 0202ed7d0..53b8909be 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -38,11 +38,10 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_HEARTBEAT = 0x21; public static final int MSG_POSITION_REQUEST = 0x30; - public static final int MSG_POSITION_PERIODIC = 0x34; - public static final int MSG_SET_SPEED_LIMIT = 0x3F; - public static final int MSG_SET_ODOMETER = 0x6B; - public static final int MSG_RESTORES_THE_OIL_DUCT = 0x38; - public static final int MSG_CLOSE_THE_OIL_DUCT = 0x39; + public static final int MSG_OVERSPEED_ALARM = 0x3F; + public static final int MSG_RESET_MILEAGE = 0x6B; + public static final int MSG_RESTORE_OIL_DUCT = 0x38; + public static final int MSG_CLOSE_OIL_DUCT = 0x39; public static final int MSG_POSITION_DATA = 0x80; public static final int MSG_ROLLCALL_RESPONSE = 0x81; public static final int MSG_ALARM_DATA = 0x82; diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 895c68af5..6c6b9a54a 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -51,8 +51,7 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { buf.writeByte(type); buf.writeByte(0x00); - // ip 4 bytes, content length, checksum and end byte - buf.writeByte(4 + 1 + (content != null ? content.readableBytes() : 0) + 1); + buf.writeByte(4 + 1 + (content != null ? content.readableBytes() : 0) + 1); // length ByteBuf pseudoIPAddress = encodeId(deviceId); buf.writeBytes(pseudoIPAddress); @@ -76,23 +75,17 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, null); case Command.TYPE_ENGINE_STOP: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_THE_OIL_DUCT, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_OIL_DUCT, null); case Command.TYPE_ENGINE_RESUME: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORES_THE_OIL_DUCT, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORE_OIL_DUCT, null); case Command.TYPE_SET_SPEED_LIMIT: content.writeByte(command.getInteger(Command.KEY_DATA)); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_SPEED_LIMIT, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESET_MILEAGE, content); case Command.TYPE_SET_ODOMETER: content.writeShort(command.getInteger(Command.KEY_DATA)); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_SET_ODOMETER, content); - case Command.TYPE_POSITION_PERIODIC: - String[] data = command.getString(Command.KEY_FREQUENCY).split(";"); - content.writeShort(Integer.valueOf(data[0])); - content.writeShort(Integer.valueOf(data[1])); - content.writeByte(Integer.valueOf(data[2])); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_PERIODIC, content); + return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_OVERSPEED_ALARM, content); default: return null; } diff --git a/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java index 1559e8294..af6c71e37 100644 --- a/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java +++ b/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java @@ -20,17 +20,4 @@ public class GatorProtocolEncoderTest extends ProtocolTest { command.setType(Command.TYPE_POSITION_SINGLE); verifyCommand(encoder, command, binary("24243000062008958C070D")); } - - @Test - public void testEncodePeriodicPositionRetrievalIntervalSet() throws Exception { - var encoder = inject(new GatorProtocolEncoder(null)); - var device = encoder.getCacheManager().getObject(Device.class, 1); - when(device.getUniqueId()).thenReturn("13088005658"); - - Command command = new Command(); - command.setDeviceId(1); - command.set(command.KEY_FREQUENCY, "5;5;120"); - command.setType(Command.TYPE_POSITION_PERIODIC); - verifyCommand(encoder, command, binary("242434000b5800383a00050005781d0d")); - } } -- cgit v1.2.3 From eaacc24b7461efc6f939efcf7ecc17ae646b13a5 Mon Sep 17 00:00:00 2001 From: seym45 Date: Tue, 29 Aug 2023 17:41:06 +0400 Subject: Undo import order --- src/main/java/org/traccar/protocol/GatorProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java index 53b8909be..a9c620090 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolDecoder.java @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.helper.BcdUtil; @@ -26,7 +27,6 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; -import org.traccar.session.DeviceSession; import java.net.SocketAddress; -- cgit v1.2.3