aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java111
1 files changed, 86 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java b/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java
index 6a81a452a..1178b9b83 100644
--- a/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java
@@ -19,21 +19,45 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.UnitsConverter;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Position;
import org.traccar.session.DeviceSession;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
public class T622IridiumProtocolDecoder extends BaseProtocolDecoder {
+ private String format;
+
public T622IridiumProtocolDecoder(Protocol protocol) {
super(protocol);
}
@Override
+ protected void init() {
+ super.init();
+ }
+
+ public List<Integer> getParameters(long deviceId) {
+ String value = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_FORMAT.withPrefix(getProtocolName()), deviceId);
+ return Arrays.stream((value != null ? value : format).split(","))
+ .map(s -> Integer.parseInt(s, 16))
+ .collect(Collectors.toList());
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ @Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -61,31 +85,68 @@ public class T622IridiumProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
-
- position.setLatitude(buf.readIntLE() / 1000000.0);
- position.setLongitude(buf.readIntLE() / 1000000.0);
- position.setTime(new Date((buf.readUnsignedIntLE() + 946713600) * 1000));
- position.setValid(buf.readUnsignedByte() > 0);
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
- position.setCourse(buf.readUnsignedShortLE());
-
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
-
- position.setAltitude(buf.readShortLE());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
- position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000);
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
- position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
-
- buf.readUnsignedByte(); // geofence
+ List<Integer> parameters = getParameters(deviceSession.getDeviceId());
+
+ for (int parameter : parameters) {
+ switch (parameter) {
+ case 0x01:
+ position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+ break;
+ case 0x02:
+ position.setLatitude(buf.readIntLE() / 1000000.0);
+ break;
+ case 0x03:
+ position.setLongitude(buf.readIntLE() / 1000000.0);
+ break;
+ case 0x04:
+ position.setTime(new Date((buf.readUnsignedIntLE() + 946713600) * 1000));
+ break;
+ case 0x05:
+ position.setValid(buf.readUnsignedByte() > 0);
+ break;
+ case 0x06:
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ break;
+ case 0x07:
+ position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ break;
+ case 0x08:
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
+ break;
+ case 0x09:
+ position.setCourse(buf.readUnsignedShortLE());
+ break;
+ case 0x0A:
+ position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
+ break;
+ case 0x0B:
+ position.setAltitude(buf.readShortLE());
+ break;
+ case 0x0C:
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ break;
+ case 0x0D:
+ position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000);
+ break;
+ case 0x14:
+ position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
+ break;
+ case 0x15:
+ position.set(Position.KEY_INPUT, buf.readUnsignedByte());
+ break;
+ case 0x19:
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
+ break;
+ case 0x1A:
+ position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
+ break;
+ case 0x1B:
+ buf.readUnsignedByte(); // geofence
+ break;
+ default:
+ break;
+ }
+ }
return position;
}