diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-03-05 20:05:55 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-05 20:05:55 +1300 |
commit | 8163115306af5f82a3c7664daf03e375da3f6a3d (patch) | |
tree | 3d52b57791001ca91737c2ab20284cef7b1a0792 /src/org/traccar/BaseProtocol.java | |
parent | 644d9c440eb193dabeb14ad81c838dbb824bb950 (diff) | |
parent | 075307c35605cb6ad9ebbdf547fee8e649507098 (diff) | |
download | trackermap-server-8163115306af5f82a3c7664daf03e375da3f6a3d.tar.gz trackermap-server-8163115306af5f82a3c7664daf03e375da3f6a3d.tar.bz2 trackermap-server-8163115306af5f82a3c7664daf03e375da3f6a3d.zip |
Merge pull request #2971 from Abyss777/sms_commands
Implement SMS commands
Diffstat (limited to 'src/org/traccar/BaseProtocol.java')
-rw-r--r-- | src/org/traccar/BaseProtocol.java | 36 |
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"); + } + } + } |