diff options
-rw-r--r-- | checkstyle.xml | 4 | ||||
-rw-r--r-- | src/org/traccar/api/resource/MaintenanceResource.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gl200TextProtocolDecoder.java | 78 | ||||
-rw-r--r-- | src/org/traccar/protocol/SuntechProtocolDecoder.java | 8 | ||||
-rw-r--r-- | src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 64 | ||||
-rw-r--r-- | src/org/traccar/protocol/WialonProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Xrb28ProtocolDecoder.java | 13 | ||||
-rw-r--r-- | swagger.json | 8 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java | 12 | ||||
-rw-r--r-- | test/org/traccar/protocol/SuntechProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/WialonProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java | 12 |
13 files changed, 170 insertions, 42 deletions
diff --git a/checkstyle.xml b/checkstyle.xml index 9d0314b06..d85100471 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -67,7 +67,9 @@ <module name="LineLength"> <property name="max" value="120"/> </module> - <module name="MethodLength"/> + <module name="MethodLength"> + <property name="max" value="200"/> + </module> <module name="ParameterNumber"/> <!-- Checks for whitespace --> diff --git a/src/org/traccar/api/resource/MaintenanceResource.java b/src/org/traccar/api/resource/MaintenanceResource.java index b3726b429..fa1b359ce 100644 --- a/src/org/traccar/api/resource/MaintenanceResource.java +++ b/src/org/traccar/api/resource/MaintenanceResource.java @@ -24,7 +24,7 @@ import javax.ws.rs.core.MediaType; import org.traccar.api.ExtendedObjectResource; import org.traccar.model.Maintenance; -@Path("maintenances") +@Path("maintenance") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class MaintenanceResource extends ExtendedObjectResource<Maintenance> { diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java index 0d600e240..e004ce994 100644 --- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -581,6 +581,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { index += 1; // report type index += 1; // canbus state long reportMask = Long.parseLong(values[index++], 16); + long reportMaskExt = 0; if (BitUtil.check(reportMask, 0)) { position.set(Position.KEY_VIN, values[index++]); @@ -649,7 +650,79 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.set("engineOverspeed", Double.parseDouble(values[index - 1])); } if (BitUtil.check(reportMask, 29)) { - index += 1; // expansion + reportMaskExt = Long.parseLong(values[index++], 16); + } + if (BitUtil.check(reportMaskExt, 0) && !values[index++].isEmpty()) { + position.set("adBlueLevel", Integer.parseInt(values[index - 1])); + } + if (BitUtil.check(reportMaskExt, 1) && !values[index++].isEmpty()) { + position.set("axleWeight1", Integer.parseInt(values[index - 1])); + } + if (BitUtil.check(reportMaskExt, 2) && !values[index++].isEmpty()) { + position.set("axleWeight3", Integer.parseInt(values[index - 1])); + } + if (BitUtil.check(reportMaskExt, 3) && !values[index++].isEmpty()) { + position.set("axleWeight4", Integer.parseInt(values[index - 1])); + } + if (BitUtil.check(reportMaskExt, 4)) { + index += 1; // tachograph overspeed + } + if (BitUtil.check(reportMaskExt, 5)) { + index += 1; // tachograph motion + } + if (BitUtil.check(reportMaskExt, 6)) { + index += 1; // tachograph direction + } + if (BitUtil.check(reportMaskExt, 7) && !values[index++].isEmpty()) { + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[index - 1]) * 0.001); + } + if (BitUtil.check(reportMaskExt, 8)) { + index += 1; // pedal breaking factor + } + if (BitUtil.check(reportMaskExt, 9)) { + index += 1; // engine breaking factor + } + if (BitUtil.check(reportMaskExt, 10)) { + index += 1; // total accelerator kick-downs + } + if (BitUtil.check(reportMaskExt, 11)) { + index += 1; // total effective engine speed + } + if (BitUtil.check(reportMaskExt, 12)) { + index += 1; // total cruise control time + } + if (BitUtil.check(reportMaskExt, 13)) { + index += 1; // total accelerator kick-down time + } + if (BitUtil.check(reportMaskExt, 14)) { + index += 1; // total brake application + } + if (BitUtil.check(reportMaskExt, 15) && !values[index++].isEmpty()) { + position.set("driver1Card", values[index - 1]); + } + if (BitUtil.check(reportMaskExt, 16) && !values[index++].isEmpty()) { + position.set("driver2Card", values[index - 1]); + } + if (BitUtil.check(reportMaskExt, 17) && !values[index++].isEmpty()) { + position.set("driver1Name", values[index - 1]); + } + if (BitUtil.check(reportMaskExt, 18) && !values[index++].isEmpty()) { + position.set("driver2Name", values[index - 1]); + } + if (BitUtil.check(reportMaskExt, 19) && !values[index++].isEmpty()) { + position.set("registration", values[index - 1]); + } + if (BitUtil.check(reportMaskExt, 20)) { + index += 1; // expansion information + } + if (BitUtil.check(reportMaskExt, 21)) { + index += 1; // rapid brakings + } + if (BitUtil.check(reportMaskExt, 22)) { + index += 1; // rapid accelerations + } + if (BitUtil.check(reportMaskExt, 23)) { + index += 1; // engine torque } DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); @@ -674,10 +747,9 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(reportMask, 31)) { index += 4; // cell + index += 1; // reserved } - index += 1; // reserved - if (ignoreFixTime) { position.setTime(dateFormat.parse(values[index])); } else { diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 48eb3a71d..ad1da537b 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -317,9 +317,11 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { } if (includeAdc) { - position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++])); - position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++])); - position.set(Position.PREFIX_ADC + 3, Double.parseDouble(values[index++])); + for (int i = 1; i <= 3; i++) { + if (!values[index++].isEmpty()) { + position.set(Position.PREFIX_ADC + i, Double.parseDouble(values[index - 1])); + } + } } if (values.length - index >= 2) { diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 5c3af026c..f69059104 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -70,7 +70,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } public static final int CODEC_GH3000 = 0x07; - public static final int CODEC_FM4X00 = 0x08; + public static final int CODEC_8 = 0x08; + public static final int CODEC_8_EXT = 0x8E; public static final int CODEC_12 = 0x0C; public static final int CODEC_16 = 0x10; @@ -271,6 +272,21 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } + private int readExtByte(ByteBuf buf, int codec, int... codecs) { + boolean ext = false; + for (int c : codecs) { + if (codec == c) { + ext = true; + break; + } + } + if (ext) { + return buf.readUnsignedShort(); + } else { + return buf.readUnsignedByte(); + } + } + private void decodeLocation(Position position, ByteBuf buf, int codec) { int globalMask = 0x0f; @@ -354,62 +370,70 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); + position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16)); if (codec == CODEC_16) { - position.set(Position.KEY_EVENT, buf.readUnsignedShort()); buf.readUnsignedByte(); // generation type - } else { - position.set(Position.KEY_EVENT, buf.readUnsignedByte()); } - buf.readUnsignedByte(); // total IO data records + readExtByte(buf, codec, CODEC_8_EXT); // total IO data records } // Read 1 byte data if (BitUtil.check(globalMask, 1)) { - int cnt = buf.readUnsignedByte(); + int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { - int id = codec == CODEC_16 ? buf.readUnsignedShort() : buf.readUnsignedByte(); - decodeParameter(position, id, buf, 1, codec); + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec); } } // Read 2 byte data if (BitUtil.check(globalMask, 2)) { - int cnt = buf.readUnsignedByte(); + int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { - int id = codec == CODEC_16 ? buf.readUnsignedShort() : buf.readUnsignedByte(); - decodeParameter(position, id, buf, 2, codec); + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec); } } // Read 4 byte data if (BitUtil.check(globalMask, 3)) { - int cnt = buf.readUnsignedByte(); + int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { - int id = codec == CODEC_16 ? buf.readUnsignedShort() : buf.readUnsignedByte(); - decodeParameter(position, id, buf, 4, codec); + decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec); } } // Read 8 byte data - if (codec == CODEC_FM4X00 || codec == CODEC_16) { - int cnt = buf.readUnsignedByte(); + if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) { + int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { - int id = codec == CODEC_16 ? buf.readUnsignedShort() : buf.readUnsignedByte(); - decodeOtherParameter(position, id, buf, 8); + decodeOtherParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8); } } // Read 16 byte data if (extended) { - int cnt = buf.readUnsignedByte(); + int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { - int id = codec == CODEC_16 ? buf.readUnsignedShort() : buf.readUnsignedByte(); + int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16); position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16))); } } + // Read X byte data + if (codec == CODEC_8_EXT) { + int cnt = buf.readUnsignedShort(); + for (int j = 0; j < cnt; j++) { + int id = buf.readUnsignedShort(); + int length = buf.readUnsignedShort(); + if (id == 256) { + position.set(Position.KEY_VIN, buf.readSlice(length).toString(StandardCharsets.US_ASCII)); + } else { + position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length))); + } + } + } + decodeNetwork(position); } diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index 7939c7b67..de7073b67 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -47,7 +47,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]);") .number("(d+.?d*)?;") // speed .number("(d+.?d*)?;") // course - .number("(?:NA|(d+.?d*));") // altitude + .number("(?:NA|(-?d+.?d*));") // altitude .number("(?:NA|(d+))") // satellites .groupBegin().text(";") .number("(?:NA|(d+.?d*));") // hdop diff --git a/src/org/traccar/protocol/Xrb28ProtocolDecoder.java b/src/org/traccar/protocol/Xrb28ProtocolDecoder.java index c3af2c4f3..7c382900a 100644 --- a/src/org/traccar/protocol/Xrb28ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xrb28ProtocolDecoder.java @@ -42,7 +42,8 @@ public class Xrb28ProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .text("*HBCR,") + .text("*") + .expression("....,") .expression("..,") // vendor .number("d{15},") // imei .expression("..,") // type @@ -67,25 +68,25 @@ public class Xrb28ProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(10, 26)); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(8, 24)); if (deviceSession == null) { return null; } - String type = sentence.substring(27, 29); + String type = sentence.substring(25, 27); if (channel != null) { if (type.matches("L0|L1|W0|E1")) { channel.write(new NetworkMessage( - sentence.substring(0, 29) + "#\n", remoteAddress)); + sentence.substring(0, 27) + "#\n", remoteAddress)); } else if (type.equals("R0") && pendingCommand != null) { String command = pendingCommand.equals(Command.TYPE_ALARM_ARM) ? "L1," : "L0,"; channel.write(new NetworkMessage( - sentence.substring(0, 27) + command + sentence.substring(32) + "\n", remoteAddress)); + sentence.substring(0, 25) + command + sentence.substring(30) + "\n", remoteAddress)); pendingCommand = null; } } - Parser parser = new Parser(PATTERN, sentence.substring(2)); + Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } diff --git a/swagger.json b/swagger.json index 1c2d42e76..183330bdd 100644 --- a/swagger.json +++ b/swagger.json @@ -1351,10 +1351,10 @@ } } }, - "/maintenances": { + "/maintenance": { "get": { - "summary": "Fetch a list of Maintenances", - "description": "Without params, it returns a list of Maintenances the user has access to", + "summary": "Fetch a list of Maintenance", + "description": "Without params, it returns a list of Maintenance the user has access to", "parameters": [ { "$ref": "#/parameters/all" @@ -1401,7 +1401,7 @@ } } }, - "/maintenances/{id}": { + "/maintenance/{id}": { "put": { "summary": "Update a Maintenance", "parameters": [ diff --git a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index cc5ef63d4..abca940b5 100644 --- a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -11,6 +11,18 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { Gl200TextProtocolDecoder decoder = new Gl200TextProtocolDecoder(null); verifyPositions(decoder, buffer( + "+RESP:GTERI,310701,863286023712855,,00000004,28378,10,1,1,0.0,294,358.4,14.271475,50.110771,20181111185001,0230,0003,94D4,3B30,00,14.5,,,,110000,2,0,C03FFFFF,,0,H46400,12310.70,0,0,83,,,,0,,0.53,3.43,,,,40,,0,,,20181111185252,2DFF")); + + verifyAttributes(decoder, buffer( + "+RESP:GTCAN,310701,863286023712855,,10,0,003FFFFF,,2,H46358,12305.50,601,0,83,,P53.00,,0,2749.15,0.19,2.80,,,,40,,0,,,20181110103016,2945$")); + + verifyAttributes(decoder, buffer( + "+RESP:GTCAN,310701,863286023712855,,10,0,203FFFFF,,2,H46358,12305.50,601,0,83,,P53.00,,0,2749.15,0.19,2.80,,,,40,,0,,,007FFFFF,,,,,,0,,,134,37,6,0.19,,0.00,0,,,,,,0,0,0,20181110112126,299F$")); + + verifyPosition(decoder, buffer( + "+RESP:GTCAN,310701,863286023712855,,10,0,E03FFFFF,,2,H46358,12305.50,601,0,83,,P53.00,,0,2749.15,0.19,2.80,,,,40,,0,,,007FFFFF,,,,,,0,,,134,37,6,0.19,,0.00,0,,,,,,0,0,0,0,0.0,312,358.4,14.271460,50.110796,20181110103130,0230,0003,94D4,3B30,00,20181110105348,2969$")); + + verifyPositions(decoder, buffer( "+RESP:GTFRI,1F0301,862193022001432,WF0GXXGBBGBM26503,,14900,41,1,1,11.6,74,356.0,14.120023,50.167894,20181104080703,0230,0003,9B14,5891,00,74.1,,,,83,220000,799,7.3,,20181104080703,099B$")); verifyPosition(decoder, buffer( diff --git a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java index 7e4de91d6..daf011206 100644 --- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java @@ -20,6 +20,9 @@ public class SuntechProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "ST300EVT;205173382;07;564;20160322;23:23:18;232e19;+19.288278;-099.128750;000.122;000.00;9;1;478391;11.53;000100;2;1;9498;079324;4.3;1;0.00;0.00;0.00;00000000000000;0;2898E16006000058:-20.8;2861626006000039:+2.5;:")); + verifyPosition(decoder, text( + "ST600STT;008349958;35;523;20181112;00:49:30;0bf10d4e;334;20;2f19;22;+20.552718;-100.824478;050.021;095.41;12;1;1303603;14.30;10000000;4;8911;001987;4.1;0;0.00;;;;00000000000000;0;2826C8A70800000C:+26.6;:;:")); + } @Test diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java index 802cae877..6450a8591 100644 --- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -15,6 +15,9 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest { "000F313233343536373839303132333435")); verifyPositions(decoder, false, binary( + "00000000000000818e0100000166e368a510000f0d8b5b20961c35008d010308000000000014000900ef0000f00100500100150400c800004501001e00002500002900000a00b5000800b60007004230dc0018000000430fcb0044005f001103de001200e50013001200240000000000000001010000113141314a433534343452373235323336370100005e99")); + + verifyPositions(decoder, false, binary( "000000000000009D10020000013feb55ff74000f0ea850209a690000AE00B90B00000000070A050001000002000003000004000120000200180000004601290200C700000000004C0000000001003E00000000000000000000015B198C7498000F0DBC502095872F00AE00B90B00000000070A050001000002000003000004000120000200180000004601290200C700000000004C0000000001003E000000000000000002000009A5")); verifyPositions(decoder, false, binary( diff --git a/test/org/traccar/protocol/WialonProtocolDecoderTest.java b/test/org/traccar/protocol/WialonProtocolDecoderTest.java index b7d2149dd..40b0469ea 100644 --- a/test/org/traccar/protocol/WialonProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WialonProtocolDecoderTest.java @@ -23,6 +23,9 @@ public class WialonProtocolDecoderTest extends ProtocolTest { "#P#")); verifyPosition(decoder, text( + "#D#101118;061143;0756.0930;N;12338.6403;E;18.223;99.766;-4.000;10;0.800;NA;NA;NA;NA;101_521347:1:521249,101_521126:1:6593598,101_521127:1:774780,101_521072_21.1:1:0,101_521072_21.2:1:71353;F24A")); + + verifyPosition(decoder, text( "#D#151216;135910;5321.1466;N;04441.7929;E;87;156;265.000000;12;1.000000;241;NA;NA;NA;odo:2:0.000000,total_fuel:1:430087,can_fls:1:201,can_taho:1:11623,can_mileage:1:140367515")); verifyPosition(decoder, text( diff --git a/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java b/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java index 441d7b811..eaa28906e 100644 --- a/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java @@ -11,13 +11,19 @@ public class Xrb28ProtocolDecoderTest extends ProtocolTest { Xrb28ProtocolDecoder decoder = new Xrb28ProtocolDecoder(null); verifyNull(decoder, text( - "\u00ff\u00ff*HBCR,OM,123456789123456,Q0,412,80#")); + "*SCOR,OM,863158022988725,H0,0,412,28,80,0#")); verifyNull(decoder, text( - "\u00ff\u00ff*HBCR,OM,123456789123456,R0,0,55,1234,1497689816#")); + "*HBCR,OM,123456789123456,Q0,412,80#")); + + verifyNull(decoder, text( + "*HBCR,OM,123456789123456,R0,0,55,1234,1497689816#")); + + verifyPosition(decoder, text( + "*HBCR,OM,123456789123456,D0,0,124458.00,A,2237.7514,N,11408.6214,E,6,0.21,151216,10,M,A#")); verifyPosition(decoder, text( - "\u00ff\u00ff*HBCR,OM,123456789123456,D0,0,124458.00,A,2237.7514,N,11408.6214,E,6,0.21,151216,10,M,A#")); + "*SCOR,OM,863158022988725,D0,0,124458.00,A,2237.7514,N,11408.6214,E,6,0.21,151216,10,M,A#")); } |