From f7474589a77ca99a3543e16a0609dc4a010c0e4b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 11 Dec 2017 06:55:37 +1300 Subject: Decode T333 taximeter data --- .../traccar/protocol/MeitrackProtocolDecoder.java | 37 ++++++++++++++++++++-- .../protocol/MeitrackProtocolDecoderTest.java | 7 ++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 5b67aebe3..1fd1bb3ac 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -75,13 +75,20 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { .number("(x+)|") // battery .number("(x+)?,") // power .groupBegin() - .expression("([^,]+)?,") // event specific + .expression("([^,]+)?,").optional() // event specific .expression("[^,]*,") // reserved .number("(d+)?,") // protocol .number("(x{4})?") // fuel - .number("(?:,(x{6}(?:|x{6})*))?") // temperature + .groupBegin() + .number(",(x{6}(?:|x{6})*)?") // temperature + .groupBegin() + .number(",(d+)") // data count + .expression(",([^*]*)") // data .groupEnd("?") + .groupEnd("?") + .or() .any() + .groupEnd() .text("*") .number("xx") .text("\r\n").optional() @@ -234,9 +241,35 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } } + if (parser.hasNext(2)) { + decodeDataFields(position, parser.nextInt(), parser.next().split(",")); + } + return position; } + private void decodeDataFields(Position position, int count, String[] values) { + + if (values.length > 1 && !values[1].isEmpty()) { + position.set("tempData", values[1]); + } + + if (values.length > 5 && !values[5].isEmpty()) { + String[] data = values[5].split("\\|"); + boolean started = data[0].charAt(0) == '0'; + position.set("taximeterOn", started); + position.set("taximeterStart", data[1]); + if (!started) { + position.set("taximeterEnd", data[2]); + position.set("taximeterDistance", Integer.parseInt(data[3])); + position.set("taximeterFare", Integer.parseInt(data[4])); + position.set("taximeterTrip", data[5]); + position.set("taximeterWait", data[6]); + } + } + + } + private List decodeBinaryC(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { List positions = new LinkedList<>(); diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 4ec2211bc..35529f721 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new MeitrackProtocol()); + verifyPosition(decoder, buffer( + "$$S214,864507031219974,AAA,109,13.844643,100.644395,171207021520,A,10,28,0,31,0.8,6,390,421327,520|0|0016|000F2DB0,8400,0000|0000|0000|018D|04C6,,,108,0000,,6,0,,,,,11|171207091500|171207091500|78|3500|000000|000003*12")); + verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "24245f3237382c3836353738393032313434373233322c4343452c5b00000003005000130006012305010608070d15001b0006080000091e010a09000b2e0019a1011af90106025c033300039be60c06044f6678210c6f1806000d48db06001c41000000010e0cf60113002005912b830001ff5000130006012305010608070d15001b0006080000091e010a09000b2e0019a0011af90106025c033300039be60c0604506678210c6f1806000d49db06001c41000000010e0cf60113002005912b830001ff5000130006012305010608070d15001b0006080000091e010a09000b2e0019a1011af90106025c033300039be60c0604516678210c6f1806000d4adb06001c41000000010e0cf60113002005912b830001ff2a37460d0a")); @@ -94,8 +97,8 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "2424473937302c3336393830303031333436303637342c4343432c020134005b000000010ce304035db9e000ec6f591a000013000000000c001801edb70200c96d0100e60001004838576501000300a101c20400000000010ce304035db9e000ee6f591a000013000000000c001801edb70200ca6d0100e60001004838576501000300a101c20400000000010ce304035db9e000ef6f591a000013000000000c001801edb70200cc6d0100e60001004838576501000300a101c20400000000020ce304035db9e000f76f591a000016000000000c001801edb70200d36d0100e60001004838576502000300a101bf04000000000a0ce304035db9e000f76f591a000016000000000c001801edb70200d46d0100e60001004838576500000300a101bf0400000000020ce304035db9e000fb6f591a000016000000000c001801edb70200d86d0100e60001004838576502000300a101760400000000180ce304035db9e000fc6f591a0000120000000000008c00edb70200d96d0100e60001004838576502000300a10176040000000019b1e2040323b9e0000b70591a0105150600bb0012002901edb70200e76d0100e60001004838576502000300a2017005000000002023e304031fb9e0001070591a010615070027010d001601fcb70200ec6d0100e60001004838576502000300a201800500000000201fe3040302b9e0001170591a010615090019010d001501feb70200ed6d0100e60001004838576502000300a2018005000000002018e30403dcb8e0001270591a0106150b0011010d00150100b80200ee6d0100e60001004838576502000300a2018005000000002036e3040345b8e0001570591a0107150b002d010b0013010ab80200f16d0100e60001004838576502000300a2018005000000002053e3040326b8e0001670591a0107150d0041010b0013010eb80200f26d0100e60001004838576502000300a2018005000000002070e3040310b8e0001770591a0107150e004f010b00130111b80200f36d0100e60001004838576502000300a2018005000000002095e3040306b8e0001870591a0107150d005a010b00140115b80200f46d0100e60001004838576502000300a20180050000000020b3e3040305b8e0001970591a0107150b0060010b00140118b80200f56d0100e60001004838576502000300a20183050000000020cfe3040308b8e0001a70591a0107150b0066010b0014011bb80200f66d0100e60001004838576502000300a20183050000000020eee304030cb8e0001b70591a0106170b0004000d0014011eb80200f76d0100e60001004838576502000300a2018305000000002a62350d0a")); - //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, - // "2424473937302C3336393830303031333232303032302C4343432C02013400540000001F0E885701225FCC06F574A419000614000000001200280012390C0081080000CC01000062305446000000007901000000000000000000000000000000000000000000008004000080040000800400008004000000000000000000000000000000000000FEEE00001F0E885701225FCC06CD7AA419000614000000001200280012390C00260D0000CC01000062305446000000007801A403000000001F0E885701225FCC06257DA419000617000000001200280012390C007E0F0000CC01000062305446000000007701A403000000001F0E885701225FCC067E7FA419000016000000001200280012390C00D6110000CC01000062305446000000007701A603000000001F0E885701225FCC06D681A419000017000000001200280012390C002E140000CC01000062305446000000007601A603000000001F0E885701225FCC062E84A419000015000000001200280012390C0086160000CC01000062305446000000007501A603000000001F0E885701225FCC067A83A51900060E000000001200280012390C0065190000CC0100006230EAB7000000007301A403000000001F0E885701225FCC06D285A51900060E000000001200280012390C00BD1B0000CC01000062305446000000007101A203000000001F0E885701225FCC062B88A51900060F000000001200280012390C00151E0000CC01000062305446000000007001A203000000001F0E885701225FCC06838AA519000613000000001200280012390C006D200000CC01000062305446000000007001A603000000001F0E885701225FCC06DB8CA519000010000000001200280012390C00C5220000CC01000062305446000000006E01A603000000001F0E885701225FCC06348FA519000016000000001200280012390C001D250000CC01000062305446000000006401000000000000020E885701225FCC06D9D9A519000600000000001200280012390C007828000000000000000000000200000054010000000000001F0E885701225FCC062DDCA519000616000000001200280012390C00CC2A0000CC01000062305446020000007B010000000000000A0E885701225FCC065BDDA519000613000000001200280012390C00F92B0000CC01000062305446000000007C01000000000000020E885701225FCC065CDDA519000010000000001200280012390C00FB2B0000CC01000062305446020000007C010000000000001F0E885701225FCC0685DEA519000013000000001200280012390C00242D0000CC01000062305446020000007D010000000000002A35620D0A")); + /*verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "2424473937302C3336393830303031333232303032302C4343432C02013400540000001F0E885701225FCC06F574A419000614000000001200280012390C0081080000CC01000062305446000000007901000000000000000000000000000000000000000000008004000080040000800400008004000000000000000000000000000000000000FEEE00001F0E885701225FCC06CD7AA419000614000000001200280012390C00260D0000CC01000062305446000000007801A403000000001F0E885701225FCC06257DA419000617000000001200280012390C007E0F0000CC01000062305446000000007701A403000000001F0E885701225FCC067E7FA419000016000000001200280012390C00D6110000CC01000062305446000000007701A603000000001F0E885701225FCC06D681A419000017000000001200280012390C002E140000CC01000062305446000000007601A603000000001F0E885701225FCC062E84A419000015000000001200280012390C0086160000CC01000062305446000000007501A603000000001F0E885701225FCC067A83A51900060E000000001200280012390C0065190000CC0100006230EAB7000000007301A403000000001F0E885701225FCC06D285A51900060E000000001200280012390C00BD1B0000CC01000062305446000000007101A203000000001F0E885701225FCC062B88A51900060F000000001200280012390C00151E0000CC01000062305446000000007001A203000000001F0E885701225FCC06838AA519000613000000001200280012390C006D200000CC01000062305446000000007001A603000000001F0E885701225FCC06DB8CA519000010000000001200280012390C00C5220000CC01000062305446000000006E01A603000000001F0E885701225FCC06348FA519000016000000001200280012390C001D250000CC01000062305446000000006401000000000000020E885701225FCC06D9D9A519000600000000001200280012390C007828000000000000000000000200000054010000000000001F0E885701225FCC062DDCA519000616000000001200280012390C00CC2A0000CC01000062305446020000007B010000000000000A0E885701225FCC065BDDA519000613000000001200280012390C00F92B0000CC01000062305446000000007C01000000000000020E885701225FCC065CDDA519000010000000001200280012390C00FB2B0000CC01000062305446020000007C010000000000001F0E885701225FCC0685DEA519000013000000001200280012390C00242D0000CC01000062305446020000007D010000000000002A35620D0A"));*/ } -- cgit v1.2.3