aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-03-15 15:39:12 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-03-15 15:39:12 -0700
commitf98c3aa5b65e9fa06bcea38d96959b43f6a38245 (patch)
tree4931ddab528c6d6cc42e2cff5f820e15ddb4690f /src/main/java
parentc43208bf5339244cd9a47348ec9daa1805099718 (diff)
downloadtrackermap-server-f98c3aa5b65e9fa06bcea38d96959b43f6a38245.tar.gz
trackermap-server-f98c3aa5b65e9fa06bcea38d96959b43f6a38245.tar.bz2
trackermap-server-f98c3aa5b65e9fa06bcea38d96959b43f6a38245.zip
Simplify data commands
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/BaseProtocol.java15
-rw-r--r--src/main/java/org/traccar/Protocol.java4
-rw-r--r--src/main/java/org/traccar/database/ActiveDevice.java8
3 files changed, 14 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/BaseProtocol.java b/src/main/java/org/traccar/BaseProtocol.java
index 6d459f7d4..bd3391822 100644
--- a/src/main/java/org/traccar/BaseProtocol.java
+++ b/src/main/java/org/traccar/BaseProtocol.java
@@ -15,12 +15,14 @@
*/
package org.traccar;
+import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import io.netty.handler.codec.string.StringEncoder;
-import org.traccar.database.ActiveDevice;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
+import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -83,15 +85,16 @@ public abstract class BaseProtocol implements Protocol {
}
@Override
- public void sendDataCommand(ActiveDevice activeDevice, Command command) {
+ public void sendDataCommand(Channel channel, SocketAddress remoteAddress, Command command) {
if (supportedDataCommands.contains(command.getType())) {
- activeDevice.write(command);
+ channel.writeAndFlush(new NetworkMessage(command, remoteAddress));
} else if (command.getType().equals(Command.TYPE_CUSTOM)) {
String data = command.getString(Command.KEY_DATA);
- if (BasePipelineFactory.getHandler(activeDevice.getChannel().pipeline(), StringEncoder.class) != null) {
- activeDevice.write(data);
+ if (BasePipelineFactory.getHandler(channel.pipeline(), StringEncoder.class) != null) {
+ channel.writeAndFlush(new NetworkMessage(data, remoteAddress));
} else {
- activeDevice.write(Unpooled.wrappedBuffer(DataConverter.parseHex(data)));
+ ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(data));
+ channel.writeAndFlush(new NetworkMessage(buf, remoteAddress));
}
} else {
throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName());
diff --git a/src/main/java/org/traccar/Protocol.java b/src/main/java/org/traccar/Protocol.java
index 3b66f2598..9d257be78 100644
--- a/src/main/java/org/traccar/Protocol.java
+++ b/src/main/java/org/traccar/Protocol.java
@@ -15,9 +15,11 @@
*/
package org.traccar;
+import io.netty.channel.Channel;
import org.traccar.database.ActiveDevice;
import org.traccar.model.Command;
+import java.net.SocketAddress;
import java.util.Collection;
public interface Protocol {
@@ -28,7 +30,7 @@ public interface Protocol {
Collection<String> getSupportedDataCommands();
- void sendDataCommand(ActiveDevice activeDevice, Command command);
+ void sendDataCommand(Channel channel, SocketAddress remoteAddress, Command command);
Collection<String> getSupportedTextCommands();
diff --git a/src/main/java/org/traccar/database/ActiveDevice.java b/src/main/java/org/traccar/database/ActiveDevice.java
index 207fc454b..698cc851e 100644
--- a/src/main/java/org/traccar/database/ActiveDevice.java
+++ b/src/main/java/org/traccar/database/ActiveDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,11 +45,7 @@ public class ActiveDevice {
}
public void sendCommand(Command command) {
- protocol.sendDataCommand(this, command);
- }
-
- public void write(Object message) {
- channel.writeAndFlush(new NetworkMessage(message, remoteAddress));
+ protocol.sendDataCommand(channel, remoteAddress, command);
}
}