aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocol.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/BaseProtocol.java')
-rw-r--r--src/org/traccar/BaseProtocol.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index 59331d7cc..bccc4e184 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2017 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.
@@ -30,6 +30,9 @@ public abstract class BaseProtocol implements Protocol {
private final String name;
private final Set<String> supportedCommands = new HashSet<>();
+ private final Set<String> supportedSmsCommands = new HashSet<>();
+
+ private StringProtocolEncoder smsEncoder = null;
public BaseProtocol(String name) {
this.name = name;
@@ -44,6 +47,10 @@ public abstract class BaseProtocol implements Protocol {
supportedCommands.addAll(Arrays.asList(commands));
}
+ public void setSupportedSmsCommands(String... commands) {
+ supportedSmsCommands.addAll(Arrays.asList(commands));
+ }
+
@Override
public Collection<String> getSupportedCommands() {
Set<String> commands = new HashSet<>(supportedCommands);
@@ -52,6 +59,13 @@ public abstract class BaseProtocol implements Protocol {
}
@Override
+ public Collection<String> getSupportedSmsCommands() {
+ Set<String> commands = new HashSet<>(supportedSmsCommands);
+ commands.add(Command.TYPE_CUSTOM);
+ return commands;
+ }
+
+ @Override
public void sendCommand(ActiveDevice activeDevice, Command command) {
if (supportedCommands.contains(command.getType())) {
activeDevice.write(command);
@@ -67,4 +81,24 @@ public abstract class BaseProtocol implements Protocol {
}
}
+ public void setSmsEncoder(StringProtocolEncoder smsEncoder) {
+ this.smsEncoder = smsEncoder;
+ }
+
+ @Override
+ public void sendSmsCommand(String phone, Command command) throws Exception {
+ if (Context.getSmppManager() != null) {
+ if (command.getType().equals(Command.TYPE_CUSTOM)) {
+ Context.getSmppManager().sendMessageSync(phone, command.getString(Command.KEY_DATA), true);
+ } else if (supportedSmsCommands.contains(command.getType()) && smsEncoder != null) {
+ Context.getSmppManager().sendMessageSync(phone, (String) smsEncoder.encodeCommand(command), true);
+ } else {
+ throw new RuntimeException(
+ "Command " + command.getType() + " is not supported in protocol " + getName());
+ }
+ } else {
+ throw new RuntimeException("SMPP client is not enabled");
+ }
+ }
+
}