From 735fc1483817da385dce0fb572440261b6a644a3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 30 Oct 2018 16:37:19 +1300 Subject: Alternative H02 SOS and commands --- src/org/traccar/protocol/H02ProtocolDecoder.java | 2 +- src/org/traccar/protocol/H02ProtocolEncoder.java | 15 ++++++++++----- test/org/traccar/protocol/H02ProtocolEncoderTest.java | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index eece99ebb..a5f87fe8f 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -74,7 +74,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { if (!BitUtil.check(status, 0)) { position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); - } else if (!BitUtil.check(status, 1)) { + } else if (!BitUtil.check(status, 1) || !BitUtil.check(status, 18)) { position.set(Position.KEY_ALARM, Position.ALARM_SOS); } else if (!BitUtil.check(status, 2)) { position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); diff --git a/src/org/traccar/protocol/H02ProtocolEncoder.java b/src/org/traccar/protocol/H02ProtocolEncoder.java index 6d5cfb298..614a07dd1 100644 --- a/src/org/traccar/protocol/H02ProtocolEncoder.java +++ b/src/org/traccar/protocol/H02ProtocolEncoder.java @@ -16,6 +16,7 @@ */ package org.traccar.protocol; +import org.traccar.Context; import org.traccar.StringProtocolEncoder; import org.traccar.model.Command; @@ -48,13 +49,17 @@ public class H02ProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ALARM_DISARM: return formatCommand(time, uniqueId, "SCF", "1", "1"); case Command.TYPE_ENGINE_STOP: - return formatCommand( - time, uniqueId, "S20", "1", "3", "10", "3", "5", "5", "3", "5", "3", "5", "3", "5"); + return formatCommand(time, uniqueId, "S20", "1", "1"); case Command.TYPE_ENGINE_RESUME: - return formatCommand(time, uniqueId, "S20", "0", "0"); + return formatCommand(time, uniqueId, "S20", "1", "0"); case Command.TYPE_POSITION_PERIODIC: - return formatCommand( - time, uniqueId, "S71", "22", command.getAttributes().get(Command.KEY_FREQUENCY).toString()); + String frequency = command.getAttributes().get(Command.KEY_FREQUENCY).toString(); + if (Context.getIdentityManager().lookupAttributeBoolean( + command.getDeviceId(), "h02.alternative", false, true)) { + return formatCommand(time, uniqueId, "D1", frequency); + } else { + return formatCommand(time, uniqueId, "S71", "22", frequency); + } default: return null; } diff --git a/test/org/traccar/protocol/H02ProtocolEncoderTest.java b/test/org/traccar/protocol/H02ProtocolEncoderTest.java index e022a7b7e..a7ce3fc7e 100644 --- a/test/org/traccar/protocol/H02ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolEncoderTest.java @@ -45,7 +45,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest { command.setDeviceId(1); command.setType(Command.TYPE_ENGINE_STOP); - assertEquals("*HQ,123456789012345,S20,010203,1,3,10,3,5,5,3,5,3,5,3,5#", encoder.encodeCommand(command, time)); + assertEquals("*HQ,123456789012345,S20,010203,1,1#", encoder.encodeCommand(command, time)); } @Test @@ -55,7 +55,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest { command.setDeviceId(1); command.setType(Command.TYPE_ENGINE_RESUME); - assertEquals("*HQ,123456789012345,S20,010203,0,0#", encoder.encodeCommand(command, time)); + assertEquals("*HQ,123456789012345,S20,010203,1,0#", encoder.encodeCommand(command, time)); } @Test -- cgit v1.2.3