From 569fb5c36eb4b8b36196114bdeb64030b1516e48 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 31 Aug 2018 15:47:20 +1200 Subject: Implement Suntech ST410 support --- .../traccar/protocol/SuntechProtocolDecoder.java | 63 +++++++++++++++++++++- .../protocol/SuntechProtocolDecoderTest.java | 3 ++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index b076546a6..5166240d0 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -157,6 +157,65 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { return null; } } + private Position decode4( + Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException { + int index = 0; + + String type = values[index++].substring(5); + + if (!type.equals("STT") && !type.equals("ALT")) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_TYPE, type); + + position.set(Position.KEY_VERSION_FW, values[index++]); + index += 1; // model + + Network network = new Network(); + + for (int i = 0; i < 7; i++) { + int cid = Integer.parseInt(values[index++]); + int mcc = Integer.parseInt(values[index++]); + int mnc = Integer.parseInt(values[index++]); + int rssi = Integer.parseInt(values[index++]); + int lac = Integer.parseInt(values[index++]); + index += 1; // timing advance + if (cid > 0) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi)); + } + } + + position.setNetwork(network); + + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++])); + position.set(Position.KEY_ARCHIVE, values[index++].equals("0") ? true : null); + position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); + + index += 1; // mode + + DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss"); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + position.setTime(dateFormat.parse(values[index++] + values[index++])); + + position.setLatitude(Double.parseDouble(values[index++])); + position.setLongitude(Double.parseDouble(values[index++])); + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++]))); + position.setCourse(Double.parseDouble(values[index++])); + + position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++])); + + position.setValid(values[index++].equals("1")); + + return position; + } private Position decode2356( Channel channel, SocketAddress remoteAddress, String protocol, String[] values) throws ParseException { @@ -373,8 +432,10 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { if (values[0].length() < 5) { return decodeUniversal(channel, remoteAddress, values); - } else if (values[0].equals("ST910")) { + } else if (values[0].startsWith("ST9")) { return decode9(channel, remoteAddress, values); + } else if (values[0].startsWith("ST4")) { + return decode4(channel, remoteAddress, values); } else { return decode2356(channel, remoteAddress, values[0].substring(0, 5), values); } diff --git a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java index b369ab41b..3b907e080 100644 --- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java @@ -27,6 +27,9 @@ public class SuntechProtocolDecoderTest extends ProtocolTest { SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(new SuntechProtocol()); + verifyPosition(decoder, text( + "ST410STT;007272376;408;01;21651;732;123;-65;1824;1;21654;732;123;1824;0;0;22542;732;123;1824;0;0;21656;732;123;1824;0;0;21655;732;123;1824;0;0;22541;732;123;1824;0;0;0;0;0;0;0;0;3.7;1;0156;1;20180816;05:18:52;+04.722322;-074.052776;000.074;000.00;10;1")); + verifyPosition(decoder, text( "ST600STT;008084783;20;419;20180308;18:00:36;0032cc3e;736;3;445c;41;-16.530023;-068.084267;018.640;267.99;10;1;11655;13.33;100000;2;0336;000061;4.5;0;0.00")); -- cgit v1.2.3