From d7725b0fb8ecde4d883a07d8bc4e77974c56eada Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 19 Aug 2017 12:55:25 +1200 Subject: Add Suntech temperature support --- .../traccar/protocol/SuntechProtocolDecoder.java | 50 +++++++++++++++++++++- .../protocol/SuntechProtocolDecoderTest.java | 23 ++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 42e81f60c..93c53d2cf 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -32,18 +32,34 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { private int protocolType; private boolean hbm; + private boolean includeAdc; + private boolean includeTemp; public SuntechProtocolDecoder(SuntechProtocol protocol) { super(protocol); protocolType = Context.getConfig().getInteger(getProtocolName() + ".protocolType"); hbm = Context.getConfig().getBoolean(getProtocolName() + ".hbm"); + includeAdc = Context.getConfig().getBoolean(getProtocolName() + ".includeAdc"); + includeTemp = Context.getConfig().getBoolean(getProtocolName() + ".includeTemp"); } public void setProtocolType(int protocolType) { this.protocolType = protocolType; } + public void setHbm(boolean hbm) { + this.hbm = hbm; + } + + public void setIncludeAdc(boolean includeAdc) { + this.includeAdc = includeAdc; + } + + public void setIncludeTemp(boolean includeTemp) { + this.includeTemp = includeTemp; + } + private Position decode9( Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { int index = 1; @@ -87,7 +103,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setValid(values[index++].equals("1")); if (protocolType == 1) { - position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index])); + position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++])); } return position; @@ -155,7 +171,37 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { } if (index < values.length) { - position.set(Position.KEY_BATTERY, Double.parseDouble(values[index])); + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + } + + if (index < values.length) { + if (values[index++].equals("0")) { + position.set(Position.KEY_ARCHIVE, true); + } + } + + if (includeAdc) { + position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++])); + position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++])); + position.set(Position.PREFIX_ADC + 3, Double.parseDouble(values[index++])); + } + + if (values.length - index >= 2) { + String driverUniqueId = values[index++]; + if (values[index++].equals("1") && !driverUniqueId.isEmpty()) { + position.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId); + } + } + + if (includeTemp) { + for (int i = 1; i <= 3; i++) { + String temperature = values[index++]; + String value = temperature.substring(temperature.indexOf(':') + 1); + if (!value.isEmpty()) { + position.set(Position.PREFIX_TEMP + i, Double.parseDouble(value)); + } + } + } } diff --git a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java index a9b13b3e6..bb0710340 100644 --- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java @@ -5,11 +5,34 @@ import org.traccar.ProtocolTest; public class SuntechProtocolDecoderTest extends ProtocolTest { + @Test + public void testDecodeTemperature() throws Exception { + + SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(new SuntechProtocol()); + + decoder.setHbm(true); + decoder.setIncludeAdc(true); + decoder.setIncludeTemp(true); + + /*verifyPosition(decoder, text( + "ST300STT;205170303;12;561;20170816;09:10:34;173f53;+19.082370;-098.214287;006.776;000.00;0;0;52982186;12.75;100000;2;6328;155747;4.2;1;0.00;0;0.00;0.00;00000000000000;0;28F2B7600600005D:+5.2;:;:"));*/ + + verifyPosition(decoder, text( + "ST300STT;205173382;07;564;20160322;23:23:18;232e19;+19.288278;-099.128750;000.122;000.00;9;1;478391;11.53;000100;1;9498;079324;4.3;1;0.00;0.00;0.00;00000000000000;0;2898E16006000058:-20.8;2861626006000039:+2.5;:")); + + verifyPosition(decoder, text( + "ST300EVT;205173382;07;564;20160322;23:23:18;232e19;+19.288278;-099.128750;000.122;000.00;9;1;478391;11.53;000100;2;1;9498;079324;4.3;1;0.00;0.00;0.00;00000000000000;0;2898E16006000058:-20.8;2861626006000039:+2.5;:")); + + } + @Test public void testDecode() throws Exception { SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(new SuntechProtocol()); + verifyPosition(decoder, text( + "ST300STT;205170303;12;561;20170816;09:10:34;173f53;+19.082370;-098.214287;006.776;000.00;0;0;52982186;12.75;100000;2;6328;155747;4.2;1;0.00;0;0.00;0.00;00000000000000;0;28F2B7600600005D:+5.2;:;:")); + verifyPosition(decoder, text( "ST910;Location;205576803;500;20170319;12:18:17;-22.846014;-046.322176;000.000;000.00;0;3.8;0;1;9159")); -- cgit v1.2.3