aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/BaseProtocol.java
diff options
context:
space:
mode:
authorYuriy Piskarev <yuriy.piskarev@gmail.com>2023-08-24 14:16:17 +0300
committerGitHub <noreply@github.com>2023-08-24 14:16:17 +0300
commitae406c7b49a72de24d81fd74386d9638342c90ee (patch)
tree6fbcf557375b98e926c78af9c757e62c79d72a1b /src/main/java/org/traccar/BaseProtocol.java
parent56ff656c908b19feb2fa3dcffa48cc3bcdfe9b3b (diff)
parent9aeedc90da24848ff97227d6f281eb4d1e1506ef (diff)
downloadtrackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.gz
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.bz2
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.zip
Merge branch 'traccar:master' into master
Diffstat (limited to 'src/main/java/org/traccar/BaseProtocol.java')
-rw-r--r--src/main/java/org/traccar/BaseProtocol.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/BaseProtocol.java b/src/main/java/org/traccar/BaseProtocol.java
index 52d34dc44..ea302997c 100644
--- a/src/main/java/org/traccar/BaseProtocol.java
+++ b/src/main/java/org/traccar/BaseProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 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.
@@ -21,7 +21,10 @@ import io.netty.channel.Channel;
import io.netty.handler.codec.string.StringEncoder;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
+import org.traccar.sms.SmsManager;
+import jakarta.annotation.Nullable;
+import jakarta.inject.Inject;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
@@ -37,6 +40,8 @@ public abstract class BaseProtocol implements Protocol {
private final Set<String> supportedTextCommands = new HashSet<>();
private final List<TrackerConnector> connectorList = new LinkedList<>();
+ private SmsManager smsManager;
+
private StringProtocolEncoder textCommandEncoder = null;
public static String nameFromClass(Class<?> clazz) {
@@ -48,6 +53,11 @@ public abstract class BaseProtocol implements Protocol {
name = nameFromClass(getClass());
}
+ @Inject
+ public void setSmsManager(@Nullable SmsManager smsManager) {
+ this.smsManager = smsManager;
+ }
+
@Override
public String getName() {
return name;
@@ -95,7 +105,8 @@ public abstract class BaseProtocol implements Protocol {
} else if (command.getType().equals(Command.TYPE_CUSTOM)) {
String data = command.getString(Command.KEY_DATA);
if (BasePipelineFactory.getHandler(channel.pipeline(), StringEncoder.class) != null) {
- channel.writeAndFlush(new NetworkMessage(data, remoteAddress));
+ channel.writeAndFlush(new NetworkMessage(
+ data.replace("\\r", "\r").replace("\\n", "\n"), remoteAddress));
} else {
ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(data));
channel.writeAndFlush(new NetworkMessage(buf, remoteAddress));
@@ -111,13 +122,13 @@ public abstract class BaseProtocol implements Protocol {
@Override
public void sendTextCommand(String destAddress, Command command) throws Exception {
- if (Context.getSmsManager() != null) {
+ if (smsManager != null) {
if (command.getType().equals(Command.TYPE_CUSTOM)) {
- Context.getSmsManager().sendMessageSync(destAddress, command.getString(Command.KEY_DATA), true);
+ smsManager.sendMessage(destAddress, command.getString(Command.KEY_DATA), true);
} else if (supportedTextCommands.contains(command.getType()) && textCommandEncoder != null) {
String encodedCommand = (String) textCommandEncoder.encodeCommand(command);
if (encodedCommand != null) {
- Context.getSmsManager().sendMessageSync(destAddress, encodedCommand, true);
+ smsManager.sendMessage(destAddress, encodedCommand, true);
} else {
throw new RuntimeException("Failed to encode command");
}