Skip to content

Commit

Permalink
Support iStartek command results
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jul 11, 2021
1 parent c915753 commit 1d3cd09
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/main/java/org/traccar/protocol/StartekProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public StartekProtocolDecoder(Protocol protocol) {
.expression(".") // index
.number("d+,") // length
.number("(d+),") // imei
.expression("(.+)") // content
.number("xx") // checksum
.compile();

private static final Pattern PATTERN_POSITION = new PatternBuilder()
.number("xxx,") // command
.number("(d+),") // event
.expression("([^,]+)?,") // event data
Expand Down Expand Up @@ -75,7 +80,6 @@ public StartekProtocolDecoder(Protocol protocol) {
.expression("([^,]+)?") // temperature
.groupEnd("?")
.groupEnd("?")
.number("xx") // checksum
.compile();

private String decodeAlarm(int value) {
Expand Down Expand Up @@ -108,6 +112,32 @@ protected Object decode(
return null;
}

String content = parser.next();
if (content.length() < 100) {

Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());

getLastLocation(position, null);

position.set(Position.KEY_RESULT, content);

return position;

} else {

return decodePosition(deviceSession, content);

}
}

protected Object decodePosition(DeviceSession deviceSession, String content) throws Exception {

Parser parser = new Parser(PATTERN_POSITION, content);
if (!parser.matches()) {
return null;
}

Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());

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

var decoder = new StartekProtocolDecoder(null);

verifyAttribute(decoder, text(
"&&:23,860262050015424,129,OKA2"),
Position.KEY_RESULT, "129,OK");

verifyPosition(decoder, text(
"&&o125,861157040554384,000,0,,210702235150,A,27.263505,153.037061,11,1.2,0,0,31,5125,505|1|7032|8C89802,20,0000002D,00,00,01E2|019DF0"));

Expand Down

0 comments on commit 1d3cd09

Please sign in to comment.