From aa59b968c7d6a89b8e6285647ab2e6e62f02cf7f Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 27 Dec 2021 20:48:47 -0600 Subject: Revert "Merge branch 'master' into suntech-fixes" This reverts commit f03b999d6d17e53c1c1e1aa2f9271d03f12f2264, reversing changes made to 3a528ddc88f72f39ff9566cf5e0f54938b1584ef. --- .../traccar/protocol/MobilogixProtocolDecoder.java | 75 ++++++---------------- 1 file changed, 18 insertions(+), 57 deletions(-) (limited to 'src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java index 86c89e336..8677ba9ec 100644 --- a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 - 2021 Anton Tananaev (anton@traccar.org) + * Copyright 2020 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. @@ -39,52 +39,28 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { .text("[") .number("(dddd)-(dd)-(dd) ") // date (yyyymmdd) .number("(dd):(dd):(dd),") // time (hhmmss) - .number("Td+,") // type - .number("(d),") // archive + .number("Td,") // type + .number("d+,") // device type .expression("[^,]+,") // protocol version .expression("([^,]+),") // serial number .number("(xx),") // status - .number("(d+.d+)") // battery - .groupBegin() - .text(",") - .number("(d)") // satellites + .number("(d+.d+),") // battery + .number("(d)") // valid .number("(d)") // rssi - .number("(d),") // valid + .number("(d),") // satellites .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*)") // course - .groupEnd("?") .any() .compile(); - private String decodeAlarm(String type) { - switch (type) { - case "T8": - return Position.ALARM_LOW_BATTERY; - case "T9": - return Position.ALARM_VIBRATION; - case "T10": - return Position.ALARM_POWER_CUT; - case "T11": - return Position.ALARM_LOW_POWER; - case "T12": - return Position.ALARM_GEOFENCE_EXIT; - case "T13": - return Position.ALARM_OVERSPEED; - case "T15": - return Position.ALARM_TOW; - default: - return null; - } - } - @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = ((String) msg).trim(); - String type = sentence.substring(21, sentence.indexOf(',', 21)); + String sentence = (String) msg; + String type = sentence.substring(21, 21 + 2); if (channel != null) { String time = sentence.substring(1, 20); @@ -92,22 +68,19 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { if (type.equals("T1")) { response = String.format("[%s,S1,1]", time); } else { - response = String.format("[%s,S%s]", time, type.substring(1)); + response = String.format("[%s,S%c]", time, type.charAt(1)); } channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } - Parser parser = new Parser(PATTERN, sentence); + Parser parser = new Parser(PATTERN, (String) msg); if (!parser.matches()) { return null; } Position position = new Position(getProtocolName()); - position.setDeviceTime(parser.nextDateTime()); - if (parser.nextInt() == 0) { - position.set(Position.KEY_ARCHIVE, true); - } + position.setTime(parser.nextDateTime()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { @@ -115,9 +88,6 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - position.set(Position.KEY_TYPE, type); - position.set(Position.KEY_ALARM, decodeAlarm(type)); - int status = parser.nextHexInt(); position.set(Position.KEY_IGNITION, BitUtil.check(status, 2)); position.set(Position.KEY_MOTION, BitUtil.check(status, 3)); @@ -125,24 +95,15 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, parser.nextDouble()); - if (parser.hasNext(7)) { + position.setValid(parser.nextInt() > 0); - position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.set(Position.KEY_RSSI, 6 * parser.nextInt() - 111); + position.set(Position.KEY_RSSI, parser.nextInt()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.setValid(parser.nextInt() > 0); - position.setFixTime(position.getDeviceTime()); - - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - position.setCourse(parser.nextDouble()); - - } else { - - getLastLocation(position, position.getDeviceTime()); - - } + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); return position; } -- cgit v1.2.3