From 273a4b7ab23a66ddfdeb05f69edc21a970b6844c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 30 Oct 2017 21:37:13 +1300 Subject: Support Oner OCT retransmission --- .../traccar/protocol/MeiligaoProtocolDecoder.java | 116 ++++++++++++++------- 1 file changed, 81 insertions(+), 35 deletions(-) (limited to 'src/org/traccar/protocol/MeiligaoProtocolDecoder.java') diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index e41a42843..0b63620b5 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2017 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. @@ -30,6 +30,8 @@ import org.traccar.model.Position; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; +import java.util.LinkedList; +import java.util.List; import java.util.regex.Pattern; public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { @@ -118,6 +120,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_POSITION_LOGGED = 0x9016; public static final int MSG_ALARM = 0x9999; public static final int MSG_RFID = 0x9966; + public static final int MSG_RETRANSMISSION = 0x6688; public static final int MSG_OBD_RT = 0x9901; public static final int MSG_OBD_RTA = 0x9902; @@ -328,6 +331,40 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return position; } + private List decodeRetransmission(ChannelBuffer buf, DeviceSession deviceSession) { + List positions = new LinkedList<>(); + + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + + buf.readUnsignedByte(); // alarm + + int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\\'); + if (endIndex < 0) { + endIndex = buf.writerIndex() - 4; + } + + String sentence = buf.readBytes(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position = decodeRegular(position, sentence); + + if (position != null) { + positions.add(position); + } + + if (buf.readableBytes() > 4) { + buf.readUnsignedByte(); // delimiter + } + + } + + return positions; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -355,48 +392,57 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } } - Position position = new Position(); - position.setProtocol(getProtocolName()); - - if (command == MSG_ALARM) { - short alarmCode = buf.readUnsignedByte(); - position.set(Position.KEY_ALARM, decodeAlarm(alarmCode)); - if (alarmCode >= 0x02 && alarmCode <= 0x05) { - position.set(Position.PREFIX_IN + alarmCode, 1); - } else if (alarmCode >= 0x32 && alarmCode <= 0x35) { - position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0); - } - } else if (command == MSG_POSITION_LOGGED) { - buf.skipBytes(6); - } - DeviceSession deviceSession = identify(id, channel, remoteAddress); if (deviceSession == null) { return null; } - position.setDeviceId(deviceSession.getDeviceId()); - - if (command == MSG_RFID) { - for (int i = 0; i < 15; i++) { - long rfid = buf.readUnsignedInt(); - if (rfid != 0) { - String card = String.format("%010d", rfid); - position.set("card" + (i + 1), card); - position.set(Position.KEY_DRIVER_UNIQUE_ID, card); + + if (command == MSG_RETRANSMISSION) { + + return decodeRetransmission(buf, deviceSession); + + } else { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + + if (command == MSG_ALARM) { + short alarmCode = buf.readUnsignedByte(); + position.set(Position.KEY_ALARM, decodeAlarm(alarmCode)); + if (alarmCode >= 0x02 && alarmCode <= 0x05) { + position.set(Position.PREFIX_IN + alarmCode, 1); + } else if (alarmCode >= 0x32 && alarmCode <= 0x35) { + position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0); + } + } else if (command == MSG_POSITION_LOGGED) { + buf.skipBytes(6); + } + + position.setDeviceId(deviceSession.getDeviceId()); + + if (command == MSG_RFID) { + for (int i = 0; i < 15; i++) { + long rfid = buf.readUnsignedInt(); + if (rfid != 0) { + String card = String.format("%010d", rfid); + position.set("card" + (i + 1), card); + position.set(Position.KEY_DRIVER_UNIQUE_ID, card); + } } } - } - String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII); + String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII); + + if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) { + return decodeRegular(position, sentence); + } else if (command == MSG_RFID) { + return decodeRfid(position, sentence); + } else if (command == MSG_OBD_RT) { + return decodeObd(position, sentence); + } else if (command == MSG_OBD_RTA) { + return decodeObdA(position, sentence); + } - if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) { - return decodeRegular(position, sentence); - } else if (command == MSG_RFID) { - return decodeRfid(position, sentence); - } else if (command == MSG_OBD_RT) { - return decodeObd(position, sentence); - } else if (command == MSG_OBD_RTA) { - return decodeObdA(position, sentence); } return null; -- cgit v1.2.3 From c62dd84c7ad4061c0c6d8a521c63857ccde461ba Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 1 Nov 2017 22:57:10 +1300 Subject: Support iStartrek VT900 protocol --- src/org/traccar/helper/Parser.java | 16 ++++++++++ .../traccar/protocol/MeiligaoProtocolDecoder.java | 37 ++++++++++------------ .../protocol/MeiligaoProtocolDecoderTest.java | 3 ++ 3 files changed, 36 insertions(+), 20 deletions(-) (limited to 'src/org/traccar/protocol/MeiligaoProtocolDecoder.java') diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index 582b497cf..1471ec237 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -109,6 +109,22 @@ public class Parser { } } + public Long nextLong() { + if (hasNext()) { + return Long.parseLong(next()); + } else { + return null; + } + } + + public Long nextHexLong() { + if (hasNext()) { + return Long.parseLong(next(), 16); + } else { + return null; + } + } + public long nextLong(long defaultValue) { return nextLong(10, defaultValue); } diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 0b63620b5..b0793037f 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -57,11 +57,19 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .number("|(xxxx)?") // state .groupBegin() .number("|(xxxx),(xxxx)") // adc - .number("(?:,(xxxx),(xxxx),(xxxx),(xxxx),(xxxx),(xxxx))?") + .number(",(xxxx)").optional() + .number(",(xxxx)").optional() + .number(",(xxxx)").optional() + .number(",(xxxx)").optional() + .number(",(xxxx)").optional() + .number(",(xxxx)").optional() .groupBegin() - .number("|x{16}") // cell - .number("|(xx)") // gsm + .number("|x{16,20}") // cell + .number("|(xx)") // rssi .number("|(x{8})") // odometer + .groupBegin() + .number("|(xx)") // satellites + .groupEnd("?") .or() .number("|(x{9})") // odometer .groupBegin() @@ -245,25 +253,14 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, parser.next()); for (int i = 1; i <= 8; i++) { - if (parser.hasNext()) { - position.set(Position.PREFIX_ADC + i, parser.nextHexInt(0)); - } + position.set(Position.PREFIX_ADC + i, parser.nextHexInt()); } - if (parser.hasNext()) { - position.set(Position.KEY_RSSI, parser.nextHexInt(0)); - } - - if (parser.hasNext()) { - position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0)); - } - if (parser.hasNext()) { - position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0)); - } - - if (parser.hasNext()) { - position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(parser.nextHexInt(0))); - } + position.set(Position.KEY_RSSI, parser.nextHexInt()); + position.set(Position.KEY_ODOMETER, parser.nextHexLong()); + position.set(Position.KEY_SATELLITES, parser.nextHexInt()); + position.set(Position.KEY_ODOMETER, parser.nextHexLong()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); return position; } diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 020078f4a..f5f3b3057 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class MeiligaoProtocolDecoderTest extends ProtocolTest { MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol()); + verifyPosition(decoder, binary( + "2424010a142170525979ff9999753137353830322e3030302c412c313330362e303639342c4e2c31303035342e323439302c452c302e30302c3331332c3234313031372c2c2a30457c302e397c377c323530307c303030302c303030302c303130312c303241447c30323038303030353043313330313638353333427c30427c30303032313034357c30417c2520205e59454e53414241494348414924534f4e474b52414e244d522e5e5e3f3b363030373634333130303530303337333835333d3135303531393637303631343d3f2b202020202020202020202020203234202020202020202020202020312020202020202020202020203030303431313120203030313030545c0d0a")); + verifyPositions(decoder, binary( "2424006661172036237118668801003039333630342e3030302c562c303330332e333231352c4e2c31303134372e313530302c452c302e30302c2c3235313031377c302e307c302e307c303030307c303030302c303030307c30303030303230343259ca0d0a")); -- cgit v1.2.3