From 1948e0f63202dddca607dcb51fa9a92a83e49154 Mon Sep 17 00:00:00 2001 From: jon-stumpf Date: Fri, 10 Oct 2014 19:23:21 -0400 Subject: Eliminated the need for hardcoded protocol strings in the src/org/traccar/protocol/*ProtocolDecoder.java files. --- .../traccar/protocol/GlobalSatProtocolDecoder.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/GlobalSatProtocolDecoder.java') diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index 5b4dc5e9b..bd56fde1f 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -36,6 +36,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { public GlobalSatProtocolDecoder(ServerManager serverManager) { super(serverManager); + // This is now only called by test classes. + // This will be deleted in the next commit. + assert (serverManager == null); + // Initialize format strings format0 = "TSPRXAB27GHKLMnaicz*U!"; format1 = "SARY*U!"; @@ -49,6 +53,23 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { } } } + + public GlobalSatProtocolDecoder(ServerManager serverManager, String protocol) { + super(serverManager, protocol); + + // Initialize format strings + format0 = "TSPRXAB27GHKLMnaicz*U!"; + format1 = "SARY*U!"; + if (getServerManager() != null) { + Properties p = getServerManager().getProperties(); + if (p.containsKey(protocol + ".format0")) { + format0 = p.getProperty(protocol + ".format0"); + } + if (p.containsKey(protocol + ".format1")) { + format1 = p.getProperty(protocol + ".format1"); + } + } + } private Position decodeOriginal(Channel channel, String sentence) { @@ -83,7 +104,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { // Parse data Position position = new Position(); - ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("globalsat"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol()); for (int formatIndex = 0, valueIndex = 1; formatIndex < format.length() && valueIndex < values.length; formatIndex++) { String value = values[valueIndex]; @@ -204,7 +225,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("globalsat"); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol()); Integer index = 1; // Identification -- cgit v1.2.3