diff options
Diffstat (limited to 'src/main')
6 files changed, 102 insertions, 27 deletions
diff --git a/src/main/java/org/traccar/api/resource/EventResource.java b/src/main/java/org/traccar/api/resource/EventResource.java index e0ccf7020..34e4a94ce 100644 --- a/src/main/java/org/traccar/api/resource/EventResource.java +++ b/src/main/java/org/traccar/api/resource/EventResource.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 - 2021 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.api.resource; import java.sql.SQLException; @@ -7,7 +22,9 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.traccar.Context; import org.traccar.api.BaseResource; @@ -25,6 +42,9 @@ public class EventResource extends BaseResource { @GET public Event get(@PathParam("id") long id) throws SQLException { Event event = Context.getDataManager().getObject(Event.class, id); + if (event == null) { + throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); + } Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId()); if (event.getGeofenceId() != 0) { Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId()); diff --git a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java index cb3094e16..2535970d3 100644 --- a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java +++ b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java @@ -49,7 +49,15 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider { json.getJsonNumber("lat").doubleValue(), json.getJsonNumber("lon").doubleValue(), 0); } else { - callback.onFailure(new GeolocationException("Coordinates are missing")); + if (json.containsKey("error")) { + String errorMessage = json.getString("error"); + if (json.containsKey("code")) { + errorMessage += " (" + json.getInt("code") + ")"; + } + callback.onFailure(new GeolocationException(errorMessage)); + } else { + callback.onFailure(new GeolocationException("Coordinates are missing")); + } } } diff --git a/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java b/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java index ebf9a006c..cffc1f3eb 100644 --- a/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java @@ -159,11 +159,17 @@ public class DmtHttpProtocolDecoder extends BaseHttpProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - position.setValid(true); - position.setTime(new Date(OffsetDateTime.parse(root.getString("date")).toInstant().toEpochMilli())); - position.setLatitude(root.getJsonNumber("lat").doubleValue()); - position.setLongitude(root.getJsonNumber("lng").doubleValue()); - position.setAccuracy(root.getJsonNumber("posAcc").doubleValue()); + Date time = new Date(OffsetDateTime.parse(root.getString("date")).toInstant().toEpochMilli()); + + if (root.containsKey("lat") && root.containsKey("lng")) { + position.setValid(true); + position.setTime(time); + position.setLatitude(root.getJsonNumber("lat").doubleValue()); + position.setLongitude(root.getJsonNumber("lng").doubleValue()); + position.setAccuracy(root.getJsonNumber("posAcc").doubleValue()); + } else { + getLastLocation(position, time); + } position.set(Position.KEY_INDEX, root.getInt("sqn")); position.set(Position.KEY_EVENT, root.getInt("reason")); diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index b313802b3..4c71d3724 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -1141,9 +1141,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_GPS_MODULAR) { - sendResponse(channel, true, type, buf.getShort(buf.writerIndex() - 6), null); - - return decodeExtendedModular(buf, deviceSession); + return decodeExtendedModular(channel, buf, deviceSession); } else { @@ -1154,7 +1152,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return null; } - private Object decodeExtendedModular(ByteBuf buf, DeviceSession deviceSession) { + private Object decodeExtendedModular(Channel channel, ByteBuf buf, DeviceSession deviceSession) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -1255,6 +1253,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } + if (position.getFixTime() == null) { + getLastLocation(position, null); + } + + sendResponse(channel, false, MSG_GPS_MODULAR, buf.readUnsignedShort(), null); + return position; } diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java index bee21982e..0e829e7f7 100644 --- a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java @@ -461,9 +461,11 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_TYPE, type); - int mask = Integer.parseInt(values[index++], 16); + int mask; if (type.equals("BLE")) { mask = 0b1100000110110; + } else { + mask = Integer.parseInt(values[index++], 16); } if (BitUtil.check(mask, 1)) { @@ -518,7 +520,6 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); int count = Integer.parseInt(values[index++]); - index += 1; for (int i = 1; i <= count; i++) { position.set("tag" + i + "Rssi", Integer.parseInt(values[index++])); diff --git a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java index 4f6854098..b8477dcb6 100644 --- a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.Protocol; +import org.traccar.helper.BcdUtil; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; @@ -256,9 +257,28 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { int blockLength = buf.readUnsignedShort(); int blockEnd = buf.readerIndex() + blockLength; - if (blockLength > 0 && (hardware == 0x10A || hardware == 0x10B || hardware == 0x406)) { - position.setNetwork(new Network( - CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); + if (blockLength > 0) { + if (hardware == 0x10A || hardware == 0x10B || hardware == 0x406) { + + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); + + } else if (hardware == 0x407) { + + Network network = new Network(); + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + buf.readUnsignedByte(); // signal information + + int mcc = BcdUtil.readInteger(buf, 4); + int mnc = BcdUtil.readInteger(buf, 4) % 1000; + + network.addCellTower(CellTower.from( + mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedInt())); + } + position.setNetwork(network); + + } } buf.readerIndex(blockEnd); @@ -268,25 +288,41 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { blockLength = buf.readUnsignedShort(); blockEnd = buf.readerIndex() + blockLength; - if (blockLength >= 13) { + if (hardware == 0x407 || blockLength >= 13) { position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); position.set("terminalInfo", buf.readUnsignedByte()); - int status = buf.readUnsignedByte(); - position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 0)); - position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 1)); - status = buf.readUnsignedByte(); - position.set(Position.PREFIX_IN + 1, BitUtil.check(status, 4)); - if (BitUtil.check(status, 0)) { - position.set(Position.KEY_ALARM, Position.ALARM_SOS); + if (hardware != 0x407) { + int status = buf.readUnsignedByte(); + position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 0)); + position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 1)); + status = buf.readUnsignedByte(); + position.set(Position.PREFIX_IN + 1, BitUtil.check(status, 4)); + if (BitUtil.check(status, 0)) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } } position.set(Position.KEY_RSSI, buf.readUnsignedByte()); position.set("gsmStatus", buf.readUnsignedByte()); position.set(Position.KEY_BATTERY, buf.readUnsignedShort()); - position.set(Position.KEY_POWER, buf.readUnsignedShort()); - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); - position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort()); + + if (hardware != 0x407) { + position.set(Position.KEY_POWER, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort()); + } else { + int temperature = buf.readUnsignedShort(); + if (!BitUtil.check(temperature, 15)) { + double value = BitUtil.to(temperature, 14) * 0.01; + position.set(Position.PREFIX_TEMP + 1, BitUtil.check(temperature, 14) ? -value : value); + } + int humidity = buf.readUnsignedShort(); + if (!BitUtil.check(humidity, 15)) { + position.set("humidity", BitUtil.to(humidity, 15)); + } + position.set("lightSensor", buf.readUnsignedByte() == 0); + } } if (blockLength >= 15) { |