From 11aec11f7a4d65f08fb32dd7604c4cbf8ee2e0de Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 9 Oct 2020 11:44:24 -0700 Subject: Support per device attributes --- .../traccar/protocol/StarLinkProtocolDecoder.java | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java index 155f26c5b..7ba41ad56 100644 --- a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java @@ -49,8 +49,8 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { .number("xx") // checksum .compile(); - private String[] dataTags; - private DateFormat dateFormat; + private String format; + private String dateFormat; public StarLinkProtocolDecoder(Protocol protocol) { super(protocol); @@ -62,13 +62,24 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { setDateFormat(Context.getConfig().getString(getProtocolName() + ".dateFormat", "yyMMddHHmmss")); } + public String[] getFormat(long deviceId) { + return Context.getIdentityManager().lookupAttributeString( + deviceId, getProtocolName() + ".format", format, false, false).split(","); + } + public void setFormat(String format) { - dataTags = format.split(","); + this.format = format; + } + + public DateFormat getDateFormat(long deviceId) { + DateFormat dateFormat = new SimpleDateFormat(Context.getIdentityManager().lookupAttributeString( + deviceId, getProtocolName() + ".dateFormat", this.dateFormat, false, false)); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + return dateFormat; } public void setDateFormat(String dateFormat) { - this.dateFormat = new SimpleDateFormat(dateFormat); - this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + this.dateFormat = dateFormat; } private double parseCoordinate(String value) { @@ -130,6 +141,9 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { Integer lac = null, cid = null; int event = 0; + String[] dataTags = getFormat(deviceSession.getDeviceId()); + DateFormat dateFormat = getDateFormat(deviceSession.getDeviceId()); + for (int i = 0; i < Math.min(data.length, dataTags.length); i++) { if (data[i].isEmpty()) { continue; -- cgit v1.2.3