use of org.traccar.model.Position in project traccar by tananaev.
the class ArknavProtocolDecoder 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.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class ArknavX8ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.charAt(2) != ',') {
getDeviceSession(channel, remoteAddress, sentence.substring(0, 15));
return null;
}
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_TYPE, parser.next());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.set(Position.KEY_STATUS, parser.next());
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class ArnaviProtocolDecoder 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_INDEX, parser.nextInt(0));
position.set(Position.KEY_POWER, parser.nextInt(0) * 0.01);
position.set(Position.KEY_BATTERY, parser.nextInt(0) * 0.01);
position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
position.set(Position.KEY_INPUT, parser.nextInt(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(true);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class AtrackProtocolDecoder method decodeString.
private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
Position position = new Position(getProtocolName());
getLastLocation(position, null);
DeviceSession deviceSession;
if (sentence.startsWith("$INFO")) {
Parser parser = new Parser(PATTERN_INFO, sentence);
if (!parser.matches()) {
return null;
}
deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
position.set("model", parser.next());
position.set(Position.KEY_VERSION_FW, parser.next());
position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1);
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
} else {
deviceSession = getDeviceSession(channel, remoteAddress);
position.set(Position.KEY_RESULT, sentence);
}
if (deviceSession == null) {
return null;
} else {
position.setDeviceId(deviceSession.getDeviceId());
return position;
}
}
use of org.traccar.model.Position in project traccar by tananaev.
the class AutoFonProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (!history) {
// interval
buf.readUnsignedByte();
// settings
buf.skipBytes(8);
}
position.set(Position.KEY_STATUS, buf.readUnsignedByte());
if (!history) {
buf.readUnsignedShort();
}
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
// time
buf.skipBytes(6);
if (!history) {
for (int i = 0; i < 2; i++) {
// time
buf.skipBytes(5);
// interval
buf.readUnsignedShort();
// mode
buf.skipBytes(5);
}
}
position.set(Position.PREFIX_TEMP + 1, buf.readByte());
int rssi = buf.readUnsignedByte();
CellTower cellTower = CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), rssi);
position.setNetwork(new Network(cellTower));
int valid = buf.readUnsignedByte();
position.setValid((valid & 0xc0) != 0);
position.set(Position.KEY_SATELLITES, valid & 0x3f);
DateBuilder dateBuilder = new DateBuilder().setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
position.setLatitude(convertCoordinate(buf.readInt()));
position.setLongitude(convertCoordinate(buf.readInt()));
position.setAltitude(buf.readShort());
position.setSpeed(buf.readUnsignedByte());
position.setCourse(buf.readUnsignedByte() * 2.0);
position.set(Position.KEY_HDOP, buf.readUnsignedShort());
// reserved
buf.readUnsignedShort();
// checksum
buf.readUnsignedByte();
return position;
}
Aggregations