use of org.traccar.model.Position in project traccar by tananaev.
the class CastelProtocolDecoder method createPosition.
private Position createPosition(DeviceSession deviceSession) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class DishaProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Parser parser = new Parser(PATTERN, (String) msg);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(parser.next().equals("A"));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_HDOP, parser.nextDouble());
position.set(Position.KEY_RSSI, parser.nextDouble());
position.set(Position.KEY_CHARGE, parser.nextInt(0) == 2);
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
position.set(Position.PREFIX_ADC + 2, parser.nextInt(0));
position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
position.set(Position.KEY_INPUT, parser.next());
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class DmtProtocolDecoder method decodeStandard.
private List<Position> decodeStandard(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
List<Position> positions = new LinkedList<>();
while (buf.readable()) {
int recordEnd = buf.readerIndex() + buf.readUnsignedShort();
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, buf.readUnsignedInt());
// since 1 Jan 2013
position.setDeviceTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000));
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
while (buf.readerIndex() < recordEnd) {
int fieldId = buf.readUnsignedByte();
int fieldLength = buf.readUnsignedByte();
int fieldEnd = buf.readerIndex() + (fieldLength == 255 ? buf.readUnsignedShort() : fieldLength);
if (fieldId == 0) {
position.setFixTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000));
position.setLatitude(buf.readInt() * 0.0000001);
position.setLongitude(buf.readInt() * 0.0000001);
position.setAltitude(buf.readShort());
position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
// speed accuracy
buf.readUnsignedByte();
position.setCourse(buf.readUnsignedByte() * 2);
position.set(Position.KEY_PDOP, buf.readUnsignedByte() * 0.1);
position.setAccuracy(buf.readUnsignedByte());
position.setValid(buf.readUnsignedByte() != 0);
} else if (fieldId == 2) {
int input = buf.readInt();
int output = buf.readUnsignedShort();
int status = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
position.set(Position.KEY_INPUT, input);
position.set(Position.KEY_OUTPUT, output);
position.set(Position.KEY_STATUS, status);
} else if (fieldId == 6) {
while (buf.readerIndex() < fieldEnd) {
switch(buf.readUnsignedByte()) {
case 1:
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
break;
case 2:
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
break;
case 3:
position.set(Position.KEY_DEVICE_TEMP, buf.readShort() * 0.01);
break;
case 4:
position.set(Position.KEY_RSSI, buf.readUnsignedShort());
break;
case 5:
position.set("solarPower", buf.readUnsignedShort() * 0.001);
break;
default:
break;
}
}
}
buf.readerIndex(fieldEnd);
}
if (position.getFixTime() == null) {
getLastLocation(position, position.getDeviceTime());
}
positions.add(position);
}
return positions;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class EasyTrackProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Parser parser = new Parser(PATTERN, (String) msg);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_COMMAND, parser.next());
position.setValid(parser.next().equals("A"));
DateBuilder dateBuilder = new DateBuilder().setDate(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0)).setTime(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0));
position.setTime(dateBuilder.getDate());
if (BitUtil.check(parser.nextHexInt(0), 3)) {
position.setLatitude(-parser.nextHexInt(0) / 600000.0);
} else {
position.setLatitude(parser.nextHexInt(0) / 600000.0);
}
if (BitUtil.check(parser.nextHexInt(0), 3)) {
position.setLongitude(-parser.nextHexInt(0) / 600000.0);
} else {
position.setLongitude(parser.nextHexInt(0) / 600000.0);
}
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextHexInt(0) / 100.0));
position.setCourse(parser.nextHexInt(0) / 100.0);
position.set(Position.KEY_STATUS, parser.next());
position.set("signal", parser.next());
position.set(Position.KEY_POWER, parser.nextDouble(0));
position.set("oil", parser.nextHexInt(0));
position.set(Position.KEY_ODOMETER, parser.nextHexInt(0) * 100);
position.setAltitude(parser.nextDouble(0));
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class EelinkProtocolDecoder method decodeResult.
private Position decodeResult(DeviceSession deviceSession, ChannelBuffer buf, int index) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
// type
buf.readUnsignedByte();
// uid
buf.readUnsignedInt();
String sentence = buf.toString(StandardCharsets.UTF_8);
Parser parser = new Parser(PATTERN, sentence);
if (parser.matches()) {
position.setValid(true);
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setCourse(parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.setTime(parser.nextDateTime());
} else {
getLastLocation(position, null);
position.set(Position.KEY_RESULT, sentence);
}
return position;
}
Aggregations