use of org.traccar.model.Position in project traccar by traccar.
the class MegastekProtocolDecoder method decodeNew.
private Position decodeNew(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_NEW, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.next().equals("S")) {
position.set(Position.KEY_ARCHIVE, true);
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
}
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
position.set(Position.KEY_INPUT, parser.nextBinInt(0));
position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
for (int i = 1; i <= 3; i++) {
position.set(Position.PREFIX_ADC + i, parser.nextInt(0));
}
for (int i = 1; i <= 2; i++) {
String adc = parser.next();
if (adc != null) {
position.set(Position.PREFIX_TEMP + i, Double.parseDouble(adc));
}
}
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
String battery = parser.next();
if (battery != null) {
position.set(Position.KEY_BATTERY, Integer.parseInt(battery));
}
position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
return position;
}
use of org.traccar.model.Position in project traccar by traccar.
the class RecodaProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
int type = buf.readInt();
// length
buf.readUnsignedInt();
if (type != MSG_HEARTBEAT) {
// version
buf.readUnsignedShort();
// index
buf.readUnsignedShort();
}
if (type == MSG_SIGNAL_LINK_REGISTRATION) {
getDeviceSession(channel, remoteAddress, buf.readBytes(12).toString(StandardCharsets.US_ASCII));
} else if (type == MSG_GPS_DATA) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readLong()));
int flags = buf.readUnsignedByte();
if (BitUtil.check(flags, 0)) {
// declination
buf.readUnsignedShort();
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setLongitude(buf.readUnsignedByte() + buf.readUnsignedByte() / 60.0);
position.setLatitude(buf.readUnsignedByte() + buf.readUnsignedByte() / 60.0);
position.setLongitude(position.getLongitude() + buf.readUnsignedInt() / 3600.0);
position.setLatitude(position.getLatitude() + buf.readUnsignedInt() / 3600.0);
int status = buf.readUnsignedByte();
position.setValid(BitUtil.check(status, 0));
if (BitUtil.check(status, 1)) {
position.setLongitude(-position.getLongitude());
}
if (!BitUtil.check(status, 2)) {
position.setLatitude(-position.getLatitude());
}
} else {
getLastLocation(position, position.getDeviceTime());
}
return position;
}
return null;
}
use of org.traccar.model.Position in project traccar by traccar.
the class RitiProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(2);
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set("mode", buf.readUnsignedByte());
position.set(Position.KEY_COMMAND, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
// status
buf.skipBytes(5);
// idleCount
buf.readUnsignedShort();
// idleTime in seconds
buf.readUnsignedShort();
position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
// Parse GPRMC
int end = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
String gprmc = buf.toString(buf.readerIndex(), end - buf.readerIndex(), StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, gprmc);
if (!parser.matches()) {
return null;
}
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
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 traccar.
the class SanavProtocolDecoder 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());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
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 traccar.
the class Pt502ProtocolDecoder 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());
String type = parser.next();
if (type.startsWith("PHO") && channel != null) {
photo = new byte[Integer.parseInt(type.substring(3))];
channel.write("#PHD0," + Math.min(photo.length, MAX_CHUNK_SIZE) + "\r\n");
}
position.set(Position.KEY_ALARM, decodeAlarm(type));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
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());
position.set(Position.KEY_INPUT, parser.next());
position.set(Position.KEY_OUTPUT, parser.next());
if (parser.hasNext()) {
String[] values = parser.next().split(",");
for (int i = 0; i < values.length; i++) {
position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(values[i], 16));
}
}
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
if (parser.hasNext()) {
int value = parser.nextHexInt(0);
position.set(Position.KEY_BATTERY, value >> 8);
position.set(Position.KEY_RSSI, (value >> 4) & 0xf);
position.set(Position.KEY_SATELLITES, value & 0xf);
}
return position;
}
Aggregations