Skip to content

Commit

Permalink
Decode additional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 8, 2019
1 parent 9a5891a commit 90416b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ public Tlt2hProtocolDecoder(Protocol protocol) {
}

private static final Pattern PATTERN_HEADER = new PatternBuilder()
.number("#(d+)#") // imei
.any()
.expression("#([^#]+)#") // status
.number("d+") // number of records
.number("#(d+)") // imei
.expression("#[^#]*") // user
.number("#d+") // password
.groupBegin()
.number("#([01])") // door
.number("#(d+)") // fuel voltage
.number("#(d+)") // power
.number("#(d+)") // battery
.number("#(d+)") // temperature
.groupEnd("?")
.expression("#([^#]+)") // status
.number("#d+") // number of records
.compile();

private static final Pattern PATTERN_POSITION = new PatternBuilder()
Expand Down Expand Up @@ -114,6 +122,19 @@ protected Object decode(
return null;
}

Boolean door = null;
Double adc = null;
Double power = null;
Double battery = null;
Double temperature = null;
if (parser.hasNext(5)) {
door = parser.nextInt() == 1;
adc = parser.nextInt() * 0.1;
power = parser.nextInt() * 0.1;
battery = parser.nextInt() * 0.1;
temperature = parser.nextInt() * 0.1;
}

String status = parser.next();

String[] messages = sentence.substring(sentence.indexOf('\n') + 1).split("\r\n");
Expand All @@ -140,6 +161,11 @@ protected Object decode(
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());

position.set(Position.KEY_DOOR, door);
position.set(Position.PREFIX_ADC + 1, adc);
position.set(Position.KEY_POWER, power);
position.set(Position.KEY_BATTERY, battery);
position.set(Position.PREFIX_TEMP + 1, temperature);
decodeStatus(position, status);

positions.add(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public void testDecode() throws Exception {

Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(null);

verifyPositions(decoder, text(
"#860425040088567#MT600+#0000#0#1#129#40#0#AUTOLOW#1\r\n",
"#000321901$GPRMC,172030.00,A,4845.2906,N,01910.2742,E,0.01,,041219,,,A*43\r\n"));

verifyAttribute(decoder, text(
"#869260042149724#MP90_4G#0000#AUTOLOW#1\r\n" +
"#02201be0000$GPRMC,001645.00,A,5333.2920,N,11334.3857,W,0.03,,250419,,,A*5E\r\n"),
Expand Down

0 comments on commit 90416b2

Please sign in to comment.