use of org.traccar.model.Position in project traccar by tananaev.
the class CalAmpProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, int type, ChannelBuffer buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
if (type != MSG_MINI_EVENT_REPORT) {
// fix time
buf.readUnsignedInt();
}
position.setLatitude(buf.readInt() * 0.0000001);
position.setLongitude(buf.readInt() * 0.0000001);
if (type != MSG_MINI_EVENT_REPORT) {
position.setAltitude(buf.readInt() * 0.01);
position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedInt()));
}
position.setCourse(buf.readShort());
if (type == MSG_MINI_EVENT_REPORT) {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
}
if (type == MSG_MINI_EVENT_REPORT) {
position.set(Position.KEY_SATELLITES, buf.getUnsignedByte(buf.readerIndex()) & 0xf);
position.setValid((buf.readUnsignedByte() & 0x20) == 0);
} else {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setValid((buf.readUnsignedByte() & 0x08) == 0);
}
if (type != MSG_MINI_EVENT_REPORT) {
position.set("carrier", buf.readUnsignedShort());
position.set(Position.KEY_RSSI, buf.readShort());
}
position.set("modem", buf.readUnsignedByte());
if (type != MSG_MINI_EVENT_REPORT) {
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
}
int input = buf.readUnsignedByte();
position.set(Position.KEY_INPUT, input);
position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
if (type != MSG_MINI_EVENT_REPORT) {
position.set(Position.KEY_STATUS, buf.readUnsignedByte());
}
if (type == MSG_EVENT_REPORT || type == MSG_MINI_EVENT_REPORT) {
if (type != MSG_MINI_EVENT_REPORT) {
// event index
buf.readUnsignedByte();
}
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
}
int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6);
int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
if (type != MSG_MINI_EVENT_REPORT) {
position.set("append", buf.readUnsignedByte());
}
if (accType == 1) {
// threshold
buf.readUnsignedInt();
// mask
buf.readUnsignedInt();
}
for (int i = 0; i < accCount; i++) {
if (buf.readableBytes() >= 4) {
position.set("acc" + i, buf.readUnsignedInt());
}
}
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class CarTrackProtocolDecoder 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());
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.PREFIX_IO + 1, parser.next());
String odometer = parser.next();
odometer = odometer.replace(":", "A");
odometer = odometer.replace(";", "B");
odometer = odometer.replace("<", "C");
odometer = odometer.replace("=", "D");
odometer = odometer.replace(">", "E");
odometer = odometer.replace("?", "F");
position.set(Position.KEY_ODOMETER, Integer.parseInt(odometer, 16));
// there is no meaningful alarms
parser.next();
position.set(Position.PREFIX_ADC + 1, parser.next());
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class CarcellProtocolDecoder 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());
position.set(Position.KEY_ARCHIVE, parser.next().equals("%"));
position.setValid(true);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext(8)) {
position.setLatitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG_MIN_MIN));
position.setLongitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG_MIN_MIN));
}
if (parser.hasNext(4)) {
position.setLatitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG));
position.setLongitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG));
}
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.setCourse(parser.nextInt(0));
if (parser.hasNext(3)) {
position.set("x", parser.nextInt(0));
position.set("y", parser.nextInt(0));
position.set("z", parser.nextInt(0));
}
if (parser.hasNext(1)) {
position.set(Position.KEY_ACCELERATION, parser.nextInt(0));
}
Double internalBattery = (parser.nextDouble(0) + 100d) * 0.0294d;
position.set(Position.KEY_BATTERY, internalBattery);
position.set(Position.KEY_RSSI, parser.nextInt(0));
position.set("jamming", parser.next().equals("1"));
position.set(Position.KEY_GPS, parser.nextInt(0));
position.set("clockType", parser.next());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.set("blocked", parser.next().equals("1"));
position.set(Position.KEY_IGNITION, parser.next().equals("1"));
if (parser.hasNext(4)) {
position.set("cloned", parser.next().equals("1"));
// panic button status
parser.next();
String painelStatus = parser.next();
if (painelStatus.equals("1")) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
position.set("painel", painelStatus.equals("2"));
Double mainVoltage = parser.nextDouble(0) / 100d;
position.set(Position.KEY_POWER, mainVoltage);
}
if (parser.hasNext(5)) {
position.set("timeUntilDelivery", parser.nextInt(0));
// panic button status
parser.next();
position.set(Position.KEY_INPUT, parser.next());
Double mainVoltage = parser.nextDouble(0) / 100d;
position.set(Position.KEY_POWER, mainVoltage);
position.set("iccid", parser.next());
}
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class CguardProtocolDecoder method decodeStatus.
private Position decodeStatus(DeviceSession deviceSession, String sentence) {
Parser parser = new Parser(PATTERN_BC, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime());
String[] data = parser.next().split(":");
for (int i = 0; i < data.length / 2; i++) {
String key = data[i * 2];
String value = data[i * 2 + 1];
switch(key) {
case "CSQ1":
position.set(Position.KEY_RSSI, Integer.parseInt(value));
break;
case "NSQ1":
position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
break;
case "BAT1":
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value));
break;
case "PWR1":
position.set(Position.KEY_POWER, Double.parseDouble(value));
break;
default:
position.set(key.toLowerCase(), value);
break;
}
}
return position;
}
use of org.traccar.model.Position in project traccar by tananaev.
the class CastelProtocolDecoder method readPosition.
private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
double lat = buf.readUnsignedInt() / 3600000.0;
double lon = buf.readUnsignedInt() / 3600000.0;
position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort() * 0.1);
int flags = buf.readUnsignedByte();
if ((flags & 0x02) == 0) {
lat = -lat;
}
if ((flags & 0x01) == 0) {
lon = -lon;
}
position.setLatitude(lat);
position.setLongitude(lon);
position.setValid((flags & 0x0C) > 0);
position.set(Position.KEY_SATELLITES, flags >> 4);
return position;
}
Aggregations