aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/helper/ObdDecoder.java36
-rw-r--r--src/main/java/org/traccar/protocol/CastelProtocolDecoder.java31
-rw-r--r--src/test/java/org/traccar/protocol/CastelProtocolDecoderTest.java8
3 files changed, 56 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/helper/ObdDecoder.java b/src/main/java/org/traccar/helper/ObdDecoder.java
index b22065f4e..3cbae334a 100644
--- a/src/main/java/org/traccar/helper/ObdDecoder.java
+++ b/src/main/java/org/traccar/helper/ObdDecoder.java
@@ -51,22 +51,7 @@ public final class ObdDecoder {
StringBuilder codes = new StringBuilder();
for (int i = 0; i < value.length() / 4; i++) {
int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16);
- codes.append(' ');
- switch (numValue >> 14) {
- case 1:
- codes.append('C');
- break;
- case 2:
- codes.append('B');
- break;
- case 3:
- codes.append('U');
- break;
- default:
- codes.append('P');
- break;
- }
- codes.append(String.format("%04X", numValue & 0x3FFF));
+ codes.append(' ').append(decodeCode(numValue));
}
if (codes.length() > 0) {
return createEntry(Position.KEY_DTCS, codes.toString().trim());
@@ -75,6 +60,25 @@ public final class ObdDecoder {
}
}
+ public static String decodeCode(int value) {
+ char prefix;
+ switch (value >> 14) {
+ case 1:
+ prefix = 'C';
+ break;
+ case 2:
+ prefix = 'B';
+ break;
+ case 3:
+ prefix = 'U';
+ break;
+ default:
+ prefix = 'P';
+ break;
+ }
+ return String.format("%c%04X", prefix, value & 0x3FFF);
+ }
+
public static Map.Entry<String, Object> decodeData(int pid, long value, boolean convert) {
switch (pid) {
case 0x04:
diff --git a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
index 4aa65245b..4d56e40c9 100644
--- a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
@@ -284,15 +284,27 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
case 0x0C:
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
break;
+ case 0x0D:
+ position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING);
+ break;
case 0x0E:
position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
break;
+ case 0x11:
+ position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT);
+ break;
+ case 0x12:
+ position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
+ break;
case 0x16:
position.set(Position.KEY_IGNITION, true);
break;
case 0x17:
position.set(Position.KEY_IGNITION, false);
break;
+ case 0x1C:
+ position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
+ break;
default:
break;
}
@@ -359,9 +371,9 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
int alarmCount = buf.readUnsignedByte();
for (int i = 0; i < alarmCount; i++) {
if (buf.readUnsignedByte() != 0) {
- int alarm = buf.readUnsignedByte();
+ int event = buf.readUnsignedByte();
for (Position p : positions) {
- decodeAlarm(p, alarm);
+ decodeAlarm(p, event);
}
buf.readUnsignedShortLE(); // description
buf.readUnsignedShortLE(); // threshold
@@ -421,12 +433,25 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return position;
case MSG_SC_DTCS_PASSENGER:
+ case MSG_SC_DTCS_COMMERCIAL:
position = createPosition(deviceSession);
decodeStat(position, buf);
buf.readUnsignedByte(); // flag
- position.add(ObdDecoder.decodeCodes(ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))));
+
+ count = buf.readUnsignedByte();
+ StringBuilder codes = new StringBuilder();
+ for (int i = 0; i < count; i++) {
+ if (type == MSG_SC_DTCS_COMMERCIAL) {
+ codes.append(ObdDecoder.decodeCode(buf.readUnsignedShortLE()));
+ buf.readUnsignedByte(); // attribute
+ buf.readUnsignedByte(); // occurrence
+ } else {
+ codes.append(ObdDecoder.decodeCode(buf.readUnsignedShortLE()));
+ }
+ }
+ position.set(Position.KEY_DTCS, codes.toString().trim());
return position;
diff --git a/src/test/java/org/traccar/protocol/CastelProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/CastelProtocolDecoderTest.java
index e9cbac5ce..52c6a86a6 100644
--- a/src/test/java/org/traccar/protocol/CastelProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/CastelProtocolDecoderTest.java
@@ -12,6 +12,14 @@ public class CastelProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new CastelProtocolDecoder(null));
verifyAttribute(decoder, binary(
+ "40404700043231335732303139303033353400000000000000400BBE723A5DEF723A5D000000000000000000000000000000000000030100011900030001012603030145C90D0A"),
+ Position.KEY_DTCS, "P0326");
+
+ verifyAttribute(decoder, binary(
+ "40404500033231334c323031373030303432320000000000004006e1ad205bf1ad205b48510f000000000050160000000000020400053f007c000083040001511346160d0a"),
+ Position.KEY_DTCS, "P1351");
+
+ verifyAttribute(decoder, binary(
"40403a00043231334744503230313830323133343300000000a002000001000001012011004d414c43333831434d4b4d353637313438c8fc0d0a"),
Position.KEY_RESULT, "MALC381CMKM567148");