From 04e482bd22029710fd512bfd7916781cd5c79495 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Mar 2024 06:52:02 -0800 Subject: Fix Esky ES840 decoding --- src/main/java/org/traccar/protocol/EskyProtocolDecoder.java | 2 +- src/test/java/org/traccar/protocol/EskyProtocolDecoderTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java b/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java index 4239022d0..14b6aaa5a 100644 --- a/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java @@ -49,7 +49,7 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+)[+;]") // speed .number("(d+)[+;]") // course .groupBegin() - .text("0x").number("(d+)[+;]") // input + .text("0x").number("(x+)[+;]") // input .number("(d+)[+;]") // message type .number("(d+)[+;]") // odometer .groupEnd("?") diff --git a/src/test/java/org/traccar/protocol/EskyProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/EskyProtocolDecoderTest.java index feec3ebfb..26132eb4e 100644 --- a/src/test/java/org/traccar/protocol/EskyProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/EskyProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class EskyProtocolDecoderTest extends ProtocolTest { var decoder = inject(new EskyProtocolDecoder(null)); + verifyPosition(decoder, text( + "ET;1;864431045310325;R;0+240303180628+-33.40958+149.56797+0.00+63+0xb+0+17814846+1168+0+0+WVWZZZ6RZFY242201+135+DTCNULL")); + verifyAttribute(decoder, text( "ET;0;860337031066546;R;9+200717114059+41.32053+19.80761+0.30+0+0x2+8+40381744+0+1409+11"), Position.KEY_BATTERY, 14.09); -- cgit v1.2.3 From 43508913a7f3356324ec5af447980121d9c64dd0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Mar 2024 09:38:03 -0800 Subject: Add Huabao frame encoder --- .../org/traccar/protocol/HuabaoFrameEncoder.java | 44 ++++++++++++++++++++++ .../java/org/traccar/protocol/HuabaoProtocol.java | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java diff --git a/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java b/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java new file mode 100644 index 000000000..808529a98 --- /dev/null +++ b/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +public class HuabaoFrameEncoder extends MessageToByteEncoder { + + @Override + protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) { + + while (msg.isReadable()) { + int b = msg.readUnsignedByte(); + switch (b) { + case 0x7d: + out.writeByte(0x7d); + out.writeByte(0x01); + break; + case 0x7e: + out.writeByte(0x7d); + out.writeByte(0x02); + break; + default: + out.writeByte(b); + break; + } + } + } +} diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocol.java b/src/main/java/org/traccar/protocol/HuabaoProtocol.java index fc12d7d71..575d15b02 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocol.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2024 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. @@ -33,6 +33,7 @@ public class HuabaoProtocol extends BaseProtocol { addServer(new TrackerServer(config, getName(), false) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) { + pipeline.addLast(new HuabaoFrameEncoder()); pipeline.addLast(new HuabaoFrameDecoder()); pipeline.addLast(new HuabaoProtocolEncoder(HuabaoProtocol.this)); pipeline.addLast(new HuabaoProtocolDecoder(HuabaoProtocol.this)); -- cgit v1.2.3 From 165a6c76e8127bae7bdf16a9e9a4a24247f1dec4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Mar 2024 21:26:09 -0800 Subject: Fix Huabao frame encoder --- .../org/traccar/protocol/HuabaoFrameEncoder.java | 22 ++++++++++------------ .../traccar/protocol/HuabaoFrameEncoderTest.java | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 src/test/java/org/traccar/protocol/HuabaoFrameEncoderTest.java diff --git a/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java b/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java index 808529a98..5e48a466a 100644 --- a/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java @@ -24,20 +24,18 @@ public class HuabaoFrameEncoder extends MessageToByteEncoder { @Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) { + int startIndex = msg.readerIndex(); while (msg.isReadable()) { + int index = msg.readerIndex(); int b = msg.readUnsignedByte(); - switch (b) { - case 0x7d: - out.writeByte(0x7d); - out.writeByte(0x01); - break; - case 0x7e: - out.writeByte(0x7d); - out.writeByte(0x02); - break; - default: - out.writeByte(b); - break; + if (b == 0x7d) { + out.writeByte(0x7d); + out.writeByte(0x01); + } else if (b == 0x7e && index != startIndex && msg.isReadable()) { + out.writeByte(0x7d); + out.writeByte(0x02); + } else { + out.writeByte(b); } } } diff --git a/src/test/java/org/traccar/protocol/HuabaoFrameEncoderTest.java b/src/test/java/org/traccar/protocol/HuabaoFrameEncoderTest.java new file mode 100644 index 000000000..a2799e9a8 --- /dev/null +++ b/src/test/java/org/traccar/protocol/HuabaoFrameEncoderTest.java @@ -0,0 +1,21 @@ +package org.traccar.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import org.junit.jupiter.api.Test; +import org.traccar.ProtocolTest; + +public class HuabaoFrameEncoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + var encoder = new HuabaoFrameEncoder(); + + ByteBuf buf = Unpooled.buffer(); + encoder.encode(null, binary("7e307e087d557e"), buf); + verifyFrame(binary("7e307d02087d01557e"), buf); + + } + +} -- cgit v1.2.3 From 823878d4f797cf2fb8e2c6e3b466b3316613d886 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 9 Mar 2024 14:27:13 -0800 Subject: Expand GV355CEU CAN support --- .../traccar/protocol/Gl200TextProtocolDecoder.java | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java index 2e5ffa8d6..7a8d67cf9 100644 --- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -468,7 +468,6 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { index += 1; // report type index += 1; // can bus state long reportMask = Long.parseLong(v[index++], 16); - long reportMaskExt = 0; if (BitUtil.check(reportMask, 0)) { position.set(Position.KEY_VIN, v[index++]); @@ -572,6 +571,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { index += 1; // electric report mask } } + + long reportMaskExt = 0; if (BitUtil.check(reportMask, 29) && !v[index++].isEmpty()) { reportMaskExt = Long.parseLong(v[index - 1], 16); } @@ -647,6 +648,41 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(reportMaskExt, 23)) { index += 1; // engine torque } + if (BitUtil.check(reportMaskExt, 24)) { + index += 1; // service distance + } + if (BitUtil.check(reportMaskExt, 25)) { + index += 1; // ambient temperature + } + if (BitUtil.check(reportMaskExt, 26)) { + index += 1; // tachograph driver1 working time mask + } + if (BitUtil.check(reportMaskExt, 27)) { + index += 1; // tachograph driver2 working time mask + } + if (BitUtil.check(reportMaskExt, 28)) { + index += 1; // dtc codes + } + if (BitUtil.check(reportMaskExt, 29)) { + index += 1; // gaseous fuel level + } + if (BitUtil.check(reportMaskExt, 30)) { + index += 1; // tachograph information expand + } + + long reportMaskCan = 0; + if (BitUtil.check(reportMaskExt, 31) && !v[index++].isEmpty()) { + reportMaskCan = Long.parseLong(v[index - 1], 16); + } + if (BitUtil.check(reportMaskCan, 0)) { + index += 1; // retarder usage + } + if (BitUtil.check(reportMaskCan, 1)) { + index += 1; // power mode + } + if (BitUtil.check(reportMaskCan, 2)) { + index += 1; // tachograph timestamp + } DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); -- cgit v1.2.3