aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/BaseProtocol.java
diff options
context:
space:
mode:
authorjcardus <joaquim.cardeira@gmail.com>2020-03-25 17:25:19 +0000
committerjcardus <joaquim.cardeira@gmail.com>2020-03-25 17:25:19 +0000
commitfeac85bad4004fb3e316a88285626e12840398d2 (patch)
treed268a79d63b9d1f27b6e433fedc90de7b427b172 /src/main/java/org/traccar/BaseProtocol.java
parent7b669e3181f637f06b31b55bd930584c7b08e897 (diff)
parentf3d465abe7f255ec44e976caade642e4c2fd7598 (diff)
downloadtrackermap-server-feac85bad4004fb3e316a88285626e12840398d2.tar.gz
trackermap-server-feac85bad4004fb3e316a88285626e12840398d2.tar.bz2
trackermap-server-feac85bad4004fb3e316a88285626e12840398d2.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/main/java/org/traccar/BaseProtocol.java')
-rw-r--r--src/main/java/org/traccar/BaseProtocol.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/BaseProtocol.java b/src/main/java/org/traccar/BaseProtocol.java
index c0fd1e27f..bd3391822 100644
--- a/src/main/java/org/traccar/BaseProtocol.java
+++ b/src/main/java/org/traccar/BaseProtocol.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.
@@ -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;
@@ -68,11 +70,6 @@ public abstract class BaseProtocol implements Protocol {
supportedTextCommands.addAll(Arrays.asList(commands));
}
- public void setSupportedCommands(String... commands) {
- supportedDataCommands.addAll(Arrays.asList(commands));
- supportedTextCommands.addAll(Arrays.asList(commands));
- }
-
@Override
public Collection<String> getSupportedDataCommands() {
Set<String> commands = new HashSet<>(supportedDataCommands);
@@ -88,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());